#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*/ assert(int);
int errno;
int fork();
int kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char const *argv[]) {
  int pid, err;
  pid = fork();
  if (pid > 0) {
    err = kill(pid, SIGKILL);
    assert(err == -1);
    err = kill(pid, SIGKILL);
    assert(err == -1);
    wait(NULL);
  } else if (pid == 0) {
    printf("kill fail should prevent child sleep\n");
    sleep(5);
  }
  return errno;
}


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)
cmpl   $0x0,-0x14(%rbp)
jle    11e2 <main+0x82>
mov    -0x14(%rbp),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
jmp    1207 <main+0xa7>
cmpl   $0x0,-0x14(%rbp)
jne    1202 <main+0xa2>
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    1207 <main+0xa7>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jle    11b1 <main+0x51>
mov    %eax,%ebx
mov    0x2e60(%rip),%r14
mov    (%r14),%esi
mov    %eax,%edi
call   1050 <kill@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
mov    (%r14),%esi
mov    %ebx,%edi
call   1050 <kill@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
call   1070 <wait@plt>
jmp    11c9 <main+0x69>
jne    11c9 <main+0x69>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SIGKILL = global i32 0
@.str = [38 x i8] c"kill fail should prevent child sleep\0A\00"
@errno = global i32 0
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 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i32, i32* %6
%13 = load i32, i32* @SIGKILL
%14 = call i32 @kill(i32 %12, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %6
%20 = load i32, i32* @SIGKILL
%21 = call i32 @kill(i32 %19, i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @wait(i32* null)
br label %34
27: ; preds = %2
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @sleep(i32 5)
br label %33
33: ; preds = %30, %27
br label %34
34: ; preds = %33, %11
%35 = load i32, i32* @errno
ret i32 %35
}

LLVM IR (-O2):
@SIGKILL = global i32 0
@errno = global i32 0
@str = [37 x i8] c"kill fail should prevent child sleep\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = load i32, i32* @SIGKILL
%7 = tail call i32 @kill(i32 %3, i32 %6)
%8 = icmp eq i32 %7, -1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* @SIGKILL
%12 = tail call i32 @kill(i32 %3, i32 %11)
%13 = icmp eq i32 %12, -1
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i32 @wait(i32* null)
br label %22
17: ; preds = %2
%18 = icmp eq i32 %3, 0
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @sleep(i32 5)
br label %22
22: ; preds = %17, %19, %5
%23 = load i32, i32* @errno
ret i32 %23
}