#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*/ addrlist;

/* 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 printStackTrace() {
  void *addrlist[100];
  int addrlen = backtrace(addrlist, (int)(sizeof(addrlist) / sizeof(void *)));
  if (addrlen == 0) {
    fprintf(stderr, "\n");
    return;
  }
  char **symbols = backtrace_symbols(addrlist, addrlen);
  int i;
  for (i = 1; i < addrlen; i++)
    fprintf(stderr, "%s\n", symbols[i]);
  free(symbols);
}


x86 assembly (clang, -O0):
<printStackTrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
lea    -0x320(%rbp),%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x324(%rbp)
cmpl   $0x0,-0x324(%rbp)
jne    118b <printStackTrace+0x4b>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1209 <printStackTrace+0xc9>
lea    -0x320(%rbp),%rdi
mov    -0x324(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x330(%rbp)
movl   $0x1,-0x334(%rbp)
mov    -0x334(%rbp),%eax
cmp    -0x324(%rbp),%eax
jge    11fd <printStackTrace+0xbd>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x330(%rbp),%rax
movslq -0x334(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    11ae <printStackTrace+0x6e>
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printStackTrace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x320,%rsp
mov    %rsp,%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
test   %eax,%eax
je     11b5 <printStackTrace+0x75>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r15
cmp    $0x2,%ebp
jl     11ab <printStackTrace+0x6b>
mov    %ebp,%ebp
mov    $0x1,%ebx
mov    0x2e5e(%rip),%r12
lea    0xe77(%rip),%r14
nopl   0x0(%rax)
mov    (%r12),%edi
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <printStackTrace+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11cc <printStackTrace+0x8c>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x320,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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