#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 */
size_t backtrace(void **, int);
char **backtrace_symbols(void **, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ stderr;
void print_trace(void) {
  void *buffer[100] = {0};
  size_t size = 0;
  char **strings = NULL;
  size = backtrace(buffer, 100);
  strings = backtrace_symbols(buffer, size);
  (void)fprintf(stderr, "Obtained %zd stack frames.\n", size);
  size_t i;
  for (i = 0; i < size; i++)
    (void)fprintf(stderr, "%s\n", strings[i]);
  if (strings)
    free(strings);
  strings = NULL;
}


x86 assembly (clang, -O0):
<print_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
lea    -0x320(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1060 <memset@plt>
movq   $0x0,-0x328(%rbp)
movq   $0x0,-0x330(%rbp)
lea    -0x320(%rbp),%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x328(%rbp)
lea    -0x320(%rbp),%rdi
mov    -0x328(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x330(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x328(%rbp),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x338(%rbp)
mov    -0x338(%rbp),%rax
cmp    -0x328(%rbp),%rax
jae    1233 <print_trace+0xe3>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x330(%rbp),%rax
mov    -0x338(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x338(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x338(%rbp)
jmp    11df <print_trace+0x8f>
cmpq   $0x0,-0x330(%rbp)
je     124d <print_trace+0xfd>
mov    -0x330(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x330(%rbp)
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_trace>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x320,%rsp
mov    %rsp,%r14
mov    $0x320,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %r14,%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r14
mov    0x2e49(%rip),%r12
mov    (%r12),%edi
lea    0xe5e(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r13,%r13
je     11dd <print_trace+0x8d>
lea    0xe64(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    (%r14,%rbx,8),%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11c0 <print_trace+0x70>
jmp    11e2 <print_trace+0x92>
test   %r14,%r14
je     11ea <print_trace+0x9a>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x320,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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