#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*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pre_exit(int);
scalar_t__ wait(int *);
int main(void) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0)
    perror("fork");
  else if (pid == 0)
    exit(7);
  if (wait(&status) != pid)
    perror("wait");
  pre_exit(status);
  if ((pid = fork()) < 0)
    perror("fork");
  else if (pid == 0)
    abort();
  if (wait(&status) != pid)
    perror("wait");
  pre_exit(status);
  if ((pid = fork()) < 0)
    perror("fork");
  else if (pid == 0)
    status /= 0;
  if (wait(&status) != pid)
    perror("wait");
  pre_exit(status);
  return 0;
}


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   1050 <perror@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    0xe3c(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <pre_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   1050 <perror@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    0xdd8(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <pre_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   1050 <perror@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    0xd70(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <pre_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     11ee <main+0x8e>
je     1248 <main+0xe8>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
jne    11ff <main+0x9f>
mov    0xc(%rsp),%edi
call   1040 <pre_exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     1210 <main+0xb0>
je     1252 <main+0xf2>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
jne    121e <main+0xbe>
mov    0xc(%rsp),%edi
call   1040 <pre_exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     122c <main+0xcc>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
jne    123a <main+0xda>
mov    0xc(%rsp),%edi
call   1040 <pre_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
call   1050 <perror@plt>
jmp    117a <main+0x1a>
lea    0xdff(%rip),%rdi
call   1050 <perror@plt>
jmp    1189 <main+0x29>
lea    0xde9(%rip),%rdi
call   1050 <perror@plt>
jmp    11a7 <main+0x47>
lea    0xde0(%rip),%rdi
call   1050 <perror@plt>
jmp    11b6 <main+0x56>
lea    0xdcd(%rip),%rdi
call   1050 <perror@plt>
jmp    11ce <main+0x6e>
lea    0xdc4(%rip),%rdi
call   1050 <perror@plt>
jmp    11dd <main+0x7d>
mov    $0x7,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [5 x i8] c"wait\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 @perror(i8* getelementptr inbounds ([5 x i8], [5 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 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %3
%22 = call i32 @pre_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 @perror(i8* getelementptr inbounds ([5 x i8], [5 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 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = load i32, i32* %3
%41 = call i32 @pre_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 @perror(i8* getelementptr inbounds ([5 x i8], [5 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 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i32, i32* %3
%61 = call i32 @pre_exit(i32 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [5 x i8] c"wait\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 @perror(i8* getelementptr inbounds ([5 x i8], [5 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 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* %1
%18 = call i32 @pre_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 @perror(i8* getelementptr inbounds ([5 x i8], [5 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 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = load i32, i32* %1
%34 = call i32 @pre_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 @perror(i8* getelementptr inbounds ([5 x i8], [5 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 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = load i32, i32* %1
%46 = call i32 @pre_exit(i32 %45)
ret i32 0
}