Skip to content

Instantly share code, notes, and snippets.

@volodymyrsmirnov
Last active August 29, 2015 13:57
Show Gist options
  • Save volodymyrsmirnov/9784586 to your computer and use it in GitHub Desktop.
Save volodymyrsmirnov/9784586 to your computer and use it in GitHub Desktop.
~ smirnov$ echo "int main(){}; int sum(x, y){int result; result=x+y; return result;}" | clang -O3 -o test.o -xc - && otool -vt test.o -p _sum
test.o:
(__TEXT,__text) section
_sum:
0000000100000f90 pushq %rbp
0000000100000f91 movq %rsp, %rbp
0000000100000f94 addl %esi, %edi
0000000100000f96 movl %edi, %eax
0000000100000f98 popq %rbp
0000000100000f99 ret
~ smirnov$ echo "int main(){}; int sum(x, y){return x+y;}" | clang -O3 -o test.o -xc - && otool -vt test.o -p _sum
test.o:
(__TEXT,__text) section
_sum:
0000000100000f90 pushq %rbp
0000000100000f91 movq %rsp, %rbp
0000000100000f94 addl %esi, %edi
0000000100000f96 movl %edi, %eax
0000000100000f98 popq %rbp
0000000100000f99 ret
~ smirnov$ echo "int main(){}; void sum(int x, int y, int *sum){ *sum = x + y; }; " | clang -O3 -o test.o -xc - && otool -vt test.o -p _sum
test.o:
(__TEXT,__text) section
_sum:
0000000100000f90 pushq %rbp
0000000100000f91 movq %rsp, %rbp
0000000100000f94 addl %esi, %edi
0000000100000f96 movl %edi, (%rdx)
0000000100000f98 popq %rbp
0000000100000f99 ret
@volodymyrsmirnov
Copy link
Author

~ smirnov$ echo "int main(){}; int max(int x, int y){ return x>y ? x : y; }" | clang -o test.o -xc - && otool -vt test.o -p _max
test.o:
(__TEXT,__text) section
_max:
0000000100000f70 pushq %rbp
0000000100000f71 movq %rsp, %rbp
0000000100000f74 movl %edi, -0x4(%rbp)
0000000100000f77 movl %esi, -0x8(%rbp)
0000000100000f7a movl -0x4(%rbp), %esi
0000000100000f7d cmpl -0x8(%rbp), %esi
0000000100000f80 jle 0x100000f91
0000000100000f86 movl -0x4(%rbp), %eax
0000000100000f89 movl %eax, -0xc(%rbp)
0000000100000f8c jmpq 0x100000f97
0000000100000f91 movl -0x8(%rbp), %eax
0000000100000f94 movl %eax, -0xc(%rbp)
0000000100000f97 movl -0xc(%rbp), %eax
0000000100000f9a popq %rbp
0000000100000f9b ret

~ smirnov$ echo "int main(){}; int max(int x, int y){ if(x>y) return x; else return y; }" | clang -o test.o -xc - && otool -vt test.o -p _max
test.o:
(__TEXT,__text) section
_max:
0000000100000f70 pushq %rbp
0000000100000f71 movq %rsp, %rbp
0000000100000f74 movl %edi, -0x8(%rbp)
0000000100000f77 movl %esi, -0xc(%rbp)
0000000100000f7a movl -0x8(%rbp), %esi
0000000100000f7d cmpl -0xc(%rbp), %esi
0000000100000f80 jle 0x100000f91
0000000100000f86 movl -0x8(%rbp), %eax
0000000100000f89 movl %eax, -0x4(%rbp)
0000000100000f8c jmpq 0x100000f97
0000000100000f91 movl -0xc(%rbp), %eax
0000000100000f94 movl %eax, -0x4(%rbp)
0000000100000f97 movl -0x4(%rbp), %eax
0000000100000f9a popq %rbp
0000000100000f9b ret

~ smirnov$ echo "int main(){}; int max(int x, int y){ if(x>y) return x; return y; }" | clang -o test.o -xc - && otool -vt test.o -p _max
test.o:
(__TEXT,__text) section
_max:
0000000100000f70 pushq %rbp
0000000100000f71 movq %rsp, %rbp
0000000100000f74 movl %edi, -0x8(%rbp)
0000000100000f77 movl %esi, -0xc(%rbp)
0000000100000f7a movl -0x8(%rbp), %esi
0000000100000f7d cmpl -0xc(%rbp), %esi
0000000100000f80 jle 0x100000f91
0000000100000f86 movl -0x8(%rbp), %eax
0000000100000f89 movl %eax, -0x4(%rbp)
0000000100000f8c jmpq 0x100000f97
0000000100000f91 movl -0xc(%rbp), %eax
0000000100000f94 movl %eax, -0x4(%rbp)
0000000100000f97 movl -0x4(%rbp), %eax
0000000100000f9a popq %rbp
0000000100000f9b ret

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment