int callsite(char *tag) {
  unsigned long *ebp;
  asm volatile("movl %%ebp,%0" : "=m"(ebp));
  printf("%-20.20s ", tag);
  while (*(unsigned long *)(ebp)) {
    printf("0x%x<-", *((unsigned long *)(ebp + 1)));
    ebp = *(unsigned long *)(ebp);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<callsite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %ebp,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1165 <callsite+0x55>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1131 <callsite+0x21>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<callsite>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rsi
mov    %ebp,0x8(%rsp)
lea    0xecd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,(%rax)
je     1171 <callsite+0x51>
lea    0xebe(%rip),%rbx
nopl   0x0(%rax)
mov    0x8(%rax),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
cmpq   $0x0,(%rax)
jne    1150 <callsite+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%-20.20s \00"
@.str.1 = [7 x i8] c"0x%x<-\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @callsite(i8* %0) {
%2 = alloca i8*
%3 = alloca i64*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %6
6: ; preds = %10, %1
%7 = load i64*, i64** %3
%8 = load i64, i64* %7
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i64*, i64** %3
%12 = getelementptr inbounds i64, i64* %11, i64 1
%13 = load i64, i64* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%15 = load i64*, i64** %3
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i64*
store i64* %17, i64** %3
br label %6
18: ; preds = %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"%-20.20s \00"
@.str.1 = [7 x i8] c"0x%x<-\00"
define i32 @callsite(i8* %0) {
%2 = alloca i64*
%3 = bitcast i64** %2 to i8*
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i64*, i64** %2
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %1, %8
%9 = phi i64* [ %15, %8 ], [ %5, %1 ]
%10 = getelementptr inbounds i64, i64* %9, i64 1
%11 = load i64, i64* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = load i64*, i64** %2
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to i64*
store i64* %15, i64** %2
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %8, %1
%19 = call i32 @putchar(i32 10)
ret i32 0
}