#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*/ EXIT_FAILURE;
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ execle(char *, char *, char *, int /*<<< orphan*/ *,
                          char **);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  const int version = 4;
  if (version == 0) {
    execl("./argv-argc", "./argv-argc", "hello", "world", "testing a space!",
          NULL);
  } else if (version == 1) {
    execlp("ls", "ls", "-l", NULL);
  } else if (version == 2) {
    char *envp[] = {"HOME=/home/no.such.user", NULL};
    execle("/bin/ls", "ls", "~", NULL, envp);
  } else if (version == 3) {
    char *argv[] = {"ls", "-l", "-a", NULL};
    execv("/bin/ls", argv);
  } else if (version == 4) {
    char *argv[] = {"ls", "-l", NULL};
    char *envp[] = {NULL};
    execve("/bin/ls", argv, envp);
  } else {
    printf("You selected an invalid parameter.\n");
    exit(EXIT_FAILURE);
  }
  perror("exec-related problem");
  printf("exec functions only return if there is an error. Therefore, this "
         "message is unlikely to be displayed.\n");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
mov    0x2c93(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c90(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2c8d(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    0xe5d(%rip),%rdi
call   1050 <execve@plt>
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0x2cc5(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2ca9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe97(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <execve@plt>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@__const.main.argv = [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 = [8 x i8] c"/bin/ls\00"
@.str.3 = [21 x i8] c"exec-related problem\00"
@.str.4 = [103 x i8] c"exec functions only return if there is an error. Therefore, this message is unlikely to be displayed.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8*]
%4 = alloca [1 x i8*]
store i32 0, i32* %1
store i32 4, i32* %2
%5 = bitcast [3 x i8*]* %3 to i8*
%6 = bitcast [1 x i8*]* %4 to i8*
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1 x i8*], [1 x i8*]* %4, i64 0, i64 0
%9 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %7, i8** %8)
%10 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@__const.main.argv = [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 = [8 x i8] c"/bin/ls\00"
@.str.3 = [21 x i8] c"exec-related problem\00"
@EXIT_FAILURE = global i32 0
@str = [102 x i8] c"exec functions only return if there is an error. Therefore, this message is unlikely to be displayed.\00"
define i32 @main() {
%1 = alloca [3 x i8*]
%2 = alloca [1 x i8*]
%3 = bitcast [3 x i8*]* %1 to i8*
%4 = bitcast [1 x i8*]* %2 to i8*
%5 = bitcast [1 x i8*]* %2 to i64*
store i64 0, i64* %5
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
%7 = getelementptr inbounds [1 x i8*], [1 x i8*]* %2, i64 0, i64 0
%8 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %6, i8** %7)
%9 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
}