#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__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int read(int, char *, int);
void read_one_byte(int fd) {
  for (;;) {
    char c;
    ssize_t rc = read(fd, &c, 1);
    if (rc == 1) {
      break;
    }
    if (rc == 0) {
      exit(127);
    }
    if (errno != EINTR) {
      exit(127);
    }
  }
}


x86 assembly (clang, -O0):
<read_one_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    114e <read_one_byte+0x2e>
jmp    118b <read_one_byte+0x6b>
cmpl   $0x0,-0xc(%rbp)
jne    1162 <read_one_byte+0x42>
mov    $0x7f,%edi
call   1040 <exit@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
je     1186 <read_one_byte+0x66>
mov    $0x7f,%edi
call   1040 <exit@plt>
jmp    112b <read_one_byte+0xb>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_one_byte>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x7(%rsp),%r14
mov    0x2eaa(%rip),%r15
mov    0x2e9b(%rip),%r12
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     116b <read_one_byte+0x4b>
test   %eax,%eax
je     1161 <read_one_byte+0x41>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1140 <read_one_byte+0x20>
mov    $0x7f,%edi
call   1040 <exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define void @read_one_byte(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %2
%7 = call i32 @read(i32 %6, i8* %3, i32 1)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %5
br label %23
11: ; preds = %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @exit(i32 127)
unreachable
16: ; preds = %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @exit(i32 127)
unreachable
22: ; preds = %16
br label %5
23: ; preds = %10
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define void @read_one_byte(i32 %0) {
%2 = alloca i8
br label %3
3: ; preds = %13, %1
%4 = call i32 @read(i32 %0, i8* %2, i32 1)
switch i32 %4, label %7 [
i32 1, label %14
i32 0, label %5
]
5: ; preds = %3
%6 = tail call i32 @exit(i32 127)
unreachable
7: ; preds = %3
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @exit(i32 127)
unreachable
13: ; preds = %7
br label %3
14: ; preds = %3
ret void
}