#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 /*<<< orphan*/ LOG_ERR;
size_t backtrace(void **, int);
char **backtrace_symbols(void **, size_t);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
void pfpanic_show_stacktrace(unsigned short _syslog) {
  void *buffer[10];
  size_t buffer_size;
  char **symbols;
  buffer_size = backtrace(buffer, 10);
  symbols = backtrace_symbols(buffer, buffer_size);
  for (size_t i = 0; i < buffer_size; i++)
    if (_syslog)
      syslog(LOG_ERR, "%s\n", symbols[i]);
    else
      printf("%s\n", symbols[i]);
  free(symbols);
}


x86 assembly (clang, -O0):
<pfpanic_show_stacktrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    11fa <pfpanic_show_stacktrace+0xaa>
cmpw   $0x0,-0x2(%rbp)
je     11cc <pfpanic_show_stacktrace+0x7c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe3e(%rip),%rsi
call   1070 <syslog@plt>
jmp    11e4 <pfpanic_show_stacktrace+0x94>
mov    -0x70(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe21(%rip),%rdi
call   1060 <printf@plt>
jmp    11e9 <pfpanic_show_stacktrace+0x99>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    118d <pfpanic_show_stacktrace+0x3d>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfpanic_show_stacktrace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edi,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,%rbp
test   %r12,%r12
je     11cf <pfpanic_show_stacktrace+0x7f>
xor    %ebx,%ebx
lea    0xe70(%rip),%r15
mov    0x2e41(%rip),%r13
jmp    11b6 <pfpanic_show_stacktrace+0x66>
nopl   0x0(%rax)
mov    0x0(%rbp,%rbx,8),%rsi
mov    %r15,%rdi
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     11cf <pfpanic_show_stacktrace+0x7f>
test   %r14w,%r14w
je     11a0 <pfpanic_show_stacktrace+0x50>
mov    0x0(%r13),%edi
mov    0x0(%rbp,%rbx,8),%rdx
mov    %r15,%rsi
call   1070 <syslog@plt>
jmp    11ad <pfpanic_show_stacktrace+0x5d>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @pfpanic_show_stacktrace(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca [10 x i8*]
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i64
store i16 %0, i16* %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
store i64 0, i64* %6
br label %12
12: ; preds = %33, %1
%13 = load i64, i64* %6
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = load i16, i16* %2
%18 = icmp ne i16 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* @LOG_ERR
%21 = load i8**, i8*** %5
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @syslog(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %32
26: ; preds = %16
%27 = load i8**, i8*** %5
%28 = load i64, i64* %6
%29 = getelementptr inbounds i8*, i8** %27, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %26, %19
br label %33
33: ; preds = %32
%34 = load i64, i64* %6
%35 = add i64 %34, 1
store i64 %35, i64* %6
br label %12
36: ; preds = %12
%37 = load i8**, i8*** %5
%38 = call i32 @free(i8** %37)
ret void
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @pfpanic_show_stacktrace(i16 zeroext %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 = icmp eq i64 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = icmp eq i16 %0, 0
br label %12
10: ; preds = %23, %1
%11 = call i32 @free(i8** %6)
ret void
12: ; preds = %8, %23
%13 = phi i64 [ 0, %8 ], [ %24, %23 ]
br i1 %9, label %19, label %14
14: ; preds = %12
%15 = load i32, i32* @LOG_ERR
%16 = getelementptr inbounds i8*, i8** %6, i64 %13
%17 = load i8*, i8** %16
%18 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %23
19: ; preds = %12
%20 = getelementptr inbounds i8*, i8** %6, i64 %13
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %14, %19
%24 = add nuw i64 %13, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %10, label %12
}