#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 /*<<< orphan*/ free(char **);
char **get_backtrace_symbols(void **, int);
int /*<<< orphan*/ printf(char *, int, char *);
void print_backtrace(void **addr, int len) {
  int i;
  char **symbollist = get_backtrace_symbols(addr, len);
  for (i = 0; i < len && addr[i] != NULL; i++) {
    printf("[%02d]: %s\n", i, symbollist[i]);
  }
  free(symbollist);
}


x86 assembly (clang, -O0):
<print_backtrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <get_backtrace_symbols@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x19(%rbp)
jge    117a <print_backtrace+0x4a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118a <print_backtrace+0x5a>
jmp    11b3 <print_backtrace+0x83>
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <print_backtrace+0x26>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_backtrace>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
call   1050 <get_backtrace_symbols@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    117e <print_backtrace+0x4e>
mov    %ebx,%r13d
xor    %ebx,%ebx
lea    0xeaa(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
cmpq   $0x0,(%r14,%rbx,8)
je     117e <print_backtrace+0x4e>
mov    (%r15,%rbx,8),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <print_backtrace+0x30>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [12 x i8] c"[%02d]: %s\0A\00"
define void @print_backtrace(i8** %0, i32 %1) {
%3 = tail call i8** @get_backtrace_symbols(i8** %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %12
%8 = phi i64 [ 0, %5 ], [ %17, %12 ]
%9 = getelementptr inbounds i8*, i8** %0, i64 %8
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %3, i64 %8
%14 = load i8*, i8** %13
%15 = trunc i64 %8 to i32
%16 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %14)
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %19, label %7
19: ; preds = %7, %12, %2
%20 = tail call i32 @free(i8** %3)
ret void
}