#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*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[], char *envp[]) {
  pid_t pid;
  if (argc != 2) {
    printf("usage: %s dirname\n", argv[0]);
    exit(1);
  }
  pid = fork();
  if (pid > 0) {
    printf("My child is going to execute command \"ls -laR %s\"\n", argv[1]);
    wait(NULL);
  } else if (pid == 0) {
    execlp("ls", "ls -laR", argv[1], NULL);
    printf("Command not executed !\n");
    exit(1);
  }
  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    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11cd <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
jmp    1214 <main+0xc4>
cmpq   $0x0,-0x20(%rbp)
jne    120f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5f(%rip),%rdi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <execlp@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    1214 <main+0xc4>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1195 <main+0x35>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jle    11b0 <main+0x50>
mov    0x8(%rbx),%rsi
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    (%rbx),%rsi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jne    11e1 <main+0x81>
mov    0x8(%rbx),%rdx
lea    0xe89(%rip),%rdi
lea    0xe85(%rip),%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"usage: %s dirname\0A\00"
@.str.1 = [51 x i8] c"My child is going to execute command \22ls -laR %s\22\0A\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [8 x i8] c"ls -laR\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
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = call i64 (...) @fork()
store i64 %18, i64* %8
%19 = load i64, i64* %8
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i8**, i8*** %6
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @wait(i32* null)
br label %38
27: ; preds = %17
%28 = load i64, i64* %8
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i8**, i8*** %6
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %33, i32* null)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
br label %38
38: ; preds = %37, %21
%39 = call i32 @exit(i32 0)
unreachable
}

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