#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 errno;
scalar_t__ execl(char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  pid_t pid;
  if ((pid = fork()) < 0) {
    fprintf(stderr, "fork error\n");
  } else if (pid == 0) {
    if (execl("/Users/James/_projects/class_systemProgramming_2016/"
              "lecture_sysprog/05_process/codes/testinterp",
              "testinterp", "myarg1", "MY ARG2", (char *)0) < 0)
      fprintf(stderr, "execl error (%d)\n", errno);
  }
  if (waitpid(pid, NULL, 0) < 0)
    fprintf(stderr, "waitpid error\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1197 <main+0x47>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11fc <main+0xac>
cmpq   $0x0,-0x18(%rbp)
jne    11f7 <main+0xa7>
lea    0xe63(%rip),%rdi
lea    0xeb1(%rip),%rsi
lea    0xeb5(%rip),%rdx
lea    0xeb5(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <execl@plt>
cmp    $0x0,%rax
jge    11f2 <main+0xa2>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11f7 <main+0xa7>
jmp    11fc <main+0xac>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    122c <main+0xdc>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1179 <main+0x29>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11c4 <main+0x74>
jne    11c4 <main+0x74>
lea    0xe8a(%rip),%rdi
lea    0xed8(%rip),%rsi
lea    0xedc(%rip),%rdx
lea    0xedc(%rip),%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
test   %rax,%rax
jns    11c4 <main+0x74>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
lea    0xebe(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
jns    11ec <main+0x9c>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"fork error\0A\00"
@.str.1 = [96 x i8] c"/Users/James/_projects/class_systemProgramming_2016/lecture_sysprog/05_process/codes/testinterp\00"
@.str.2 = [11 x i8] c"testinterp\00"
@.str.3 = [7 x i8] c"myarg1\00"
@.str.4 = [8 x i8] c"MY ARG2\00"
@.str.5 = [18 x i8] c"execl error (%d)\0A\00"
@errno = global i32 0
@.str.6 = [15 x i8] c"waitpid error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %24
12: ; preds = %2
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = call i64 @execl(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15
br label %23
23: ; preds = %22, %12
br label %24
24: ; preds = %23, %9
%25 = load i64, i64* %6
%26 = call i64 @waitpid(i64 %25, i32* null, i32 0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %28, %24
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"fork error\0A\00"
@.str.1 = [96 x i8] c"/Users/James/_projects/class_systemProgramming_2016/lecture_sysprog/05_process/codes/testinterp\00"
@.str.2 = [11 x i8] c"testinterp\00"
@.str.3 = [7 x i8] c"myarg1\00"
@.str.4 = [8 x i8] c"MY ARG2\00"
@.str.5 = [18 x i8] c"execl error (%d)\0A\00"
@errno = global i32 0
@.str.6 = [15 x i8] c"waitpid error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
8: ; preds = %2
%9 = icmp eq i64 %3, 0
br i1 %9, label %10, label %17
10: ; preds = %8
%11 = tail call i64 @execl(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* null)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %8, %13, %10, %5
%18 = tail call i64 @waitpid(i64 %3, i32* null, i32 0)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %20, %17
%24 = tail call i32 @exit(i32 0)
unreachable
}