#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__ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int get_bits_from_file(FILE *fp, int *arr, int length) {
  unsigned char byte;
  for (int i = 0; i < length; i++) {
    if (i % 8 == 0) {
      if (feof(fp)) {
        return -1;
      }
      byte = fgetc(fp);
    }
    arr[i] = (((&byte)[(i % 8) / 8] & (1 << ((i % 8) % 8))) > 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_bits_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ed <get_bits_from_file+0xcd>
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1185 <get_bits_from_file+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1179 <get_bits_from_file+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <get_bits_from_file+0xd4>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1d(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
movzbl -0x1d(%rbp,%rax,1),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%eax
mov    %edx,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113a <get_bits_from_file+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bits_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1179 <get_bits_from_file+0x59>
mov    %rsi,%r15
mov    %rdi,%r14
mov    %edx,%r12d
mov    $0x1,%r13b
xor    %ebx,%ebx
jmp    115b <get_bits_from_file+0x3b>
nop
movzbl %al,%edx
mov    %ebp,%ecx
shr    %cl,%edx
and    $0x1,%edx
mov    %edx,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %r12,%rbx
setb   %r13b
je     117c <get_bits_from_file+0x5c>
mov    %ebx,%ebp
and    $0x7,%ebp
jne    1140 <get_bits_from_file+0x20>
mov    %r14,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    117c <get_bits_from_file+0x5c>
mov    %r14,%rdi
call   1030 <fgetc@plt>
jmp    1140 <get_bits_from_file+0x20>
xor    %r13d,%r13d
movzbl %r13b,%eax
and    $0x1,%eax
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_bits_from_file(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %45, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %48
14: ; preds = %10
%15 = load i32, i32* %9
%16 = srem i32 %15, 8
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = call i64 @feof(i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %4
br label %49
23: ; preds = %18
%24 = load i32*, i32** %5
%25 = call zeroext i8 @fgetc(i32* %24)
store i8 %25, i8* %8
br label %26
26: ; preds = %23, %14
%27 = load i32, i32* %9
%28 = srem i32 %27, 8
%29 = sdiv i32 %28, 8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %8, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = load i32, i32* %9
%35 = srem i32 %34, 8
%36 = srem i32 %35, 8
%37 = shl i32 1, %36
%38 = and i32 %33, %37
%39 = icmp sgt i32 %38, 0
%40 = zext i1 %39 to i32
%41 = load i32*, i32** %6
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
br label %45
45: ; preds = %26
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %10
48: ; preds = %10
store i32 0, i32* %4
br label %49
49: ; preds = %48, %22
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @get_bits_from_file(i32* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %29
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %5, %20
%9 = phi i64 [ 0, %5 ], [ %26, %20 ]
%10 = phi i1 [ true, %5 ], [ %27, %20 ]
%11 = phi i8 [ undef, %5 ], [ %21, %20 ]
%12 = trunc i64 %9 to i32
%13 = and i32 %12, 7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = tail call i64 @feof(i32* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = tail call zeroext i8 @fgetc(i32* %0)
br label %20
20: ; preds = %18, %8
%21 = phi i8 [ %19, %18 ], [ %11, %8 ]
%22 = zext i8 %21 to i32
%23 = lshr i32 %22, %13
%24 = and i32 %23, 1
%25 = getelementptr inbounds i32, i32* %1, i64 %9
store i32 %24, i32* %25
%26 = add nuw nsw i64 %9, 1
%27 = icmp ult i64 %26, %6
%28 = icmp eq i64 %26, %7
br i1 %28, label %29, label %8
29: ; preds = %20, %15, %3
%30 = phi i1 [ false, %3 ], [ %10, %15 ], [ %27, %20 ]
%31 = sext i1 %30 to i32
ret i32 %31
}