#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*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int readBit(FILE *file, unsigned char *dataByte, unsigned char *dataMask) {
  int tmp;
  if (*dataMask == 0) {
    fread(dataByte, 1, 1, file);
    *dataMask = 0x80;
  }
  tmp = *dataByte & *dataMask;
  *dataMask = *dataMask >> 1;
  return tmp ? 1 : 0;
}


x86 assembly (clang, -O0):
<readBit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    114f <readBit+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rax
movb   $0x80,(%rax)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%ecx
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
sar    $0x1,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBit>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    (%rdx),%al
test   %al,%al
jne    113a <readBit+0x2a>
mov    %rdi,%rcx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movb   $0x80,(%rbx)
mov    $0x80,%al
mov    (%r14),%cl
and    %al,%cl
shr    %al
mov    %al,(%rbx)
xor    %eax,%eax
test   %cl,%cl
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @readBit(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i32*, i32** %4
%15 = call i32 @fread(i8* %13, i32 1, i32 1, i32* %14)
%16 = load i8*, i8** %6
store i8 -128, i8* %16
br label %17
17: ; preds = %12, %3
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = and i32 %20, %23
store i32 %24, i32* %7
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = ashr i32 %27, 1
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %6
store i8 %29, i8* %30
%31 = load i32, i32* %7
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 1, i32 0
ret i32 %34
}

LLVM IR (-O2):
define i32 @readBit(i32* nocapture %0, i8* nocapture %1, i8* nocapture %2) {
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @fread(i8* %1, i32 1, i32 1, i32* %0)
store i8 -128, i8* %2
br label %8
8: ; preds = %6, %3
%9 = phi i8 [ -128, %6 ], [ %4, %3 ]
%10 = load i8, i8* %1
%11 = and i8 %9, %10
%12 = lshr i8 %9, 1
store i8 %12, i8* %2
%13 = icmp ne i8 %11, 0
%14 = zext i1 %13 to i32
ret i32 %14
}