#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 EXIT_FAILURE;
int /*<<< orphan*/ LOG_NOTICE;
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
void signal_fault_handler(int sig) {
  int j, nptrs;
  void *buffer[100];
  char **strings;
  nptrs = backtrace(buffer, 100);
  syslog(LOG_NOTICE, "%s", "fault");
  strings = backtrace_symbols(buffer, nptrs);
  if (strings == NULL) {
    syslog(LOG_NOTICE, "fault: %s", "no symbols");
    exit(EXIT_FAILURE);
  }
  for (j = 0; j < nptrs; j++) {
    syslog(LOG_NOTICE, "%d: %s", j, strings[j]);
  }
  free(strings);
  exit(-1);
}


x86 assembly (clang, -O0):
<signal_fault_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x330(%rbp),%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
lea    0xe77(%rip),%rdx
mov    $0x0,%al
call   1060 <syslog@plt>
lea    -0x330(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x338(%rbp)
cmpq   $0x0,-0x338(%rbp)
jne    11e0 <signal_fault_handler+0x90>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
lea    0xe45(%rip),%rdx
mov    $0x0,%al
call   1060 <syslog@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122a <signal_fault_handler+0xda>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x338(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e7 <signal_fault_handler+0x97>
mov    -0x338(%rbp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<signal_fault_handler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x320,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebp
mov    0x2e60(%rip),%r15
mov    (%r15),%edi
lea    0xe9d(%rip),%rsi
lea    0xe77(%rip),%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
jne    11c5 <signal_fault_handler+0x75>
mov    (%r15),%edi
lea    0xe5d(%rip),%rsi
lea    0xe60(%rip),%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    11fc <signal_fault_handler+0xac>
mov    %ebp,%ebx
lea    0xe46(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    (%r12,%rbp,8),%rcx
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11e0 <signal_fault_handler+0x90>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@LOG_NOTICE = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"fault\00"
@.str.2 = [10 x i8] c"fault: %s\00"
@.str.3 = [11 x i8] c"no symbols\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [7 x i8] c"%d: %s\00"
define void @signal_fault_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8*]
%6 = alloca i8**
store i32 %0, i32* %2
%7 = getelementptr inbounds [100 x i8*], [100 x i8*]* %5, i64 0, i64 0
%8 = call i32 @backtrace(i8** %7, i32 100)
store i32 %8, i32* %4
%9 = load i32, i32* @LOG_NOTICE
%10 = call i32 (i32, i8*, ...) @syslog(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [100 x i8*], [100 x i8*]* %5, i64 0, i64 0
%12 = load i32, i32* %4
%13 = call i8** @backtrace_symbols(i8** %11, i32 %12)
store i8** %13, i8*** %6
%14 = load i8**, i8*** %6
%15 = icmp eq i8** %14, null
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i32, i32* @LOG_NOTICE
%18 = call i32 (i32, i8*, ...) @syslog(i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %1
store i32 0, i32* %3
br label %22
22: ; preds = %35, %21
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i32, i32* @LOG_NOTICE
%28 = load i32, i32* %3
%29 = load i8**, i8*** %6
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %28, i8* %33)
br label %35
35: ; preds = %26
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %22
38: ; preds = %22
%39 = load i8**, i8*** %6
%40 = call i32 @free(i8** %39)
%41 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@LOG_NOTICE = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"fault\00"
@.str.2 = [10 x i8] c"fault: %s\00"
@.str.3 = [11 x i8] c"no symbols\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [7 x i8] c"%d: %s\00"
define void @signal_fault_handler(i32 %0) {
%2 = alloca [100 x i8*]
%3 = bitcast [100 x i8*]* %2 to i8*
%4 = getelementptr inbounds [100 x i8*], [100 x i8*]* %2, i64 0, i64 0
%5 = call i32 @backtrace(i8** %4, i32 100)
%6 = load i32, i32* @LOG_NOTICE
%7 = call i32 (i32, i8*, ...) @syslog(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = call i8** @backtrace_symbols(i8** %4, i32 %5)
%9 = icmp eq i8** %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = icmp sgt i32 %5, 0
br i1 %11, label %12, label %28
12: ; preds = %10
%13 = zext i32 %5 to i64
br label %19
14: ; preds = %1
%15 = load i32, i32* @LOG_NOTICE
%16 = call i32 (i32, i8*, ...) @syslog(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12, %19
%20 = phi i64 [ 0, %12 ], [ %26, %19 ]
%21 = load i32, i32* @LOG_NOTICE
%22 = getelementptr inbounds i8*, i8** %8, i64 %20
%23 = load i8*, i8** %22
%24 = trunc i64 %20 to i32
%25 = call i32 (i32, i8*, ...) @syslog(i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %24, i8* %23)
%26 = add nuw nsw i64 %20, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %28, label %19
28: ; preds = %19, %10
%29 = call i32 @free(i8** %8)
%30 = call i32 @exit(i32 -1)
unreachable
}