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

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  pid_t pid;
  if ((pid = fork()) < 0) {
    err_sys("error on fork");
  } else if (pid != 0) {
    sleep(2);
    exit(2);
  }
  if ((pid = fork()) < 0) {
    err_sys("error on fork");
  } else if (pid != 0) {
    sleep(4);
    abort();
  }
  if ((pid = fork()) < 0) {
    err_sys("error on fork");
  } else if (pid != 0) {
    execl("/bin/dd", "dd", "if=/etc/termcap", "of=/dev/null", NULL);
    exit(7);
  }
  if ((pid = fork()) < 0) {
    err_sys("error on fork");
  } else if (pid != 0) {
    sleep(8);
    exit(0);
  }
  sleep(6);
  kill(getpid(), SIGKILL);
  exit(6);
}


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   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11bc <main+0x3c>
lea    0xe4e(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11e0 <main+0x60>
cmpq   $0x0,-0x18(%rbp)
je     11db <main+0x5b>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
jmp    11e0 <main+0x60>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1206 <main+0x86>
lea    0xe04(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1227 <main+0xa7>
cmpq   $0x0,-0x18(%rbp)
je     1222 <main+0xa2>
mov    $0x4,%edi
call   1090 <sleep@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1227 <main+0xa7>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    124d <main+0xcd>
lea    0xdbd(%rip),%rdi
call   1040 <err_sys@plt>
jmp    128d <main+0x10d>
cmpq   $0x0,-0x18(%rbp)
je     1288 <main+0x108>
lea    0xdaf(%rip),%rdi
lea    0xdad(%rip),%rsi
lea    0xda9(%rip),%rdx
lea    0xdb2(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <execl@plt>
mov    $0x7,%edi
call   1070 <exit@plt>
jmp    128d <main+0x10d>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    12b3 <main+0x133>
lea    0xd57(%rip),%rdi
call   1040 <err_sys@plt>
jmp    12d4 <main+0x154>
cmpq   $0x0,-0x18(%rbp)
je     12cf <main+0x14f>
mov    $0x8,%edi
call   1090 <sleep@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    12d4 <main+0x154>
mov    $0x6,%edi
call   1090 <sleep@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
mov    $0x6,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jns    119b <main+0x1b>
lea    0xe6c(%rip),%rdi
call   1040 <err_sys@plt>
jmp    119d <main+0x1d>
jne    11ef <main+0x6f>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jns    11b7 <main+0x37>
lea    0xe50(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11b9 <main+0x39>
jne    1230 <main+0xb0>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jns    11d3 <main+0x53>
lea    0xe34(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11d5 <main+0x55>
jne    1241 <main+0xc1>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jns    1203 <main+0x83>
lea    0xe18(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1205 <main+0x85>
mov    $0x2,%edi
call   1090 <sleep@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
jne    126f <main+0xef>
mov    $0x6,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    0x2dc3(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1060 <kill@plt>
mov    $0x6,%edi
call   1070 <exit@plt>
mov    $0x4,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xdc6(%rip),%rdi
lea    0xdc4(%rip),%rsi
lea    0xdc0(%rip),%rdx
lea    0xdc9(%rip),%rcx
xor    %r8d,%r8d
call   1080 <execl@plt>
mov    $0x7,%edi
call   1070 <exit@plt>
mov    $0x8,%edi
call   1090 <sleep@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"error on fork\00"
@.str.1 = [8 x i8] c"/bin/dd\00"
@.str.2 = [3 x i8] c"dd\00"
@.str.3 = [16 x i8] c"if=/etc/termcap\00"
@.str.4 = [13 x i8] c"of=/dev/null\00"
@SIGKILL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %2
%12 = load i64, i64* %6
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @sleep(i32 2)
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %11
br label %18
18: ; preds = %17, %9
%19 = call i64 (...) @fork()
store i64 %19, i64* %6
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %30
23: ; preds = %18
%24 = load i64, i64* %6
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @sleep(i32 4)
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %23
br label %30
30: ; preds = %29, %21
%31 = call i64 (...) @fork()
store i64 %31, i64* %6
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %42
35: ; preds = %30
%36 = load i64, i64* %6
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32* null)
%40 = call i32 @exit(i32 7)
unreachable
41: ; preds = %35
br label %42
42: ; preds = %41, %33
%43 = call i64 (...) @fork()
store i64 %43, i64* %6
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %54
47: ; preds = %42
%48 = load i64, i64* %6
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 @sleep(i32 8)
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %47
br label %54
54: ; preds = %53, %45
%55 = call i32 @sleep(i32 6)
%56 = call i32 (...) @getpid()
%57 = load i32, i32* @SIGKILL
%58 = call i32 @kill(i32 %56, i32 %57)
%59 = call i32 @exit(i32 6)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"error on fork\00"
@.str.1 = [8 x i8] c"/bin/dd\00"
@.str.2 = [3 x i8] c"dd\00"
@.str.3 = [16 x i8] c"if=/etc/termcap\00"
@.str.4 = [13 x i8] c"of=/dev/null\00"
@SIGKILL = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %2
%8 = icmp eq i64 %3, 0
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = tail call i32 @sleep(i32 2)
%11 = tail call i32 @exit(i32 2)
unreachable
12: ; preds = %7, %5
%13 = tail call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
17: ; preds = %12
%18 = icmp eq i64 %13, 0
br i1 %18, label %22, label %19
19: ; preds = %17
%20 = tail call i32 @sleep(i32 4)
%21 = tail call i32 (...) @abort()
unreachable
22: ; preds = %17, %15
%23 = tail call i64 (...) @fork()
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %32
27: ; preds = %22
%28 = icmp eq i64 %23, 0
br i1 %28, label %32, label %29
29: ; preds = %27
%30 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32* null)
%31 = tail call i32 @exit(i32 7)
unreachable
32: ; preds = %27, %25
%33 = tail call i64 (...) @fork()
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %42
37: ; preds = %32
%38 = icmp eq i64 %33, 0
br i1 %38, label %42, label %39
39: ; preds = %37
%40 = tail call i32 @sleep(i32 8)
%41 = tail call i32 @exit(i32 0)
unreachable
42: ; preds = %37, %35
%43 = tail call i32 @sleep(i32 6)
%44 = tail call i32 (...) @getpid()
%45 = load i32, i32* @SIGKILL
%46 = tail call i32 @kill(i32 %44, i32 %45)
%47 = tail call i32 @exit(i32 6)
unreachable
}