#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 */
typedef int /*<<< orphan*/ array;

/* Variables and functions */
size_t backtrace(void **, int);
char **backtrace_symbols(void **, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ stderr;
void print_backtrace(void) {
  void *array[256];
  size_t i, size;
  char **strings;
  fprintf(stderr, "Backtrace:\n\n");
  size = backtrace(array, (sizeof(array) / sizeof((array)[0])));
  strings = backtrace_symbols(array, size);
  if (strings == NULL) {
    fprintf(stderr, " Could not obtain backtrace (ENOMEM)\n");
    return;
  }
  for (i = 0; i < size; i++)
    fprintf(stderr, "  %s\n", strings[i]);
  free(strings);
}


x86 assembly (clang, -O0):
<print_backtrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x800(%rbp),%rdi
mov    $0x100,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x810(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x810(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
jne    11be <print_backtrace+0x7e>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1229 <print_backtrace+0xe9>
movq   $0x0,-0x808(%rbp)
mov    -0x808(%rbp),%rax
cmp    -0x810(%rbp),%rax
jae    121d <print_backtrace+0xdd>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x818(%rbp),%rax
mov    -0x808(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x808(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x808(%rbp)
jmp    11c9 <print_backtrace+0x89>
mov    -0x818(%rbp),%rdi
call   1030 <free@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_backtrace>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    0x2e89(%rip),%r12
mov    (%r12),%edi
lea    0xe9e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <backtrace@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     11c6 <print_backtrace+0x86>
mov    %rax,%r13
test   %r14,%r14
je     11bc <print_backtrace+0x7c>
lea    0xe98(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r12),%edi
mov    0x0(%r13,%rbx,8),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11a0 <print_backtrace+0x60>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11d8 <print_backtrace+0x98>
mov    (%r12),%edi
lea    0xe3c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"Backtrace:\0A\0A\00"
@.str.1 = [38 x i8] c" Could not obtain backtrace (ENOMEM)\0A\00"
@.str.2 = [6 x i8] c" %s\0A\00"
define void @print_backtrace() {
%1 = alloca [256 x i8*]
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8**
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [256 x i8*], [256 x i8*]* %1, i64 0, i64 0
%8 = call i64 @backtrace(i8** %7, i32 256)
store i64 %8, i64* %3
%9 = getelementptr inbounds [256 x i8*], [256 x i8*]* %1, i64 0, i64 0
%10 = load i64, i64* %3
%11 = call i8** @backtrace_symbols(i8** %9, i64 %10)
store i8** %11, i8*** %4
%12 = load i8**, i8*** %4
%13 = icmp eq i8** %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %35
17: ; preds = %0
store i64 0, i64* %2
br label %18
18: ; preds = %29, %17
%19 = load i64, i64* %2
%20 = load i64, i64* %3
%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*** %4
%25 = load i64, i64* %2
%26 = getelementptr inbounds i8*, i8** %24, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %22
%30 = load i64, i64* %2
%31 = add i64 %30, 1
store i64 %31, i64* %2
br label %18
32: ; preds = %18
%33 = load i8**, i8*** %4
%34 = call i32 @free(i8** %33)
br label %35
35: ; preds = %32, %14
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"Backtrace:\0A\0A\00"
@.str.1 = [38 x i8] c" Could not obtain backtrace (ENOMEM)\0A\00"
@.str.2 = [6 x i8] c" %s\0A\00"
define void @print_backtrace() {
%1 = alloca [256 x i8*]
%2 = bitcast [256 x i8*]* %1 to i8*
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [256 x i8*], [256 x i8*]* %1, i64 0, i64 0
%6 = call i64 @backtrace(i8** %5, i32 256)
%7 = call i8** @backtrace_symbols(i8** %5, i64 %6)
%8 = icmp eq i8** %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = icmp eq i64 %6, 0
br i1 %10, label %22, label %14
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %24
14: ; preds = %9, %14
%15 = phi i64 [ %20, %14 ], [ 0, %9 ]
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds i8*, i8** %7, i64 %15
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = add nuw i64 %15, 1
%21 = icmp eq i64 %20, %6
br i1 %21, label %22, label %14
22: ; preds = %14, %9
%23 = call i32 @free(i8** %7)
br label %24
24: ; preds = %22, %11
ret void
}