#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 = 0;
  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);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    119c <main+0x3c>
lea    0xe6e(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11b6 <main+0x56>
cmpq   $0x0,-0x10(%rbp)
jne    11b1 <main+0x51>
mov    $0x7,%edi
call   1060 <exit@plt>
jmp    11b6 <main+0x56>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x10(%rbp),%rax
je     11d5 <main+0x75>
lea    0xe3b(%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    1203 <main+0xa3>
lea    0xe07(%rip),%rdi
call   1040 <err_sys@plt>
jmp    121a <main+0xba>
cmpq   $0x0,-0x10(%rbp)
jne    1215 <main+0xb5>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    121a <main+0xba>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x10(%rbp),%rax
je     1239 <main+0xd9>
lea    0xdd7(%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    1267 <main+0x107>
lea    0xda3(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1282 <main+0x122>
cmpq   $0x0,-0x10(%rbp)
jne    127d <main+0x11d>
mov    -0x14(%rbp),%eax
xor    %ecx,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    1282 <main+0x122>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x10(%rbp),%rax
je     12a1 <main+0x141>
lea    0xd6f(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    118a <main+0x2a>
lea    0xe7d(%rip),%rdi
call   1040 <err_sys@plt>
jmp    1196 <main+0x36>
jne    1196 <main+0x36>
mov    $0x7,%edi
call   1060 <exit@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     11b1 <main+0x51>
lea    0xe5f(%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    11d7 <main+0x77>
lea    0xe30(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11e0 <main+0x80>
jne    11e0 <main+0x80>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     11fb <main+0x9b>
lea    0xe15(%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    121f <main+0xbf>
lea    0xde6(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     123a <main+0xda>
lea    0xdd6(%rip),%rdi
call   1040 <err_sys@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fork error\00"
@.str.1 = [11 x i8] c"wait error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"fork error\00"
@.str.1 = [11 x i8] c"wait error\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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 ([11 x i8], [11 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)
%47 = call i32 @exit(i32 0)
unreachable
}