#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;
int execve(char *, char **, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void my_execve() {
  char *argv[] = {"ls", "-l", NULL};
  char *envv[] = {"CONTENT_LENGTH=1024", NULL};
  if (execve("/bin/ls", argv, envv) == -1) {
    fprintf(stderr, "error : %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<my_execve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2ca1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c9e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2c9b(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2ca0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c9d(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    0xe99(%rip),%rdi
call   1030 <execve@plt>
cmp    $0xffffffff,%eax
jne    11b8 <my_execve+0x88>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_execve>:
push   %rbx
sub    $0x30,%rsp
mov    0x2cb4(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c98(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2cac(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb8(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <execve@plt>
cmp    $0xffffffff,%eax
jne    1199 <my_execve+0x69>
mov    0x2e68(%rip),%rax
mov    (%rax),%ebx
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe90(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@__const.my_execve.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 = [20 x i8] c"CONTENT_LENGTH=1024\00"
@__const.my_execve.envv = [2 x i8*] [i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [8 x i8] c"/bin/ls\00"
@stderr = global i32 0
@.str.4 = [12 x i8] c"error : %s\0A\00"
@errno = global i32 0
define void @my_execve() {
%1 = alloca [3 x i8*]
%2 = alloca [2 x i8*]
%3 = bitcast [3 x i8*]* %1 to i8*
%4 = bitcast [2 x i8*]* %2 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%7 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %5, i8** %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %9, %0
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"-l\00"
@__const.my_execve.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 = [20 x i8] c"CONTENT_LENGTH=1024\00"
@__const.my_execve.envv = [2 x i8*] [i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [8 x i8] c"/bin/ls\00"
@stderr = global i32 0
@.str.4 = [12 x i8] c"error : %s\0A\00"
@errno = global i32 0
define void @my_execve() {
%1 = alloca [3 x i8*]
%2 = alloca [2 x i8*]
%3 = bitcast [3 x i8*]* %1 to i8*
%4 = bitcast [2 x i8*]* %2 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%7 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %5, i8** %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %9, %0
ret void
}