#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*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ kill(int, int);
int /*<<< orphan*/ perror(char *);
int scanf(char *, int *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  int pid;
  if ((pid = fork()) < 0) {
    perror("Fail to fork");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    while (1)
      ;
  } else {
    int signum;
    while (scanf("%d", &signum) == 1) {
      kill(pid, signum);
      system("ps -aux | grep ./test_kill1");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11a3 <main+0x43>
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11b7 <main+0x57>
jmp    11b2 <main+0x52>
jmp    11b2 <main+0x52>
jmp    11bc <main+0x5c>
lea    0xe4a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11f1 <main+0x91>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <kill@plt>
lea    0xe29(%rip),%rdi
call   1030 <system@plt>
jmp    11bc <main+0x5c>
jmp    11f6 <main+0x96>
jmp    11fb <main+0x9b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
js     11e2 <main+0x82>
je     11e0 <main+0x80>
mov    %eax,%ebx
lea    0xe8f(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11c3 <main+0x63>
lea    0xe7c(%rip),%r14
lea    0xe72(%rip),%r15
lea    0x4(%rsp),%r12
mov    0x4(%rsp),%esi
mov    %ebx,%edi
call   1040 <kill@plt>
mov    %r14,%rdi
call   1030 <system@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     11a0 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jmp    11e0 <main+0x80>
lea    0xe17(%rip),%rdi
call   1060 <perror@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Fail to fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"ps -aux | grep ./test_kill1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
br label %18
18: ; preds = %17, %18
br label %18
19: ; preds = %14
br label %20
20: ; preds = %23, %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = call i32 @kill(i32 %24, i32 %25)
%27 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %20
28: ; preds = %20
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Fail to fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"ps -aux | grep ./test_kill1\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = icmp eq i32 %4, 0
br i1 %11, label %12, label %13
12: ; preds = %10, %12
br label %12
13: ; preds = %10
%14 = bitcast i32* %3 to i8*
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %13, %17
%18 = load i32, i32* %3
%19 = call i32 @kill(i32 %4, i32 %18)
%20 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = icmp eq i32 %21, 1
br i1 %22, label %17, label %23
23: ; preds = %17, %13
ret i32 0
}