#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 */
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int *);
void fork9() {
  int child_status;
  if (fork() == 0) {
    printf("HC: hello from child\n");
  } else {
    printf("HP: hello from parent\n");
    wait(&child_status);
    printf("CT: child has terminated\n");
  }
  printf("Bye\n");
}


x86 assembly (clang, -O0):
<fork9>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <fork@plt>
cmp    $0x0,%rax
jne    115a <fork9+0x2a>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
jmp    117b <fork9+0x4b>
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1040 <wait@plt>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork9>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
je     115c <fork9+0x2c>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1040 <wait@plt>
lea    0xebc(%rip),%rdi
jmp    1163 <fork9+0x33>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [22 x i8] c"HC: hello from child\0A\00"
@.str.1 = [23 x i8] c"HP: hello from parent\0A\00"
@.str.2 = [26 x i8] c"CT: child has terminated\0A\00"
@.str.3 = [5 x i8] c"Bye\0A\00"
define void @fork9() {
%1 = alloca i32
%2 = call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %10
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @wait(i32* %1)
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %6, %4
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@str = [22 x i8] c"HP: hello from parent\00"
@str.4 = [25 x i8] c"CT: child has terminated\00"
@str.5 = [4 x i8] c"Bye\00"
@str.6 = [21 x i8] c"HC: hello from child\00"
define void @fork9() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
br label %11
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%9 = call i32 @wait(i32* %1)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
br label %11
11: ; preds = %7, %5
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.5, i64 0, i64 0))
ret void
}