#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*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[], char *envp[]) {
  pid_t pid;
  if (argc != 2) {
    printf("usage: %s <dirname>\n", argv[0]);
    exit(1);
  }
  char *args[] = {"ls", "-laR", argv[1], NULL};
  pid = fork();
  if (pid > 0)
    printf("My child is going to execute command \"%s %s %s\"\n", args[0],
           args[1], args[2]);
  else if (pid == 0) {
    execvp("ls", args);
    printf("Command not executed !\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1183 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe8b(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11e2 <main+0xa2>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <main+0xda>
cmpq   $0x0,-0x20(%rbp)
jne    1215 <main+0xd5>
lea    -0x40(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1040 <execvp@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    121a <main+0xda>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x2,%edi
jne    11b5 <main+0x65>
lea    0xeb4(%rip),%rax
mov    %rax,(%rsp)
lea    0xeac(%rip),%rax
mov    %rax,0x8(%rsp)
mov    0x8(%rsi),%rbx
mov    %rbx,0x10(%rsp)
movq   $0x0,0x18(%rsp)
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    11d0 <main+0x80>
lea    0xe87(%rip),%rdi
lea    0xe78(%rip),%rsi
lea    0xe74(%rip),%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    (%rsi),%rsi
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jne    11f7 <main+0xa7>
lea    0xe3c(%rip),%rdi
mov    %rsp,%rsi
call   1050 <execvp@plt>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"usage: %s <dirname>\0A\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [5 x i8] c"-laR\00"
@.str.3 = [49 x i8] c"My child is going to execute command \22%s %s %s\22\0A\00"
@.str.4 = [24 x i8] c"Command not executed !\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca [4 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8**, i8*** %6
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %21
%25 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* null, i8** %25
%26 = call i64 (...) @fork()
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %18
%30 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
%31 = load i8*, i8** %30
%32 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %33, i8* %35)
br label %46
37: ; preds = %18
%38 = load i64, i64* %8
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 0
%42 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %37
br label %46
46: ; preds = %45, %29
%47 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [21 x i8] c"usage: %s <dirname>\0A\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [5 x i8] c"-laR\00"
@.str.3 = [49 x i8] c"My child is going to execute command \22%s %s %s\22\0A\00"
@str = [23 x i8] c"Command not executed !\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca [4 x i8*]
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = bitcast [4 x i8*]* %4 to i8*
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %14
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 3
store i8* null, i8** %17
%18 = tail call i64 (...) @fork()
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %28
22: ; preds = %10
%23 = icmp eq i64 %18, 0
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %12)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22, %20
%29 = tail call i32 @exit(i32 0)
unreachable
}