#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *const, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
unsigned int fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ perror(char const *const);
unsigned char *realloc(unsigned char *, unsigned int);
int /*<<< orphan*/ stderr;
int read_whole_file(char const *const path, unsigned char **buf,
                    unsigned int *data_size) {
  FILE *stream;
  unsigned int alloc_size = 0, bytes_read, goal;
  *buf = NULL;
  *data_size = 0;
  if (!(stream = fopen(path, "rb"))) {
    perror(path);
    do {
      fprintf(stderr,
              "at "
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/michael-redman/verity-backup/refs/"
              "heads/master/read_whole_file.c"
              ": %u\n",
              13);
    } while (0);
    return -1;
  }
  while (!feof(stream)) {
    if (alloc_size == *data_size) {
      alloc_size = 1 + 3 * alloc_size;
      if (!(*buf = realloc(*buf, alloc_size))) {
        fputs("alloc failed\n", stderr);
        do {
          fprintf(stderr,
                  "at "
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/michael-redman/"
                  "verity-backup/refs/heads/master/read_whole_file.c"
                  ": %u\n",
                  18);
        } while (0);
        goto out1;
      }
    }
    goal = alloc_size - *data_size;
    if ((bytes_read = fread(&(*buf)[*data_size], 1, goal, stream)) != goal)
      if (ferror(stream)) {
        perror(path);
        do {
          fprintf(stderr,
                  "at "
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/michael-redman/"
                  "verity-backup/refs/heads/master/read_whole_file.c"
                  ": %u\n",
                  21);
        } while (0);
        goto out1;
      }
    *data_size += bytes_read;
  }
  if (fclose(stream)) {
    perror(path);
    do {
      fprintf(stderr,
              "at "
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/michael-redman/verity-backup/refs/"
              "heads/master/read_whole_file.c"
              ": %u\n",
              23);
    } while (0);
    goto out0;
  }
  return 0;
out1:
  if (fclose(stream)) {
    perror(path);
    do {
      fprintf(stderr,
              "at "
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/michael-redman/verity-backup/refs/"
              "heads/master/read_whole_file.c"
              ": %u\n",
              25);
    } while (0);
  }
out0:
  if (*buf)
    free(*buf);
  return -1;
}


