#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);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int *);
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);
    printf("Código de terminação: %i\n", WEXITSTATUS(status));
    if (WIFEXITED(status)) {
      printf("O processo terminou autónomamente.\n");
    } else {
      printf("O processo terminou por um sinal!\n");
    }
  } 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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    1238 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x24(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x24(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1225 <main+0xb5>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1233 <main+0xc3>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1283 <main+0x113>
cmpq   $0x0,-0x20(%rbp)
jne    127e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe59(%rip),%rsi
lea    0xe55(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1070 <execlp@plt>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1283 <main+0x113>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11f8 <main+0x78>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
jle    1213 <main+0x93>
mov    0x8(%rbx),%rsi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
call   1090 <wait@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
lea    0xea1(%rip),%rax
lea    0xebc(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    (%rbx),%rsi
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jne    1248 <main+0xc8>
mov    0x8(%rbx),%rcx
lea    0xe43(%rip),%rdi
lea    0xe3f(%rip),%rdx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1080 <execlp@plt>
lea    0xe32(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1070 <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 = [29 x i8] c"C\C3\B3digo de termina\C3\A7\C3\A3o: %i\0A\00"
@.str.3 = [37 x i8] c"O processo terminou aut\C3\B3nomamente.\0A\00"
@.str.4 = [35 x i8] c"O processo terminou por um sinal!\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 ([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 %39
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 i32, i32* %9
%29 = call i32 @WEXITSTATUS(i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %9
%32 = call i64 @WIFEXITED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %38
36: ; preds = %22
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
br label %50
39: ; preds = %18
%40 = load i64, i64* %8
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i8**, i8*** %6
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = 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* %45, i32* null)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %39
br label %50
50: ; preds = %49, %38
%51 = 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 = [29 x i8] c"C\C3\B3digo de termina\C3\A7\C3\A3o: %i\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"
@str.8 = [34 x i8] c"O processo terminou por um sinal!\00"
@str.9 = [36 x i8] c"O processo terminou aut\C3\B3nomamente.\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 %27
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* %4
%20 = call i32 @WEXITSTATUS(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %4
%23 = call i64 @WIFEXITED(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0)
%26 = call i32 @puts(i8* dereferenceable(1) %25)
br label %35
27: ; preds = %10
%28 = icmp eq i64 %11, 0
br i1 %28, label %29, label %35
29: ; preds = %27
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = 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* %31, i32* null)
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %27, %13
%36 = call i32 @exit(i32 0)
unreachable
}