#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*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  pid_t pid = fork();
  printf("PID of child is %d: \n", pid);
  if (pid == 0) {
    execvp(argv[1], argv + 1);
    printf("Error in child: %d\n", errno);
    fflush(stdout);
    _exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11c8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <execvp@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebp
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
test   %ebp,%ebp
je     117a <main+0x2a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1060 <execvp@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"PID of child is %d: \0A\00"
@.str.1 = [20 x i8] c"Error in child: %d\0A\00"
@errno = global i32 0
@stdout = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = call i32 @execvp(i8* %14, i8** %16)
%18 = load i32, i32* @errno
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @_exit(i32 %22)
unreachable
24: ; preds = %2
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"PID of child is %d: \0A\00"
@.str.1 = [20 x i8] c"Error in child: %d\0A\00"
@errno = global i32 0
@stdout = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (...) @fork()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %3, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @execvp(i8* %8, i8** %7)
%10 = load i32, i32* @errno
%11 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @stdout
%13 = tail call i32 @fflush(i32 %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @_exit(i32 %14)
unreachable
16: ; preds = %2
ret i32 0
}