#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*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  int res;
  char pass[30];
  printf("ExploitMe - Mission 1\n");
  if (argc != 2) {
    printf("Please provide a password...\n");
    return 1;
  }
  res = 0;
  strcpy(pass, argv[1]);
  if (strcmp(pass, "stupidlyinsecure") == 0)
    res = 1;
  if (res)
    printf("Access granted!\n");
  else
    printf("Access denied!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     1174 <main+0x44>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11db <main+0xab>
movl   $0x0,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ad <main+0x7d>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c8 <main+0x98>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
jmp    11d4 <main+0xa4>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xecf(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
jne    1178 <main+0x48>
mov    0x8(%rbx),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     118b <main+0x5b>
lea    0xeb1(%rip),%rdi
jmp    1192 <main+0x62>
lea    0xec7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1199 <main+0x69>
lea    0xea4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"ExploitMe - Mission 1\0A\00"
@.str.1 = [30 x i8] c"Please provide a password...\0A\00"
@.str.2 = [17 x i8] c"stupidlyinsecure\00"
@.str.3 = [17 x i8] c"Access granted!\0A\00"
@.str.4 = [16 x i8] c"Access denied!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [30 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %31
13: ; preds = %2
store i32 0, i32* %6
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %14, i8* %17)
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 1, i32* %6
br label %23
23: ; preds = %22, %13
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %30
28: ; preds = %23
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
store i32 0, i32* %3
br label %31
31: ; preds = %30, %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str.2 = [17 x i8] c"stupidlyinsecure\00"
@str = [22 x i8] c"ExploitMe - Mission 1\00"
@str.5 = [15 x i8] c"Access denied!\00"
@str.6 = [16 x i8] c"Access granted!\00"
@str.7 = [29 x i8] c"Please provide a password...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %0, 2
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.7, i64 0, i64 0))
br label %19
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strcpy(i8* %4, i8* %11)
%13 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
br label %19
17: ; preds = %9
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
br label %19
19: ; preds = %15, %17, %7
%20 = phi i32 [ 1, %7 ], [ 0, %17 ], [ 0, %15 ]
ret i32 %20
}