#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recurse(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ waitpid(int, int *, int);
int main(int argc, char **argv) {
  int pid = fork();
  if (pid > 0) {
    int result;
    waitpid(pid, &result, 0x0);
    printf("Testing stack...\t\t\t\t\t\t\t");
    if (result != 5)
      printf("[FAIL]\n");
    else
      printf("[ OK ]\n");
  } else if (pid == 0) {
    recurse(10, NULL);
    exit(5);
  } else {
    printf("Fork failed!\n");
    exit(1);
  }
  pid = fork();
  if (pid > 0) {
    int result;
    waitpid(pid, &result, 0x0);
    printf("Massive stack test...\t\t\t\t\t\t\t");
    if (result != 5)
      printf("[FAIL]  %d\n", result);
    else
      printf("[ OK ]\n");
  } else if (pid == 0) {
    recurse(2000, NULL);
    exit(5);
  } else {
    printf("Fork failed!\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11c6 <main+0x76>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x5,-0x18(%rbp)
je     11b3 <main+0x63>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c1 <main+0x71>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1200 <main+0xb0>
cmpl   $0x0,-0x14(%rbp)
jne    11e8 <main+0x98>
mov    $0xa,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <recurse@plt>
mov    $0x5,%edi
call   1060 <exit@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1263 <main+0x113>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x5,-0x1c(%rbp)
je     1250 <main+0x100>
mov    -0x1c(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125e <main+0x10e>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129d <main+0x14d>
cmpl   $0x0,-0x14(%rbp)
jne    1285 <main+0x135>
mov    $0x7d0,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <recurse@plt>
mov    $0x5,%edi
call   1060 <exit@plt>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jle    11e4 <main+0x84>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x5,0x4(%rsp)
lea    0xeba(%rip),%rax
lea    0xeba(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jle    11ed <main+0x8d>
mov    %rsp,%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%esi
cmp    $0x5,%esi
jne    121b <main+0xbb>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jne    1205 <main+0xa5>
mov    $0xa,%edi
jmp    11f4 <main+0x94>
jne    1205 <main+0xa5>
mov    $0x7d0,%edi
xor    %esi,%esi
call   1030 <recurse@plt>
mov    $0x5,%edi
call   1070 <exit@plt>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Testing stack...\09\09\09\09\09\09\09\00"
@.str.1 = [8 x i8] c"[FAIL]\0A\00"
@.str.2 = [8 x i8] c"[ OK ]\0A\00"
@.str.3 = [14 x i8] c"Fork failed!\0A\00"
@.str.4 = [29 x i8] c"Massive stack test...\09\09\09\09\09\09\09\00"
@.str.5 = [12 x i8] c"[FAIL] %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = load i32, i32* %6
%14 = call i32 @waitpid(i32 %13, i32* %7, i32 0)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 5
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %12
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
br label %32
23: ; preds = %2
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @recurse(i32 10, i32* null)
%28 = call i32 @exit(i32 5)
unreachable
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %22
%33 = call i32 (...) @fork()
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32, i32* %6
%38 = call i32 @waitpid(i32 %37, i32* %8, i32 0)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 5
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %47
45: ; preds = %36
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
br label %57
48: ; preds = %32
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @recurse(i32 2000, i32* null)
%53 = call i32 @exit(i32 5)
unreachable
54: ; preds = %48
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %47
%58 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [24 x i8] c"Testing stack...\09\09\09\09\09\09\09\00"
@.str.4 = [29 x i8] c"Massive stack test...\09\09\09\09\09\09\09\00"
@.str.5 = [12 x i8] c"[FAIL] %d\0A\00"
@str.7 = [13 x i8] c"Fork failed!\00"
@str.8 = [7 x i8] c"[ OK ]\00"
@str.9 = [7 x i8] c"[FAIL]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 (...) @fork()
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = bitcast i32* %3 to i8*
%9 = call i32 @waitpid(i32 %5, i32* %3, i32 0)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 5
%13 = select i1 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0)
%14 = call i32 @puts(i8* dereferenceable(1) %13)
%15 = call i32 (...) @fork()
%16 = icmp sgt i32 %15, 0
br i1 %16, label %25, label %37
17: ; preds = %2
%18 = icmp eq i32 %5, 0
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = tail call i32 @recurse(i32 10, i32* null)
%21 = tail call i32 @exit(i32 5)
unreachable
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %7
%26 = bitcast i32* %4 to i8*
%27 = call i32 @waitpid(i32 %15, i32* %4, i32 0)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 5
br i1 %30, label %33, label %31
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %29)
br label %35
33: ; preds = %25
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.8, i64 0, i64 0))
br label %35
35: ; preds = %33, %31
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %7
%38 = icmp eq i32 %15, 0
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = call i32 @recurse(i32 2000, i32* null)
%41 = call i32 @exit(i32 5)
unreachable
42: ; preds = %37
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
}