#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ stderr;
void death_function() {
  fprintf(stderr, "DEATH CALLBACK\n");
  void *callstack[128];
  int i, frames = backtrace(callstack, 128);
  char **strs = backtrace_symbols(callstack, frames);
  for (i = 0; i < frames; ++i) {
    fprintf(stderr, "%s\n", strs[i]);
  }
  free(strs);
  fprintf(stderr, "END OF BACKTRACE\n");
}


x86 assembly (clang, -O0):
<death_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x80,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x410(%rbp)
movl   $0x0,-0x404(%rbp)
mov    -0x404(%rbp),%eax
cmp    -0x408(%rbp),%eax
jge    11eb <death_function+0xab>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x410(%rbp),%rax
movslq -0x404(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    119c <death_function+0x5c>
mov    -0x410(%rbp),%rdi
call   1030 <free@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<death_function>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    0x2e8a(%rip),%r15
mov    (%r15),%edi
lea    0xea0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <backtrace@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    11ba <death_function+0x7a>
mov    %r14d,%ebp
lea    0xe7a(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    (%r12,%rbx,8),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <death_function+0x60>
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%r15),%edi
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"DEATH CALLBACK\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [18 x i8] c"END OF BACKTRACE\0A\00"
define void @death_function() {
%1 = alloca [128 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8**
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [128 x i8*], [128 x i8*]* %1, i64 0, i64 0
%8 = call i32 @backtrace(i8** %7, i32 128)
store i32 %8, i32* %3
%9 = getelementptr inbounds [128 x i8*], [128 x i8*]* %1, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i8** @backtrace_symbols(i8** %9, i32 %10)
store i8** %11, i8*** %4
store i32 0, i32* %2
br label %12
12: ; preds = %24, %0
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %4
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %16
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %12
27: ; preds = %12
%28 = load i8**, i8*** %4
%29 = call i32 @free(i8** %28)
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"DEATH CALLBACK\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [18 x i8] c"END OF BACKTRACE\0A\00"
define void @death_function() {
%1 = alloca [128 x i8*]
%2 = load i32, i32* @stderr
%3 = tail call i32 (i32, i8*, ...) @fprintf(i32 %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [128 x i8*]* %1 to i8*
%5 = getelementptr inbounds [128 x i8*], [128 x i8*]* %1, i64 0, i64 0
%6 = call i32 @backtrace(i8** %5, i32 128)
%7 = call i8** @backtrace_symbols(i8** %5, i32 %6)
%8 = icmp sgt i32 %6, 0
br i1 %8, label %9, label %19
9: ; preds = %0
%10 = zext i32 %6 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %17, %11 ]
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds i8*, i8** %7, i64 %12
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %0
%20 = call i32 @free(i8** %7)
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
ret void
}