#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
void rtpp_stacktrace_print(const char *msg) {
  void *array[10];
  size_t size;
  char **strings;
  int i;
  size = backtrace(array, 10);
  strings = backtrace_symbols(array, size);
  fprintf(stderr, "%s\nTraceback:\n", msg);
  for (i = 0; i < size; i++)
    fprintf(stderr, "  %s\n", strings[i]);
  fflush(stderr);
}


x86 assembly (clang, -O0):
<rtpp_stacktrace_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0xa,%esi
call   1040 <backtrace@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1030 <backtrace_symbols@plt>
mov    %rax,-0x70(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    11cf <rtpp_stacktrace_print+0x8f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1192 <rtpp_stacktrace_print+0x52>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtpp_stacktrace_print>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <backtrace@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <backtrace_symbols@plt>
mov    %rax,%r13
mov    0x2e68(%rip),%r12
mov    (%r12),%edi
lea    0xe7d(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
test   %r14,%r14
je     11ba <rtpp_stacktrace_print+0x7a>
xor    %ebx,%ebx
lea    0xe76(%rip),%r15
nopl   0x0(%rax)
mov    (%r12),%edi
mov    0x0(%r13,%rbx,8),%rdx
mov    %r15,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11a0 <rtpp_stacktrace_print+0x60>
mov    (%r12),%edi
call   1060 <fflush@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"%s\0ATraceback:\0A\00"
@.str.1 = [6 x i8] c" %s\0A\00"
define void @rtpp_stacktrace_print(i8* %0) {
%2 = alloca [10 x i8*]
%3 = bitcast [10 x i8*]* %2 to i8*
%4 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 0
%5 = call i64 @backtrace(i8** %4, i32 10)
%6 = call i8** @backtrace_symbols(i8** %4, i64 %5)
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = icmp eq i64 %5, 0
br i1 %9, label %18, label %10
10: ; preds = %1, %10
%11 = phi i64 [ %16, %10 ], [ 0, %1 ]
%12 = load i32, i32* @stderr
%13 = getelementptr inbounds i8*, i8** %6, i64 %11
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = add nuw i64 %11, 1
%17 = icmp eq i64 %16, %5
br i1 %17, label %18, label %10
18: ; preds = %10, %1
%19 = load i32, i32* @stderr
%20 = call i32 @fflush(i32 %19)
ret void
}