#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*/ exit(int);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ printf(char *, ...);
void exit_trace(void) {
  unsigned int i;
  void *array[50];
  size_t size;
  char **strings;
  size = backtrace(array, 50);
  strings = backtrace_symbols(array, size);
  printf("Obtained %zd stack frames.\n", size);
  for (i = 0; i < size; i++)
    printf("%s\n", strings[i]);
  free(strings);
  exit(1);
}


x86 assembly (clang, -O0):
<exit_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
lea    -0x1a0(%rbp),%rdi
mov    $0x32,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x1a8(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x1a8(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x1b0(%rbp)
mov    -0x1a8(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x1a8(%rbp),%rax
jae    11e3 <exit_trace+0x93>
mov    -0x1b0(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <exit_trace+0x59>
mov    -0x1b0(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<exit_trace>:
push   %r15
push   %r14
push   %rbx
sub    $0x190,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1060 <backtrace@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <backtrace_symbols@plt>
mov    %rax,%r15
lea    0xe6c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r14,%r14
je     11c1 <exit_trace+0x61>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbx,8),%rdi
call   1040 <puts@plt>
add    $0x1,%ebx
cmp    %rbx,%r14
ja     11b0 <exit_trace+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [28 x i8] c"Obtained %zd stack frames.\0A\00"
define void @exit_trace() {
%1 = alloca [50 x i8*]
%2 = bitcast [50 x i8*]* %1 to i8*
%3 = getelementptr inbounds [50 x i8*], [50 x i8*]* %1, i64 0, i64 0
%4 = call i64 @backtrace(i8** %3, i32 50)
%5 = call i8** @backtrace_symbols(i8** %3, i64 %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %4)
%7 = icmp eq i64 %4, 0
br i1 %7, label %16, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %14, %8 ], [ 0, %0 ]
%10 = getelementptr inbounds i8*, i8** %5, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 @puts(i8* dereferenceable(1) %11)
%13 = add nuw nsw i64 %9, 1
%14 = and i64 %13, 4294967295
%15 = icmp ugt i64 %4, %14
br i1 %15, label %8, label %16
16: ; preds = %8, %0
%17 = call i32 @free(i8** %5)
%18 = call i32 @exit(i32 1)
unreachable
}