#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*/ exit(int);
int fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
int main() {
  char filename[] = "access.txt";
  FILE *fp;
  char pin[6], input[6];
  char *r;
  int x, fr;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "Unable to open %s\n", filename);
    exit(1);
  }
  r = fgets(pin, 6, fp);
  if (r == NULL) {
    fprintf(stderr, "Bad file read\n");
    exit(1);
  }
  fr = fclose(fp);
  if (fr != 0) {
    perror("Error closing file: ");
  }
  printf("Enter your PIN: ");
  r = fgets(input, 6, stdin);
  if (r == NULL) {
    fprintf(stderr, "Invalid input\n");
    exit(1);
  }
  if (strcmp(input, pin) == 0) {
    for (x = 0; x < 6; x++) {
      input[x] = '\0';
      pin[x] = '\0';
    }
    puts("Access granted");
  } else {
    puts("Intruder alert!");
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xe57(%rip),%ax
mov    %ax,-0x7(%rbp)
mov    0xe4f(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0xf(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1202 <main+0x72>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    -0xf(%rbp),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x1e(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x6,%esi
call   1060 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1244 <main+0xb4>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1266 <main+0xd6>
lea    0xdce(%rip),%rdi
call   10a0 <perror@plt>
lea    0xdd7(%rip),%rdi
call   1050 <printf@plt>
lea    -0x24(%rbp),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%rdx
mov    $0x6,%esi
call   1060 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12ba <main+0x12a>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x24(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1313 <main+0x183>
movl   $0x0,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
jge    1302 <main+0x172>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x24(%rbp,%rax,1)
movslq -0x34(%rbp),%rax
movb   $0x0,-0x1e(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12d8 <main+0x148>
lea    0xd5b(%rip),%rdi
call   1030 <puts@plt>
jmp    131f <main+0x18f>
lea    0xd59(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movabs $0x742e737365636361,%rax
73 2e 74
mov    %rax,0x10(%rsp)
movl   $0x747874,0x17(%rsp)
lea    0xe58(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1279 <main+0xe9>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x6,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     129f <main+0x10f>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %eax,%eax
jne    1268 <main+0xd8>
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%rdx
mov    %rsp,%rdi
mov    $0x6,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12b1 <main+0x121>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1237 <main+0xa7>
lea    0xe3e(%rip),%rdi
jmp    125b <main+0xcb>
movw   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movw   $0x0,0xc(%rsp)
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdc0(%rip),%rdi
call   10a0 <perror@plt>
jmp    11f0 <main+0x60>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xd71(%rip),%rsi
jmp    12c1 <main+0x131>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.filename = [11 x i8] c"access.txt\00"
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Unable to open %s\0A\00"
@.str.2 = [15 x i8] c"Bad file read\0A\00"
@.str.3 = [21 x i8] c"Error closing file: \00"
@.str.4 = [17 x i8] c"Enter your PIN: \00"
@stdin = global i32* null
@.str.5 = [15 x i8] c"Invalid input\0A\00"
@.str.6 = [15 x i8] c"Access granted\00"
@.str.7 = [16 x i8] c"Intruder alert!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i32*
%4 = alloca [6 x i8]
%5 = alloca [6 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [11 x i8]* %2 to i8*
%10 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i8* @fgets(i8* %20, i32 6, i32* %21)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%39 = load i32*, i32** @stdin
%40 = call i8* @fgets(i8* %38, i32 6, i32* %39)
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %36
%48 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%49 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%50 = call i64 @strcmp(i8* %48, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %68
52: ; preds = %47
store i32 0, i32* %7
br label %53
53: ; preds = %63, %52
%54 = load i32, i32* %7
%55 = icmp slt i32 %54, 6
br i1 %55, label %56, label %66
56: ; preds = %53
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 %58
store i8 0, i8* %59
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %56
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %53
66: ; preds = %53
%67 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %70
68: ; preds = %47
%69 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %70
70: ; preds = %68, %66
ret i32 0
}

LLVM IR (-O2):
@__const.main.filename = [11 x i8] c"access.txt\00"
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Unable to open %s\0A\00"
@.str.2 = [15 x i8] c"Bad file read\0A\00"
@.str.3 = [21 x i8] c"Error closing file: \00"
@.str.4 = [17 x i8] c"Enter your PIN: \00"
@stdin = global i32* null
@.str.5 = [15 x i8] c"Invalid input\0A\00"
@.str.6 = [15 x i8] c"Access granted\00"
@.str.7 = [16 x i8] c"Intruder alert!\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i8* @fgets(i8* %7, i32 6, i32* %9)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = call i32 @fclose(i32* %9)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%29 = load i32*, i32** @stdin
%30 = call i8* @fgets(i8* %8, i32 6, i32* %29)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = call i64 @strcmp(i8* %8, i8* %7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
br label %40
40: ; preds = %36, %39
%41 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), %39 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), %36 ]
%42 = call i32 @puts(i8* dereferenceable(1) %41)
ret i32 0
}