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

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ pread(int, unsigned char *, size_t, scalar_t__);
int /*<<< orphan*/ stderr;
int pread_all(int fd, unsigned char *data, size_t len, off_t offset) {
  size_t got = 0;
  ssize_t bytes = 0;
  while (got < len) {
    do {
      bytes = pread(fd, data + got, len - got, offset + got);
    } while (bytes < 0 && EINTR == errno);
    if (bytes < 0) {
      abort();
      perror("Reading temporary file");
      return -1;
    }
    if (bytes == 0) {
      fprintf(stderr, "Unexpected end of file reading temporary file\n");
      return -1;
    }
    got += bytes;
  }
  return 0;
}


x86 assembly (clang, -O0):
<pread_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1212 <pread_all+0xe2>
jmp    116a <pread_all+0x3a>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
call   1050 <pread@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x31(%rbp)
jge    11b8 <pread_all+0x88>
mov    0x2e2b(%rip),%rax
mov    (%rax),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    116a <pread_all+0x3a>
cmpq   $0x0,-0x30(%rbp)
jge    11d5 <pread_all+0xa5>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1201 <pread_all+0xd1>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <pread_all+0xe9>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1157 <pread_all+0x27>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pread_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
test   %rdx,%rdx
je     11c8 <pread_all+0x98>
mov    %rdx,%rbp
mov    %edi,%r13d
xor    %ecx,%ecx
mov    0x2e74(%rip),%r12
mov    0x2e75(%rip),%r15
mov    %rdx,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
lea    (%rax,%rcx,1),%rbx
sub    %rcx,%rbp
mov    0x18(%rsp),%rax
mov    %rcx,0x20(%rsp)
lea    (%rcx,%rax,1),%r14
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1050 <pread@plt>
test   %rax,%rax
jns    11af <pread_all+0x7f>
mov    (%r15),%rcx
cmp    %rcx,(%r12)
je     1190 <pread_all+0x60>
test   %rax,%rax
js     11f5 <pread_all+0xc5>
mov    0x20(%rsp),%rcx
je     11cc <pread_all+0x9c>
add    %rax,%rcx
mov    0x8(%rsp),%rbp
cmp    %rbp,%rcx
jb     1170 <pread_all+0x40>
xor    %eax,%eax
jmp    11e6 <pread_all+0xb6>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@EINTR = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str = [47 x i8] c"Unexpected end of file reading temporary file\0A\00"
define i32 @pread_all(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
%11 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
br label %12
12: ; preds = %49, %4
%13 = load i64, i64* %10
%14 = load i64, i64* %8
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
br label %17
17: ; preds = %36, %16
%18 = load i32, i32* %6
%19 = load i8*, i8** %7
%20 = load i64, i64* %10
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i64, i64* %8
%23 = load i64, i64* %10
%24 = sub i64 %22, %23
%25 = load i64, i64* %9
%26 = load i64, i64* %10
%27 = add i64 %25, %26
%28 = call i64 @pread(i32 %18, i8* %21, i64 %24, i64 %27)
store i64 %28, i64* %11
br label %29
29: ; preds = %17
%30 = load i64, i64* %11
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i64, i64* @EINTR
%34 = load i64, i64* @errno
%35 = icmp eq i64 %33, %34
br label %36
36: ; preds = %32, %29
%37 = phi i1 [ false, %29 ], [ %35, %32 ]
br i1 %37, label %17, label %38
38: ; preds = %36
%39 = load i64, i64* %11
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %38
%44 = load i64, i64* %11
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %54
49: ; preds = %43
%50 = load i64, i64* %11
%51 = load i64, i64* %10
%52 = add i64 %51, %50
store i64 %52, i64* %10
br label %12
53: ; preds = %12
store i32 0, i32* %5
br label %54
54: ; preds = %53, %46
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
@EINTR = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str = [47 x i8] c"Unexpected end of file reading temporary file\0A\00"
define i32 @pread_all(i32 %0, i8* nocapture %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %29, label %8
6: ; preds = %23
%7 = icmp ult i64 %25, %2
br i1 %7, label %8, label %29
8: ; preds = %4, %6
%9 = phi i64 [ %25, %6 ], [ 0, %4 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = sub i64 %2, %9
%12 = add i64 %9, %3
br label %13
13: ; preds = %8, %13
%14 = tail call i64 @pread(i32 %0, i8* %10, i64 %11, i64 %12)
%15 = icmp slt i64 %14, 0
%16 = load i64, i64* @EINTR
%17 = load i64, i64* @errno
%18 = icmp eq i64 %16, %17
%19 = select i1 %15, i1 %18, i1 false
br i1 %19, label %13, label %20
20: ; preds = %13
br i1 %15, label %21, label %23
21: ; preds = %20
%22 = tail call i32 (...) @abort()
unreachable
23: ; preds = %20
%24 = icmp eq i64 %14, 0
%25 = add i64 %14, %9
br i1 %24, label %26, label %6
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %6, %4, %26
%30 = phi i32 [ -1, %26 ], [ 0, %4 ], [ 0, %6 ]
ret i32 %30
}