#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 fork();
int /*<<< orphan*/ printf(char *);
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 return...\t\t\t\t\t\t\t");
    if (result != 5)
      printf("[FAIL]\n");
    else
      printf("[ OK ]\n");
  } else if (pid == 0) {
    return 5;
  } else {
    printf("Fork failed!\n");
    return 1;
  }
  return 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   1050 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11a0 <main+0x70>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x5,-0x18(%rbp)
je     118f <main+0x5f>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    119b <main+0x6b>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
jmp    11ce <main+0x9e>
cmpl   $0x0,-0x14(%rbp)
jne    11b6 <main+0x86>
movl   $0x5,-0x4(%rbp)
jmp    11d5 <main+0xa5>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <main+0xa5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jle    118a <main+0x4a>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x5,0xc(%rsp)
lea    0xeae(%rip),%rax
lea    0xeae(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
jmp    11a4 <main+0x64>
je     119f <main+0x5f>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11a4 <main+0x64>
mov    $0x5,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Testing return...\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"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = load i32, i32* %6
%13 = call i32 @waitpid(i32 %12, i32* %7, i32 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 5
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %11
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
br label %28
22: ; preds = %2
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 5, i32* %3
br label %29
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %29
28: ; preds = %21
store i32 0, i32* %3
br label %29
29: ; preds = %28, %26, %25
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [25 x i8] c"Testing return...\09\09\09\09\09\09\09\00"
@str = [13 x i8] c"Fork failed!\00"
@str.4 = [7 x i8] c"[ OK ]\00"
@str.5 = [7 x i8] c"[FAIL]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @fork()
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = bitcast i32* %3 to i8*
%8 = call i32 @waitpid(i32 %4, i32* %3, i32 0)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 5
%12 = select i1 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.5, i64 0, i64 0)
%13 = call i32 @puts(i8* dereferenceable(1) %12)
br label %18
14: ; preds = %2
%15 = icmp eq i32 %4, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %14, %6, %16
%19 = phi i32 [ 0, %6 ], [ 1, %16 ], [ 5, %14 ]
ret i32 %19
}