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

/* Variables and functions */
#define SIGABRT 131
#define SIGFPE 130
#define SIGPIPE 129
#define SIGTRAP 128
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ gettid();
int /*<<< orphan*/ have_siginfo(int);
int /*<<< orphan*/ log_signal_summary(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ send_debuggerd_packet(int /*<<< orphan*/ *);
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
int /*<<< orphan*/ tgkill(int /*<<< orphan*/, int /*<<< orphan*/, int);
void debuggerd_signal_handler(int signal_number, siginfo_t *info, void *p) {
  if (!have_siginfo(signal_number)) {
    info = NULL;
  }
  log_signal_summary(signal_number, info);
  send_debuggerd_packet(info);
  signal(signal_number, SIG_DFL);
  switch (signal_number) {
  case SIGABRT:
  case SIGFPE:
  case SIGPIPE:
  case SIGTRAP:
    tgkill(getpid(), gettid(), signal_number);
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<debuggerd_signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <have_siginfo@plt>
cmp    $0x0,%eax
jne    119c <debuggerd_signal_handler+0x2c>
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <log_signal_summary@plt>
mov    -0x10(%rbp),%rdi
call   1090 <send_debuggerd_packet@plt>
mov    -0x4(%rbp),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     11f9 <debuggerd_signal_handler+0x89>
jmp    11d6 <debuggerd_signal_handler+0x66>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <gettid@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
mov    -0x4(%rbp),%edx
call   1060 <tgkill@plt>
jmp    11fe <debuggerd_signal_handler+0x8e>
jmp    11fe <debuggerd_signal_handler+0x8e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debuggerd_signal_handler>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1050 <have_siginfo@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmove  %rcx,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <log_signal_summary@plt>
mov    %rbx,%rdi
call   1090 <send_debuggerd_packet@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <signal@plt>
mov    %ebp,%eax
and    $0xfffffffc,%eax
cmp    $0x80,%eax
jne    11d4 <debuggerd_signal_handler+0x64>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <gettid@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <tgkill@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIG_DFL = global i32 0
define void @debuggerd_signal_handler(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%7 = load i32, i32* %4
%8 = call i32 @have_siginfo(i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %3
store i32* null, i32** %5
br label %11
11: ; preds = %10, %3
%12 = load i32, i32* %4
%13 = load i32*, i32** %5
%14 = call i32 @log_signal_summary(i32 %12, i32* %13)
%15 = load i32*, i32** %5
%16 = call i32 @send_debuggerd_packet(i32* %15)
%17 = load i32, i32* %4
%18 = load i32, i32* @SIG_DFL
%19 = call i32 @signal(i32 %17, i32 %18)
%20 = load i32, i32* %4
switch i32 %20, label %26 [
i32 131, label %21
i32 130, label %21
i32 129, label %21
i32 128, label %21
]
21: ; preds = %11, %11, %11, %11
%22 = call i32 (...) @getpid()
%23 = call i32 (...) @gettid()
%24 = load i32, i32* %4
%25 = call i32 @tgkill(i32 %22, i32 %23, i32 %24)
br label %27
26: ; preds = %11
br label %27
27: ; preds = %26, %21
ret void
}

LLVM IR (-O2):
@SIG_DFL = global i32 0
define void @debuggerd_signal_handler(i32 %0, i32* %1, i8* nocapture readnone %2) {
%4 = tail call i32 @have_siginfo(i32 %0)
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i32* null, i32* %1
%7 = tail call i32 @log_signal_summary(i32 %0, i32* %6)
%8 = tail call i32 @send_debuggerd_packet(i32* %6)
%9 = load i32, i32* @SIG_DFL
%10 = tail call i32 @signal(i32 %0, i32 %9)
%11 = and i32 %0, -4
%12 = icmp eq i32 %11, 128
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 (...) @gettid()
%16 = tail call i32 @tgkill(i32 %14, i32 %15, i32 %0)
br label %17
17: ; preds = %3, %13
ret void
}