void sigfunc(int signo) {
  printf("%s(0): %p\n", __func__, __builtin_return_address(0));
  printf("%s(1): %p\n", __func__, __builtin_return_address(1));
  printf("%s(2): %p\n", __func__, __builtin_return_address(2));
  printf("%s(3): %p\n", __func__, __builtin_return_address(3));
  printf("%s(4): %p\n", __func__, __builtin_return_address(4));
  exit(1);
}


x86 assembly (clang, -O0):
<sigfunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x8(%rbp),%rdx
lea    0xeca(%rip),%rdi
lea    0xece(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rbp,%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdx
lea    0xebe(%rip),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rbp,%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdx
lea    0xea7(%rip),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rbp,%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdx
lea    0xe8d(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rbp,%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdx
lea    0xe70(%rip),%rdi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<sigfunc>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rbp),%rdx
lea    0xecb(%rip),%rdi
lea    0xecf(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%rbp),%rax
mov    (%rax),%rbx
mov    0x8(%rax),%rdx
lea    0xebb(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%r15
mov    0x8(%rbx),%rdx
lea    0xeae(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%rbx
mov    0x8(%r15),%rdx
lea    0xea1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rbx),%rdx
lea    0xe97(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"%s(0): %p\0A\00"
@__func__.sigfunc = [8 x i8] c"sigfunc\00"
@.str.1 = [11 x i8] c"%s(1): %p\0A\00"
@.str.2 = [11 x i8] c"%s(2): %p\0A\00"
@.str.3 = [11 x i8] c"%s(3): %p\0A\00"
@.str.4 = [11 x i8] c"%s(4): %p\0A\00"
define void @sigfunc(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i8* @llvm.returnaddress(i32 0)
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %3)
%5 = call i8* @llvm.returnaddress(i32 1)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %5)
%7 = call i8* @llvm.returnaddress(i32 2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %7)
%9 = call i8* @llvm.returnaddress(i32 3)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %9)
%11 = call i8* @llvm.returnaddress(i32 4)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %11)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s(0): %p\0A\00"
@__func__.sigfunc = [8 x i8] c"sigfunc\00"
@.str.1 = [11 x i8] c"%s(1): %p\0A\00"
@.str.2 = [11 x i8] c"%s(2): %p\0A\00"
@.str.3 = [11 x i8] c"%s(3): %p\0A\00"
@.str.4 = [11 x i8] c"%s(4): %p\0A\00"
define void @sigfunc(i32 %0) {
%2 = tail call i8* @llvm.returnaddress(i32 0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %2)
%4 = tail call i8* @llvm.returnaddress(i32 1)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %4)
%6 = tail call i8* @llvm.returnaddress(i32 2)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %6)
%8 = tail call i8* @llvm.returnaddress(i32 3)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %8)
%10 = tail call i8* @llvm.returnaddress(i32 4)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__func__.sigfunc, i64 0, i64 0), i8* %10)
tail call void @exit(i32 1)
unreachable
}