#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 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) {
    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,-0x34(%rbp)
cmpl   $0x0,-0x34(%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    12e2 <main+0x152>
lea    0xd8c(%rip),%rdi
call   1030 <puts@plt>
jmp    12ee <main+0x15e>
lea    0xd8a(%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,0x8(%rsp)
movl   $0x747874,0xf(%rsp)
lea    0xe58(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1259 <main+0xc9>
mov    %rax,%rbx
lea    0x1a(%rsp),%rdi
mov    $0x6,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     127f <main+0xef>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %eax,%eax
jne    124b <main+0xbb>
lea    0xe4d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%rdx
lea    0x14(%rsp),%rdi
mov    $0x6,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1291 <main+0x101>
lea    0x14(%rsp),%rdi
lea    0x1a(%rsp),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xe31(%rip),%rax
lea    0xe39(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xddd(%rip),%rdi
call   10a0 <perror@plt>
jmp    11f0 <main+0x60>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
jmp    12a1 <main+0x111>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%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
store i32 0, i32* %1
%8 = bitcast [11 x i8]* %2 to i8*
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%20 = load i32*, i32** %3
%21 = call i8* @fgets(i8* %19, i32 6, i32* %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%38 = load i32*, i32** @stdin
%39 = call i8* @fgets(i8* %37, i32 6, i32* %38)
store i8* %39, i8** %6
%40 = load i8*, i8** %6
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %35
%47 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%49 = call i64 @strcmp(i8* %47, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %55
53: ; preds = %46
%54 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %55
55: ; preds = %53, %51
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 = alloca [6 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i8* @fgets(i8* %5, i32 6, i32* %7)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = call i32 @fclose(i32* %7)
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32*, i32** @stdin
%28 = call i8* @fgets(i8* %6, i32 6, i32* %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = call i64 @strcmp(i8* %6, i8* %5)
%36 = icmp eq i64 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0)
%38 = call i32 @puts(i8* dereferenceable(1) %37)
ret i32 0
}