Skip to content

Instantly share code, notes, and snippets.

@benjic
Created September 30, 2014 18:43
Show Gist options
  • Save benjic/9992dc740375f0207cb5 to your computer and use it in GitHub Desktop.
Save benjic/9992dc740375f0207cb5 to your computer and use it in GitHub Desktop.
.section __TEXT,__text,regular,pure_instructions
.globl _sum
.align 4, 0x90
_sum: ## @sum
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
subq $16, %rsp
movl %edi, -8(%rbp)
cmpl $0, -8(%rbp)
jle LBB0_2
## BB#1:
movl -8(%rbp), %eax
movl -8(%rbp), %ecx
subl $1, %ecx
movl %ecx, %edi
movl %eax, -12(%rbp) ## 4-byte Spill
callq _sum
movl -12(%rbp), %ecx ## 4-byte Reload
addl %eax, %ecx
movl %ecx, -4(%rbp)
jmp LBB0_3
LBB0_2:
movl $0, -4(%rbp)
LBB0_3:
movl -4(%rbp), %eax
addq $16, %rsp
popq %rbp
ret
.cfi_endproc
.globl _main
.align 4, 0x90
_main: ## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp7:
.cfi_def_cfa_offset 16
Ltmp8:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp9:
.cfi_def_cfa_register %rbp
subq $32, %rsp
movl %edi, -4(%rbp)
movq %rsi, -16(%rbp)
movq -16(%rbp), %rsi
movq 8(%rsi), %rdi
callq _atoi
movl %eax, %edi
callq _sum
leaq L_.str(%rip), %rdi
movl %eax, %esi
movb $0, %al
callq _printf
movl $0, %esi
movl %eax, -20(%rbp) ## 4-byte Spill
movl %esi, %eax
addq $32, %rsp
popq %rbp
ret
.cfi_endproc
.section __TEXT,__cstring,cstring_literals
L_.str: ## @.str
.asciz "Your sum is %d.\n"
.subsections_via_symbols
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment