#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 */

/* Variables and functions */
int /*<<< orphan*/ execv(char *, char **);
int fork();
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int args, char *argc[]) {
  char *currentPath = "./";
  char *lsPath = "/bin/ls";
  char *argv[] = {lsPath, currentPath, NULL};
  int childNum = 1;
  int childArray[childNum];
  childArray[0] = fork();
  if (childArray[0] == 0) {
    execv(lsPath, argv);
  } else {
    wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,(%rax)
jne    11cc <main+0x9c>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <execv@plt>
jmp    11d5 <main+0xa5>
xor    %eax,%eax
mov    %eax,%edi
call   1030 <wait@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%rbx
lea    0xec4(%rip),%rax
mov    %rax,(%rsp)
lea    0xeb6(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     116c <main+0x3c>
xor    %edi,%edi
call   1030 <wait@plt>
jmp    117b <main+0x4b>
lea    0xe90(%rip),%rdi
mov    %rsp,%rsi
call   1040 <execv@plt>
mov    %rbx,%rsp
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"./\00"
@.str.1 = [8 x i8] c"/bin/ls\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8*]
%4 = bitcast [3 x i8*]* %3 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %7
%8 = tail call i8* @llvm.stacksave()
%9 = tail call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %5)
br label %15
13: ; preds = %2
%14 = tail call i32 @wait(i32* null)
br label %15
15: ; preds = %13, %11
ret i32 0
}