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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__, char *);
size_t pwrite(int, void *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int disk_page_write(int fd, char *page, size_t pgnum, size_t pgsiz) {
  do {
    if (pwrite(fd, (void *)page, pgsiz, (off_t)(pgnum * pgsiz)) != pgsiz) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "disk page write error (%d:%s)\n", errno,
              strerror(errno));
      return -1;
    }
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<disk_page_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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 <pwrite@plt>
cmp    -0x20(%rbp),%rax
je     11d6 <disk_page_write+0xa6>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
jne    118b <disk_page_write+0x5b>
jmp    11db <disk_page_write+0xab>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe3b(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <disk_page_write+0xb2>
jmp    11db <disk_page_write+0xab>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"disk page write error (%d:%s)\0A\00"
define i32 @disk_page_write(i32 %0, i8* nocapture %1, i64 %2, i64 %3) {
%5 = mul i64 %3, %2
%6 = trunc i64 %5 to i32
%7 = tail call i64 @pwrite(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 ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %10, i8* %15)
br label %17
17: ; preds = %9, %4, %13
%18 = phi i32 [ -1, %13 ], [ 0, %4 ], [ 0, %9 ]
ret i32 %18
}