#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int si_pid;
};
typedef TYPE_1__ siginfo_t;
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void sig_handler(int signo, siginfo_t *info, void *vp) {
  int killResult;
  pid_t signaler = info->si_pid;
  printf("Got signaled by %d\n", signaler);
  killResult = kill(signaler, SIGKILL);
  if (killResult < 0) {
    printf("Failed to kill %d, it was stronger than me..\n", signaler);
  } else {
    printf("Hey %d, don't signal me!\n", signaler);
  }
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117d <sig_handler+0x5d>
mov    -0x20(%rbp),%esi
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
jmp    118c <sig_handler+0x6c>
mov    -0x20(%rbp),%esi
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_handler>:
push   %rbx
mov    (%rsi),%ebx
lea    0xed6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <kill@plt>
test   %eax,%eax
lea    0xeca(%rip),%rax
lea    0xef1(%rip),%rdi
cmovs  %rax,%rdi
mov    %ebx,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@.str = [20 x i8] c"Got signaled by %d\0A\00"
@SIGKILL = global i32 0
@.str.1 = [46 x i8] c"Failed to kill %d, it was stronger than me..\0A\00"
@.str.2 = [26 x i8] c"Hey %d, don't signal me!\0A\00"
define void @sig_handler(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %8
%15 = load i32, i32* @SIGKILL
%16 = call i32 @kill(i32 %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* %8
%21 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %25
22: ; preds = %3
%23 = load i32, i32* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [20 x i8] c"Got signaled by %d\0A\00"
@SIGKILL = global i32 0
@.str.1 = [46 x i8] c"Failed to kill %d, it was stronger than me..\0A\00"
@.str.2 = [26 x i8] c"Hey %d, don't signal me!\0A\00"
define void @sig_handler(i32 %0, %struct.TYPE_3__* nocapture %1, i8* nocapture readnone %2) {
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @SIGKILL
%8 = tail call i32 @kill(i32 %5, i32 %7)
%9 = icmp slt i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0)
%11 = tail call i32 @printf(i8* %10, i32 %5)
ret void
}