#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*/ frames;

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
size_t backtrace(void **, int);
int /*<<< orphan*/ backtrace_symbols_fd(void **, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
void mco_dump_traceback(const char *caller) {
  const size_t max_frame_size = 64;
  void *frames[max_frame_size];
  size_t frame_size;
  fprintf(stderr, "Stack Trace Start for <%s>\n", caller);
  frame_size = backtrace(frames, sizeof(frames) / sizeof(frames[0]));
  backtrace_symbols_fd(frames, frame_size, STDERR_FILENO);
}


x86 assembly (clang, -O0):
<mco_dump_traceback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x40,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe9e(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x220(%rbp),%rdi
mov    $0x40,%esi
call   1040 <backtrace@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
lea    -0x220(%rbp),%rdi
call   1030 <backtrace_symbols_fd@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mco_dump_traceback>:
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rdx
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1040 <backtrace@plt>
mov    0x2e71(%rip),%rcx
mov    (%rcx),%edx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <backtrace_symbols_fd@plt>
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Stack Trace Start for <%s>\0A\00"
@STDERR_FILENO = global i32 0
define void @mco_dump_traceback(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i64 64, i64* %3
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %4
%7 = alloca i8*, i64 64
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %2
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i64 @backtrace(i8** %7, i32 64)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = load i32, i32* @STDERR_FILENO
%14 = call i32 @backtrace_symbols_fd(i8** %7, i64 %12, i32 %13)
%15 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Stack Trace Start for <%s>\0A\00"
@STDERR_FILENO = global i32 0
define void @mco_dump_traceback(i8* %0) {
%2 = alloca [64 x i8*]
%3 = getelementptr inbounds [64 x i8*], [64 x i8*]* %2, i64 0, i64 0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i64 @backtrace(i8** %3, i32 64)
%7 = load i32, i32* @STDERR_FILENO
%8 = call i32 @backtrace_symbols_fd(i8** %3, i64 %6, i32 %7)
ret void
}