#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 /*<<< orphan*/ STDOUT_FILENO;
int fork();
int getppid();
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  int pid = fork();
  if (pid > 0) {
    write(STDOUT_FILENO, "Hello ", 6);
  } else {
    int myparent = getppid();
    while (myparent == getppid()) {
      usleep(10);
    }
    write(STDOUT_FILENO, "World!\n", 7);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1182 <main+0x42>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
jmp    11cf <main+0x8f>
mov    $0x0,%al
call   1040 <getppid@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getppid@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jne    11b5 <main+0x75>
mov    $0xa,%edi
call   1060 <usleep@plt>
jmp    118c <main+0x4c>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jle    1163 <main+0x23>
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    $0x6,%edx
jmp    119c <main+0x5c>
xor    %eax,%eax
call   1040 <getppid@plt>
mov    %eax,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getppid@plt>
cmp    %eax,%ebx
jne    1187 <main+0x47>
mov    $0xa,%edi
call   1060 <usleep@plt>
jmp    1170 <main+0x30>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [7 x i8] c"Hello \00"
@.str.1 = [8 x i8] c"World!\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 sgt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @write(i32 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
br label %21
10: ; preds = %0
%11 = call i32 (...) @getppid()
store i32 %11, i32* %3
br label %12
12: ; preds = %16, %10
%13 = load i32, i32* %3
%14 = call i32 (...) @getppid()
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @usleep(i32 10)
br label %12
18: ; preds = %12
%19 = load i32, i32* @STDOUT_FILENO
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
br label %21
21: ; preds = %18, %7
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [7 x i8] c"Hello \00"
@.str.1 = [8 x i8] c"World!\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @STDOUT_FILENO
%5 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
br label %17
6: ; preds = %0
%7 = tail call i32 (...) @getppid()
%8 = tail call i32 (...) @getppid()
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %6, %10
%11 = tail call i32 @usleep(i32 10)
%12 = tail call i32 (...) @getppid()
%13 = icmp eq i32 %7, %12
br i1 %13, label %10, label %14
14: ; preds = %10, %6
%15 = load i32, i32* @STDOUT_FILENO
%16 = tail call i32 @write(i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
br label %17
17: ; preds = %14, %3
ret i32 0
}