#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*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t pid = fork();
  if (!pid) {
    printf("We're the new server process!\n");
    sleep(30);
  } else if (pid == -1) {
    printf("Fork failed :(\n");
    perror("fork");
  } else {
    printf("We're the parent\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    118e <main+0x3e>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1e,%edi
call   1060 <sleep@plt>
jmp    11cd <main+0x7d>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b5 <main+0x65>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
lea    0xe84(%rip),%rdi
call   1040 <perror@plt>
jmp    11c8 <main+0x78>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11cd <main+0x7d>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    1176 <main+0x26>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1e,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
pop    %rcx
ret
cmp    $0xffffffff,%eax
jne    1195 <main+0x45>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe72(%rip),%rdi
call   1040 <perror@plt>
jmp    1172 <main+0x22>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"We're the new server process!\0A\00"
@.str.1 = [16 x i8] c"Fork failed :(\0A\00"
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [18 x i8] c"We're the parent\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @sleep(i32 30)
br label %19
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %18
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %12
br label %19
19: ; preds = %18, %6
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"fork\00"
@str = [30 x i8] c"We're the new server process!\00"
@str.4 = [17 x i8] c"We're the parent\00"
@str.5 = [15 x i8] c"Fork failed :(\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %8 [
i32 0, label %2
i32 -1, label %5
]
2: ; preds = %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @sleep(i32 30)
br label %11
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %5, %2
ret i32 0
}