#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__ EAGAIN;
int /*<<< orphan*/ STDIN_FILENO;
scalar_t__ errno;
int /*<<< orphan*/ panic();
int read(int /*<<< orphan*/, char *, int);
int get_byte(void) {
  int nread;
  char c;
  while ((nread = read(STDIN_FILENO, &c, 1)) != 1) {
    if (nread == -1 && errno != EAGAIN)
      panic();
  }
  return (int)(unsigned char)c;
}


x86 assembly (clang, -O0):
<get_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x1,%eax
je     117b <get_byte+0x5b>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1176 <get_byte+0x56>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
je     1176 <get_byte+0x56>
mov    $0x0,%al
call   1030 <panic@plt>
jmp    1128 <get_byte+0x8>
movzbl -0x5(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_byte>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2ea9(%rip),%r14
lea    0x7(%rsp),%rbx
mov    0x2ea5(%rip),%r15
mov    0x2e86(%rip),%r12
jmp    1155 <get_byte+0x35>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%eax
je     117c <get_byte+0x5c>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    1150 <get_byte+0x30>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1155 <get_byte+0x35>
xor    %eax,%eax
call   1030 <panic@plt>
jmp    1155 <get_byte+0x35>
movzbl 0x7(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @get_byte() {
%1 = alloca i32
%2 = alloca i8
br label %3
3: ; preds = %16, %0
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @read(i32 %4, i8* %2, i32 1)
store i32 %5, i32* %1
%6 = icmp ne i32 %5, 1
br i1 %6, label %7, label %17
7: ; preds = %3
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (...) @panic()
br label %16
16: ; preds = %14, %10, %7
br label %3
17: ; preds = %3
%18 = load i8, i8* %2
%19 = zext i8 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @get_byte() {
%1 = alloca i8
br label %2
2: ; preds = %5, %0
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %1, i32 1)
switch i32 %4, label %5 [
i32 1, label %12
i32 -1, label %6
]
5: ; preds = %2, %10, %6
br label %2
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EAGAIN
%9 = icmp eq i64 %7, %8
br i1 %9, label %5, label %10
10: ; preds = %6
%11 = tail call i32 (...) @panic()
br label %5
12: ; preds = %2
%13 = load i8, i8* %1
%14 = zext i8 %13 to i32
ret i32 %14
}