#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 int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ execlp(char *, char *, char, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc <= 1) {
    fprintf(stderr, "Pas d'argument !\n");
    exit(EXIT_FAILURE);
  }
  if (argc >= 3) {
    fprintf(stderr, "Trop d'argument !\n");
    exit(EXIT_FAILURE);
  }
  pid_t p;
  if ((p = fork()) == -1) {
    perror("fork");
    exit(EXIT_FAILURE);
  }
  if (p == 0) {
    execlp("ls", "ls", *argv[2], NULL);
    return -1;
  } else {
    wait(NULL);
    printf("Test\n");
  }
  return 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)
cmpl   $0x1,-0x8(%rbp)
jg     11b3 <main+0x43>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jl     11e0 <main+0x70>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    120d <main+0x9d>
lea    0xe2b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    123f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
lea    0xe04(%rip),%rsi
xor    %ecx,%ecx
mov    %rsi,%rdi
movsbl (%rax),%edx
call   1070 <execlp@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <main+0xeb>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jle    11c6 <main+0x56>
cmp    $0x2,%edi
jne    11d8 <main+0x68>
mov    %rsi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11a5 <main+0x35>
cmp    $0xffffffff,%eax
je     11ef <main+0x7f>
xor    %ebx,%ebx
xor    %edi,%edi
call   1080 <wait@plt>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x52>
mov    0x10(%rbx),%rax
movsbl (%rax),%edx
lea    0xe77(%rip),%rdi
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1070 <execlp@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
jmp    11e8 <main+0x78>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fb <main+0x8b>
lea    0xe2f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Pas d'argument !\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"Trop d'argument !\0A\00"
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [6 x i8] c"Test\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 3
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %14
%23 = call i32 (...) @fork()
store i32 %23, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %22
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i8, i8* %35
%37 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %36, i32* null)
store i32 -1, i32* %3
br label %42
38: ; preds = %29
%39 = call i32 @wait(i32* null)
%40 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %38
store i32 0, i32* %3
br label %42
42: ; preds = %41, %32
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Pas d'argument !\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"Trop d'argument !\0A\00"
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [3 x i8] c"ls\00"
@str = [5 x i8] c"Test\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
%17 = tail call i32 (...) @fork()
switch i32 %17, label %27 [
i32 -1, label %18
i32 0, label %22
]
18: ; preds = %16
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %16
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %25, i32* null)
br label %30
27: ; preds = %16
%28 = tail call i32 @wait(i32* null)
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %27, %22
%31 = phi i32 [ -1, %22 ], [ 0, %27 ]
ret i32 %31
}