#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_page_read(int fd, char *page, size_t pgnum, size_t pgsiz) {
  ssize_t nread;
  do {
    if ((nread = pread(fd, (void *)page, pgsiz, (off_t)(pgnum * pgsiz))) !=
        pgsiz) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "disk page read error (%d:%s)\n", errno, strerror(errno));
      return -1;
    }
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<disk_page_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %eax,%ecx
call   1040 <pread@plt>
mov    %rax,-0x28(%rbp)
cmp    -0x20(%rbp),%rax
je     11da <disk_page_read+0xaa>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
jne    118f <disk_page_read+0x5f>
jmp    11df <disk_page_read+0xaf>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe37(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <disk_page_read+0xb6>
jmp    11df <disk_page_read+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_page_read>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%rcx
imul   %ebx,%ecx
mov    %rbx,%rdx
call   1040 <pread@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rbx,%rcx
je     118e <disk_page_read+0x5e>
mov    0x2e83(%rip),%rcx
mov    (%rcx),%rbx
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rbx
je     118e <disk_page_read+0x5e>
mov    0x2e75(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <strerror@plt>
lea    0xe84(%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 page read error (%d:%s)\0A\00"
define i32 @disk_page_read(i32 %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
br label %11
11: ; preds = %4
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = load i64, i64* %9
%15 = load i64, i64* %8
%16 = load i64, i64* %9
%17 = mul i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @pread(i32 %12, i8* %13, i64 %14, i32 %18)
store i64 %19, i64* %10
%20 = load i64, i64* %9
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %11
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
br label %34
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i64, i64* @errno
%30 = load i64, i64* @errno
%31 = call i8* @strerror(i64 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %29, i8* %31)
store i32 -1, i32* %5
br label %35
33: ; preds = %11
br label %34
34: ; preds = %26, %33
store i32 0, i32* %5
br label %35
35: ; preds = %34, %27
%36 = load i32, i32* %5
ret i32 %36
}

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