#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*/ STDOUT_FILENO;
scalar_t__ fork();
int getppid();
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  pid_t pid = fork();
  if (pid > 0) {
    write(STDOUT_FILENO, "Hello ", strlen("Hello "));
  } else {
    while (getppid() != 1) {
    }
    pid_t pid1 = fork();
    if (pid1 > 0) {
      write(STDOUT_FILENO, "my ", strlen("my "));
    } else {
      while (getppid() != 1) {
      }
      write(STDOUT_FILENO, "friends!\n", strlen("friends!\n"));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    119a <main+0x5a>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xe81(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe70(%rip),%rsi
call   1030 <write@plt>
jmp    1240 <main+0x100>
jmp    119f <main+0x5f>
mov    $0x0,%al
call   1050 <getppid@plt>
cmp    $0x1,%eax
je     11b4 <main+0x74>
jmp    119f <main+0x5f>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11f8 <main+0xb8>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    0xe2a(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
lea    0xe19(%rip),%rsi
call   1030 <write@plt>
jmp    123b <main+0xfb>
jmp    11fd <main+0xbd>
mov    $0x0,%al
call   1050 <getppid@plt>
cmp    $0x1,%eax
je     1212 <main+0xd2>
jmp    11fd <main+0xbd>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    0xde6(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
lea    0xdd5(%rip),%rsi
call   1030 <write@plt>
jmp    1240 <main+0x100>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jle    1160 <main+0x20>
lea    0xeaa(%rip),%rbx
jmp    119c <main+0x5c>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getppid@plt>
cmp    $0x1,%eax
jne    1160 <main+0x20>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jle    1181 <main+0x41>
lea    0xe88(%rip),%rbx
jmp    119c <main+0x5c>
lea    0xe83(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getppid@plt>
cmp    $0x1,%eax
jne    1190 <main+0x50>
mov    0x2e4d(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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