#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait();
int main(void) {
  int forkRes;
  pid_t proccessID;
  forkRes = fork();
  if (forkRes == 0) {
    printf("Child proccess says hi! My process ID is: %d My"
           " "
           "parents process ID is: %d\n",
           getpid(), getppid());
  } else if (forkRes == -1) {
    printf("Something went wrong...\n");
    exit(-1);
  } else {
    printf("Parent proccess says hi! My process ID is: %d My child's process"
           " "
           "ID is: %d My parent is: %d\n",
           getpid(), forkRes, getppid());
    wait();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11ac <main+0x4c>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1207 <main+0xa7>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ce <main+0x6e>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <wait@plt>
jmp    1207 <main+0xa7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11b2 <main+0x42>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11dd <main+0x6d>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xeaf(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <wait@plt>
jmp    11d4 <main+0x64>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe37(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [75 x i8] c"Child proccess says hi! My process ID is: %d My parents process ID is: %d\0A\00"
@.str.1 = [25 x i8] c"Something went wrong...\0A\00"
@.str.2 = [93 x i8] c"Parent proccess says hi! My process ID is: %d My child's process ID is: %d My parent is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 (...) @getpid()
%9 = call i32 (...) @getppid()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
br label %24
11: ; preds = %0
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %11
%18 = call i32 (...) @getpid()
%19 = load i32, i32* %2
%20 = call i32 (...) @getppid()
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
%22 = call i32 (...) @wait()
br label %23
23: ; preds = %17
br label %24
24: ; preds = %23, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [75 x i8] c"Child proccess says hi! My process ID is: %d My parents process ID is: %d\0A\00"
@.str.2 = [93 x i8] c"Parent proccess says hi! My process ID is: %d My child's process ID is: %d My parent is: %d\0A\00"
@str = [24 x i8] c"Something went wrong...\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %9 [
i32 0, label %2
i32 -1, label %6
]
2: ; preds = %0
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (...) @getppid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
br label %14
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (...) @getppid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %1, i32 %11)
%13 = tail call i32 (...) @wait()
br label %14
14: ; preds = %9, %2
ret i32 0
}