#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  write(1, "Hello, I'm parent!", 18);
  pid_t child = fork();
  assert(child >= 0);
  if (child == 0) {
    write(1, "Hello from child!", 17);
  } else {
    printf("Hello again from the parent! My child is %d\n", child);
    int status;
    wait(&status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
lea    0xe8e(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11bf <main+0x6f>
mov    $0x1,%edi
lea    0xe63(%rip),%rsi
mov    $0x11,%edx
call   1030 <write@plt>
jmp    11d8 <main+0x88>
mov    -0x18(%rbp),%rsi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rsi
mov    $0x1,%edi
mov    $0x12,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1050 <assert@plt>
test   %rbx,%rbx
je     11a4 <main+0x54>
lea    0xe95(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
jmp    11ba <main+0x6a>
lea    0xe68(%rip),%rsi
mov    $0x1,%edi
mov    $0x11,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Hello, I'm parent!\00"
@.str.1 = [18 x i8] c"Hello from child!\00"
@.str.2 = [45 x i8] c"Hello again from the parent! My child is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 18)
%9 = call i64 (...) @fork()
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp sge i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %6
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @write(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 17)
br label %22
18: ; preds = %2
%19 = load i64, i64* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = call i32 @wait(i32* %7)
br label %22
22: ; preds = %18, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Hello, I'm parent!\00"
@.str.1 = [18 x i8] c"Hello from child!\00"
@.str.2 = [45 x i8] c"Hello again from the parent! My child is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 18)
%5 = tail call i64 (...) @fork()
%6 = lshr i64 %5, 63
%7 = trunc i64 %6 to i32
%8 = xor i32 %7, 1
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i64 %5, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 17)
br label %17
13: ; preds = %2
%14 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%15 = bitcast i32* %3 to i8*
%16 = call i32 @wait(i32* %3)
br label %17
17: ; preds = %13, %11
ret i32 0
}