#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 */

/* Variables and functions */
int /*<<< orphan*/ errno;
scalar_t__ execl(char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ execv(char *, char **);
scalar_t__ execve(char *, char **, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  char *arg[] = {"ls", "-a", NULL};
  if (fork() == 0) {
    printf("execl...........\n");
    if (execl("/bin/ls", "ls", "-a", NULL) < 0) {
      fprintf(stderr, "execl failed:%s", strerror(errno));
      return -1;
    }
  }
  if (fork() == 0) {
    printf("execv...........\n");
    if (execv("/bin/ls", arg) < 0) {
      fprintf(stderr, "execl failed:%s\n", strerror(errno));
      return -1;
    }
  }
  if (fork() == 0) {
    printf("execve...........\n");
    if (execve("/bin/ls", arg, envp) < 0) {
      fprintf(stderr, "execl failed:%s\n", strerror(errno));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2c5f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c5c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c59(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    122d <main+0xbd>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
lea    0xe46(%rip),%rdi
lea    0xe44(%rip),%rsi
lea    0xe23(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <execl@plt>
cmp    $0x0,%rax
jge    1228 <main+0xb8>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe06(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1320 <main+0x1b0>
jmp    122d <main+0xbd>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    12a1 <main+0x131>
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1080 <execv@plt>
cmp    $0x0,%rax
jge    129c <main+0x12c>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdb4(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1320 <main+0x1b0>
jmp    12a1 <main+0x131>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1319 <main+0x1a9>
lea    0xd97(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd48(%rip),%rdi
call   1040 <execve@plt>
cmp    $0x0,%rax
jge    1314 <main+0x1a4>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xd3c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1320 <main+0x1b0>
jmp    1319 <main+0x1a9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    0x2c80(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2c64(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    11c9 <main+0x59>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0xe54(%rip),%rdi
lea    0xe52(%rip),%rsi
lea    0xe43(%rip),%rdx
xor    %ecx,%ecx
call   1070 <execl@plt>
test   %rax,%rax
js     1246 <main+0xd6>
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    11f7 <main+0x87>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
lea    0xe19(%rip),%rdi
mov    %rsp,%rsi
call   1080 <execv@plt>
test   %rax,%rax
js     1226 <main+0xb6>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    1273 <main+0x103>
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
lea    0xded(%rip),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
call   1040 <execve@plt>
test   %rax,%rax
jns    1273 <main+0x103>
mov    0x2dab(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xdd7(%rip),%rsi
jmp    1264 <main+0xf4>
mov    0x2d8b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xda7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-a\00"
@__const.main.arg = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [18 x i8] c"execl...........\0A\00"
@.str.3 = [8 x i8] c"/bin/ls\00"
@stderr = global i32 0
@.str.4 = [16 x i8] c"execl failed:%s\00"
@errno = global i32 0
@.str.5 = [18 x i8] c"execv...........\0A\00"
@.str.6 = [17 x i8] c"execl failed:%s\0A\00"
@.str.7 = [19 x i8] c"execve...........\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 [3 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = bitcast [3 x i8*]* %8 to i8*
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%14 = call i64 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %19)
store i32 -1, i32* %4
br label %52
21: ; preds = %12
br label %22
22: ; preds = %21, %3
%23 = call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%28 = call i64 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %33)
store i32 -1, i32* %4
br label %52
35: ; preds = %25
br label %36
36: ; preds = %35, %22
%37 = call i64 (...) @fork()
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%41 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%42 = load i8**, i8*** %7
%43 = call i64 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %41, i8** %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %48)
store i32 -1, i32* %4
br label %52
50: ; preds = %39
br label %51
51: ; preds = %50, %36
store i32 0, i32* %4
br label %52
52: ; preds = %51, %45, %30, %16
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-a\00"
@__const.main.arg = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.3 = [8 x i8] c"/bin/ls\00"
@stderr = global i32 0
@.str.4 = [16 x i8] c"execl failed:%s\00"
@errno = global i32 0
@.str.6 = [17 x i8] c"execl failed:%s\0A\00"
@str = [18 x i8] c"execve...........\00"
@str.8 = [17 x i8] c"execv...........\00"
@str.9 = [17 x i8] c"execl...........\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** %2) {
%4 = alloca [3 x i8*]
%5 = bitcast [3 x i8*]* %4 to i8*
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i64 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %43
17: ; preds = %8, %3
%18 = tail call i64 (...) @fork()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%23 = call i64 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %28)
br label %43
30: ; preds = %20, %17
%31 = call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%35 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%36 = call i64 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %35, i8** %2)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %30, %33, %38, %25, %12
%44 = phi i32 [ -1, %12 ], [ -1, %25 ], [ -1, %38 ], [ 0, %33 ], [ 0, %30 ]
ret i32 %44
}