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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char username[100] = {0};
  char real_pass[30] = {0};
  char in_pass[100] = {0};
  FILE *pass_file = NULL;
  int rsize = 0;
  pass_file = fopen("/home/lab4B/.pass", "r");
  if (pass_file == NULL) {
    fprintf(stderr, "ERROR: failed to open password file\n");
    exit(EXIT_FAILURE);
  }
  rsize = fread(real_pass, 1, 30, pass_file);
  real_pass[strcspn(real_pass, "\n")] = '\0';
  if (rsize != 30) {
    fprintf(stderr, "ERROR: failed to read password file\n");
    exit(EXIT_FAILURE);
  }
  fclose(pass_file);
  puts("===== [ Secure Access System v1.0 ] =====");
  puts("-----------------------------------------");
  puts("- You must login to access this system. -");
  puts("-----------------------------------------");
  printf("--[ Username: ");
  fgets(username, 100, stdin);
  username[strcspn(username, "\n")] = '\0';
  printf("--[ Password: ");
  fgets(in_pass, sizeof(in_pass), stdin);
  in_pass[strcspn(in_pass, "\n")] = '\0';
  puts("-----------------------------------------");
  if (!strncmp(real_pass, in_pass, 30)) {
    printf("Greetings, %s!\n", username);
    system("/bin/sh");
  } else {
    printf(username);
    printf(" does not have access!\n");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1090 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1090 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1090 <memset@plt>
movq   $0x0,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
lea    0xdd5(%rip),%rdi
lea    0xde0(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    126f <main+0xaf>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1e,%edx
call   1050 <fread@plt>
mov    %eax,-0x11c(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   10a0 <strcspn@plt>
movb   $0x0,-0xa0(%rbp,%rax,1)
cmpl   $0x1e,-0x11c(%rbp)
je     12dd <main+0x11d>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x118(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd6e(%rip),%rdi
call   1040 <puts@plt>
lea    0xd8c(%rip),%rdi
call   1040 <puts@plt>
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xd74(%rip),%rdi
call   1040 <puts@plt>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2cb6(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10b0 <fgets@plt>
lea    -0x80(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   10a0 <strcspn@plt>
movb   $0x0,-0x80(%rbp,%rax,1)
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2c79(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10b0 <fgets@plt>
lea    -0x110(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   10a0 <strcspn@plt>
movb   $0x0,-0x110(%rbp,%rax,1)
lea    0xceb(%rip),%rdi
call   1040 <puts@plt>
lea    -0xa0(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x1e,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13e6 <main+0x226>
lea    -0x80(%rbp),%rsi
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd2e(%rip),%rdi
call   1070 <system@plt>
jmp    140d <main+0x24d>
lea    -0x80(%rbp),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2bca(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2bb4(%rip),%rax
mov    (%rax),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xf8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x80(%rsp)
movups %xmm0,0xe(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movl   $0x0,0xf0(%rsp)
lea    0xdcc(%rip),%rdi
lea    0xdd7(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1385 <main+0x1d5>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1e,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
lea    0xe9b(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcspn@plt>
movb   $0x0,(%rsp,%rax,1)
cmp    $0x1e,%ebp
jne    1397 <main+0x1e7>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
lea    0xdeb(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xe06(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d1a(%rip),%r15
mov    (%r15),%edx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
lea    0xe1e(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strcspn@plt>
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r15),%edx
lea    0x90(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strcspn@plt>
movb   $0x0,0x90(%rsp,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
mov    %rbp,%rsi
mov    $0x1e,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    13ae <main+0x1fe>
lea    0xda4(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xda1(%rip),%rdi
call   1070 <system@plt>
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
lea    0xc7f(%rip),%rsi
jmp    13a7 <main+0x1f7>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
lea    0xc92(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    13c6 <main+0x216>
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd51(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/home/lab4B/.pass\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"ERROR: failed to open password file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [37 x i8] c"ERROR: failed to read password file\0A\00"
@.str.5 = [42 x i8] c"===== [ Secure Access System v1.0 ] =====\00"
@.str.6 = [42 x i8] c"-----------------------------------------\00"
@.str.7 = [42 x i8] c"- You must login to access this system. -\00"
@.str.8 = [15 x i8] c"--[ Username: \00"
@stdin = global i32 0
@.str.9 = [15 x i8] c"--[ Password: \00"
@.str.10 = [16 x i8] c"Greetings, %s!\0A\00"
@.str.11 = [8 x i8] c"/bin/sh\00"
@.str.12 = [24 x i8] c" does not have access!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca [30 x i8]
%8 = alloca [100 x i8]
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [100 x i8]* %6 to i8*
%12 = bitcast [30 x i8]* %7 to i8*
%13 = bitcast [100 x i8]* %8 to i8*
store i32* null, i32** %9
store i32 0, i32* %10
%14 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%24 = load i32*, i32** %9
%25 = call i32 @fread(i8* %23, i32 1, i32 30, i32* %24)
store i32 %25, i32* %10
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%27 = call i64 @strcspn(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 30
br i1 %30, label %31, label %36
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %22
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
%39 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%45 = load i32, i32* @stdin
%46 = call i32 @fgets(i8* %44, i32 100, i32 %45)
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%48 = call i64 @strcspn(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %48
store i8 0, i8* %49
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* @stdin
%53 = call i32 @fgets(i8* %51, i32 100, i32 %52)
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%55 = call i64 @strcspn(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %55
store i8 0, i8* %56
%57 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%58 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%60 = call i32 @strncmp(i8* %58, i8* %59, i32 30)
%61 = icmp ne i32 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %36
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* %63)
%65 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
br label %72
66: ; preds = %36
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %62
%73 = load i32, i32* @EXIT_SUCCESS
ret i32 %73
}

LLVM IR (-O2):
@.str = [18 x i8] c"/home/lab4B/.pass\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"ERROR: failed to open password file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [37 x i8] c"ERROR: failed to read password file\0A\00"
@.str.5 = [42 x i8] c"===== [ Secure Access System v1.0 ] =====\00"
@.str.6 = [42 x i8] c"-----------------------------------------\00"
@.str.7 = [42 x i8] c"- You must login to access this system. -\00"
@.str.8 = [15 x i8] c"--[ Username: \00"
@stdin = global i32 0
@.str.9 = [15 x i8] c"--[ Password: \00"
@.str.10 = [16 x i8] c"Greetings, %s!\0A\00"
@.str.11 = [8 x i8] c"/bin/sh\00"
@EXIT_SUCCESS = global i32 0
@str = [23 x i8] c" does not have access!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca [30 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = call i32 @fread(i8* %7, i32 1, i32 30, i32* %9)
%18 = call i64 @strcspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = icmp eq i32 %17, 30
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = tail call i32 @fclose(i32* %9)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %6, i32 100, i32 %33)
%35 = call i64 @strcspn(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%38 = load i32, i32* @stdin
%39 = call i32 @fgets(i8* %8, i32 100, i32 %38)
%40 = call i64 @strcspn(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 @strncmp(i8* %7, i8* %8, i32 30)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %26
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* %6)
%47 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
49: ; preds = %26
%50 = call i32 (i8*, ...) @printf(i8* %6)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
}