int foo(int arg) {
  printf("function address: %p\n", &foo);
  printf("in function foo, argument address %p\n", &arg);
  char a[100] = {0};
  printf("in function foo, local variable address %p\n", a);
  char *p = (char *)malloc(100);
  printf("in function foo, malloc address %p\n", p);
  free(p);
  h(1);
  return 0;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9b(%rip),%rdi
mov    0x2e7c(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
mov    $0x0,%al
call   1040 <h@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbx
sub    $0x80,%rsp
mov    %edi,0xc(%rsp)
lea    0xead(%rip),%rdi
mov    0x2e8e(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
lea    0xe98(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xea4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <h@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"function address: %p\0A\00"
@.str.1 = [38 x i8] c"in function foo, argument address %p\0A\00"
@.str.2 = [44 x i8] c"in function foo, local variable address %p\0A\00"
@.str.3 = [36 x i8] c"in function foo, malloc address %p\0A\00"
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 (i32)* @foo)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = bitcast [100 x i8]* %3 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = call i8* @malloc(i64 100)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %4
%14 = call i32 (i32, ...) bitcast (i32 (...)* @h to i32 (i32, ...)*)(i32 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"function address: %p\0A\00"
@.str.1 = [38 x i8] c"in function foo, argument address %p\0A\00"
@.str.2 = [44 x i8] c"in function foo, local variable address %p\0A\00"
@.str.3 = [36 x i8] c"in function foo, malloc address %p\0A\00"
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
store i32 %0, i32* %2
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 (i32)* @foo)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = call dereferenceable_or_null(100) i8* @malloc(i64 100)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%10 = call i32 (i32, ...) bitcast (i32 (...)* @h to i32 (i32, ...)*)(i32 1)
ret i32 0
}