#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 read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
int getbyte(void) {
  int len;
  unsigned char buf[8];
  len = read(0, buf, 1);
  if (!len)
    return (EOF);
  if (len != 1) {
    fprintf(stderr, "getbyte: read error\n");
    exit(1);
  }
  return (buf[0]);
}


x86 assembly (clang, -O0):
<getbyte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x10(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1166 <getbyte+0x36>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <getbyte+0x66>
cmpl   $0x1,-0x8(%rbp)
je     118f <getbyte+0x5f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movzbl -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbyte>:
push   %rax
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     1154 <getbyte+0x24>
test   %eax,%eax
jne    115a <getbyte+0x2a>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
movzbl (%rsp),%eax
pop    %rcx
ret
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%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 = [21 x i8] c"getbyte: read error\0A\00"
define i32 @getbyte() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 1)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = load i32, i32* @EOF
store i32 %9, i32* %1
br label %21
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
store i32 %20, i32* %1
br label %21
21: ; preds = %17, %8
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"getbyte: read error\0A\00"
define i32 @getbyte() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 1)
switch i32 %3, label %6 [
i32 0, label %4
i32 1, label %10
]
4: ; preds = %0
%5 = load i32, i32* @EOF
br label %13
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
br label %13
13: ; preds = %10, %4
%14 = phi i32 [ %12, %10 ], [ %5, %4 ]
ret i32 %14
}