#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__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WNOHANG;
int WTERMSIG(int);
int /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, 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]);
    int status;
    wait(&status);
    waitpid(pid, &status, WNOHANG);
    if (WIFSIGNALED(status))
      printf("My child signal code is %d\n", WTERMSIG(status));
    else if (WIFEXITED(status))
      printf("My child exit code is %d\n", WEXITSTATUS(status));
    else
      printf("My child status is %d\n", 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     11e3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    12a7 <main+0x107>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x24(%rbp),%rdi
call   10b0 <wait@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rsi
call   1070 <waitpid@plt>
mov    -0x24(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     125d <main+0xbd>
mov    -0x24(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a2 <main+0x102>
mov    -0x24(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     128c <main+0xec>
mov    -0x24(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129d <main+0xfd>
mov    -0x24(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a2 <main+0x102>
jmp    12ed <main+0x14d>
cmpq   $0x0,-0x20(%rbp)
jne    12e8 <main+0x148>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdd4(%rip),%rsi
lea    0xdd0(%rip),%rdx
mov    %rsi,%rdi
call   10a0 <execlp@plt>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12ed <main+0x14d>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1227 <main+0x77>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
jle    1242 <main+0x92>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <wait@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1050 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
jne    1274 <main+0xc4>
call   1090 <WIFEXITED@plt>
mov    0x4(%rsp),%esi
test   %rax,%rax
jne    128b <main+0xdb>
lea    0xe59(%rip),%rdi
jmp    129b <main+0xeb>
mov    (%rbx),%rsi
lea    0xdcf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jne    1284 <main+0xd4>
mov    0x8(%rbx),%rcx
lea    0xe46(%rip),%rdi
lea    0xe42(%rip),%rdx
mov    %rdi,%rsi
call   10b0 <execlp@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
call   1060 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xdc6(%rip),%rdi
jmp    129b <main+0xeb>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    %esi,%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [21 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"
@WNOHANG = global i32 0
@.str.2 = [28 x i8] c"My child signal code is %d\0A\00"
@.str.3 = [26 x i8] c"My child exit code is %d\0A\00"
@.str.4 = [23 x i8] c"My child status is %d\0A\00"
@.str.5 = [3 x i8] c"ls\00"
@.str.6 = [5 x i8] c"-laR\00"
@.str.7 = [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 ([21 x i8], [21 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 %51
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 = call i32 @wait(i32* %9)
%28 = load i64, i64* %8
%29 = load i32, i32* @WNOHANG
%30 = call i32 @waitpid(i64 %28, i32* %9, i32 %29)
%31 = load i32, i32* %9
%32 = call i64 @WIFSIGNALED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %22
%35 = load i32, i32* %9
%36 = call i32 @WTERMSIG(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %50
38: ; preds = %22
%39 = load i32, i32* %9
%40 = call i64 @WIFEXITED(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* %9
%44 = call i32 @WEXITSTATUS(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %49
46: ; preds = %38
%47 = load i32, i32* %9
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %42
br label %50
50: ; preds = %49, %34
br label %62
51: ; preds = %18
%52 = load i64, i64* %8
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %51
%55 = load i8**, i8*** %6
%56 = getelementptr inbounds i8*, i8** %55, i64 1
%57 = load i8*, i8** %56
%58 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %51
br label %62
62: ; preds = %61, %50
%63 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [21 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"
@WNOHANG = global i32 0
@.str.2 = [28 x i8] c"My child signal code is %d\0A\00"
@.str.3 = [26 x i8] c"My child exit code is %d\0A\00"
@.str.4 = [23 x i8] c"My child status is %d\0A\00"
@.str.5 = [3 x i8] c"ls\00"
@.str.6 = [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 ([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 = tail call i64 (...) @fork()
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %37
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 @wait(i32* %4)
%19 = load i32, i32* @WNOHANG
%20 = call i32 @waitpid(i64 %11, i32* %4, i32 %19)
%21 = load i32, i32* %4
%22 = call i64 @WIFSIGNALED(i32 %21)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* %4
br i1 %23, label %27, label %25
25: ; preds = %13
%26 = call i32 @WTERMSIG(i32 %24)
br label %33
27: ; preds = %13
%28 = call i64 @WIFEXITED(i32 %24)
%29 = icmp eq i64 %28, 0
%30 = load i32, i32* %4
br i1 %29, label %33, label %31
31: ; preds = %27
%32 = call i32 @WEXITSTATUS(i32 %30)
br label %33
33: ; preds = %27, %31, %25
%34 = phi i32 [ %32, %31 ], [ %26, %25 ], [ %30, %27 ]
%35 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %31 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), %25 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), %27 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %35, i32 %34)
br label %45
37: ; preds = %10
%38 = icmp eq i64 %11, 0
br i1 %38, label %39, label %45
39: ; preds = %37
%40 = getelementptr inbounds i8*, i8** %1, i64 1
%41 = load i8*, i8** %40
%42 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %37, %33
%46 = call i32 @exit(i32 0)
unreachable
}