#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 fork();
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  printf("Hello. Before fork.\n");
  printf("Hello. Again, before fork.\n");
  int x = fork();
  char *hello = malloc(sizeof(char) * 10000);
  if (x == 0) {
    strcpy(hello, "child, baby.");
  } else {
    strcpy(hello, "parent.");
  }
  printf("Done with the %s\n", hello);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    $0x2710,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11a2 <main+0x62>
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11b2 <main+0x72>
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xecd(%rip),%rdi
call   1040 <puts@plt>
lea    0xed5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebp
mov    $0x2710,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
lea    0xe76(%rip),%rax
lea    0xe7c(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe71(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Hello. Before fork.\0A\00"
@.str.1 = [28 x i8] c"Hello. Again, before fork.\0A\00"
@.str.2 = [13 x i8] c"child, baby.\00"
@.str.3 = [8 x i8] c"parent.\00"
@.str.4 = [18 x i8] c"Done with the %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (...) @fork()
store i32 %6, i32* %2
%7 = call i8* @malloc(i32 10000)
store i8* %7, i8** %3
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %16
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
%17 = load i8*, i8** %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [13 x i8] c"child, baby.\00"
@.str.3 = [8 x i8] c"parent.\00"
@.str.4 = [18 x i8] c"Done with the %s\0A\00"
@str = [20 x i8] c"Hello. Before fork.\00"
@str.5 = [27 x i8] c"Hello. Again, before fork.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
%3 = tail call i32 (...) @fork()
%4 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%7 = tail call i32 @strcpy(i8* %4, i8* %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret i32 0
}