#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ TELL_CHILD(int);
int /*<<< orphan*/ TELL_PARENT(int /*<<< orphan*/);
int /*<<< orphan*/ TELL_WAIT();
int /*<<< orphan*/ WAIT_CHILD();
int /*<<< orphan*/ WAIT_PARENT();
int /*<<< orphan*/ dealloc_data();
int /*<<< orphan*/ eat_mem();
int /*<<< orphan*/ eat_mem_no_exit();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ handle_COW();
int /*<<< orphan*/ print_sysinfo();
int /*<<< orphan*/ set_sbrk_num(int /*<<< orphan*/);
int /*<<< orphan*/ unix_error(char *);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  pid_t pid;
  print_sysinfo();
  set_sbrk_num(0);
  eat_mem();
START:
  pid = fork();
  pid = pid < 0 ? -1 : pid;
  switch (pid) {
  case -1:
    if (!dealloc_data())
      unix_error("SBRK(-incr) FROM DEALLOC_DATA() FAILED. FATAL!!!");
    goto LAST_CONDITION;
  case 0:
    if (!handle_COW()) {
      print_sysinfo();
      exit(0);
    }
    goto START;
  default:
    if (waitpid(-1, NULL, 0) != pid)
      unix_error("WAIT_PID FAILED. FATAL!!!");
    exit(0);
  }
