#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getbyte();
int /*<<< orphan*/ stderr;
int getbit(void) {
  int ch;
  while (1) {
    ch = getbyte();
    if (ch == EOF) {
      fprintf(stderr, "getbit: end of input file\n");
      exit(1);
    }
    if (ch == '0' || ch == '1')
      break;
  }
  return (ch);
}


x86 assembly (clang, -O0):
<getbit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getbyte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e9c(%rip),%rcx
cmp    (%rcx),%eax
jne    1173 <getbit+0x43>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x30,-0x4(%rbp)
je     1187 <getbit+0x57>
cmpl   $0x31,-0x4(%rbp)
jne    118c <getbit+0x5c>
jmp    1191 <getbit+0x61>
jmp    1138 <getbit+0x8>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbit>:
push   %rbx
mov    0x2eb0(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getbyte@plt>
cmp    (%rbx),%eax
je     1157 <getbit+0x27>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
cmp    $0x30,%ecx
jne    1140 <getbit+0x10>
pop    %rbx
ret
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"getbit: end of input file\0A\00"
define i32 @getbit() {
%1 = alloca i32
br label %2
2: ; preds = %0, %18
%3 = call i32 (...) @getbyte()
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 48
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 49
br i1 %16, label %17, label %18
17: ; preds = %14, %11
br label %19
18: ; preds = %14
br label %2
19: ; preds = %17
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"getbit: end of input file\0A\00"
define i32 @getbit() {
br label %1
1: ; preds = %9, %0
%2 = tail call i32 (...) @getbyte()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = and i32 %2, -2
%11 = icmp eq i32 %10, 48
br i1 %11, label %12, label %1
12: ; preds = %9
ret i32 %2
}