#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 *, char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
void dx_trace() {
  void *buffer[100];
  char **funcNames;
  int i, nptrs;
  nptrs = backtrace(buffer, 100);
  funcNames = backtrace_symbols(buffer, nptrs);
  if (funcNames == NULL) {
    perror("Backtrace Symbols");
    return;
  }
  for (i = 0; i < nptrs; i++)
    do {
      fprintf(stdout, "%s\n", funcNames[i]);
    } while (0);
  ;
  free(funcNames);
}


x86 assembly (clang, -O0):
<dx_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
lea    -0x320(%rbp),%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x330(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x330(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x328(%rbp)
cmpq   $0x0,-0x328(%rbp)
jne    11aa <dx_trace+0x5a>
lea    0xe60(%rip),%rdi
call   1070 <perror@plt>
jmp    1217 <dx_trace+0xc7>
movl   $0x0,-0x32c(%rbp)
mov    -0x32c(%rbp),%eax
cmp    -0x330(%rbp),%eax
jge    120b <dx_trace+0xbb>
jmp    11cb <dx_trace+0x7b>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x328(%rbp),%rax
movslq -0x32c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe25(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11f7 <dx_trace+0xa7>
mov    -0x32c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x32c(%rbp)
jmp    11b4 <dx_trace+0x64>
mov    -0x328(%rbp),%rdi
call   1030 <free@plt>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dx_trace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x320,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     11d1 <dx_trace+0x81>
mov    %rax,%r15
test   %ebp,%ebp
jle    11b9 <dx_trace+0x69>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    0x2e4e(%rip),%r12
lea    0xe79(%rip),%r14
nopl   0x0(%rax)
mov    (%r12),%edi
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <dx_trace+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x320,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe28(%rip),%rdi
call   1070 <perror@plt>
jmp    11c1 <dx_trace+0x71>

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

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