#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 unsigned int uint8_t;
typedef unsigned int uint64_t;
typedef unsigned int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int *calloc(unsigned int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int *realloc(int *, unsigned int);
int /*<<< orphan*/ stderr;
bool *readDataFromFile(char *fileName, uint64_t *length) {
  printf("Reading data\n");
  FILE *file = fopen(fileName, "r");
  if (file == NULL) {
    fprintf(stderr, "Unable to open file %s\n", fileName);
    exit(1);
  }
  uint64_t pos = 0u;
  uint64_t size = 16384u;
  bool *data = calloc(size, sizeof(bool));
  int c = getc(file);
  while (c != EOF) {
    if (pos * 8u + 8u >= size) {
      size <<= 1u;
      data = realloc(data, size);
    }
    uint8_t v = c;
    uint32_t i;
    for (i = 0u; i < 8u; i++) {
      if (v & 1u) {
        data[8u * pos + 7u - i] = true;
      }
      v >>= 1u;
    }
    pos++;
    c = getc(file);
  }
  fclose(file);
  *length = pos * 8u;
  printf("Read %llu bits\n", (long long)(*length));
  return data;
}


x86 assembly (clang, -O0):
<readDataFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <readDataFromFile+0x60>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x4000,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%eax
je     12b8 <readDataFromFile+0x138>
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
add    $0x8,%eax
cmp    -0x20(%rbp),%eax
jb     1248 <readDataFromFile+0xc8>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x8,-0x34(%rbp)
jae    129e <readDataFromFile+0x11e>
mov    -0x30(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1287 <readDataFromFile+0x107>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
add    $0x7,%ecx
sub    -0x34(%rbp),%ecx
mov    %ecx,%ecx
movl   $0x1,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1255 <readDataFromFile+0xd5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x2c(%rbp)
jmp    120b <readDataFromFile+0x8b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,%esi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readDataFromFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     132a <readDataFromFile+0x19a>
mov    %rax,%r15
mov    %rbp,(%rsp)
mov    $0x4000,%r12d
mov    $0x4000,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
mov    0x2df3(%rip),%rax
xor    %r14d,%r14d
cmp    (%rax),%ebp
jne    122e <readDataFromFile+0x9e>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rax
mov    %r14d,(%rax)
mov    %r14d,%esi
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
jmp    1258 <readDataFromFile+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
mov    %r14d,%r13d
mov    0x2d94(%rip),%rax
cmp    (%rax),%ebp
je     11fc <readDataFromFile+0x6c>
lea    0x8(%r13),%r14d
cmp    %r12d,%r14d
jb     1272 <readDataFromFile+0xe2>
add    %r12d,%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1080 <realloc@plt>
mov    %rax,%rbx
add    $0x7,%r13d
test   $0x1,%bpl
jne    12b0 <readDataFromFile+0x120>
test   $0x2,%bpl
jne    12be <readDataFromFile+0x12e>
test   $0x4,%bpl
jne    12cd <readDataFromFile+0x13d>
test   $0x8,%bpl
jne    12dc <readDataFromFile+0x14c>
test   $0x10,%bpl
jne    12eb <readDataFromFile+0x15b>
test   $0x20,%bpl
jne    12fa <readDataFromFile+0x16a>
test   $0x40,%bpl
jne    1309 <readDataFromFile+0x179>
test   $0x80,%bpl
je     1240 <readDataFromFile+0xb0>
jmp    131c <readDataFromFile+0x18c>
nopl   0x0(%rax,%rax,1)
movl   $0x1,(%rbx,%r13,4)
test   $0x2,%bpl
je     1282 <readDataFromFile+0xf2>
movl   $0x1,-0x4(%rbx,%r13,4)
test   $0x4,%bpl
je     1288 <readDataFromFile+0xf8>
movl   $0x1,-0x8(%rbx,%r13,4)
test   $0x8,%bpl
je     128e <readDataFromFile+0xfe>
movl   $0x1,-0xc(%rbx,%r13,4)
test   $0x10,%bpl
je     1294 <readDataFromFile+0x104>
movl   $0x1,-0x10(%rbx,%r13,4)
test   $0x20,%bpl
je     129a <readDataFromFile+0x10a>
movl   $0x1,-0x14(%rbx,%r13,4)
test   $0x40,%bpl
je     12a0 <readDataFromFile+0x110>
movl   $0x1,-0x18(%rbx,%r13,4)
test   $0x80,%bpl
je     1240 <readDataFromFile+0xb0>
movl   $0x1,-0x1c(%rbx,%r13,4)
jmp    1240 <readDataFromFile+0xb0>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Reading data\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Unable to open file %s\0A\00"
@EOF = global i32 0
@.str.3 = [16 x i8] c"Read %llu bits\0A\00"
define i32* @readDataFromFile(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
store i32 0, i32* %6
store i32 16384, i32* %7
%23 = load i32, i32* %7
%24 = call i32* @calloc(i32 %23, i32 4)
store i32* %24, i32** %8
%25 = load i32*, i32** %5
%26 = call i32 @getc(i32* %25)
store i32 %26, i32* %9
br label %27
27: ; preds = %67, %22
%28 = load i32, i32* %9
%29 = load i32, i32* @EOF
%30 = icmp ne i32 %28, %29
br i1 %30, label %31, label %72
31: ; preds = %27
%32 = load i32, i32* %6
%33 = mul i32 %32, 8
%34 = add i32 %33, 8
%35 = load i32, i32* %7
%36 = icmp uge i32 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load i32, i32* %7
%39 = shl i32 %38, 1
store i32 %39, i32* %7
%40 = load i32*, i32** %8
%41 = load i32, i32* %7
%42 = call i32* @realloc(i32* %40, i32 %41)
store i32* %42, i32** %8
br label %43
43: ; preds = %37, %31
%44 = load i32, i32* %9
store i32 %44, i32* %10
store i32 0, i32* %11
br label %45
45: ; preds = %64, %43
%46 = load i32, i32* %11
%47 = icmp ult i32 %46, 8
br i1 %47, label %48, label %67
48: ; preds = %45
%49 = load i32, i32* %10
%50 = and i32 %49, 1
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = load i32*, i32** %8
%54 = load i32, i32* %6
%55 = mul i32 8, %54
%56 = add i32 %55, 7
%57 = load i32, i32* %11
%58 = sub i32 %56, %57
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %53, i64 %59
store i32 1, i32* %60
br label %61
61: ; preds = %52, %48
%62 = load i32, i32* %10
%63 = lshr i32 %62, 1
store i32 %63, i32* %10
br label %64
64: ; preds = %61
%65 = load i32, i32* %11
%66 = add i32 %65, 1
store i32 %66, i32* %11
br label %45
67: ; preds = %45
%68 = load i32, i32* %6
%69 = add i32 %68, 1
store i32 %69, i32* %6
%70 = load i32*, i32** %5
%71 = call i32 @getc(i32* %70)
store i32 %71, i32* %9
br label %27
72: ; preds = %27
%73 = load i32*, i32** %5
%74 = call i32 @fclose(i32* %73)
%75 = load i32, i32* %6
%76 = mul i32 %75, 8
%77 = load i32*, i32** %4
store i32 %76, i32* %77
%78 = load i32*, i32** %4
%79 = load i32, i32* %78
%80 = zext i32 %79 to i64
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %80)
%82 = load i32*, i32** %8
ret i32* %82
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Unable to open file %s\0A\00"
@EOF = global i32 0
@.str.3 = [16 x i8] c"Read %llu bits\0A\00"
@str = [13 x i8] c"Reading data\00"
define i32* @readDataFromFile(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32* @calloc(i32 16384, i32 4)
%12 = tail call i32 @getc(i32* %4)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %84, label %15
15: ; preds = %10, %77
%16 = phi i32 [ %79, %77 ], [ %12, %10 ]
%17 = phi i32* [ %28, %77 ], [ %11, %10 ]
%18 = phi i32 [ %27, %77 ], [ 16384, %10 ]
%19 = phi i32 [ %78, %77 ], [ 0, %10 ]
%20 = shl i32 %19, 3
%21 = add i32 %20, 8
%22 = icmp ult i32 %21, %18
br i1 %22, label %26, label %23
23: ; preds = %15
%24 = shl i32 %18, 1
%25 = tail call i32* @realloc(i32* %17, i32 %24)
br label %26
26: ; preds = %23, %15
%27 = phi i32 [ %24, %23 ], [ %18, %15 ]
%28 = phi i32* [ %25, %23 ], [ %17, %15 ]
%29 = or i32 %20, 7
%30 = zext i32 %29 to i64
%31 = and i32 %16, 1
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 1, i32* %34
br label %35
35: ; preds = %33, %26
%36 = and i32 %16, 2
%37 = icmp eq i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = add nsw i64 %30, -1
%40 = getelementptr inbounds i32, i32* %28, i64 %39
store i32 1, i32* %40
br label %41
41: ; preds = %38, %35
%42 = and i32 %16, 4
%43 = icmp eq i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = add nsw i64 %30, -2
%46 = getelementptr inbounds i32, i32* %28, i64 %45
store i32 1, i32* %46
br label %47
47: ; preds = %44, %41
%48 = and i32 %16, 8
%49 = icmp eq i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = add nsw i64 %30, -3
%52 = getelementptr inbounds i32, i32* %28, i64 %51
store i32 1, i32* %52
br label %53
53: ; preds = %50, %47
%54 = and i32 %16, 16
%55 = icmp eq i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = add nsw i64 %30, -4
%58 = getelementptr inbounds i32, i32* %28, i64 %57
store i32 1, i32* %58
br label %59
59: ; preds = %56, %53
%60 = and i32 %16, 32
%61 = icmp eq i32 %60, 0
br i1 %61, label %65, label %62
62: ; preds = %59
%63 = add nsw i64 %30, -5
%64 = getelementptr inbounds i32, i32* %28, i64 %63
store i32 1, i32* %64
br label %65
65: ; preds = %62, %59
%66 = and i32 %16, 64
%67 = icmp eq i32 %66, 0
br i1 %67, label %71, label %68
68: ; preds = %65
%69 = add nsw i64 %30, -6
%70 = getelementptr inbounds i32, i32* %28, i64 %69
store i32 1, i32* %70
br label %71
71: ; preds = %68, %65
%72 = and i32 %16, 128
%73 = icmp eq i32 %72, 0
br i1 %73, label %77, label %74
74: ; preds = %71
%75 = add nsw i64 %30, -7
%76 = getelementptr inbounds i32, i32* %28, i64 %75
store i32 1, i32* %76
br label %77
77: ; preds = %74, %71
%78 = add i32 %19, 1
%79 = tail call i32 @getc(i32* %4)
%80 = load i32, i32* @EOF
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %15
82: ; preds = %77
%83 = shl i32 %78, 3
br label %84
84: ; preds = %82, %10
%85 = phi i32 [ 0, %10 ], [ %83, %82 ]
%86 = phi i32* [ %11, %10 ], [ %28, %82 ]
%87 = tail call i32 @fclose(i32* %4)
store i32 %85, i32* %1
%88 = zext i32 %85 to i64
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %88)
ret i32* %86
}