#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 */
size_t backtrace(void **, int);
char **backtrace_symbols(void **, size_t);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(void **);
scalar_t__ getpid();
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void btrace(int signo) {
  void **btrace = (void **)malloc(sizeof(void *) * 10);
  size_t bt_size, i;
  char **bt_strings;
  bt_size = backtrace(btrace, 10);
  bt_strings = backtrace_symbols(btrace, bt_size);
  fprintf(stderr, "*** backtrace of %d ***\n", (int)getpid());
  for (i = 0; i < bt_size; i++) {
    fprintf(stderr, "%s\n", bt_strings[i]);
  }
  free(btrace);
  fprintf(stderr, "*** end of backtrace ***\n");
  exit(1);
}


x86 assembly (clang, -O0):
<btrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1060 <backtrace@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    121c <btrace+0xac>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11da <btrace+0x6a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<btrace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0xa,%esi
call   1060 <backtrace@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,%rbx
mov    0x2e33(%rip),%r13
mov    0x0(%r13),%r12d
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe41(%rip),%rsi
mov    %r12d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r15,%r15
je     11fb <btrace+0x8b>
lea    0xe42(%rip),%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0x0(%r13),%edi
mov    (%rbx,%rbp,8),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11e0 <btrace+0x70>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%edi
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"*** backtrace of %d ***\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [26 x i8] c"*** end of backtrace ***\0A\00"
define void @btrace(i32 %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8**
store i32 %0, i32* %2
%7 = call i64 @malloc(i32 80)
%8 = inttoptr i64 %7 to i8**
store i8** %8, i8*** %3
%9 = load i8**, i8*** %3
%10 = call i64 @backtrace(i8** %9, i32 10)
store i64 %10, i64* %4
%11 = load i8**, i8*** %3
%12 = load i64, i64* %4
%13 = call i8** @backtrace_symbols(i8** %11, i64 %12)
store i8** %13, i8*** %6
%14 = load i32, i32* @stderr
%15 = call i64 (...) @getpid()
%16 = trunc i64 %15 to i32
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %16)
store i64 0, i64* %5
br label %18
18: ; preds = %29, %1
%19 = load i64, i64* %5
%20 = load i64, i64* %4
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %6
%25 = load i64, i64* %5
%26 = getelementptr inbounds i8*, i8** %24, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %22
%30 = load i64, i64* %5
%31 = add i64 %30, 1
store i64 %31, i64* %5
br label %18
32: ; preds = %18
%33 = load i8**, i8*** %3
%34 = call i32 @free(i8** %33)
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"*** backtrace of %d ***\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [26 x i8] c"*** end of backtrace ***\0A\00"
define void @btrace(i32 %0) {
%2 = tail call i64 @malloc(i32 80)
%3 = inttoptr i64 %2 to i8**
%4 = tail call i64 @backtrace(i8** %3, i32 10)
%5 = tail call i8** @backtrace_symbols(i8** %3, i64 %4)
%6 = load i32, i32* @stderr
%7 = tail call i64 (...) @getpid()
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %4, 0
br i1 %10, label %19, label %11
11: ; preds = %1, %11
%12 = phi i64 [ %17, %11 ], [ 0, %1 ]
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds i8*, i8** %5, i64 %12
%15 = load i8*, i8** %14
%16 = tail 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 i64 %12, 1
%18 = icmp eq i64 %17, %4
br i1 %18, label %19, label %11
19: ; preds = %11, %1
%20 = tail call i32 @free(i8** %3)
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
}