#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 /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ die(char *);
int read(int, char *, int);
int /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
unsigned char read_byte(int fd) {
  char c;
  fd_set s;
  FD_ZERO(&s);
  FD_SET(fd, &s);
  select(fd + 1, &s, NULL, NULL, NULL);
  if (read(fd, &c, 1) != 1)
    die("EOF or read error on tty\n");
  return c;
}


x86 assembly (clang, -O0):
<read_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1070 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <select@plt>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     11b0 <read_byte+0x60>
lea    0xe55(%rip),%rdi
call   1060 <die@plt>
movzbl -0x5(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_byte>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <FD_SET@plt>
lea    0x1(%rbx),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <select@plt>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     11a1 <read_byte+0x51>
lea    0xe64(%rip),%rdi
call   1060 <die@plt>
mov    0x3(%rsp),%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"EOF or read error on tty\0A\00"
define zeroext i8 @read_byte(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @FD_ZERO(i32* %4)
%6 = load i32, i32* %2
%7 = call i32 @FD_SET(i32 %6, i32* %4)
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
%10 = call i32 @select(i32 %9, i32* %4, i32* null, i32* null, i32* null)
%11 = load i32, i32* %2
%12 = call i32 @read(i32 %11, i8* %3, i32 1)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i8, i8* %3
ret i8 %17
}

LLVM IR (-O2):
@.str = [26 x i8] c"EOF or read error on tty\0A\00"
define zeroext i8 @read_byte(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @FD_ZERO(i32* %3)
%6 = call i32 @FD_SET(i32 %0, i32* %3)
%7 = add nsw i32 %0, 1
%8 = call i32 @select(i32 %7, i32* %3, i32* null, i32* null, i32* null)
%9 = call i32 @read(i32 %0, i8* %2, i32 1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i8, i8* %2
ret i8 %14
}