#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*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "Fork Failed");
    exit(-1);
  } else if (pid == 0) {
    execlp("/bin/ls", "ls", NULL);
  }
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "Fork Failed");
    exit(-1);
  } else if (pid == 0) {
    execlp("/bin/pwd", "pwd", NULL);
  } else {
    wait(NULL);
    printf("Child Complete\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11a4 <main+0x44>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11c6 <main+0x66>
lea    0xe56(%rip),%rdi
lea    0xe54(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
jmp    11cb <main+0x6b>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1200 <main+0xa0>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1227 <main+0xc7>
lea    0xe02(%rip),%rdi
lea    0xe00(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
jmp    1243 <main+0xe3>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
lea    0xde6(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    1248 <main+0xe8>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11ab <main+0x4b>
jne    1184 <main+0x24>
lea    0xe96(%rip),%rdi
lea    0xe94(%rip),%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11ab <main+0x4b>
jne    11ca <main+0x6a>
lea    0xe7b(%rip),%rdi
lea    0xe79(%rip),%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"Fork Failed\00"
@.str.1 = [8 x i8] c"/bin/ls\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [9 x i8] c"/bin/pwd\00"
@.str.4 = [4 x i8] c"pwd\00"
@.str.5 = [16 x i8] c"Child Complete\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = load i64, i64* %2
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %15
15: ; preds = %13, %10
br label %16
16: ; preds = %15
%17 = call i64 (...) @fork()
store i64 %17, i64* %2
%18 = load i64, i64* %2
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
%25 = load i64, i64* %2
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @execlp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* null)
br label %33
29: ; preds = %24
%30 = call i32 @wait(i32* null)
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %27
br label %34
34: ; preds = %33
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"Fork Failed\00"
@.str.1 = [8 x i8] c"/bin/ls\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [9 x i8] c"/bin/pwd\00"
@.str.4 = [4 x i8] c"pwd\00"
@str = [15 x i8] c"Child Complete\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = icmp eq i64 %1, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %11
11: ; preds = %7, %9
%12 = tail call i64 (...) @fork()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
%19 = icmp eq i64 %12, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = tail call i32 @execlp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* null)
ret i32 0
22: ; preds = %18
%23 = tail call i32 @wait(i32* null)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 0)
unreachable
}