Skip to content

Instantly share code, notes, and snippets.

@pixie-grasper
Created December 23, 2015 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixie-grasper/ba2d0ade523b8599c182 to your computer and use it in GitHub Desktop.
Save pixie-grasper/ba2d0ade523b8599c182 to your computer and use it in GitHub Desktop.
.text
.file "fib.cc"
.globl _Z3fibi
.align 16, 0x90
.type _Z3fibi,@function
_Z3fibi: # @_Z3fibi
.cfi_startproc
# BB#0:
pushq %rbp
.Ltmp0:
.cfi_def_cfa_offset 16
pushq %rbx
.Ltmp1:
.cfi_def_cfa_offset 24
pushq %rax
.Ltmp2:
.cfi_def_cfa_offset 32
.Ltmp3:
.cfi_offset %rbx, -24
.Ltmp4:
.cfi_offset %rbp, -16
movl %edi, %ebx
cmpl $2, %ebx
jge .LBB0_1
# BB#2:
movl %ebx, %eax
jmp .LBB0_3
.LBB0_1:
leal -1(%rbx), %edi
callq _Z3fibi
movl %eax, %ebp
addl $-2, %ebx
movl %ebx, %edi
callq _Z3fibi
addl %ebp, %eax
.LBB0_3:
addq $8, %rsp
popq %rbx
popq %rbp
retq
.Ltmp5:
.size _Z3fibi, .Ltmp5-_Z3fibi
.cfi_endproc
.globl main
.align 16, 0x90
.type main,@function
main: # @main
.cfi_startproc
# BB#0:
pushq %rax
.Ltmp6:
.cfi_def_cfa_offset 16
movl $10, %edi
callq _Z3fibi
movl %eax, %ecx
movl $.L.str, %edi
xorl %eax, %eax
movl %ecx, %esi
callq printf
xorl %eax, %eax
popq %rdx
retq
.Ltmp7:
.size main, .Ltmp7-main
.cfi_endproc
.type .L.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "%d\n"
.size .L.str, 4
.ident "clang version 3.6.1 (tags/RELEASE_361/final 238189)"
.section ".note.GNU-stack","",@progbits
#include <stdio.h>
int fib(int n) {
if (n < 2) {
return n;
} else {
return fib(n - 1) + fib(n - 2);
}
}
int main() {
printf("%d\n", fib(10));
return 0;
}
.file "fib.cc"
.text
.p2align 4,,15
.globl _Z3fibi
.type _Z3fibi, @function
_Z3fibi:
.LFB12:
.cfi_startproc
pushq %r12
.cfi_def_cfa_offset 16
.cfi_offset 12, -16
cmpl $1, %edi
movl %edi, %r12d
pushq %rbp
.cfi_def_cfa_offset 24
.cfi_offset 6, -24
pushq %rbx
.cfi_def_cfa_offset 32
.cfi_offset 3, -32
jle .L5
movl %edi, %ebx
xorl %ebp, %ebp
.p2align 4,,10
.p2align 3
.L4:
leal -1(%rbx), %edi
subl $2, %ebx
call _Z3fibi
addl %eax, %ebp
cmpl $1, %ebx
jg .L4
andl $1, %r12d
.L2:
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 24
leal (%r12,%rbp), %eax
popq %rbp
.cfi_def_cfa_offset 16
popq %r12
.cfi_def_cfa_offset 8
ret
.L5:
.cfi_restore_state
xorl %ebp, %ebp
jmp .L2
.cfi_endproc
.LFE12:
.size _Z3fibi, .-_Z3fibi
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB13:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $10, %edi
call _Z3fibi
movl $.LC0, %edi
movl %eax, %esi
xorl %eax, %eax
call printf
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE13:
.size main, .-main
.ident "GCC: (GNU) 4.8.4"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment