#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int *);
int main(void) {
  pid_t f;
  if ((f = fork()) < 0) {
    perror("Couldn't fork");
    exit(EXIT_FAILURE);
  }
  if (f == 0) {
    exit(EXIT_SUCCESS);
  } else {
    int status;
    wait(&status);
    pr_exit(status);
  }
  if ((f = fork()) < 0) {
    perror("Couldn't fork");
    exit(EXIT_FAILURE);
  }
  if (f == 0) {
    abort();
  } else {
    int status;
    wait(&status);
    pr_exit(status);
  }
  if ((f = fork()) < 0) {
    perror("Couldn't fork");
    exit(EXIT_FAILURE);
  }
  if (f == 0) {
    int a = 3;
    int b = 0;
    int c = a / b;
    printf("%d\n", c);
  } else {
    int status;
    wait(&status);
    pr_exit(status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    11ae <main+0x3e>
lea    0xe65(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11c7 <main+0x57>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x14(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1207 <main+0x97>
lea    0xe0c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1219 <main+0xa9>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x18(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x18(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1259 <main+0xe9>
lea    0xdba(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1290 <main+0x120>
movl   $0x3,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd88(%rip),%rdi
call   1040 <printf@plt>
jmp    12a1 <main+0x131>
lea    -0x28(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x28(%rbp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11f0 <main+0x80>
je     120a <main+0x9a>
lea    0x14(%rsp),%rdi
call   1080 <wait@plt>
mov    0x14(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11f0 <main+0x80>
je     1218 <main+0xa8>
lea    0x10(%rsp),%rdi
call   1080 <wait@plt>
mov    0x10(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11f0 <main+0x80>
je     11dd <main+0x6d>
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
jmp    11e9 <main+0x79>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe09(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

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