#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);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
int getfile(const char *filename, char **text) {
  FILE *file = NULL;
  int total_read = 0;
  file = fopen(filename, "r");
  if (file == NULL) {
    fprintf(stderr, "io error: %s, %d\n", filename, 64);
    return -1;
  } else {
    int char_size = sizeof(char);
    int index = 0;
    int cap = 1024;
    char *buf;
    *text = (char *)malloc(cap);
    if (*text == NULL) {
      fprintf(stderr, "memory allocation failure\n");
      exit(1);
    }
    buf = (char *)malloc(1024);
    if (buf == NULL) {
      fprintf(stderr, "memory allocation failure\n");
      exit(1);
    }
    do {
      int read;
      read = fread(buf, char_size, 1024, file);
      if (ferror(file) != 0) {
        free(buf);
        free(*text);
        fclose(file);
        fprintf(stderr, "io error: %d\n", 92);
        exit(1);
      }
      total_read += read;
      if (total_read > cap) {
        char *newmem = realloc(*text, (cap * 2));
        if (newmem == NULL) {
          free(buf);
          free(*text);
          fprintf(stderr, "io error: %d\n", 101);
          exit(1);
        }
        *text = newmem;
        cap = total_read;
      }
      memcpy((*text) + index, buf, read);
      index = total_read;
    } while (feof(file) == 0);
    free(buf);
    (*text)[total_read] = '\0';
    if (fclose(file) != 0) {
      fprintf(stderr, "io error: %d\n", 115);
      exit(1);
    }
  }
  return total_read;
}


