#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 */
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ stderr;
void sysapi_stack_trace(void) {
  int j, nptrs;
  void *buffer[200];
  char **strings;
  nptrs = backtrace(buffer, 200);
  strings = backtrace_symbols(buffer, nptrs);
  if (!strings)
    return;
  for (j = 0; j < nptrs; j++)
    fprintf(stderr, "%s\n", strings[j]);
  free(strings);
}


x86 assembly (clang, -O0):
<sysapi_stack_trace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
lea    -0x650(%rbp),%rdi
mov    $0xc8,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x8(%rbp)
lea    -0x650(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x658(%rbp)
cmpq   $0x0,-0x658(%rbp)
jne    1188 <sysapi_stack_trace+0x48>
jmp    11d9 <sysapi_stack_trace+0x99>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cd <sysapi_stack_trace+0x8d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x658(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe46(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118f <sysapi_stack_trace+0x4f>
mov    -0x658(%rbp),%rdi
call   1030 <free@plt>
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysapi_stack_trace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x640,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc8,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     11b1 <sysapi_stack_trace+0x71>
mov    %rax,%r15
test   %ebp,%ebp
jle    11a9 <sysapi_stack_trace+0x69>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    0x2e5e(%rip),%r12
lea    0xe77(%rip),%r14
nopl   0x0(%rax)
mov    (%r12),%edi
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <sysapi_stack_trace+0x50>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x640,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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