LAST_CONDITION:
  TELL_WAIT();
  pid = fork();
  pid = pid < 0 ? -1 : pid;
  switch (pid) {
  case -1:
    unix_error("FORK FAILED.");
  case 0:
    eat_mem_no_exit();
    WAIT_PARENT();
    print_sysinfo();
    TELL_PARENT(getppid());
    exit(0);
  default:
    eat_mem_no_exit();
    TELL_CHILD(pid);
    WAIT_CHILD();
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <print_sysinfo@plt>
xor    %edi,%edi
call   1090 <set_sbrk_num@plt>
mov    $0x0,%al
call   10c0 <eat_mem@plt>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    124c <main+0x4c>
mov    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1252 <main+0x52>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     127c <main+0x7c>
jmp    126c <main+0x6c>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     129d <main+0x9d>
jmp    12c0 <main+0xc0>
mov    $0x0,%al
call   1110 <dealloc_data@plt>
cmp    $0x0,%eax
jne    1298 <main+0x98>
lea    0xd6d(%rip),%rdi
call   10b0 <unix_error@plt>
jmp    12ec <main+0xec>
mov    $0x0,%al
call   1040 <handle_COW@plt>
cmp    $0x0,%eax
jne    12bb <main+0xbb>
mov    $0x0,%al
call   1060 <print_sysinfo@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    122b <main+0x2b>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
cmp    -0x14(%rbp),%eax
je     12e5 <main+0xe5>
lea    0xd51(%rip),%rdi
call   10b0 <unix_error@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   10a0 <TELL_WAIT@plt>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1314 <main+0x114>
mov    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    131a <main+0x11a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xffffffff,%eax
je     1344 <main+0x144>
jmp    1334 <main+0x134>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     1350 <main+0x150>
jmp    137a <main+0x17a>
lea    0xd00(%rip),%rdi
call   10b0 <unix_error@plt>
mov    $0x0,%al
call   1080 <eat_mem_no_exit@plt>
mov    $0x0,%al
call   1100 <WAIT_PARENT@plt>
mov    $0x0,%al
call   1060 <print_sysinfo@plt>
mov    $0x0,%al
call   10e0 <getppid@plt>
mov    %eax,%edi
call   1070 <TELL_PARENT@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   1080 <eat_mem_no_exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <TELL_CHILD@plt>
mov    $0x0,%al
call   1030 <WAIT_CHILD@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <print_sysinfo@plt>
xor    %edi,%edi
call   1090 <set_sbrk_num@plt>
xor    %eax,%eax
call   10c0 <eat_mem@plt>
mov    $0xffffffff,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1120 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
cmovs  %ebp,%ebx
test   %ebx,%ebx
jne    124b <main+0x4b>
xor    %eax,%eax
call   1040 <handle_COW@plt>
test   %eax,%eax
jne    1220 <main+0x20>
xor    %eax,%eax
call   1060 <print_sysinfo@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
cmp    $0xffffffff,%ebx
jne    12be <main+0xbe>
xor    %eax,%eax
call   1110 <dealloc_data@plt>
test   %eax,%eax
jne    1267 <main+0x67>
lea    0xd9e(%rip),%rdi
call   10b0 <unix_error@plt>
xor    %eax,%eax
call   10a0 <TELL_WAIT@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
mov    $0xffffffff,%ebx
cmovns %eax,%ebx
test   %ebx,%ebx
je     1294 <main+0x94>
cmp    $0xffffffff,%ebx
jne    12e3 <main+0xe3>
lea    0xdbc(%rip),%rdi
call   10b0 <unix_error@plt>
xor    %eax,%eax
call   1080 <eat_mem_no_exit@plt>
xor    %eax,%eax
call   1100 <WAIT_PARENT@plt>
xor    %eax,%eax
call   1060 <print_sysinfo@plt>
xor    %eax,%eax
call   10e0 <getppid@plt>
mov    %eax,%edi
call   1070 <TELL_PARENT@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <waitpid@plt>
cmp    %ebx,%eax
je     12dc <main+0xdc>
lea    0xd5a(%rip),%rdi
call   10b0 <unix_error@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
xor    %eax,%eax
call   1080 <eat_mem_no_exit@plt>
mov    %ebx,%edi
call   1050 <TELL_CHILD@plt>
xor    %eax,%eax
call   1030 <WAIT_CHILD@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"SBRK(-incr) FROM DEALLOC_DATA() FAILED. FATAL!!!\00"
@.str.1 = [26 x i8] c"WAIT_PID FAILED. FATAL!!!\00"
@.str.2 = [13 x i8] c"FORK FAILED.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @print_sysinfo()
%8 = call i32 @set_sbrk_num(i32 0)
%9 = call i32 (...) @eat_mem()
br label %10
10: ; preds = %32, %2
%11 = call i32 (...) @fork()
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
br label %17
15: ; preds = %10
%16 = load i32, i32* %6
br label %17
17: ; preds = %15, %14
%18 = phi i32 [ -1, %14 ], [ %16, %15 ]
store i32 %18, i32* %6
%19 = load i32, i32* %6
switch i32 %19, label %33 [
i32 -1, label %20
i32 0, label %26
]
20: ; preds = %17
%21 = call i32 (...) @dealloc_data()
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @unix_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
br label %41
26: ; preds = %17
%27 = call i32 (...) @handle_COW()
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i32 (...) @print_sysinfo()
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %26
br label %10
33: ; preds = %17
%34 = call i32 @waitpid(i32 -1, i32* null, i32 0)
%35 = load i32, i32* %6
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @unix_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %25
%42 = call i32 (...) @TELL_WAIT()
%43 = call i32 (...) @fork()
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
br label %49
47: ; preds = %41
%48 = load i32, i32* %6
br label %49
49: ; preds = %47, %46
%50 = phi i32 [ -1, %46 ], [ %48, %47 ]
store i32 %50, i32* %6
%51 = load i32, i32* %6
switch i32 %51, label %61 [
i32 -1, label %52
i32 0, label %54
]
52: ; preds = %49
%53 = call i32 @unix_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %49, %52
%55 = call i32 (...) @eat_mem_no_exit()
%56 = call i32 (...) @WAIT_PARENT()
%57 = call i32 (...) @print_sysinfo()
%58 = call i32 (...) @getppid()
%59 = call i32 @TELL_PARENT(i32 %58)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %49
%62 = call i32 (...) @eat_mem_no_exit()
%63 = load i32, i32* %6
%64 = call i32 @TELL_CHILD(i32 %63)
%65 = call i32 (...) @WAIT_CHILD()
%66 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [49 x i8] c"SBRK(-incr) FROM DEALLOC_DATA() FAILED. FATAL!!!\00"
@.str.1 = [26 x i8] c"WAIT_PID FAILED. FATAL!!!\00"
@.str.2 = [13 x i8] c"FORK FAILED.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @print_sysinfo()
%4 = tail call i32 @set_sbrk_num(i32 0)
%5 = tail call i32 (...) @eat_mem()
br label %6
6: ; preds = %15, %2
%7 = tail call i32 (...) @fork()
%8 = icmp sgt i32 %7, -1
%9 = select i1 %8, i32 %7, i32 -1
switch i32 %9, label %21 [
i32 -1, label %10
i32 0, label %15
]
10: ; preds = %6
%11 = tail call i32 (...) @dealloc_data()
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = tail call i32 @unix_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %28
15: ; preds = %6
%16 = tail call i32 (...) @handle_COW()
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %15
%19 = tail call i32 (...) @print_sysinfo()
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %6
%22 = tail call i32 @waitpid(i32 -1, i32* null, i32 0)
%23 = icmp eq i32 %22, %9
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @unix_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %10, %13
%29 = tail call i32 (...) @TELL_WAIT()
%30 = tail call i32 (...) @fork()
%31 = icmp sgt i32 %30, -1
%32 = select i1 %31, i32 %30, i32 -1
switch i32 %32, label %42 [
i32 -1, label %33
i32 0, label %35
]
33: ; preds = %28
%34 = tail call i32 @unix_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %28, %33
%36 = tail call i32 (...) @eat_mem_no_exit()
%37 = tail call i32 (...) @WAIT_PARENT()
%38 = tail call i32 (...) @print_sysinfo()
%39 = tail call i32 (...) @getppid()
%40 = tail call i32 @TELL_PARENT(i32 %39)
%41 = tail call i32 @exit(i32 0)
unreachable
42: ; preds = %28
%43 = tail call i32 (...) @eat_mem_no_exit()
%44 = tail call i32 @TELL_CHILD(i32 %32)
%45 = tail call i32 (...) @WAIT_CHILD()
%46 = tail call i32 @exit(i32 0)
unreachable
}