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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__, char *);
size_t pread(int, void *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int disk_byte_read(int fd, void *buf, size_t count, off_t offset) {
  ssize_t nread;
  do {
    if ((nread = pread(fd, buf, count, offset)) != count) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "disk byte read error (%d:%s)\n", errno, strerror(errno));
      return -1;
    }
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<disk_byte_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <pread@plt>
mov    %rax,-0x28(%rbp)
cmp    -0x18(%rbp),%rax
je     11d1 <disk_byte_read+0xa1>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <disk_byte_read+0x56>
jmp    11d6 <disk_byte_read+0xa6>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe40(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <disk_byte_read+0xad>
jmp    11d6 <disk_byte_read+0xa6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_byte_read>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
call   1040 <pread@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rbx,%rcx
je     1185 <disk_byte_read+0x55>
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%rbx
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rbx
je     1185 <disk_byte_read+0x55>
mov    0x2e7e(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <strerror@plt>
lea    0xe8d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [30 x i8] c"disk byte read error (%d:%s)\0A\00"
define i32 @disk_byte_read(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
br label %11
11: ; preds = %4
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = load i64, i64* %8
%15 = load i32, i32* %9
%16 = call i64 @pread(i32 %12, i8* %13, i64 %14, i32 %15)
store i64 %16, i64* %10
%17 = load i64, i64* %8
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %11
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
br label %31
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i64, i64* @errno
%27 = load i64, i64* @errno
%28 = call i8* @strerror(i64 %27)
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %26, i8* %28)
store i32 -1, i32* %5
br label %32
30: ; preds = %11
br label %31
31: ; preds = %23, %30
store i32 0, i32* %5
br label %32
32: ; preds = %31, %24
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [30 x i8] c"disk byte read error (%d:%s)\0A\00"
define i32 @disk_byte_read(i32 %0, i8* nocapture %1, i64 %2, i32 %3) {
%5 = tail call i64 @pread(i32 %0, i8* %1, i64 %2, i32 %3)
%6 = icmp eq i64 %5, %2
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i8* @strerror(i64 %8)
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %8, i8* %13)
br label %15
15: ; preds = %4, %7, %11
%16 = phi i32 [ -1, %11 ], [ 0, %7 ], [ 0, %4 ]
ret i32 %16
}