#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 */
char getchar();
int read_next_byte(void) {
  int byte = 0x0;
  for (int mask = 0x80; mask != 0x00; mask >>= 1) {
    if (getchar() == '1')
      byte |= mask;
  }
  return byte;
}


x86 assembly (clang, -O0):
<read_next_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x80,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     115f <read_next_byte+0x4f>
mov    $0x0,%al
call   1030 <getchar@plt>
movsbl %al,%eax
cmp    $0x31,%eax
jne    114c <read_next_byte+0x3c>
mov    -0x8(%rbp),%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1151 <read_next_byte+0x41>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <read_next_byte+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_next_byte>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ebx,%ebx
cmp    $0x31,%al
sete   %bl
shl    $0x7,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ebp,%ebp
cmp    $0x31,%al
sete   %bpl
shl    $0x6,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ebx,%ebx
cmp    $0x31,%al
sete   %bl
shl    $0x5,%ebx
or     %ebp,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ebp,%ebp
cmp    $0x31,%al
sete   %bpl
shl    $0x4,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x31,%al
sete   %cl
lea    0x0(%rbp,%rcx,8),%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x31,%al
sete   %cl
lea    (%rbx,%rcx,4),%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x31,%al
sete   %cl
lea    (%rbx,%rcx,2),%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x31,%al
sete   %cl
or     %ebx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_next_byte() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 128, i32* %2
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = call signext i8 (...) @getchar()
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 49
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* %2
%12 = load i32, i32* %1
%13 = or i32 %12, %11
store i32 %13, i32* %1
br label %14
14: ; preds = %10, %6
br label %15
15: ; preds = %14
%16 = load i32, i32* %2
%17 = ashr i32 %16, 1
store i32 %17, i32* %2
br label %3
18: ; preds = %3
%19 = load i32, i32* %1
ret i32 %19
}

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