#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*/ SIGKILL;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int pipes[2];
  pipe(pipes);
  int child = fork();
  if (child == 0) {
    close(pipes[0]);
    printf("Waiting to be killed\n");
    write(pipes[1], "R", 1);
    sleep(30);
    exit(0);
  }
  close(pipes[1]);
  char c;
  read(pipes[0], &c, 1);
  kill(child, SIGKILL);
  while (wait(NULL) > 0)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1205 <main+0x65>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe2c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x1e,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    -0x10(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
cmp    $0x0,%rax
jle    1247 <main+0xa7>
jmp    122f <main+0x8f>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1204 <main+0x64>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1080 <kill@plt>
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   10b0 <wait@plt>
test   %rax,%rax
jg     11f0 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%edi
call   1050 <close@plt>
lea    0xdee(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0xddc(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    $0x1e,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Waiting to be killed\0A\00"
@.str.1 = [2 x i8] c"R\00"
@SIGKILL = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%18 = call i32 @sleep(i32 30)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @read(i32 %25, i8* %4, i32 1)
%27 = load i32, i32* %3
%28 = load i32, i32* @SIGKILL
%29 = call i32 @kill(i32 %27, i32 %28)
br label %30
30: ; preds = %33, %20
%31 = call i64 @wait(i32* null)
%32 = icmp sgt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
br label %30
34: ; preds = %30
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"R\00"
@SIGKILL = global i32 0
@str = [21 x i8] c"Waiting to be killed\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i8
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %0
%9 = load i32, i32* %4
%10 = call i32 @close(i32 %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%15 = call i32 @sleep(i32 30)
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @read(i32 %21, i8* %2, i32 1)
%23 = load i32, i32* @SIGKILL
%24 = call i32 @kill(i32 %6, i32 %23)
br label %25
25: ; preds = %25, %17
%26 = call i64 @wait(i32* null)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %25, label %28
28: ; preds = %25
ret i32 0
}