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

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
size_t backtrace(void **, int);
scalar_t__ backtrace_symbols(void **, size_t);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void crash_sig(int signum) {
  void *array[10];
  size_t size;
  char **strings;
  size_t i;
  signal(signum, SIG_DFL);
  size = backtrace(array, sizeof(array) / sizeof(void *));
  strings = (char **)backtrace_symbols(array, size);
  for (i = 0; i < size; ++i) {
    fprintf(stderr, "%s\n", strings[i]);
  }
  free(strings);
  exit(1);
}


x86 assembly (clang, -O0):
<crash_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
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    11ea <crash_sig+0x8a>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    11aa <crash_sig+0x4a>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<crash_sig>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1060 <signal@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <backtrace@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <backtrace_symbols@plt>
mov    %rax,%r12
test   %r14,%r14
je     11d9 <crash_sig+0x79>
xor    %ebx,%ebx
mov    0x2e36(%rip),%r13
lea    0xe4f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    (%r12,%rbx,8),%rdx
mov    %r15,%rsi
call   1070 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11c0 <crash_sig+0x60>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@SIG_DFL = global i32 0
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @crash_sig(i32 %0) {
%2 = alloca [10 x i8*]
%3 = bitcast [10 x i8*]* %2 to i8*
%4 = load i32, i32* @SIG_DFL
%5 = tail call i32 @signal(i32 %0, i32 %4)
%6 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 0
%7 = call i64 @backtrace(i8** %6, i32 10)
%8 = call i64 @backtrace_symbols(i8** %6, i64 %7)
%9 = inttoptr i64 %8 to i8**
%10 = icmp eq i64 %7, 0
br i1 %10, label %19, label %11
11: ; preds = %1, %11
%12 = phi i64 [ %17, %11 ], [ 0, %1 ]
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds i8*, i8** %9, 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 i64 %12, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %19, label %11
19: ; preds = %11, %1
%20 = call i32 @free(i8** %9)
%21 = call i32 @exit(i32 1)
unreachable
}