Skip to content

Instantly share code, notes, and snippets.

@matklad
Last active December 18, 2015 18:40
Show Gist options
  • Save matklad/f03afefc2cc1b37ab75e to your computer and use it in GitHub Desktop.
Save matklad/f03afefc2cc1b37ab75e to your computer and use it in GitHub Desktop.
matklad@nixos [09:31:33] [~/quest]
-> % cat g.c
int a;
int b;
int inc_a() { return a++; }
int inc_b() { return b++; }
int main() {
inc_a();
inc_b();
}
matklad@nixos [09:31:44] [~/quest]
-> % clang -O0 -c g.c
matklad@nixos [09:31:47] [~/quest]
-> % objdump -d g.o
g.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <inc_a>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 8b 04 25 00 00 00 00 mov 0x0,%eax
b: 89 c1 mov %eax,%ecx
d: 81 c1 01 00 00 00 add $0x1,%ecx
13: 89 0c 25 00 00 00 00 mov %ecx,0x0
1a: 5d pop %rbp
1b: c3 retq
1c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000000020 <inc_b>:
20: 55 push %rbp
21: 48 89 e5 mov %rsp,%rbp
24: 8b 04 25 00 00 00 00 mov 0x0,%eax
2b: 89 c1 mov %eax,%ecx
2d: 81 c1 01 00 00 00 add $0x1,%ecx
33: 89 0c 25 00 00 00 00 mov %ecx,0x0
3a: 5d pop %rbp
3b: c3 retq
3c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000000040 <main>:
40: 55 push %rbp
41: 48 89 e5 mov %rsp,%rbp
44: 48 83 ec 10 sub $0x10,%rsp
48: e8 b3 ff ff ff callq 0 <inc_a>
4d: 89 45 fc mov %eax,-0x4(%rbp)
50: e8 cb ff ff ff callq 20 <inc_b>
55: 31 c9 xor %ecx,%ecx
57: 89 45 f8 mov %eax,-0x8(%rbp)
5a: 89 c8 mov %ecx,%eax
5c: 48 83 c4 10 add $0x10,%rsp
60: 5d pop %rbp
61: c3 retq
@matklad
Copy link
Author

matklad commented Dec 18, 2015

Question: how it happened that inc_a and inc_b have exactly the same code?

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