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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fwrite(void *, int, char, int /*<<< orphan*/ *);
void *getBytes(char *, void *, char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
void *readPtrFile(char *, char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ scryptLogout(void *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char const *argv[]) {
  puts("What is the path for your randoms?");
  char path[150];
  scanf("%s", path);
  if (access(path, R_OK) < 0) {
    printf("Path entered cannot be read, does it exist?\n");
    exit(-1);
  }
  char ptrPath[150];
  printf("Is your state file stored off disk? y/n\n");
  char ptrChoice = ' ';
  while (!(ptrChoice == 'y' | ptrChoice == 'n')) {
    scanf(" %c", &ptrChoice);
  }
  if (ptrChoice == 'y') {
    printf("Please enter the path where your state is saved.\n");
    scanf("%s", ptrPath);
  } else {
    strcpy(ptrPath, path);
  }
  if (access(ptrPath, R_OK) < 0) {
    printf("Pointer path entered cannot be read, does it exist?\n");
    exit(-1);
  }
  struct pointerFile *ptr = readPtrFile(ptrPath, "nextAvailable.ptr");
  if (ptr == NULL) {
    perror("Could not read pointer");
    return -1;
  }
  puts("How many bytes do you want to read?");
  uint32_t bytesAmt;
  scanf("%d", &bytesAmt);
  void *resulting = getBytes(path, ptr, bytesAmt);
  if (resulting == NULL) {
    exit(-1);
  }
  char savepath[250];
  sprintf(savepath, "%s/output.bin", path);
  FILE *saveFile = fopen(savepath, "wb");
  fwrite(resulting, 1, bytesAmt, saveFile);
  fclose(saveFile);
  free(resulting);
  scryptLogout(ptr);
  free(ptr);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdf0(%rip),%rdi
call   1050 <puts@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1090 <scanf@plt>
lea    -0xb0(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   10a0 <access@plt>
cmp    $0x0,%rax
jge    125d <main+0x6d>
lea    0xdd8(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    0xdef(%rip),%rdi
call   1070 <printf@plt>
movb   $0x20,-0x151(%rbp)
movsbl -0x151(%rbp),%eax
cmp    $0x79,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
movsbl -0x151(%rbp),%ecx
cmp    $0x6e,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12ac <main+0xbc>
jmp    12c4 <main+0xd4>
lea    0xdc9(%rip),%rdi
lea    -0x151(%rbp),%rsi
call   1090 <scanf@plt>
jmp    1270 <main+0x80>
movsbl -0x151(%rbp),%eax
cmp    $0x79,%eax
jne    12f8 <main+0x108>
lea    0xda5(%rip),%rdi
call   1070 <printf@plt>
lea    -0x150(%rbp),%rsi
lea    0xd35(%rip),%rdi
call   1090 <scanf@plt>
jmp    130b <main+0x11b>
lea    -0x150(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x150(%rbp),%rdi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
call   10a0 <access@plt>
cmp    $0x0,%rax
jge    1340 <main+0x150>
lea    0xd81(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    -0x150(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1080 <readPtrFile@plt>
mov    %rax,-0x160(%rbp)
cmpq   $0x0,-0x160(%rbp)
jne    1380 <main+0x190>
lea    0xd8a(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145d <main+0x26d>
lea    0xd89(%rip),%rdi
call   1050 <puts@plt>
lea    0xda1(%rip),%rdi
lea    -0x161(%rbp),%rsi
call   1090 <scanf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x160(%rbp),%rsi
movsbl -0x161(%rbp),%edx
call   10e0 <getBytes@plt>
mov    %rax,-0x170(%rbp)
cmpq   $0x0,-0x170(%rbp)
jne    13d8 <main+0x1e8>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    -0x270(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
lea    0xd4a(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x270(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x278(%rbp)
mov    -0x170(%rbp),%rdi
mov    -0x161(%rbp),%al
mov    -0x278(%rbp),%rcx
mov    $0x1,%esi
movsbl %al,%edx
call   1110 <fwrite@plt>
mov    -0x278(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x170(%rbp),%rdi
call   1030 <free@plt>
mov    -0x160(%rbp),%rdi
call   10b0 <scryptLogout@plt>
mov    -0x160(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x258,%rsp
lea    0xe0b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe22(%rip),%rdi
lea    0xb0(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x2dc8(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1090 <access@plt>
test   %rax,%rax
js     1394 <main+0x1b4>
lea    0xe58(%rip),%rdi
call   1050 <puts@plt>
movb   $0x20,0xf(%rsp)
mov    $0x20,%al
lea    0xde0(%rip),%r14
lea    0xf(%rsp),%rbx
cmp    $0x6e,%al
je     1268 <main+0x88>
nop
cmp    $0x79,%al
je     127c <main+0x9c>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
movzbl 0xf(%rsp),%eax
cmp    $0x6e,%al
jne    1250 <main+0x70>
lea    0x10(%rsp),%rdi
lea    0xb0(%rsp),%rsi
call   1040 <strcpy@plt>
jmp    1299 <main+0xb9>
lea    0xe64(%rip),%rdi
call   1050 <puts@plt>
lea    0xd94(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <scanf@plt>
mov    (%r15),%esi
lea    0x10(%rsp),%rdi
call   1090 <access@plt>
test   %rax,%rax
js     139d <main+0x1bd>
lea    0xd74(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <readPtrFile@plt>
test   %rax,%rax
je     1381 <main+0x1a1>
mov    %rax,%r14
lea    0xd80(%rip),%rdi
call   1050 <puts@plt>
lea    0xd98(%rip),%rdi
lea    0xe(%rsp),%rsi
call   1080 <scanf@plt>
movsbl 0xe(%rsp),%edx
lea    0xb0(%rsp),%rdi
mov    %r14,%rsi
call   10d0 <getBytes@plt>
test   %rax,%rax
je     13a9 <main+0x1c9>
mov    %rax,%r12
lea    0xd69(%rip),%rsi
lea    0x150(%rsp),%r15
lea    0xb0(%rsp),%rdx
mov    %r15,%rdi
call   10e0 <sprintf@plt>
lea    0xd58(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
movsbl 0xe(%rsp),%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1100 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   10a0 <scryptLogout@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x258,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xcb4(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1372 <main+0x192>
lea    0xd7d(%rip),%rdi
jmp    13a4 <main+0x1c4>
lea    0xd0f(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.pointerFile = type opaque
@.str = [35 x i8] c"What is the path for your randoms?\00"
@.str.1 = [3 x i8] c"%s\00"
@R_OK = global i32 0
@.str.2 = [45 x i8] c"Path entered cannot be read, does it exist?\0A\00"
@.str.3 = [41 x i8] c"Is your state file stored off disk? y/n\0A\00"
@.str.4 = [4 x i8] c" %c\00"
@.str.5 = [50 x i8] c"Please enter the path where your state is saved.\0A\00"
@.str.6 = [53 x i8] c"Pointer path entered cannot be read, does it exist?\0A\00"
@.str.7 = [18 x i8] c"nextAvailable.ptr\00"
@.str.8 = [23 x i8] c"Could not read pointer\00"
@.str.9 = [36 x i8] c"How many bytes do you want to read?\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [14 x i8] c"%s/output.bin\00"
@.str.12 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [150 x i8]
%7 = alloca [150 x i8]
%8 = alloca i8
%9 = alloca %struct.pointerFile*
%10 = alloca i8
%11 = alloca i8*
%12 = alloca [250 x i8]
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [150 x i8], [150 x i8]* %6, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [150 x i8], [150 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* @R_OK
%19 = call i64 @access(i8* %17, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %2
%25 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i8 32, i8* %8
br label %26
26: ; preds = %38, %24
%27 = load i8, i8* %8
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 121
%30 = zext i1 %29 to i32
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 110
%34 = zext i1 %33 to i32
%35 = or i32 %30, %34
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %40
38: ; preds = %26
%39 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %8)
br label %26
40: ; preds = %26
%41 = load i8, i8* %8
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 121
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
%46 = getelementptr inbounds [150 x i8], [150 x i8]* %7, i64 0, i64 0
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %46)
br label %52
48: ; preds = %40
%49 = getelementptr inbounds [150 x i8], [150 x i8]* %7, i64 0, i64 0
%50 = getelementptr inbounds [150 x i8], [150 x i8]* %6, i64 0, i64 0
%51 = call i32 @strcpy(i8* %49, i8* %50)
br label %52
52: ; preds = %48, %44
%53 = getelementptr inbounds [150 x i8], [150 x i8]* %7, i64 0, i64 0
%54 = load i32, i32* @R_OK
%55 = call i64 @access(i8* %53, i32 %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
%59 = call i32 @exit(i32 -1)
unreachable
60: ; preds = %52
%61 = getelementptr inbounds [150 x i8], [150 x i8]* %7, i64 0, i64 0
%62 = call i8* @readPtrFile(i8* %61, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%63 = bitcast i8* %62 to %struct.pointerFile*
store %struct.pointerFile* %63, %struct.pointerFile** %9
%64 = load %struct.pointerFile*, %struct.pointerFile** %9
%65 = icmp eq %struct.pointerFile* %64, null
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %3
br label %100
68: ; preds = %60
%69 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%70 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %10)
%71 = getelementptr inbounds [150 x i8], [150 x i8]* %6, i64 0, i64 0
%72 = load %struct.pointerFile*, %struct.pointerFile** %9
%73 = bitcast %struct.pointerFile* %72 to i8*
%74 = load i8, i8* %10
%75 = call i8* @getBytes(i8* %71, i8* %73, i8 signext %74)
store i8* %75, i8** %11
%76 = load i8*, i8** %11
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %80
78: ; preds = %68
%79 = call i32 @exit(i32 -1)
unreachable
80: ; preds = %68
%81 = getelementptr inbounds [250 x i8], [250 x i8]* %12, i64 0, i64 0
%82 = getelementptr inbounds [150 x i8], [150 x i8]* %6, i64 0, i64 0
%83 = call i32 @sprintf(i8* %81, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %82)
%84 = getelementptr inbounds [250 x i8], [250 x i8]* %12, i64 0, i64 0
%85 = call i32* @fopen(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
store i32* %85, i32** %13
%86 = load i8*, i8** %11
%87 = load i8, i8* %10
%88 = load i32*, i32** %13
%89 = call i32 @fwrite(i8* %86, i32 1, i8 signext %87, i32* %88)
%90 = load i32*, i32** %13
%91 = call i32 @fclose(i32* %90)
%92 = load i8*, i8** %11
%93 = call i32 @free(i8* %92)
%94 = load %struct.pointerFile*, %struct.pointerFile** %9
%95 = bitcast %struct.pointerFile* %94 to i8*
%96 = call i32 @scryptLogout(i8* %95)
%97 = load %struct.pointerFile*, %struct.pointerFile** %9
%98 = bitcast %struct.pointerFile* %97 to i8*
%99 = call i32 @free(i8* %98)
br label %100
100: ; preds = %80, %66
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@.str = [35 x i8] c"What is the path for your randoms?\00"
@.str.1 = [3 x i8] c"%s\00"
@R_OK = global i32 0
@.str.4 = [4 x i8] c" %c\00"
@.str.7 = [18 x i8] c"nextAvailable.ptr\00"
@.str.8 = [23 x i8] c"Could not read pointer\00"
@.str.9 = [36 x i8] c"How many bytes do you want to read?\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [14 x i8] c"%s/output.bin\00"
@.str.12 = [3 x i8] c"wb\00"
@str = [40 x i8] c"Is your state file stored off disk? y/n\00"
@str.13 = [52 x i8] c"Pointer path entered cannot be read, does it exist?\00"
@str.14 = [49 x i8] c"Please enter the path where your state is saved.\00"
@str.15 = [44 x i8] c"Path entered cannot be read, does it exist?\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [150 x i8]
%4 = alloca [150 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = alloca [250 x i8]
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @R_OK
%12 = call i64 @access(i8* %9, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.15, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
store i8 32, i8* %5
br label %20
20: ; preds = %22, %17
%21 = phi i8 [ %24, %22 ], [ 32, %17 ]
switch i8 %21, label %22 [
i8 121, label %25
i8 110, label %28
]
22: ; preds = %20
%23 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%24 = load i8, i8* %5
br label %20
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.14, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %30
28: ; preds = %20
%29 = call i32 @strcpy(i8* %18, i8* %9)
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* @R_OK
%32 = call i64 @access(i8* %18, i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.13, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
%38 = call i8* @readPtrFile(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %60
42: ; preds = %37
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %6)
%45 = load i8, i8* %6
%46 = call i8* @getBytes(i8* %9, i8* %38, i8 signext %45)
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %42
%51 = getelementptr inbounds [250 x i8], [250 x i8]* %7, i64 0, i64 0
%52 = call i32 @sprintf(i8* %51, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0), i8* %9)
%53 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%54 = load i8, i8* %6
%55 = call i32 @fwrite(i8* %46, i32 1, i8 signext %54, i32* %53)
%56 = call i32 @fclose(i32* %53)
%57 = call i32 @free(i8* %46)
%58 = call i32 @scryptLogout(i8* %38)
%59 = call i32 @free(i8* %38)
br label %60
60: ; preds = %50, %40
%61 = phi i32 [ -1, %40 ], [ 0, %50 ]
ret i32 %61
}