#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ perror(char *);
scalar_t__ realloc(unsigned char *, size_t);
int /*<<< orphan*/ stderr;
void read_file(unsigned char **buf, size_t *buflen, size_t *len, FILE *f) {
  if (*buflen == 0) {
    *buflen = 4000;
    *len = 0;
    *buf = (unsigned char *)malloc(*buflen);
    if (!*buf) {
      fprintf(stderr, "Sorry, not enough memory available!\n");
      exit(1);
    }
  }
  do {
    *len += fread(*buf + *len, 1, *buflen - *len, f);
    if (*len == *buflen) {
      *buflen *= 2;
      *buf = (unsigned char *)realloc(*buf, *buflen);
      if (!*buf) {
        fprintf(stderr, "Sorry, not enough memory available!\n");
        exit(1);
      }
    }
    if (ferror(f)) {
      perror("Problem while reading input file");
      exit(1);
    }
  } while (!feof(f));
  *buflen = *len;
  *buf = (unsigned char *)realloc(*buf, *buflen);
  if (!*buf) {
    fprintf(stderr, "Oops, realloc failed when shrinking buffer!\n");
    exit(1);
  }
  return;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1204 <read_file+0x84>
mov    -0x10(%rbp),%rax
movq   $0xfa0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ff <read_file+0x7f>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1204 <read_file+0x84>
jmp    1209 <read_file+0x89>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
add    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
sub    (%rax),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    12b1 <read_file+0x131>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
shl    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1080 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12ac <read_file+0x12c>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12b1 <read_file+0x131>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12da <read_file+0x15a>
lea    0xd5a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12df <read_file+0x15f>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1209 <read_file+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1080 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1350 <read_file+0x1d0>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xd05(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
cmpq   $0x0,(%rsi)
jne    11c0 <read_file+0x40>
movq   $0xfa0,(%r15)
movq   $0x0,(%rbx)
mov    (%r15),%rdi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1251 <read_file+0xd1>
nopl   0x0(%rax)
mov    (%rbx),%rax
mov    (%r14),%rdi
add    %rax,%rdi
mov    (%r15),%rdx
sub    %rax,%rdx
mov    $0x1,%esi
mov    %r12,%rcx
call   1040 <fread@plt>
add    (%rbx),%rax
mov    %rax,(%rbx)
cmp    (%r15),%rax
jne    1200 <read_file+0x80>
add    %rax,%rax
mov    %rax,(%r15)
mov    (%r14),%rdi
mov    %rax,%rsi
call   1080 <realloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1251 <read_file+0xd1>
mov    %r12,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    123b <read_file+0xbb>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11c0 <read_file+0x40>
mov    (%rbx),%rsi
mov    %rsi,(%r15)
mov    (%r14),%rdi
call   1080 <realloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1270 <read_file+0xf0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xde3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
jmp    1261 <read_file+0xe1>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Sorry, not enough memory available!\0A\00"
@.str.1 = [33 x i8] c"Problem while reading input file\00"
@.str.2 = [45 x i8] c"Oops, realloc failed when shrinking buffer!\0A\00"
define void @read_file(i8** %0, i64* %1, i64* %2, i32* %3) {
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i32*
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i32* %3, i32** %8
%9 = load i64*, i64** %6
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %4
%13 = load i64*, i64** %6
store i64 4000, i64* %13
%14 = load i64*, i64** %7
store i64 0, i64* %14
%15 = load i64*, i64** %6
%16 = load i64, i64* %15
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = load i8**, i8*** %5
store i8* %18, i8** %19
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = icmp ne i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %12
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %12
br label %28
28: ; preds = %27, %4
br label %29
29: ; preds = %77, %28
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = load i64*, i64** %7
%33 = load i64, i64* %32
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i64*, i64** %6
%36 = load i64, i64* %35
%37 = load i64*, i64** %7
%38 = load i64, i64* %37
%39 = sub i64 %36, %38
%40 = load i32*, i32** %8
%41 = call i64 @fread(i8* %34, i32 1, i64 %39, i32* %40)
%42 = load i64*, i64** %7
%43 = load i64, i64* %42
%44 = add i64 %43, %41
store i64 %44, i64* %42
%45 = load i64*, i64** %7
%46 = load i64, i64* %45
%47 = load i64*, i64** %6
%48 = load i64, i64* %47
%49 = icmp eq i64 %46, %48
br i1 %49, label %50, label %69
50: ; preds = %29
%51 = load i64*, i64** %6
%52 = load i64, i64* %51
%53 = mul i64 %52, 2
store i64 %53, i64* %51
%54 = load i8**, i8*** %5
%55 = load i8*, i8** %54
%56 = load i64*, i64** %6
%57 = load i64, i64* %56
%58 = call i64 @realloc(i8* %55, i64 %57)
%59 = inttoptr i64 %58 to i8*
%60 = load i8**, i8*** %5
store i8* %59, i8** %60
%61 = load i8**, i8*** %5
%62 = load i8*, i8** %61
%63 = icmp ne i8* %62, null
br i1 %63, label %68, label %64
64: ; preds = %50
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %50
br label %69
69: ; preds = %68, %29
%70 = load i32*, i32** %8
%71 = call i64 @ferror(i32* %70)
%72 = icmp ne i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %69
br label %77
77: ; preds = %76
%78 = load i32*, i32** %8
%79 = call i32 @feof(i32* %78)
%80 = icmp ne i32 %79, 0
%81 = xor i1 %80, true
br i1 %81, label %29, label %82
82: ; preds = %77
%83 = load i64*, i64** %7
%84 = load i64, i64* %83
%85 = load i64*, i64** %6
store i64 %84, i64* %85
%86 = load i8**, i8*** %5
%87 = load i8*, i8** %86
%88 = load i64*, i64** %6
%89 = load i64, i64* %88
%90 = call i64 @realloc(i8* %87, i64 %89)
%91 = inttoptr i64 %90 to i8*
%92 = load i8**, i8*** %5
store i8* %91, i8** %92
%93 = load i8**, i8*** %5
%94 = load i8*, i8** %93
%95 = icmp ne i8* %94, null
br i1 %95, label %100, label %96
96: ; preds = %82
%97 = load i32, i32* @stderr
%98 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %82
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Sorry, not enough memory available!\0A\00"
@.str.1 = [33 x i8] c"Problem while reading input file\00"
@.str.2 = [45 x i8] c"Oops, realloc failed when shrinking buffer!\0A\00"
define void @read_file(i8** nocapture %0, i64* nocapture %1, i64* nocapture %2, i32* nocapture %3) {
%5 = load i64, i64* %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %8, %4
br label %17
8: ; preds = %4
store i64 4000, i64* %1
store i64 0, i64* %2
%9 = load i64, i64* %1
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %0
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %7
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %7, %44
%18 = load i8*, i8** %0
%19 = load i64, i64* %2
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i64, i64* %1
%22 = sub i64 %21, %19
%23 = tail call i64 @fread(i8* %20, i32 1, i64 %22, i32* %3)
%24 = load i64, i64* %2
%25 = add i64 %24, %23
store i64 %25, i64* %2
%26 = load i64, i64* %1
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %17
%29 = shl i64 %25, 1
store i64 %29, i64* %1
%30 = load i8*, i8** %0
%31 = tail call i64 @realloc(i8* %30, i64 %29)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %0
%33 = icmp eq i64 %31, 0
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %28, %17
%39 = tail call i64 @ferror(i32* %3)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %38
%45 = tail call i32 @feof(i32* %3)
%46 = icmp eq i32 %45, 0
br i1 %46, label %17, label %47
47: ; preds = %44
%48 = load i64, i64* %2
store i64 %48, i64* %1
%49 = load i8*, i8** %0
%50 = tail call i64 @realloc(i8* %49, i64 %48)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %0
%52 = icmp eq i64 %50, 0
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = tail call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%56 = tail call i32 @exit(i32 1)
unreachable
57: ; preds = %47
ret void
}