#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*/ free(char **);
int /*<<< orphan*/ printf(char *, char *);
void dump_trace() {
  void *buffer[100] = {NULL};
  char **trace = NULL;
  int size = backtrace(buffer, 10);
  trace = backtrace_symbols(buffer, size);
  if (NULL != trace) {
    int i = 0;
    for (i = 0; i < size; ++i) {
      printf("%s\n", trace[i]);
    }
    free(trace);
  }
}


x86 assembly (clang, -O0):
<dump_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
lea    -0x320(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1070 <memset@plt>
movq   $0x0,-0x328(%rbp)
lea    -0x320(%rbp),%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x32c(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x32c(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x328(%rbp)
xor    %eax,%eax
cmp    -0x328(%rbp),%rax
je     121c <dump_trace+0xcc>
movl   $0x0,-0x330(%rbp)
movl   $0x0,-0x330(%rbp)
mov    -0x330(%rbp),%eax
cmp    -0x32c(%rbp),%eax
jge    1210 <dump_trace+0xc0>
mov    -0x328(%rbp),%rax
movslq -0x330(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe09(%rip),%rdi
call   1060 <printf@plt>
mov    -0x330(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x330(%rbp)
jmp    11cc <dump_trace+0x7c>
mov    -0x328(%rbp),%rdi
call   1030 <free@plt>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_trace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x328,%rsp
mov    %rsp,%rbx
mov    $0x320,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     11bd <dump_trace+0x6d>
mov    %rax,%r15
test   %ebp,%ebp
jle    11b5 <dump_trace+0x65>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe61(%rip),%r14
nop
mov    (%r15,%rbx,8),%rsi
mov    %r14,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <dump_trace+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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