#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*/ printf(char *, ...);
void makeZombie() {
  pid_t pid = fork();
  if (pid == 0) {
    printf("Hello from child, will be zombie soon... NEED BRAINS!, MUST EAT "
           "BRAINS!... UH I MEAN CPU CYCLES!\n");
    _exit(0);
  } else if (pid == -1) {
    printf("Error when creating chiled process, good riddance, heard the last "
           "one was a zombie\n");
  } else if (pid > 0) {
    printf("Hello from parent, my child PID is %i, it has been asking for a "
           "lot of brains lately...\n",
           pid);
  }
}


x86 assembly (clang, -O0):
<makeZombie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1161 <makeZombie+0x31>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0x4(%rbp)
jne    117e <makeZombie+0x4e>
lea    0xef0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119e <makeZombie+0x6e>
cmpl   $0x0,-0x4(%rbp)
jle    1199 <makeZombie+0x69>
mov    -0x4(%rbp),%esi
lea    0xf24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119e <makeZombie+0x6e>
jmp    11a3 <makeZombie+0x73>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeZombie>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     1164 <makeZombie+0x24>
test   %eax,%eax
je     1173 <makeZombie+0x33>
jle    1171 <makeZombie+0x31>
lea    0xea6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rcx
jmp    1050 <printf@plt>
lea    0xeee(%rip),%rdi
pop    %rax
jmp    1040 <puts@plt>
pop    %rax
ret
lea    0xf32(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [98 x i8] c"Hello from child, will be zombie soon... NEED BRAINS!, MUST EAT BRAINS!... UH I MEAN CPU CYCLES!\0A\00"
@.str.1 = [84 x i8] c"Error when creating chiled process, good riddance, heard the last one was a zombie\0A\00"
@.str.2 = [89 x i8] c"Hello from parent, my child PID is %i, it has been asking for a lot of brains lately...\0A\00"
define void @makeZombie() {
%1 = alloca i32
%2 = call i32 (...) @fork()
store i32 %2, i32* %1
%3 = load i32, i32* %1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @_exit(i32 0)
unreachable
8: ; preds = %0
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0))
br label %20
13: ; preds = %8
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19, %11
br label %21
21: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str.2 = [89 x i8] c"Hello from parent, my child PID is %i, it has been asking for a lot of brains lately...\0A\00"
@str = [83 x i8] c"Error when creating chiled process, good riddance, heard the last one was a zombie\00"
@str.3 = [97 x i8] c"Hello from child, will be zombie soon... NEED BRAINS!, MUST EAT BRAINS!... UH I MEAN CPU CYCLES!\00"
define void @makeZombie() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %7 [
i32 0, label %2
i32 -1, label %5
]
2: ; preds = %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([97 x i8], [97 x i8]* @str.3, i64 0, i64 0))
%4 = tail call i32 @_exit(i32 0)
unreachable
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str, i64 0, i64 0))
br label %11
7: ; preds = %0
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %11
11: ; preds = %5, %9, %7
ret void
}