x86 assembly (clang, -O0):
<read_whole_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    121d <read_whole_file+0x7d>
mov    -0x10(%rbp),%rdi
call   10c0 <perror@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
mov    $0xd,%edx
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <read_whole_file+0x243>
jmp    1222 <read_whole_file+0x82>
mov    -0x28(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1240 <read_whole_file+0xa0>
jmp    133b <read_whole_file+0x19b>
mov    -0x2c(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jne    12b2 <read_whole_file+0x112>
imul   $0x3,-0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x2c(%rbp),%esi
call   10a0 <realloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    12ad <read_whole_file+0x10d>
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
call   1070 <fputs@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
mov    $0x12,%edx
call   1080 <fprintf@plt>
jmp    1382 <read_whole_file+0x1e2>
jmp    12b2 <read_whole_file+0x112>
mov    -0x2c(%rbp),%eax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    %rax,%rdi
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %eax,-0x30(%rbp)
cmp    -0x34(%rbp),%eax
je     132b <read_whole_file+0x18b>
mov    -0x28(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1326 <read_whole_file+0x186>
mov    -0x10(%rbp),%rdi
call   10c0 <perror@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
lea    0xcec(%rip),%rsi
mov    $0x15,%edx
call   1080 <fprintf@plt>
jmp    1382 <read_whole_file+0x1e2>
jmp    132b <read_whole_file+0x18b>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    1222 <read_whole_file+0x82>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     1376 <read_whole_file+0x1d6>
mov    -0x10(%rbp),%rdi
call   10c0 <perror@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
lea    0xc9c(%rip),%rsi
mov    $0x17,%edx
call   1080 <fprintf@plt>
jmp    13c2 <read_whole_file+0x222>
movl   $0x0,-0x4(%rbp)
jmp    13e3 <read_whole_file+0x243>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     13bd <read_whole_file+0x21d>
mov    -0x10(%rbp),%rdi
call   10c0 <perror@plt>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
lea    0xc55(%rip),%rsi
mov    $0x19,%edx
call   1080 <fprintf@plt>
jmp    13bd <read_whole_file+0x21d>
jmp    13c2 <read_whole_file+0x222>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     13dc <read_whole_file+0x23c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_whole_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,(%rsi)
movl   $0x0,(%rdx)
lea    0xe38(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12ec <read_whole_file+0x14c>
mov    %rax,%r12
mov    %rbx,(%rsp)
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     120d <read_whole_file+0x6d>
mov    %r12,%rdi
call   1060 <fclose@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1318 <read_whole_file+0x178>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1230 <read_whole_file+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebp,0x0(%r13)
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    11e9 <read_whole_file+0x49>
mov    0x0(%r13),%ecx
cmp    %ecx,%ebx
jne    1260 <read_whole_file+0xc0>
lea    (%rbx,%rbx,2),%ebx
add    $0x1,%ebx
mov    (%r15),%rdi
mov    %ebx,%esi
call   10a0 <realloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     12a5 <read_whole_file+0x105>
mov    0x0(%r13),%ecx
jmp    1263 <read_whole_file+0xc3>
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%rax
mov    %ebx,%r14d
sub    %ecx,%r14d
mov    %ecx,%edi
add    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
cmp    %r14d,%eax
je     1220 <read_whole_file+0x80>
mov    %r12,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1220 <read_whole_file+0x80>
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <perror@plt>
mov    $0x15,%edx
jmp    12c3 <read_whole_file+0x123>
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
lea    0xdf1(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x12,%edx
mov    (%rsp),%rbp
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
call   1080 <fprintf@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
je     1340 <read_whole_file+0x1a0>
mov    $0x19,%ebx
jmp    1321 <read_whole_file+0x181>
mov    %rbx,%rdi
call   10c0 <perror@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
mov    $0xd,%edx
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11fc <read_whole_file+0x5c>
mov    $0x17,%ebx
mov    (%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <perror@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
mov    %ebx,%edx
call   1080 <fprintf@plt>
mov    (%r15),%rdi
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     11fc <read_whole_file+0x5c>
call   1030 <free@plt>
jmp    11fc <read_whole_file+0x5c>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [163 x i8] c"at /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/michael-redman/verity-backup/refs/heads/master/read_whole_file.c: %u\0A\00"
@.str.2 = [14 x i8] c"alloc failed\0A\00"
define i32 @read_whole_file(i8* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32 0, i32* %9
%12 = load i8**, i8*** %6
store i8* null, i8** %12
%13 = load i32*, i32** %7
store i32 0, i32* %13
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %24, label %17
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i32 @perror(i8* %18)
br label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 13)
br label %23
23: ; preds = %20
store i32 -1, i32* %4
br label %119
24: ; preds = %3
br label %25
25: ; preds = %81, %24
%26 = load i32*, i32** %8
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %86
30: ; preds = %25
%31 = load i32, i32* %9
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = icmp eq i32 %31, %33
br i1 %34, label %35, label %53
35: ; preds = %30
%36 = load i32, i32* %9
%37 = mul i32 3, %36
%38 = add i32 1, %37
store i32 %38, i32* %9
%39 = load i8**, i8*** %6
%40 = load i8*, i8** %39
%41 = load i32, i32* %9
%42 = call i8* @realloc(i8* %40, i32 %41)
%43 = load i8**, i8*** %6
store i8* %42, i8** %43
%44 = icmp ne i8* %42, null
br i1 %44, label %52, label %45
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 18)
br label %51
51: ; preds = %48
br label %98
52: ; preds = %35
br label %53
53: ; preds = %52, %30
%54 = load i32, i32* %9
%55 = load i32*, i32** %7
%56 = load i32, i32* %55
%57 = sub i32 %54, %56
store i32 %57, i32* %11
%58 = load i8**, i8*** %6
%59 = load i8*, i8** %58
%60 = load i32*, i32** %7
%61 = load i32, i32* %60
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i32, i32* %11
%65 = load i32*, i32** %8
%66 = call i32 @fread(i8* %63, i32 1, i32 %64, i32* %65)
store i32 %66, i32* %10
%67 = load i32, i32* %11
%68 = icmp ne i32 %66, %67
br i1 %68, label %69, label %81
69: ; preds = %53
%70 = load i32*, i32** %8
%71 = call i64 @ferror(i32* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %80
73: ; preds = %69
%74 = load i8*, i8** %5
%75 = call i32 @perror(i8* %74)
br label %76
76: ; preds = %73
%77 = load i32, i32* @stderr
%78 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 21)
br label %79
79: ; preds = %76
br label %98
80: ; preds = %69
br label %81
81: ; preds = %80, %53
%82 = load i32, i32* %10
%83 = load i32*, i32** %7
%84 = load i32, i32* %83
%85 = add i32 %84, %82
store i32 %85, i32* %83
br label %25
86: ; preds = %25
%87 = load i32*, i32** %8
%88 = call i64 @fclose(i32* %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %97
90: ; preds = %86
%91 = load i8*, i8** %5
%92 = call i32 @perror(i8* %91)
br label %93
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 23)
br label %96
96: ; preds = %93
br label %110
97: ; preds = %86
store i32 0, i32* %4
br label %119
98: ; preds = %79, %51
%99 = load i32*, i32** %8
%100 = call i64 @fclose(i32* %99)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %109
102: ; preds = %98
%103 = load i8*, i8** %5
%104 = call i32 @perror(i8* %103)
br label %105
105: ; preds = %102
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 25)
br label %108
108: ; preds = %105
br label %109
109: ; preds = %108, %98
br label %110
110: ; preds = %109, %96
%111 = load i8**, i8*** %6
%112 = load i8*, i8** %111
%113 = icmp ne i8* %112, null
br i1 %113, label %114, label %118
114: ; preds = %110
%115 = load i8**, i8*** %6
%116 = load i8*, i8** %115
%117 = call i32 @free(i8* %116)
br label %118
118: ; preds = %114, %110
store i32 -1, i32* %4
br label %119
119: ; preds = %118, %97, %23
%120 = load i32, i32* %4
ret i32 %120
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [163 x i8] c"at /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/michael-redman/verity-backup/refs/heads/master/read_whole_file.c: %u\0A\00"
@.str.2 = [14 x i8] c"alloc failed\0A\00"
define i32 @read_whole_file(i8* nocapture %0, i8** nocapture %1, i32* nocapture %2) {
store i8* null, i8** %1
store i32 0, i32* %2
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %49
9: ; preds = %3
%10 = tail call i32 @perror(i8* %0)
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 13)
br label %68
13: ; preds = %6, %44
%14 = phi i32 [ %33, %44 ], [ 0, %6 ]
%15 = load i32, i32* %2
%16 = icmp eq i32 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = load i8*, i8** %1
br label %30
19: ; preds = %13
%20 = mul i32 %14, 3
%21 = add i32 %20, 1
%22 = load i8*, i8** %1
%23 = tail call i8* @realloc(i8* %22, i32 %21)
store i8* %23, i8** %1
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = load i32, i32* %2
br label %30
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = tail call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %52
30: ; preds = %17, %25
%31 = phi i8* [ %23, %25 ], [ %18, %17 ]
%32 = phi i32 [ %26, %25 ], [ %15, %17 ]
%33 = phi i32 [ %21, %25 ], [ %14, %17 ]
%34 = sub i32 %33, %32
%35 = zext i32 %32 to i64
%36 = getelementptr inbounds i8, i8* %31, i64 %35
%37 = tail call i32 @fread(i8* %36, i32 1, i32 %34, i32* %4)
%38 = icmp eq i32 %37, %34
br i1 %38, label %44, label %39
39: ; preds = %30
%40 = tail call i64 @ferror(i32* %4)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = tail call i32 @perror(i8* %0)
br label %52
44: ; preds = %39, %30
%45 = load i32, i32* %2
%46 = add i32 %45, %37
store i32 %46, i32* %2
%47 = tail call i32 @feof(i32* %4)
%48 = icmp eq i32 %47, 0
br i1 %48, label %13, label %49
49: ; preds = %44, %6
%50 = tail call i64 @fclose(i32* %4)
%51 = icmp eq i64 %50, 0
br i1 %51, label %68, label %58
52: ; preds = %42, %27
%53 = phi i32 [ 21, %42 ], [ 18, %27 ]
%54 = load i32, i32* @stderr
%55 = tail call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%56 = tail call i64 @fclose(i32* %4)
%57 = icmp eq i64 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %52, %49
%59 = phi i32 [ 23, %49 ], [ 25, %52 ]
%60 = tail call i32 @perror(i8* %0)
%61 = load i32, i32* @stderr
%62 = tail call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str.1, i64 0, i64 0), i32 %59)
br label %63
63: ; preds = %58, %52
%64 = load i8*, i8** %1
%65 = icmp eq i8* %64, null
br i1 %65, label %68, label %66
66: ; preds = %63
%67 = tail call i32 @free(i8* %64)
br label %68
68: ; preds = %63, %66, %49, %9
%69 = phi i32 [ -1, %9 ], [ 0, %49 ], [ -1, %66 ], [ -1, %63 ]
ret i32 %69
}