#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 WEXITSTATUS(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  if (argc != 2) {
    printf("usage: %s dirname\n", argv[0]);
    exit(1);
  }
  pid_t pid = fork();
  if (pid > 0) {
    printf("My child is going to execute command \"ls -laR %s\"\n", argv[1]);
    int status;
    waitpid(pid, &status, 0);
    if (WIFSIGNALED(status) != 0) {
      printf("Command was killed with signal: %d\n", WTERMSIG(status));
    } else {
      printf("Command exited with code: %d\n", WEXITSTATUS(status));
    }
  } else if (pid == 0) {
    execlp("ls", "ls", "-laR", argv[1]);
    printf("Command not executed !\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    124a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    -0x24(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     122d <main+0xad>
mov    -0x24(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1245 <main+0xc5>
mov    -0x24(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1290 <main+0x110>
cmpq   $0x0,-0x20(%rbp)
jne    128b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe24(%rip),%rsi
lea    0xe20(%rip),%rdx
mov    %rsi,%rdi
call   1090 <execlp@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1290 <main+0x110>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ec <main+0x5c>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jle    1207 <main+0x77>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1050 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
jne    1239 <main+0xa9>
call   1070 <WEXITSTATUS@plt>
lea    0xe80(%rip),%rdi
jmp    1245 <main+0xb5>
mov    (%rbx),%rsi
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jne    124e <main+0xbe>
mov    0x8(%rbx),%rcx
lea    0xe74(%rip),%rdi
lea    0xe70(%rip),%rdx
mov    %rdi,%rsi
call   10a0 <execlp@plt>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
call   1060 <WTERMSIG@plt>
lea    0xe01(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <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 = [36 x i8] c"Command was killed with signal: %d\0A\00"
@.str.3 = [30 x i8] c"Command exited with code: %d\0A\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [5 x i8] c"-laR\00"
@.str.6 = [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 i32
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 ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = call i64 (...) @fork()
store i64 %19, i64* %8
%20 = load i64, i64* %8
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %41
22: ; preds = %18
%23 = load i8**, i8*** %6
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i64, i64* %8
%28 = call i32 @waitpid(i64 %27, i32* %9, i32 0)
%29 = load i32, i32* %9
%30 = call i64 @WIFSIGNALED(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %22
%33 = load i32, i32* %9
%34 = call i32 @WTERMSIG(i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %40
36: ; preds = %22
%37 = load i32, i32* %9
%38 = call i32 @WEXITSTATUS(i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %36, %32
br label %52
41: ; preds = %18
%42 = load i64, i64* %8
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i8**, i8*** %6
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
br label %52
52: ; preds = %51, %40
%53 = 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 = [36 x i8] c"Command was killed with signal: %d\0A\00"
@.str.3 = [30 x i8] c"Command exited with code: %d\0A\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [5 x i8] c"-laR\00"
@str = [23 x i8] c"Command not executed !\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca i32
%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 ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i64 (...) @fork()
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = bitcast i32* %4 to i8*
%18 = call i32 @waitpid(i64 %11, i32* %4, i32 0)
%19 = load i32, i32* %4
%20 = call i64 @WIFSIGNALED(i32 %19)
%21 = icmp eq i64 %20, 0
%22 = load i32, i32* %4
br i1 %21, label %25, label %23
23: ; preds = %13
%24 = call i32 @WTERMSIG(i32 %22)
br label %27
25: ; preds = %13
%26 = call i32 @WEXITSTATUS(i32 %22)
br label %27
27: ; preds = %25, %23
%28 = phi i32 [ %26, %25 ], [ %24, %23 ]
%29 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), %25 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), %23 ]
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %29, i32 %28)
br label %39
31: ; preds = %10
%32 = icmp eq i64 %11, 0
br i1 %32, label %33, label %39
33: ; preds = %31
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %31, %27
%40 = call i32 @exit(i32 0)
unreachable
}