#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*/ assert(char **);
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ stderr;
void mloop__print_backtrace(int depth) {
  void *buffer[128] = {0};
  int nptrs;
  char **strings;
  nptrs = backtrace(buffer, 128);
  strings = backtrace_symbols(buffer + depth, 128 - depth);
  assert(strings);
  for (int i = 0; i < nptrs; ++i)
    fprintf(stderr, "\t%s\n", strings[i]);
  free(strings);
}


x86 assembly (clang, -O0):
<mloop__print_backtrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    $0x80,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x80,%esi
sub    -0x4(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
call   1070 <assert@plt>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
cmp    -0x414(%rbp),%eax
jge    1221 <mloop__print_backtrace+0xc1>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x420(%rbp),%rax
movslq -0x424(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdf8(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    11d4 <mloop__print_backtrace+0x74>
mov    -0x420(%rbp),%rdi
call   1030 <free@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mloop__print_backtrace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r14d
mov    %rsp,%rbp
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x80,%ebx
mov    %rbp,%rdi
mov    $0x80,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
movslq %r14d,%rax
lea    (%rsp,%rax,8),%rdi
sub    %eax,%ebx
mov    %ebx,%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <assert@plt>
test   %ebp,%ebp
jle    11e9 <mloop__print_backtrace+0x89>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    0x2e1e(%rip),%r12
lea    0xe37(%rip),%r14
nopl   0x0(%rax)
mov    (%r12),%edi
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rsi
call   1080 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <mloop__print_backtrace+0x70>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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