#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t child_pid;
  char *program = "pwd";
  char *arg_list[] = {"pwd", NULL};
  child_pid = fork();
  printf("The fork return is %5d, PID is %5d, PPID is %5d\n", child_pid,
         getpid(), getppid());
  if (child_pid > 0) {
    sleep(60);
  } else {
    execvp(program, arg_list);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2c7f(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c7c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11ee <main+0x7e>
mov    $0x3c,%edi
call   1080 <sleep@plt>
jmp    1202 <main+0x92>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <execvp@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movaps 0x2c93(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <printf@plt>
test   %ebx,%ebx
jle    11c3 <main+0x53>
mov    $0x3c,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe36(%rip),%rdi
mov    %rsp,%rsi
call   1050 <execvp@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"pwd\00"
@__const.main.arg_list = [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [49 x i8] c"The fork return is %5d, PID is %5d, PPID is %5d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i8*]
store i32 0, i32* %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = bitcast [2 x i8*]* %4 to i8*
%6 = call i32 (...) @fork()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 (...) @getpid()
%9 = call i32 (...) @getppid()
%10 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8, i32 %9)
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @sleep(i32 60)
br label %20
15: ; preds = %0
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
%18 = call i32 @execvp(i8* %16, i8** %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"pwd\00"
@__const.main.arg_list = [2 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [49 x i8] c"The fork return is %5d, PID is %5d, PPID is %5d\0A\00"
define i32 @main() {
%1 = alloca [2 x i8*]
%2 = bitcast [2 x i8*]* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %4, i32 %5)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @sleep(i32 60)
ret i32 0
10: ; preds = %0
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 0
%12 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %11)
%13 = call i32 @exit(i32 0)
unreachable
}