x86 assembly (clang, -O0):
<getfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121a <getfile+0x6a>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe00(%rip),%rsi
mov    $0x40,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    142f <getfile+0x27f>
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x400,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1270 <getfile+0xc0>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12aa <getfile+0xfa>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    12af <getfile+0xff>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x400,%edx
call   1050 <fread@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     131e <getfile+0x16e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
mov    $0x5c,%edx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x3c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    13a0 <getfile+0x1f0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%esi
shl    $0x1,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    138f <getfile+0x1df>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xcb6(%rip),%rsi
mov    $0x65,%edx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1090 <memcpy@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12af <getfile+0xff>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     1424 <getfile+0x274>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
lea    0xc21(%rip),%rsi
mov    $0x73,%edx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1429 <getfile+0x279>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe38(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12fd <getfile+0x14d>
mov    %rax,%r12
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     1374 <getfile+0x1c4>
mov    %rbp,(%rsp)
mov    $0x400,%r13d
mov    $0x400,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1374 <getfile+0x1c4>
mov    %rax,%r15
xor    %r14d,%r14d
jmp    124a <getfile+0x9a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %ebp,%r13d
movslq %r14d,%rdi
add    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1090 <memcpy@plt>
mov    %r12,%rdi
call   1080 <feof@plt>
mov    %ebp,%r14d
test   %rax,%rax
jne    12c3 <getfile+0x113>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1332 <getfile+0x182>
lea    (%rbx,%r14,1),%ebp
mov    (%rsp),%rax
mov    (%rax),%rax
cmp    %r13d,%ebp
jle    122a <getfile+0x7a>
add    %r13d,%r13d
mov    %rax,%rdi
mov    %r13d,%esi
call   10b0 <realloc@plt>
test   %rax,%rax
jne    1220 <getfile+0x70>
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
mov    $0x65,%edx
jmp    1363 <getfile+0x1b3>
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
mov    (%rax),%rax
movslq %ebp,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %r12,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
je     1321 <getfile+0x171>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd39(%rip),%rsi
mov    $0x73,%edx
jmp    1363 <getfile+0x1b3>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
mov    %rbx,%rdx
mov    $0x40,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
mov    $0x5c,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    0xc90(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"io error: %s, %d\0A\00"
@.str.2 = [27 x i8] c"memory allocation failure\0A\00"
@.str.3 = [14 x i8] c"io error: %d\0A\00"
define i32 @getfile(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %7
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %4
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 64)
store i32 -1, i32* %3
br label %123
22: ; preds = %2
store i32 1, i32* %8
store i32 0, i32* %9
store i32 1024, i32* %10
%23 = load i32, i32* %10
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = load i8**, i8*** %5
store i8* %25, i8** %26
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %22
%35 = call i64 @malloc(i32 1024)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %11
%37 = load i8*, i8** %11
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %34
br label %44
44: ; preds = %101, %43
%45 = load i8*, i8** %11
%46 = load i32, i32* %8
%47 = load i32*, i32** %6
%48 = call i32 @fread(i8* %45, i32 %46, i32 1024, i32* %47)
store i32 %48, i32* %12
%49 = load i32*, i32** %6
%50 = call i64 @ferror(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %63
52: ; preds = %44
%53 = load i8*, i8** %11
%54 = call i32 @free(i8* %53)
%55 = load i8**, i8*** %5
%56 = load i8*, i8** %55
%57 = call i32 @free(i8* %56)
%58 = load i32*, i32** %6
%59 = call i64 @fclose(i32* %58)
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 92)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %44
%64 = load i32, i32* %12
%65 = load i32, i32* %7
%66 = add nsw i32 %65, %64
store i32 %66, i32* %7
%67 = load i32, i32* %7
%68 = load i32, i32* %10
%69 = icmp sgt i32 %67, %68
br i1 %69, label %70, label %91
70: ; preds = %63
%71 = load i8**, i8*** %5
%72 = load i8*, i8** %71
%73 = load i32, i32* %10
%74 = mul nsw i32 %73, 2
%75 = call i8* @realloc(i8* %72, i32 %74)
store i8* %75, i8** %13
%76 = load i8*, i8** %13
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %87
78: ; preds = %70
%79 = load i8*, i8** %11
%80 = call i32 @free(i8* %79)
%81 = load i8**, i8*** %5
%82 = load i8*, i8** %81
%83 = call i32 @free(i8* %82)
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 101)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %70
%88 = load i8*, i8** %13
%89 = load i8**, i8*** %5
store i8* %88, i8** %89
%90 = load i32, i32* %7
store i32 %90, i32* %10
br label %91
91: ; preds = %87, %63
%92 = load i8**, i8*** %5
%93 = load i8*, i8** %92
%94 = load i32, i32* %9
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
%97 = load i8*, i8** %11
%98 = load i32, i32* %12
%99 = call i32 @memcpy(i8* %96, i8* %97, i32 %98)
%100 = load i32, i32* %7
store i32 %100, i32* %9
br label %101
101: ; preds = %91
%102 = load i32*, i32** %6
%103 = call i64 @feof(i32* %102)
%104 = icmp eq i64 %103, 0
br i1 %104, label %44, label %105
105: ; preds = %101
%106 = load i8*, i8** %11
%107 = call i32 @free(i8* %106)
%108 = load i8**, i8*** %5
%109 = load i8*, i8** %108
%110 = load i32, i32* %7
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %109, i64 %111
store i8 0, i8* %112
%113 = load i32*, i32** %6
%114 = call i64 @fclose(i32* %113)
%115 = icmp ne i64 %114, 0
br i1 %115, label %116, label %120
116: ; preds = %105
%117 = load i32, i32* @stderr
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 115)
%119 = call i32 @exit(i32 1)
unreachable
120: ; preds = %105
br label %121
121: ; preds = %120
%122 = load i32, i32* %7
store i32 %122, i32* %3
br label %123
123: ; preds = %121, %18
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"io error: %s, %d\0A\00"
@.str.2 = [27 x i8] c"memory allocation failure\0A\00"
@.str.3 = [14 x i8] c"io error: %d\0A\00"
define i32 @getfile(i8* %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 64)
br label %73
8: ; preds = %2
%9 = tail call i64 @malloc(i32 1024)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %1
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = tail call i64 @malloc(i32 1024)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %16, %54
%25 = phi i32 [ %56, %54 ], [ 1024, %16 ]
%26 = phi i32 [ %39, %54 ], [ 0, %16 ]
%27 = tail call i32 @fread(i8* %18, i32 1, i32 1024, i32* %3)
%28 = tail call i64 @ferror(i32* %3)
%29 = icmp eq i64 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %24
%31 = tail call i32 @free(i8* %18)
%32 = load i8*, i8** %1
%33 = tail call i32 @free(i8* %32)
%34 = tail call i64 @fclose(i32* %3)
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 92)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %24
%39 = add nsw i32 %27, %26
%40 = icmp sgt i32 %39, %25
%41 = load i8*, i8** %1
br i1 %40, label %42, label %54
42: ; preds = %38
%43 = shl nsw i32 %25, 1
%44 = tail call i8* @realloc(i8* %41, i32 %43)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = tail call i32 @free(i8* %18)
%48 = load i8*, i8** %1
%49 = tail call i32 @free(i8* %48)
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 101)
%52 = tail call i32 @exit(i32 1)
unreachable
53: ; preds = %42
store i8* %44, i8** %1
br label %54
54: ; preds = %38, %53
%55 = phi i8* [ %44, %53 ], [ %41, %38 ]
%56 = phi i32 [ %39, %53 ], [ %25, %38 ]
%57 = sext i32 %26 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = tail call i32 @memcpy(i8* %58, i8* %18, i32 %27)
%60 = tail call i64 @feof(i32* %3)
%61 = icmp eq i64 %60, 0
br i1 %61, label %24, label %62
62: ; preds = %54
%63 = tail call i32 @free(i8* %18)
%64 = load i8*, i8** %1
%65 = sext i32 %39 to i64
%66 = getelementptr inbounds i8, i8* %64, i64 %65
store i8 0, i8* %66
%67 = tail call i64 @fclose(i32* %3)
%68 = icmp eq i64 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %62
%70 = load i32, i32* @stderr
%71 = tail call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 115)
%72 = tail call i32 @exit(i32 1)
unreachable
73: ; preds = %62, %5
%74 = phi i32 [ -1, %5 ], [ %39, %62 ]
ret i32 %74
}