#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 */
int power_of_two(int);
int next_bit(int(next_byte(void))) {
  static int c, n = 0;
  if (n == 0) {
    c = next_byte();
    if (c == -1)
      return -1;
    if (c == 0xFF) {
      c = next_byte();
      if (c == 0x00)
        c = 0xFF;
      else
        return -1;
    }
  }
  n--;
  if (n < 0)
    n = 7;
  if (c - power_of_two(n) >= 0) {
    c -= power_of_two(n);
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<next_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpl   $0x0,0x2f0d(%rip)
jne    1196 <next_bit+0x86>
call   *-0x10(%rbp)
mov    %eax,0x2efa(%rip)
cmpl   $0xffffffff,0x2ef3(%rip)
jne    114b <next_bit+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <next_bit+0xfe>
cmpl   $0xff,0x2ed7(%rip)
jne    1191 <next_bit+0x81>
call   *-0x10(%rbp)
mov    %eax,0x2ec8(%rip)
cmpl   $0x0,0x2ec1(%rip)
jne    1180 <next_bit+0x70>
movl   $0xff,0x2eb1(%rip)
jmp    118c <next_bit+0x7c>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <next_bit+0xfe>
jmp    1191 <next_bit+0x81>
jmp    1196 <next_bit+0x86>
mov    0x2e94(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2e8b(%rip)
cmpl   $0x0,0x2e84(%rip)
jge    11bc <next_bit+0xac>
movl   $0x7,0x2e74(%rip)
mov    0x2e6a(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e65(%rip),%edi
call   1030 <power_of_two@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
cmp    $0x0,%eax
jl     1207 <next_bit+0xf7>
mov    0x2e4a(%rip),%edi
call   1030 <power_of_two@plt>
mov    %eax,%ecx
mov    0x2e39(%rip),%eax
sub    %ecx,%eax
mov    %eax,0x2e31(%rip)
movl   $0x1,-0x4(%rbp)
jmp    120e <next_bit+0xfe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_bit>:
push   %r14
push   %rbx
push   %rax
cmpl   $0x0,0x2f15(%rip)
je     1162 <next_bit+0x52>
mov    0x2f09(%rip),%ebx
mov    0x2f07(%rip),%eax
lea    -0x1(%rax),%ecx
test   %eax,%eax
mov    $0x7,%edi
cmovg  %ecx,%edi
mov    %edi,0x2ef4(%rip)
call   1030 <power_of_two@plt>
cmp    %eax,%ebx
mov    $0x0,%ebx
jl     118e <next_bit+0x7e>
mov    0x2ee0(%rip),%edi
call   1030 <power_of_two@plt>
sub    %eax,0x2ed1(%rip)
mov    $0x1,%ebx
jmp    118e <next_bit+0x7e>
mov    %rdi,%r14
call   *%rdi
mov    %eax,%ebx
mov    %eax,0x2ebd(%rip)
cmp    $0xffffffff,%eax
je     118e <next_bit+0x7e>
cmp    $0xff,%ebx
jne    1123 <next_bit+0x13>
call   *%r14
mov    %eax,0x2ea7(%rip)
mov    $0xffffffff,%ebx
test   %eax,%eax
je     1198 <next_bit+0x88>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movl   $0xff,0x2e8a(%rip)
mov    $0xff,%ebx
jmp    1123 <next_bit+0x13>

LLVM IR (-O0):
@next_bit.c = internal global i32 0
@next_bit.n = internal global i32 0
define i32 @next_bit(i32 ()* %0) {
%2 = alloca i32
%3 = alloca i32 ()*
store i32 ()* %0, i32 ()** %3
%4 = load i32, i32* @next_bit.n
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %1
%7 = load i32 ()*, i32 ()** %3
%8 = call i32 %7()
store i32 %8, i32* @next_bit.c
%9 = load i32, i32* @next_bit.c
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %6
store i32 -1, i32* %2
br label %42
12: ; preds = %6
%13 = load i32, i32* @next_bit.c
%14 = icmp eq i32 %13, 255
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32 ()*, i32 ()** %3
%17 = call i32 %16()
store i32 %17, i32* @next_bit.c
%18 = load i32, i32* @next_bit.c
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 255, i32* @next_bit.c
br label %22
21: ; preds = %15
store i32 -1, i32* %2
br label %42
22: ; preds = %20
br label %23
23: ; preds = %22, %12
br label %24
24: ; preds = %23, %1
%25 = load i32, i32* @next_bit.n
%26 = add nsw i32 %25, -1
store i32 %26, i32* @next_bit.n
%27 = load i32, i32* @next_bit.n
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 7, i32* @next_bit.n
br label %30
30: ; preds = %29, %24
%31 = load i32, i32* @next_bit.c
%32 = load i32, i32* @next_bit.n
%33 = call i32 @power_of_two(i32 %32)
%34 = sub nsw i32 %31, %33
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i32, i32* @next_bit.n
%38 = call i32 @power_of_two(i32 %37)
%39 = load i32, i32* @next_bit.c
%40 = sub nsw i32 %39, %38
store i32 %40, i32* @next_bit.c
store i32 1, i32* %2
br label %42
41: ; preds = %30
store i32 0, i32* %2
br label %42
42: ; preds = %41, %36, %21, %11
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@next_bit.c = internal unnamed_addr global i32 0
@next_bit.n = internal unnamed_addr global i32 0
define i32 @next_bit(i32 ()* nocapture %0) {
%2 = load i32, i32* @next_bit.n
%3 = icmp eq i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = load i32, i32* @next_bit.c
br label %12
6: ; preds = %1
%7 = tail call i32 %0()
store i32 %7, i32* @next_bit.c
switch i32 %7, label %12 [
i32 -1, label %25
i32 255, label %8
]
8: ; preds = %6
%9 = tail call i32 %0()
store i32 %9, i32* @next_bit.c
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %8
store i32 255, i32* @next_bit.c
br label %12
12: ; preds = %4, %6, %11
%13 = phi i32 [ %5, %4 ], [ %7, %6 ], [ 255, %11 ]
%14 = load i32, i32* @next_bit.n
%15 = add nsw i32 %14, -1
%16 = icmp slt i32 %14, 1
%17 = select i1 %16, i32 7, i32 %15
store i32 %17, i32* @next_bit.n
%18 = tail call i32 @power_of_two(i32 %17)
%19 = icmp slt i32 %13, %18
br i1 %19, label %25, label %20
20: ; preds = %12
%21 = load i32, i32* @next_bit.n
%22 = tail call i32 @power_of_two(i32 %21)
%23 = load i32, i32* @next_bit.c
%24 = sub nsw i32 %23, %22
store i32 %24, i32* @next_bit.c
br label %25
25: ; preds = %12, %8, %6, %20
%26 = phi i32 [ 1, %20 ], [ %7, %6 ], [ -1, %8 ], [ 0, %12 ]
ret i32 %26
}