#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ check_password_char(int, int *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ password_file_exists();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  if (!password_file_exists()) {
    printf("Fatal error: File does not exist");
    return 1;
  }
  FILE *pw_file = fopen(".password", "r");
  if (!pw_file) {
    printf("Error: Could not read file\n");
    return 1;
  }
  int data_len = (2 << 3) - 1;
  int c;
  int is_wrong = 0;
  for (int i = 0; i < data_len; i++) {
    c = fgetc(pw_file);
    if (feof(pw_file)) {
      is_wrong |= 0x1337;
      break;
    }
    check_password_char(i, &c);
    is_wrong = is_wrong | c;
  }
  if (is_wrong > 0) {
    printf("Error: Wrong characters\n");
    return 1;
  }
  fclose(pw_file);
  printf("Congrats!\n");
  return 0;
}


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)
mov    $0x0,%al
call   1040 <password_file_exists@plt>
cmp    $0x0,%eax
jne    11ae <main+0x3e>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <main+0x129>
lea    0xe6c(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e8 <main+0x78>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <main+0x129>
movl   $0xf,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    125b <main+0xeb>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1238 <main+0xc8>
mov    -0x24(%rbp),%eax
or     $0x1337,%eax
mov    %eax,-0x24(%rbp)
jmp    125b <main+0xeb>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <check_password_char@plt>
mov    -0x24(%rbp),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11fd <main+0x8d>
cmpl   $0x0,-0x24(%rbp)
jle    127d <main+0x10d>
lea    0xddd(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1299 <main+0x129>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdd5(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <password_file_exists@plt>
test   %eax,%eax
je     1201 <main+0x81>
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1214 <main+0x94>
mov    %rax,%r15
xor    %ebp,%ebp
lea    0x4(%rsp),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1227 <main+0xa7>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <check_password_char@plt>
or     0x4(%rsp),%ebx
add    $0x1,%ebp
cmp    $0xf,%ebp
jne    11c0 <main+0x40>
test   %ebx,%ebx
jle    1231 <main+0xb1>
mov    $0x1,%ebx
lea    0xe53(%rip),%rdi
jmp    1242 <main+0xc2>
lea    0xdf8(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%ebx
jmp    1247 <main+0xc7>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1247 <main+0xc7>
or     $0x1337,%ebx
test   %ebx,%ebx
jg     11f3 <main+0x73>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Fatal error: File does not exist\00"
@.str.1 = [10 x i8] c".password\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"Error: Could not read file\0A\00"
@.str.4 = [25 x i8] c"Error: Wrong characters\0A\00"
@.str.5 = [11 x i8] c"Congrats!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @password_file_exists()
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %53
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %53
21: ; preds = %15
store i32 15, i32* %7
store i32 0, i32* %9
store i32 0, i32* %10
br label %22
22: ; preds = %41, %21
%23 = load i32, i32* %10
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %44
26: ; preds = %22
%27 = load i32*, i32** %6
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %8
%29 = load i32*, i32** %6
%30 = call i64 @feof(i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32, i32* %9
%34 = or i32 %33, 4919
store i32 %34, i32* %9
br label %44
35: ; preds = %26
%36 = load i32, i32* %10
%37 = call i32 @check_password_char(i32 %36, i32* %8)
%38 = load i32, i32* %9
%39 = load i32, i32* %8
%40 = or i32 %38, %39
store i32 %40, i32* %9
br label %41
41: ; preds = %35
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %22
44: ; preds = %32, %22
%45 = load i32, i32* %9
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %53
49: ; preds = %44
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
%52 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %53
53: ; preds = %49, %47, %19, %13
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [33 x i8] c"Fatal error: File does not exist\00"
@.str.1 = [10 x i8] c".password\00"
@.str.2 = [2 x i8] c"r\00"
@str = [27 x i8] c"Error: Could not read file\00"
@str.6 = [10 x i8] c"Congrats!\00"
@str.7 = [24 x i8] c"Error: Wrong characters\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @password_file_exists()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %38
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %38
13: ; preds = %8
%14 = bitcast i32* %3 to i8*
br label %15
15: ; preds = %13, %23
%16 = phi i32 [ 0, %13 ], [ %27, %23 ]
%17 = phi i32 [ 0, %13 ], [ %26, %23 ]
%18 = call i32 @fgetc(i32* %9)
store i32 %18, i32* %3
%19 = call i64 @feof(i32* %9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = or i32 %17, 4919
br label %29
23: ; preds = %15
%24 = call i32 @check_password_char(i32 %16, i32* %3)
%25 = load i32, i32* %3
%26 = or i32 %25, %17
%27 = add nuw nsw i32 %16, 1
%28 = icmp eq i32 %27, 15
br i1 %28, label %29, label %15
29: ; preds = %23, %21
%30 = phi i32 [ %22, %21 ], [ %26, %23 ]
%31 = icmp sgt i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @fclose(i32* %9)
br label %34
34: ; preds = %29, %32
%35 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0), %32 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0), %29 ]
%36 = phi i32 [ 0, %32 ], [ 1, %29 ]
%37 = call i32 @puts(i8* dereferenceable(1) %35)
br label %38
38: ; preds = %11, %34, %6
%39 = phi i32 [ 1, %6 ], [ %36, %34 ], [ 1, %11 ]
ret i32 %39
}