#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 exception_print_trace() {
  void *array[10];
  size_t size;
  char **strings;
  size_t i;
  size = backtrace(array, 10);
  strings = backtrace_symbols(array, size);
  printf("\nException: %zd stack frames\n", size);
  for (i = 0; i < size; i++)
    printf("%s\n", strings[i]);
  free(strings);
  exit(1);
}


x86 assembly (clang, -O0):
<exception_print_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x50(%rbp),%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%rax
cmp    -0x58(%rbp),%rax
jae    11ce <exception_print_trace+0x7e>
mov    -0x60(%rbp),%rax
mov    -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1195 <exception_print_trace+0x45>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

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

LLVM IR (-O2):
@.str = [30 x i8] c"\0AException: %zd stack frames\0A\00"
define void @exception_print_trace() {
%1 = alloca [10 x i8*]
%2 = bitcast [10 x i8*]* %1 to i8*
%3 = getelementptr inbounds [10 x i8*], [10 x i8*]* %1, i64 0, i64 0
%4 = call i64 @backtrace(i8** %3, i32 10)
%5 = call i8** @backtrace_symbols(i8** %3, i64 %4)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %4)
%7 = icmp eq i64 %4, 0
br i1 %7, label %15, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %13, %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 i64 %9, 1
%14 = icmp eq i64 %13, %4
br i1 %14, label %15, label %8
15: ; preds = %8, %0
%16 = call i32 @free(i8** %5)
%17 = call i32 @exit(i32 1)
unreachable
}