#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*/ execv(char *, char *const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stage1();
int main(int argc, char **argv) {
  if (argc == 2) {
    char *const args[] = {argv[1], NULL};
    printf("[*] Running as %s\n", argv[1]);
    execv(argv[0], args);
    printf("[!] Failed\n");
    return -1;
  }
  stage1();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11a4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <execv@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <main+0x82>
mov    $0x0,%al
call   1040 <stage1@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    118a <main+0x4a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
mov    %rsi,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
mov    %rsp,%rsi
call   1060 <execv@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1193 <main+0x53>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <stage1@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"[*] Running as %s\0A\00"
@.str.1 = [12 x i8] c"[!] Failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %10
%14 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* null, i8** %14
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%23 = call i32 @execv(i8* %21, i8** %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
25: ; preds = %2
%26 = call i32 (...) @stage1()
store i32 0, i32* %3
br label %27
27: ; preds = %25, %9
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [19 x i8] c"[*] Running as %s\0A\00"
@str = [11 x i8] c"[!] Failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8*]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %15
5: ; preds = %2
%6 = bitcast [2 x i8*]* %3 to i8*
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
store i8* %9, i8** %7
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* null, i8** %10
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
%12 = load i8*, i8** %1
%13 = call i32 @execv(i8* %12, i8** %7)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %17
15: ; preds = %2
%16 = tail call i32 (...) @stage1()
br label %17
17: ; preds = %15, %5
%18 = phi i32 [ -1, %5 ], [ 0, %15 ]
ret i32 %18
}