#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ PR_SET_PDEATHSIG;
int /*<<< orphan*/ SIGKILL;
int getpid();
int getppid();
int kill(int, int /*<<< orphan*/);
int prctl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
          int /*<<< orphan*/, int /*<<< orphan*/);
int set_death_signal(void) {
  int ret;
  pid_t ppid;
  ret = prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
  ppid = getppid();
  if (ppid == 1) {
    pid_t self;
    self = getpid();
    ret = kill(self, SIGKILL);
  }
  if (ret < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<set_death_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <prctl@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    119d <set_death_signal+0x5d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11b3 <set_death_signal+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <set_death_signal+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_death_signal>:
push   %r14
push   %rbx
push   %rax
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e84(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <prctl@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
cmp    $0x1,%eax
jne    1184 <set_death_signal+0x44>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    (%r14),%esi
mov    %eax,%edi
call   1050 <kill@plt>
mov    %eax,%ebx
sar    $0x1f,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@PR_SET_PDEATHSIG = global i32 0
@SIGKILL = global i32 0
define i32 @set_death_signal() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @PR_SET_PDEATHSIG
%6 = load i32, i32* @SIGKILL
%7 = call i32 @prctl(i32 %5, i32 %6, i32 0, i32 0, i32 0)
store i32 %7, i32* %2
%8 = call i32 (...) @getppid()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = call i32 (...) @getpid()
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = load i32, i32* @SIGKILL
%15 = call i32 @kill(i32 %13, i32 %14)
store i32 %15, i32* %2
br label %16
16: ; preds = %11, %0
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %1
br label %21
20: ; preds = %16
store i32 0, i32* %1
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@PR_SET_PDEATHSIG = global i32 0
@SIGKILL = global i32 0
define i32 @set_death_signal() {
%1 = load i32, i32* @PR_SET_PDEATHSIG
%2 = load i32, i32* @SIGKILL
%3 = tail call i32 @prctl(i32 %1, i32 %2, i32 0, i32 0, i32 0)
%4 = tail call i32 (...) @getppid()
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 (...) @getpid()
%8 = load i32, i32* @SIGKILL
%9 = tail call i32 @kill(i32 %7, i32 %8)
br label %10
10: ; preds = %6, %0
%11 = phi i32 [ %9, %6 ], [ %3, %0 ]
%12 = ashr i32 %11, 31
ret i32 %12
}