#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(void) {
  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);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1195 <main+0x35>
lea    0xe75(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11af <main+0x4f>
cmpq   $0x0,-0x10(%rbp)
jne    11aa <main+0x4a>
mov    $0x7,%edi
call   1060 <exit@plt>
jmp    11af <main+0x4f>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x10(%rbp),%rax
je     11ce <main+0x6e>
lea    0xe43(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    11fc <main+0x9c>
lea    0xe0e(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1213 <main+0xb3>
cmpq   $0x0,-0x10(%rbp)
jne    120e <main+0xae>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1213 <main+0xb3>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x10(%rbp),%rax
je     1232 <main+0xd2>
lea    0xddf(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1260 <main+0x100>
lea    0xdaa(%rip),%rdi
call   1040 <err_sys@plt>
jmp    127b <main+0x11b>
cmpq   $0x0,-0x10(%rbp)
jne    1276 <main+0x116>
mov    -0x14(%rbp),%eax
xor    %ecx,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    127b <main+0x11b>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x10(%rbp),%rax
je     129a <main+0x13a>
lea    0xd77(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
mov    -0x4(%rbp),%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    0xe6a(%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    0xe22(%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    0xde3(%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 = [12 x i8] c"fork error.\00"
@.str.1 = [12 x i8] c"wait error.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @exit(i32 7)
unreachable
13: ; preds = %8
br label %14
14: ; preds = %13, %6
%15 = call i64 @wait(i32* %3)
%16 = load i64, i64* %2
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %3
%22 = call i32 @pr_exit(i32 %21)
%23 = call i64 (...) @fork()
store i64 %23, i64* %2
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %33
27: ; preds = %20
%28 = load i64, i64* %2
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %27
br label %33
33: ; preds = %32, %25
%34 = call i64 @wait(i32* %3)
%35 = load i64, i64* %2
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = load i32, i32* %3
%41 = call i32 @pr_exit(i32 %40)
%42 = call i64 (...) @fork()
store i64 %42, i64* %2
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %53
46: ; preds = %39
%47 = load i64, i64* %2
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %3
%51 = sdiv i32 %50, 0
store i32 %51, i32* %3
br label %52
52: ; preds = %49, %46
br label %53
53: ; preds = %52, %44
%54 = call i64 @wait(i32* %3)
%55 = load i64, i64* %2
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i32, i32* %3
%61 = call i32 @pr_exit(i32 %60)
%62 = load i32, i32* %1
ret i32 %62
}

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