#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 main(int argc, char *argv[]) {
  if (fork() == 0) {
    printf("child1 hello\n");
  } else if (fork() == 0) {
    printf("child2 hello\n");
  }
  printf("hello\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <fork@plt>
cmp    $0x0,%rax
jne    1158 <main+0x38>
lea    0xeb2(%rip),%rdi
call   1030 <printf@plt>
jmp    117a <main+0x5a>
mov    $0x0,%al
call   1040 <fork@plt>
cmp    $0x0,%rax
jne    1175 <main+0x55>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
jmp    117a <main+0x5a>
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
je     1142 <main+0x22>
xor    %eax,%eax
call   1040 <fork@plt>
test   %rax,%rax
jne    114e <main+0x2e>
lea    0xec0(%rip),%rdi
jmp    1149 <main+0x29>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"child1 hello\0A\00"
@.str.1 = [14 x i8] c"child2 hello\0A\00"
@.str.2 = [7 x i8] c"hello\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %16
10: ; preds = %2
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
br label %16
16: ; preds = %15, %8
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@str = [6 x i8] c"hello\00"
@str.3 = [13 x i8] c"child2 hello\00"
@str.4 = [13 x i8] c"child1 hello\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5, %2
%9 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0), %2 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0), %5 ]
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
br label %11
11: ; preds = %8, %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}