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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     1164 <main+0x44>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    119f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <checkpass@plt>
cmp    $0x0,%rax
je     118c <main+0x6c>
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
jmp    1198 <main+0x78>
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebp
jne    115b <main+0x3b>
mov    0x8(%rbx),%rdi
call   1040 <checkpass@plt>
test   %rax,%rax
lea    0xeca(%rip),%rax
lea    0xed2(%rip),%rdi
cmove  %rax,%rdi
xor    %ebx,%ebx
jmp    1167 <main+0x47>
mov    $0x1,%ebx
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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