#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*/ execve(char *, char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *newargv[] = {NULL, NULL};
  char *newenviron[] = {NULL};
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file-to-exec>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  execve(argv[1], newargv, newenviron);
  perror("execve");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     11ba <main+0x6a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <execve@plt>
lea    0xe44(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jne    117b <main+0x3b>
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <execve@plt>
lea    0xea6(%rip),%rdi
call   1050 <perror@plt>
jmp    1193 <main+0x53>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe72(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: %s <file-to-exec>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"execve\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8*]
%4 = alloca [1 x i8*]
%5 = bitcast [2 x i8*]* %3 to i8*
%6 = bitcast [1 x i8*]* %4 to i8*
%7 = bitcast [1 x i8*]* %4 to i64*
store i64 0, i64* %7
%8 = icmp eq i32 %0, 2
br i1 %8, label %15, label %9
9: ; preds = %2
%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, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%19 = getelementptr inbounds [1 x i8*], [1 x i8*]* %4, i64 0, i64 0
%20 = call i32 @execve(i8* %17, i8** %18, i8** %19)
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
}