#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*/ execve(char *, char **, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[], char *env[]) {
  char *newargv[] = {NULL, "hello", "world", NULL};
  char *newenv[] = {"USER=unknown", "PATH=/tmp", NULL};
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file-to-exec>\n", argv[0]);
    return -1;
  }
  newargv[0] = argv[1];
  execve(argv[1], newargv, newenv);
  perror("execv");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2c8f(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c8c(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c89(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c86(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c83(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c7d(%rip),%rax
mov    %rax,-0x50(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c9 <main+0x99>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1030 <execve@plt>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
movaps 0x2cb5(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c99(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2cbd(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2ca1(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
je     118a <main+0x5a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
ret
mov    0x8(%rsi),%rdi
mov    %rdi,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <execve@plt>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@.str.1 = [6 x i8] c"world\00"
@__const.main.newargv = [4 x i8*] [i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [13 x i8] c"USER=unknown\00"
@.str.3 = [10 x i8] c"PATH=/tmp\00"
@__const.main.newenv = [3 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.4 = [26 x i8] c"Usage: %s <file-to-exec>\0A\00"
@.str.5 = [6 x i8] c"execv\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [4 x i8*]
%9 = alloca [3 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = bitcast [4 x i8*]* %8 to i8*
%11 = bitcast [3 x i8*]* %9 to i8*
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %6
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %18)
store i32 -1, i32* %4
br label %32
20: ; preds = %3
%21 = load i8**, i8*** %6
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
store i8* %23, i8** %24
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%29 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
%30 = call i32 @execve(i8* %27, i8** %28, i8** %29)
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %32
32: ; preds = %20, %14
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [6 x i8] c"world\00"
@__const.main.newargv = [4 x i8*] [i8* null, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [13 x i8] c"USER=unknown\00"
@.str.3 = [10 x i8] c"PATH=/tmp\00"
@__const.main.newenv = [3 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.4 = [26 x i8] c"Usage: %s <file-to-exec>\0A\00"
@.str.5 = [6 x i8] c"execv\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca [4 x i8*]
%5 = alloca [3 x i8*]
%6 = bitcast [4 x i8*]* %4 to i8*
%7 = bitcast [3 x i8*]* %5 to i8*
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %11)
br label %20
13: ; preds = %3
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
store i8* %15, i8** %16
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%18 = call i32 @execve(i8* %15, i8** %16, i8** %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %13, %9
%21 = phi i32 [ -1, %9 ], [ 0, %13 ]
ret i32 %21
}