#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*/ stderr;
void __backtrace_printf() {
  void *frames[32];
  int frame_nr;
  char **symbol;
  int i;
  frame_nr = backtrace(frames, 32);
  symbol = backtrace_symbols(frames, frame_nr);
  fprintf(stderr, "backtrace:\n");
  if (symbol) {
    for (i = 0; i < frame_nr; i++)
      fprintf(stderr, "[%02d]  %s\n", i, symbol[i]);
    fprintf(stderr, "\n");
  } else {
    fprintf(stderr, "cannot get backtrace\n");
  }
}


x86 assembly (clang, -O0):
<__backtrace_printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x100(%rbp),%rdi
mov    $0x20,%esi
call   1040 <backtrace@plt>
mov    %eax,-0x104(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x104(%rbp),%esi
call   1030 <backtrace_symbols@plt>
mov    %rax,-0x110(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x110(%rbp)
je     120b <__backtrace_printf+0xdb>
movl   $0x0,-0x114(%rbp)
mov    -0x114(%rbp),%eax
cmp    -0x104(%rbp),%eax
jge    11ef <__backtrace_printf+0xbf>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    -0x114(%rbp),%edx
mov    -0x110(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    119a <__backtrace_printf+0x6a>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1222 <__backtrace_printf+0xf2>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__backtrace_printf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <backtrace_symbols@plt>
mov    %rax,%r13
mov    0x2e79(%rip),%r12
mov    (%r12),%edi
lea    0xe8e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r13,%r13
je     11c0 <__backtrace_printf+0x90>
lea    0xe85(%rip),%r14
test   %ebp,%ebp
jle    11c7 <__backtrace_printf+0x97>
mov    %ebp,%ebx
lea    0xe7a(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edi
mov    0x0(%r13,%rbp,8),%rcx
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11a0 <__backtrace_printf+0x70>
jmp    11c7 <__backtrace_printf+0x97>
lea    0xe51(%rip),%r14
mov    (%r12),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"backtrace:\0A\00"
@.str.1 = [12 x i8] c"[%02d] %s\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [22 x i8] c"cannot get backtrace\0A\00"
define void @__backtrace_printf() {
%1 = alloca [32 x i8*]
%2 = bitcast [32 x i8*]* %1 to i8*
%3 = getelementptr inbounds [32 x i8*], [32 x i8*]* %1, i64 0, i64 0
%4 = call i32 @backtrace(i8** %3, i32 32)
%5 = call i8** @backtrace_symbols(i8** %3, i32 %4)
%6 = load i32, i32* @stderr
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8** %5, null
br i1 %8, label %22, label %9
9: ; preds = %0
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %22
11: ; preds = %9
%12 = zext i32 %4 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = load i32, i32* @stderr
%16 = getelementptr inbounds i8*, i8** %5, i64 %14
%17 = load i8*, i8** %16
%18 = trunc i64 %14 to i32
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %17)
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13, %0, %9
%23 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %0 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %13 ]
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* %23)
ret void
}