#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
size_t backtrace(void **, size_t);
int /*<<< orphan*/ backtrace_symbols_fd(void **, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void printBacktrace(FILE *f) {
  size_t stacksp = 1024;
  void *stack[stacksp];
  size_t stackl = backtrace(stack, stacksp);
  fputs("STACK TRACE:\n", f);
  backtrace_symbols_fd(stack, stackl, fileno(f));
  fputc('\n', stderr);
}


x86 assembly (clang, -O0):
<printBacktrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x400,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
call   1040 <backtrace@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <backtrace_symbols_fd@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1060 <fputc@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBacktrace>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    $0x400,%esi
mov    %r14,%rdi
call   1040 <backtrace@plt>
mov    %rax,%r15
lea    0xe87(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fileno@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <backtrace_symbols_fd@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"STACK TRACE:\0A\00"
@stderr = global i32 0
define void @printBacktrace(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i32* %0, i32** %2
store i64 1024, i64* %3
%7 = load i64, i64* %3
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8*, i64 %7
store i64 %7, i64* %5
%10 = load i64, i64* %3
%11 = call i64 @backtrace(i8** %9, i64 %10)
store i64 %11, i64* %6
%12 = load i32*, i32** %2
%13 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = load i64, i64* %6
%15 = load i32*, i32** %2
%16 = call i32 @fileno(i32* %15)
%17 = call i32 @backtrace_symbols_fd(i8** %9, i64 %14, i32 %16)
%18 = load i32, i32* @stderr
%19 = call i32 @fputc(i8 signext 10, i32 %18)
%20 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"STACK TRACE:\0A\00"
@stderr = global i32 0
define void @printBacktrace(i32* nocapture %0) {
%2 = alloca [1024 x i8*]
%3 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %2, i64 0, i64 0
%4 = call i64 @backtrace(i8** %3, i64 1024)
%5 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13, i64 1, i32* %0)
%6 = call i32 @fileno(i32* %0)
%7 = call i32 @backtrace_symbols_fd(i8** %3, i64 %4, i32 %6)
%8 = load i32, i32* @stderr
%9 = call i32 @fputc(i8 signext 10, i32 %8)
ret void
}