#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_byte_write(int fd, void *buf, size_t count, off_t offset) {
  do {
    if (pwrite(fd, buf, count, offset) != count) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "disk byte write error (%d:%s)\n", errno,
              strerror(errno));
      return -1;
    }
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<disk_byte_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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 <pwrite@plt>
cmp    -0x18(%rbp),%rax
je     11cd <disk_byte_write+0x9d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    1182 <disk_byte_write+0x52>
jmp    11d2 <disk_byte_write+0xa2>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe44(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <disk_byte_write+0xa9>
jmp    11d2 <disk_byte_write+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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