#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*/ EXIT_FAILURE;
int /*<<< orphan*/ STDERR_FILENO;
int backtrace(void **, int);
int /*<<< orphan*/ backtrace_symbols_fd(void **, int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
void handler(int sig) {
  void *buf[1000];
  int pts;
  pts = backtrace(buf, 1000);
  fprintf(stderr, "Signal: %d\n", sig);
  fprintf(stderr, "backtrace returned %d entries\n", pts);
  backtrace_symbols_fd(buf, pts, STDERR_FILENO);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f60,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x1f50(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <backtrace@plt>
mov    %eax,-0x1f54(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe88(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x1f54(%rbp),%edx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x1f50(%rbp),%rdi
mov    -0x1f54(%rbp),%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
call   1030 <backtrace_symbols_fd@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1f48,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1040 <backtrace@plt>
mov    %eax,%ebp
mov    0x2e78(%rip),%r15
mov    (%r15),%edi
lea    0xe8e(%rip),%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xe89(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <backtrace_symbols_fd@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"Signal: %d\0A\00"
@.str.1 = [31 x i8] c"backtrace returned %d entries\0A\00"
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define void @handler(i32 %0) {
%2 = alloca i32
%3 = alloca [1000 x i8*]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 0
%6 = call i32 @backtrace(i8** %5, i32 1000)
store i32 %6, i32* %4
%7 = load i32, i32* @stderr
%8 = load i32, i32* %2
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stderr
%11 = load i32, i32* %4
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 0
%14 = load i32, i32* %4
%15 = load i32, i32* @STDERR_FILENO
%16 = call i32 @backtrace_symbols_fd(i8** %13, i32 %14, i32 %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"Signal: %d\0A\00"
@.str.1 = [31 x i8] c"backtrace returned %d entries\0A\00"
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define void @handler(i32 %0) {
%2 = alloca [1000 x i8*]
%3 = bitcast [1000 x i8*]* %2 to i8*
%4 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %2, i64 0, i64 0
%5 = call i32 @backtrace(i8** %4, i32 1000)
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = load i32, i32* @STDERR_FILENO
%11 = call i32 @backtrace_symbols_fd(i8** %4, i32 %5, i32 %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
}