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

/* Variables and functions */
int backtrace(void **, int);
int /*<<< orphan*/ backtrace_symbols_fd(void **, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void ofc_bt() {
  void *trace[128];
  int n = backtrace(trace, sizeof(trace) / sizeof(trace[0]));
  fprintf(stderr, "<ofchecker> : ***  Start backtrace ***\n");
  backtrace_symbols_fd(trace, n, 2);
  fprintf(stderr, "<ofchecker> : ***   End backtrace  ***\n");
  return;
}


x86 assembly (clang, -O0):
<ofc_bt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    -0x400(%rbp),%rdi
mov    $0x80,%esi
call   1040 <backtrace@plt>
mov    %eax,-0x404(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x404(%rbp),%esi
mov    $0x2,%edx
call   1030 <backtrace_symbols_fd@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ofc_bt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x80,%esi
call   1040 <backtrace@plt>
mov    %eax,%ebp
mov    0x2e8c(%rip),%rbx
mov    (%rbx),%edi
lea    0xea3(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1030 <backtrace_symbols_fd@plt>
mov    (%rbx),%edi
lea    0xeae(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"<ofchecker> : *** Start backtrace ***\0A\00"
@.str.1 = [40 x i8] c"<ofchecker> : *** End backtrace ***\0A\00"
define void @ofc_bt() {
%1 = alloca [128 x i8*]
%2 = alloca i32
%3 = getelementptr inbounds [128 x i8*], [128 x i8*]* %1, i64 0, i64 0
%4 = call i32 @backtrace(i8** %3, i32 128)
store i32 %4, i32* %2
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [128 x i8*], [128 x i8*]* %1, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @backtrace_symbols_fd(i8** %7, i32 %8, i32 2)
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"<ofchecker> : *** Start backtrace ***\0A\00"
@.str.1 = [40 x i8] c"<ofchecker> : *** End backtrace ***\0A\00"
define void @ofc_bt() {
%1 = alloca [128 x i8*]
%2 = bitcast [128 x i8*]* %1 to i8*
%3 = getelementptr inbounds [128 x i8*], [128 x i8*]* %1, i64 0, i64 0
%4 = call i32 @backtrace(i8** %3, i32 128)
%5 = load i32, i32* @stderr
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @backtrace_symbols_fd(i8** %3, i32 %4, i32 2)
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
ret void
}