#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 eslib_dbg_print_backtrace() {
  void *funcptrs[256];
  int count = backtrace(funcptrs, 256);
  char **funcstr = backtrace_symbols(funcptrs, count);
  int i;
  for (i = 0; i < count; ++i) {
    printf("-- %s\n", funcstr[i]);
  }
  free(funcstr);
}


x86 assembly (clang, -O0):
<eslib_dbg_print_backtrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
lea    -0x800(%rbp),%rdi
mov    $0x100,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x804(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x804(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x810(%rbp)
movl   $0x0,-0x814(%rbp)
mov    -0x814(%rbp),%eax
cmp    -0x804(%rbp),%eax
jge    11c9 <eslib_dbg_print_backtrace+0x89>
mov    -0x810(%rbp),%rax
movslq -0x814(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe50(%rip),%rdi
call   1060 <printf@plt>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    1185 <eslib_dbg_print_backtrace+0x45>
mov    -0x810(%rbp),%rdi
call   1030 <free@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eslib_dbg_print_backtrace>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    1195 <eslib_dbg_print_backtrace+0x55>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe85(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rsi
mov    %r14,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <eslib_dbg_print_backtrace+0x40>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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