#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*/ abort();
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ pr_exit(int);
scalar_t__ wait(int *);
int main(int argc, char *argv[]) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0) {
    err_sys("fork error");
  } else if (pid == 0) {
    exit(7);
  }
  if (wait(&status) != pid) {
    err_sys("wait error");
  }
  pr_exit(status);
  if ((pid = fork()) < 0) {
    err_sys("fork error");
  } else if (pid == 0) {
    abort();
  }
  if (wait(&status) != pid) {
    err_sys("wait error");
  }
  pr_exit(status);
  if ((pid = fork()) < 0) {
    err_sys("fork error");
  } else if (pid == 0) {
    status /= 0;
  }
  if (wait(&status) != pid) {
    err_sys("wait error");
  }
  pr_exit(status);
  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    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    119c <main+0x3c>
lea    0xe6e(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11b6 <main+0x56>
cmpq   $0x0,-0x18(%rbp)
jne    11b1 <main+0x51>
mov    $0x7,%edi
call   1060 <exit@plt>
jmp    11b6 <main+0x56>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     11d5 <main+0x75>
lea    0xe3b(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x1c(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1203 <main+0xa3>
lea    0xe07(%rip),%rdi
call   1040 <err_sys@plt>
jmp    121a <main+0xba>
cmpq   $0x0,-0x18(%rbp)
jne    1215 <main+0xb5>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    121a <main+0xba>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     1239 <main+0xd9>
lea    0xdd7(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x1c(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1267 <main+0x107>
lea    0xda3(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1282 <main+0x122>
cmpq   $0x0,-0x18(%rbp)
jne    127d <main+0x11d>
mov    -0x1c(%rbp),%eax
xor    %ecx,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    1282 <main+0x122>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     12a1 <main+0x141>
lea    0xd6f(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x1c(%rbp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1180 <main+0x20>
jne    118c <main+0x2c>
mov    $0x7,%edi
call   1060 <exit@plt>
lea    0xe79(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     11a7 <main+0x47>
lea    0xe69(%rip),%rdi
call   1040 <err_sys@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11c8 <main+0x68>
jne    11d4 <main+0x74>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe31(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     11ef <main+0x8f>
lea    0xe21(%rip),%rdi
call   1040 <err_sys@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1213 <main+0xb3>
lea    0xdf2(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     122e <main+0xce>
lea    0xde2(%rip),%rdi
call   1040 <err_sys@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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