#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 */
typedef int ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ get_key_init();
int /*<<< orphan*/ perror(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
char get_key(void) {
  ssize_t got;
  char ch;
  get_key_init();
  got = read(0, &ch, 1);
  if (got == 1)
    return ch;
  if (got >= 0) {
    fprintf(stderr, "unexpected read() return value %d\n", (int)got);
    exit(1);
  }
  if (errno == EAGAIN)
    return 0;
  perror("read");
  exit(1);
}


x86 assembly (clang, -O0):
<get_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <get_key_init@plt>
xor    %edi,%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1187 <get_key+0x37>
mov    -0x9(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11ec <get_key+0x9c>
cmpl   $0x0,-0x8(%rbp)
jl     11b3 <get_key+0x63>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%rax
jne    11d6 <get_key+0x86>
movb   $0x0,-0x1(%rbp)
jmp    11ec <get_key+0x9c>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_key>:
push   %rax
xor    %eax,%eax
call   1030 <get_key_init@plt>
lea    0x7(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1174 <get_key+0x24>
mov    0x7(%rsp),%al
pop    %rcx
ret
test   %eax,%eax
jns    1192 <get_key+0x42>
mov    0x2e59(%rip),%rax
mov    (%rax),%rax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
jne    11b3 <get_key+0x63>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e47(%rip),%rcx
mov    (%rcx),%edi
lea    0xe5e(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"unexpected read() return value %d\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@.str.1 = [5 x i8] c"read\00"
define signext i8 @get_key() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i8
%4 = call i32 (...) @get_key_init()
%5 = call i32 @read(i32 0, i8* %3, i32 1)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i8, i8* %3
store i8 %9, i8* %1
br label %26
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
store i8 0, i8* %1
br label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %22, %8
%27 = load i8, i8* %1
ret i8 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"unexpected read() return value %d\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@.str.1 = [5 x i8] c"read\00"
define signext i8 @get_key() {
%1 = alloca i8
%2 = tail call i32 (...) @get_key_init()
%3 = call i32 @read(i32 0, i8* %1, i32 1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i8, i8* %1
br label %20
7: ; preds = %0
%8 = icmp sgt i32 %3, -1
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %3)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp eq i64 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13, %5
%21 = phi i8 [ %6, %5 ], [ 0, %13 ]
ret i8 %21
}