#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 pread(int, void *, int, int);
int do_io_read(int fd, void *address, ssize_t *bytes, off_t *offset) {
  ssize_t bytes_read = 0;
  bytes_read = pread(fd, address, *bytes, *offset);
  switch (bytes_read) {
  case -1:
    switch (errno) {
    case EAGAIN:
      break;
    defaul:
      return -1;
    }
    break;
  default:
    *bytes = bytes_read;
    *offset += bytes_read;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_io_read>:
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   1030 <pread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    $0xffffffff,%eax
jne    117d <do_io_read+0x6d>
jmp    115a <do_io_read+0x4a>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
sub    $0x80,%eax
jne    1178 <do_io_read+0x68>
jmp    1173 <do_io_read+0x63>
jmp    1178 <do_io_read+0x68>
jmp    1191 <do_io_read+0x81>
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_read>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    (%rdx),%edx
mov    (%rcx),%ecx
call   1030 <pread@plt>
cmp    $0xffffffff,%eax
je     112d <do_io_read+0x1d>
mov    %eax,(%rbx)
add    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @do_io_read(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 @pread(i32 %11, i8* %12, i32 %14, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
switch i32 %18, label %24 [
i32 -1, label %19
]
19: ; preds = %4
%20 = load i32, i32* @errno
switch i32 %20, label %23 [
i32 128, label %21
]
21: ; preds = %19
br label %23
22: ; No predecessors!
store i32 -1, i32* %5
br label %32
23: ; preds = %19, %21
br label %31
24: ; preds = %4
%25 = load i32, i32* %10
%26 = load i32*, i32** %8
store i32 %25, i32* %26
%27 = load i32, i32* %10
%28 = load i32*, i32** %9
%29 = load i32, i32* %28
%30 = add nsw i32 %29, %27
store i32 %30, i32* %28
br label %31
31: ; preds = %24, %23
store i32 0, i32* %5
br label %32
32: ; preds = %31, %22
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @do_io_read(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 @pread(i32 %0, i8* %1, i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %12, label %9
9: ; preds = %4
store i32 %7, i32* %2
%10 = load i32, i32* %3
%11 = add nsw i32 %10, %7
store i32 %11, i32* %3
br label %12
12: ; preds = %4, %9
ret i32 0
}