#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 */

/* Variables and functions */
scalar_t__ ds2751_readBit();
int ds2751_readByte() {
  int loop, result = 0;
  for (loop = 0; loop < 8; loop++) {
    result >>= 1;
    if (ds2751_readBit())
      result |= 0x80;
  }
  return result;
}


x86 assembly (clang, -O0):
<ds2751_readByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x8,-0x4(%rbp)
jge    1168 <ds2751_readByte+0x58>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <ds2751_readBit@plt>
cmp    $0x0,%rax
je     1155 <ds2751_readByte+0x45>
mov    -0x8(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0x8(%rbp)
jmp    115a <ds2751_readByte+0x4a>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1126 <ds2751_readByte+0x16>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds2751_readByte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
lea    0x2(%rbp),%ecx
test   %rbx,%rbx
cmove  %ebp,%ecx
lea    0x4(%rcx),%edx
test   %r14,%r14
cmove  %ecx,%edx
lea    0x8(%rdx),%ecx
test   %r15,%r15
cmove  %edx,%ecx
mov    %ecx,%edx
or     $0x10,%edx
test   %r12,%r12
cmove  %ecx,%edx
mov    %edx,%ecx
or     $0x20,%ecx
test   %r13,%r13
cmove  %edx,%ecx
mov    %ecx,%ebx
or     $0x40,%ebx
test   %rax,%rax
cmove  %ecx,%ebx
xor    %eax,%eax
call   1030 <ds2751_readBit@plt>
mov    %ebx,%ecx
or     $0x80,%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ds2751_readByte() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %1
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 8
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i32, i32* %2
%8 = ashr i32 %7, 1
store i32 %8, i32* %2
%9 = call i64 (...) @ds2751_readBit()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i32, i32* %2
%13 = or i32 %12, 128
store i32 %13, i32* %2
br label %14
14: ; preds = %11, %6
br label %15
15: ; preds = %14
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %3
18: ; preds = %3
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
define i32 @ds2751_readByte() {
%1 = tail call i64 (...) @ds2751_readBit()
%2 = icmp ne i64 %1, 0
%3 = zext i1 %2 to i32
%4 = tail call i64 (...) @ds2751_readBit()
%5 = icmp eq i64 %4, 0
%6 = tail call i64 (...) @ds2751_readBit()
%7 = icmp eq i64 %6, 0
%8 = tail call i64 (...) @ds2751_readBit()
%9 = icmp eq i64 %8, 0
%10 = tail call i64 (...) @ds2751_readBit()
%11 = icmp eq i64 %10, 0
%12 = tail call i64 (...) @ds2751_readBit()
%13 = icmp eq i64 %12, 0
%14 = tail call i64 (...) @ds2751_readBit()
%15 = icmp eq i64 %14, 0
%16 = or i32 %3, 2
%17 = select i1 %5, i32 %3, i32 %16
%18 = or i32 %17, 4
%19 = select i1 %7, i32 %17, i32 %18
%20 = or i32 %19, 8
%21 = select i1 %9, i32 %19, i32 %20
%22 = or i32 %21, 16
%23 = select i1 %11, i32 %21, i32 %22
%24 = or i32 %23, 32
%25 = select i1 %13, i32 %23, i32 %24
%26 = or i32 %25, 64
%27 = select i1 %15, i32 %25, i32 %26
%28 = tail call i64 (...) @ds2751_readBit()
%29 = icmp eq i64 %28, 0
%30 = or i32 %27, 128
%31 = select i1 %29, i32 %27, i32 %30
ret i32 %31
}