#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;
typedef int off_t;

/* Variables and functions */
#define EAGAIN 128
int /*<<< orphan*/ errno;
int /*<<< orphan*/ puts(int /*<<< orphan*/);
int pwrite(int, void *, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int do_io_write(int fd, void *address, ssize_t *bytes, off_t *offset) {
  ssize_t bytes_written = 0;
  bytes_written = pwrite(fd, address, *bytes, *offset);
  switch (bytes_written) {
  case -1:
    switch (errno) {
    case EAGAIN:
      break;
    default:
      puts(strerror(errno));
      return -1;
    }
    break;
  default:
    *bytes = bytes_written;
    *offset += bytes_written;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_io_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)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
call   1040 <pwrite@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    $0xffffffff,%eax
jne    11be <do_io_write+0x8e>
jmp    117a <do_io_write+0x4a>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    1198 <do_io_write+0x68>
jmp    1193 <do_io_write+0x63>
jmp    11b9 <do_io_write+0x89>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <do_io_write+0xa9>
jmp    11d2 <do_io_write+0xa2>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_io_write>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    (%rdx),%edx
mov    (%rcx),%ecx
call   1040 <pwrite@plt>
cmp    $0xffffffff,%eax
je     1151 <do_io_write+0x21>
mov    %eax,(%rbx)
add    %eax,(%r14)
xor    %eax,%eax
jmp    1175 <do_io_write+0x45>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
cmp    $0x80,%edi
je     1175 <do_io_write+0x45>
call   1050 <strerror@plt>
mov    %eax,%edi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @do_io_write(i32 %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %10
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = load i32*, i32** %8
%14 = load i32, i32* %13
%15 = load i32*, i32** %9
%16 = load i32, i32* %15
%17 = call i32 @pwrite(i32 %11, i8* %12, i32 %14, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
switch i32 %18, label %27 [
i32 -1, label %19
]
19: ; preds = %4
%20 = load i32, i32* @errno
switch i32 %20, label %22 [
i32 128, label %21
]
21: ; preds = %19
br label %26
22: ; preds = %19
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @puts(i32 %24)
store i32 -1, i32* %5
br label %35
26: ; preds = %21
br label %34
27: ; preds = %4
%28 = load i32, i32* %10
%29 = load i32*, i32** %8
store i32 %28, i32* %29
%30 = load i32, i32* %10
%31 = load i32*, i32** %9
%32 = load i32, i32* %31
%33 = add nsw i32 %32, %30
store i32 %33, i32* %31
br label %34
34: ; preds = %27, %26
store i32 0, i32* %5
br label %35
35: ; preds = %34, %22
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @do_io_write(i32 %0, i8* nocapture %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %2
%6 = load i32, i32* %3
%7 = tail call i32 @pwrite(i32 %0, i8* %1, i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = load i32, i32* @errno
%11 = icmp eq i32 %10, 128
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = tail call i32 @strerror(i32 %10)
%14 = tail call i32 @puts(i32 %13)
br label %18
15: ; preds = %4
store i32 %7, i32* %2
%16 = load i32, i32* %3
%17 = add nsw i32 %16, %7
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %9, %12
%19 = phi i32 [ -1, %12 ], [ 0, %9 ], [ 0, %15 ]
ret i32 %19
}