#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 /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  int pid = fork();
  if (pid > 0) {
    int status;
    wait(&status);
    write(STDOUT_FILENO, "friends!\n", 9);
  } else {
    int cpid = fork();
    if (cpid > 0) {
      int status;
      wait(&status);
      write(STDOUT_FILENO, "my ", 3);
    } else {
      write(STDOUT_FILENO, "Hello ", 6);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    117b <main+0x4b>
lea    -0xc(%rbp),%rdi
call   1040 <wait@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    $0x9,%edx
call   1030 <write@plt>
jmp    11d6 <main+0xa6>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11b7 <main+0x87>
lea    -0x14(%rbp),%rdi
call   1040 <wait@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
jmp    11d1 <main+0xa1>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
jmp    11d6 <main+0xa6>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jle    115d <main+0x2d>
lea    0x4(%rsp),%rdi
call   1040 <wait@plt>
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
mov    $0x9,%edx
jmp    119c <main+0x6c>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jle    1187 <main+0x57>
mov    %rsp,%rdi
call   1040 <wait@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x3,%edx
jmp    119c <main+0x6c>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [10 x i8] c"friends!\0A\00"
@.str.1 = [4 x i8] c"my \00"
@.str.2 = [7 x i8] c"Hello \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (...) @fork()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @wait(i32* %3)
%11 = load i32, i32* @STDOUT_FILENO
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9)
br label %25
13: ; preds = %0
%14 = call i32 (...) @fork()
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 @wait(i32* %5)
%19 = load i32, i32* @STDOUT_FILENO
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
br label %24
21: ; preds = %13
%22 = load i32, i32* @STDOUT_FILENO
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
br label %24
24: ; preds = %21, %17
br label %25
25: ; preds = %24, %9
%26 = load i32, i32* %1
ret i32 %26
}

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