#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int load_pass(char **password) {
  FILE *fd = 0;
  int fail = -1;
  int psize = 0;
  fd = fopen("/home/lab6A/.pass", "r");
  if (fd == NULL) {
    printf("Could not open secret pass!\n");
    return fail;
  }
  if (fseek(fd, 0, SEEK_END)) {
    printf("Failed to seek to end of pass!\n");
    return fail;
  }
  psize = ftell(fd);
  if (psize == 0 || psize == -1) {
    printf("Could not get pass size!\n");
    return fail;
  }
  if (fseek(fd, 0, SEEK_SET)) {
    printf("Failed to see to the start of pass!\n");
    return fail;
  }
  *password = (char *)malloc(psize);
  if (password == NULL) {
    printf("Could not malloc for pass!\n");
    return fail;
  }
  if (fread(*password, sizeof(char), psize, fd) != psize) {
    printf("Could not read secret pass!\n");
    free(*password);
    return fail;
  }
  fclose(fd);
  return psize;
}


x86 assembly (clang, -O0):
<load_pass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe62(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11db <load_pass+0x5b>
lea    0xe49(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <load_pass+0x183>
mov    -0x18(%rbp),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     1210 <load_pass+0x90>
lea    0xe31(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <load_pass+0x183>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1230 <load_pass+0xb0>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1247 <load_pass+0xc7>
lea    0xe1a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <load_pass+0x183>
mov    -0x18(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     127c <load_pass+0xfc>
lea    0xdff(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <load_pass+0x183>
mov    -0x20(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    12b0 <load_pass+0x130>
lea    0xdf0(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <load_pass+0x183>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x20(%rbp),%eax
je     12f4 <load_pass+0x174>
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <load_pass+0x183>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_pass>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe71(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11c4 <load_pass+0x44>
mov    %rax,%rbx
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
je     11cd <load_pass+0x4d>
lea    0xeab(%rip),%rdi
jmp    1209 <load_pass+0x89>
lea    0xec1(%rip),%rdi
jmp    1209 <load_pass+0x89>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%r15d
lea    0x1(%r15),%eax
cmp    $0x1,%eax
ja     11ea <load_pass+0x6a>
lea    0xe6c(%rip),%rdi
jmp    1209 <load_pass+0x89>
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rax,%rax
je     121d <load_pass+0x9d>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15d,%edi
call   1080 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    %r15d,%eax
jne    124a <load_pass+0xca>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    1214 <load_pass+0x94>
lea    0xdc3(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
jmp    120e <load_pass+0x8e>

LLVM IR (-O0):
@.str = [18 x i8] c"/home/lab6A/.pass\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Could not open secret pass!\0A\00"
@SEEK_END = global i32 0
@.str.3 = [32 x i8] c"Failed to seek to end of pass!\0A\00"
@.str.4 = [26 x i8] c"Could not get pass size!\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [37 x i8] c"Failed to see to the start of pass!\0A\00"
@.str.6 = [28 x i8] c"Could not malloc for pass!\0A\00"
@.str.7 = [29 x i8] c"Could not read secret pass!\0A\00"
define i32 @load_pass(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i32* null, i32** %4
store i32 -1, i32* %5
store i32 0, i32* %6
%7 = 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* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %5
store i32 %12, i32* %2
br label %68
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = load i32, i32* @SEEK_END
%16 = call i64 @fseek(i32* %14, i32 0, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* %5
store i32 %20, i32* %2
br label %68
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = call i32 @ftell(i32* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %26, %21
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* %5
store i32 %31, i32* %2
br label %68
32: ; preds = %26
%33 = load i32*, i32** %4
%34 = load i32, i32* @SEEK_SET
%35 = call i64 @fseek(i32* %33, i32 0, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* %5
store i32 %39, i32* %2
br label %68
40: ; preds = %32
%41 = load i32, i32* %6
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
%44 = load i8**, i8*** %3
store i8* %43, i8** %44
%45 = load i8**, i8*** %3
%46 = icmp eq i8** %45, null
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%49 = load i32, i32* %5
store i32 %49, i32* %2
br label %68
50: ; preds = %40
%51 = load i8**, i8*** %3
%52 = load i8*, i8** %51
%53 = load i32, i32* %6
%54 = load i32*, i32** %4
%55 = call i32 @fread(i8* %52, i32 1, i32 %53, i32* %54)
%56 = load i32, i32* %6
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %64
58: ; preds = %50
%59 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%60 = load i8**, i8*** %3
%61 = load i8*, i8** %60
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* %5
store i32 %63, i32* %2
br label %68
64: ; preds = %50
%65 = load i32*, i32** %4
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %6
store i32 %67, i32* %2
br label %68
68: ; preds = %64, %58, %47, %37, %29, %18, %10
%69 = load i32, i32* %2
ret i32 %69
}

LLVM IR (-O2):
@.str = [18 x i8] c"/home/lab6A/.pass\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [28 x i8] c"Could not read secret pass!\00"
@str.8 = [36 x i8] c"Failed to see to the start of pass!\00"
@str.9 = [25 x i8] c"Could not get pass size!\00"
@str.10 = [31 x i8] c"Failed to seek to end of pass!\00"
@str.11 = [28 x i8] c"Could not open secret pass!\00"
define i32 @load_pass(i8** nocapture %0) {
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
br label %35
6: ; preds = %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @fseek(i32* %2, i32 0, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
br label %35
12: ; preds = %6
%13 = tail call i32 @ftell(i32* %2)
%14 = add i32 %13, 1
%15 = icmp ult i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
br label %35
18: ; preds = %12
%19 = load i32, i32* @SEEK_SET
%20 = tail call i64 @fseek(i32* %2, i32 0, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.8, i64 0, i64 0))
br label %35
24: ; preds = %18
%25 = tail call i64 @malloc(i32 %13)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %0
%27 = tail call i32 @fread(i8* %26, i32 1, i32 %13, i32* %2)
%28 = icmp eq i32 %27, %13
br i1 %28, label %33, label %29
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%31 = load i8*, i8** %0
%32 = tail call i32 @free(i8* %31)
br label %35
33: ; preds = %24
%34 = tail call i32 @fclose(i32* %2)
br label %35
35: ; preds = %33, %29, %22, %16, %10, %4
%36 = phi i32 [ -1, %4 ], [ -1, %10 ], [ -1, %16 ], [ -1, %22 ], [ -1, %29 ], [ %13, %33 ]
ret i32 %36
}