#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 main(void) {
  pid_t pid;
  printf("\n");
  printf("\nHallo, I am on the way to fork now, ......lo");
  pid = fork();
  switch (pid) {
  case -1:
    perror("Could not fork");
    break;
  case 0:
    printf("ok: I am the child\n");
    break;
  default:
    printf("ok: I am the parent\n");
    break;
  }
  printf("\nclear ?\n\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xf19(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xffffffff,%eax
je     1195 <main+0x55>
jmp    1185 <main+0x45>
mov    -0xc(%rbp),%eax
test   %eax,%eax
je     11a6 <main+0x66>
jmp    11b7 <main+0x77>
lea    0xe92(%rip),%rdi
call   1040 <perror@plt>
jmp    11c3 <main+0x83>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
jmp    11c3 <main+0x83>
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe8e(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
jne    11a2 <main+0x42>
lea    0xea4(%rip),%rdi
call   1060 <perror@plt>
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
test   %eax,%eax
jne    11af <main+0x4f>
lea    0xe90(%rip),%rdi
jmp    11b6 <main+0x56>
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
jmp    118f <main+0x2f>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [46 x i8] c"\0AHallo, I am on the way to fork now, ......lo\00"
@.str.2 = [15 x i8] c"Could not fork\00"
@.str.3 = [20 x i8] c"ok: I am the child\0A\00"
@.str.4 = [21 x i8] c"ok: I am the parent\0A\00"
@.str.5 = [11 x i8] c"\0Aclear ?\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
switch i32 %6, label %11 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %13
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %11, %9, %7
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [46 x i8] c"\0AHallo, I am on the way to fork now, ......lo\00"
@.str.2 = [15 x i8] c"Could not fork\00"
@str = [19 x i8] c"ok: I am the child\00"
@str.6 = [10 x i8] c"\0Aclear ?\0A\00"
@str.7 = [20 x i8] c"ok: I am the parent\00"
define i32 @main() {
%1 = tail call i32 @putchar(i32 10)
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (...) @fork()
switch i32 %3, label %8 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %10
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
br label %10
10: ; preds = %8, %6, %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
}