#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int ssize_t;
typedef scalar_t__ off_t;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ EINVAL;
scalar_t__ EMEDIUMTYPE;
scalar_t__ ENOTSUP;
scalar_t__ EOVERFLOW;
int O_CLOEXEC;
int O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
scalar_t__ fstat(int, struct stat *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, size_t);
char *strerror(scalar_t__);
int eslib_file_read_full(char *filename, char *buf, size_t buf_size,
                         size_t *out_size) {
  struct stat st;
  size_t bytes_read = 0;
  ssize_t r;
  off_t seek;
  int fd = -1;
  errno = 0;
  *out_size = 0;
  if (buf_size < 1 || out_size == NULL) {
    errno = EINVAL;
    return -1;
  }
  fd = open(filename, O_RDONLY | O_CLOEXEC);
  if (fd < 0) {
    printf("open(%s): %s\n", filename, strerror(errno));
    return -1;
  }
  if (fstat(fd, &st)) {
    printf("fstat: %s\n", strerror(errno));
    goto err_close;
  }
  if (!S_ISREG(st.st_mode)) {
    printf("file_read_full only supports regular files\n");
    errno = EMEDIUMTYPE;
    goto err_close;
  }
  r = -1;
  while (bytes_read < buf_size) {
    r = read(fd, buf + bytes_read, buf_size - bytes_read);
    if (r < 0 && errno != EINTR) {
      printf("read(%s): %s\n", filename, strerror(errno));
      goto err_close;
    } else if (r > 0) {
      bytes_read += (size_t)r;
    } else if (r == 0) {
      break;
    }
  }
  if (bytes_read == buf_size) {
    do {
      char c;
      r = read(fd, &c, 1);
    } while (r == -1 && errno == EINTR);
  } else if (bytes_read > buf_size)
    goto err_close;
  if (r > 0) {
    if (bytes_read + (size_t)r <= bytes_read)
      goto err_close;
    bytes_read += (size_t)r;
    goto ret_file_len;
  } else if (r != 0)
    goto err_close;
  close(fd);
  *out_size = bytes_read;
  return 0;
err_close:
  close(fd);
  return -1;
ret_file_len:
  seek = lseek(fd, 0, SEEK_END);
  if (seek < 0) {
    while (1) {
      r = read(fd, buf, buf_size);
      if (r > 0) {
        if (bytes_read + (size_t)r <= bytes_read)
          goto problemo;
        bytes_read += (size_t)r;
      } else if (r < 0 && errno != EINTR) {
        goto problemo;
      } else if (r == 0) {
        break;
      }
    }
    *out_size = bytes_read;
  } else if (seek > 0)
    *out_size = (size_t)seek;
  else
    goto problemo;
  close(fd);
  errno = EOVERFLOW;
  return -1;
problemo:
  close(fd);
  errno = ENOTSUP;
  return -1;
}


x86 assembly (clang, -O0):
<eslib_file_read_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
mov    0x2e0a(%rip),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x1,-0x20(%rbp)
jb     11d6 <eslib_file_read_full+0x56>
cmpq   $0x0,-0x28(%rbp)
jne    11f6 <eslib_file_read_full+0x76>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rcx
mov    0x2dd1(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <eslib_file_read_full+0x431>
mov    -0x10(%rbp),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    0x2d8e(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    1256 <eslib_file_read_full+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x58(%rbp),%rsi
mov    %rax,%rdx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <eslib_file_read_full+0x431>
mov    -0x4c(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10a0 <fstat@plt>
cmp    $0x0,%rax
je     1291 <eslib_file_read_full+0x111>
mov    0x2d45(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1467 <eslib_file_read_full+0x2e7>
mov    -0x30(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    12c9 <eslib_file_read_full+0x149>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%rcx
mov    0x2cf7(%rip),%rax
mov    %rcx,(%rax)
jmp    1467 <eslib_file_read_full+0x2e7>
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1387 <eslib_file_read_full+0x207>
mov    -0x4c(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    -0x38(%rbp),%rdx
call   1060 <read@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    134e <eslib_file_read_full+0x1ce>
mov    0x2cae(%rip),%rax
mov    (%rax),%rax
mov    0x2c9c(%rip),%rcx
cmp    (%rcx),%rax
je     134e <eslib_file_read_full+0x1ce>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c8c(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1467 <eslib_file_read_full+0x2e7>
cmpl   $0x0,-0x3c(%rbp)
jle    1369 <eslib_file_read_full+0x1e9>
movslq -0x3c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    137d <eslib_file_read_full+0x1fd>
cmpl   $0x0,-0x3c(%rbp)
jne    1378 <eslib_file_read_full+0x1f8>
jmp    1387 <eslib_file_read_full+0x207>
jmp    137d <eslib_file_read_full+0x1fd>
jmp    1382 <eslib_file_read_full+0x202>
jmp    12d0 <eslib_file_read_full+0x150>
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    13e7 <eslib_file_read_full+0x267>
jmp    139a <eslib_file_read_full+0x21a>
mov    -0x4c(%rbp),%edi
lea    -0x4d(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x3c(%rbp)
mov    %al,-0x61(%rbp)
jne    13d7 <eslib_file_read_full+0x257>
mov    0x2bf4(%rip),%rax
mov    (%rax),%rax
mov    0x2be2(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    139a <eslib_file_read_full+0x21a>
jmp    13ff <eslib_file_read_full+0x27f>
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    13fa <eslib_file_read_full+0x27a>
jmp    1467 <eslib_file_read_full+0x2e7>
jmp    13ff <eslib_file_read_full+0x27f>
cmpl   $0x0,-0x3c(%rbp)
jle    1434 <eslib_file_read_full+0x2b4>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
cmp    -0x38(%rbp),%rax
ja     1423 <eslib_file_read_full+0x2a3>
jmp    1467 <eslib_file_read_full+0x2e7>
movslq -0x3c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    147b <eslib_file_read_full+0x2fb>
cmpl   $0x0,-0x3c(%rbp)
je     1443 <eslib_file_read_full+0x2c3>
jmp    1467 <eslib_file_read_full+0x2e7>
jmp    1448 <eslib_file_read_full+0x2c8>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    15b1 <eslib_file_read_full+0x431>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <eslib_file_read_full+0x431>
mov    -0x4c(%rbp),%edi
mov    0x2b53(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jge    1541 <eslib_file_read_full+0x3c1>
jmp    14a2 <eslib_file_read_full+0x322>
mov    -0x4c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <read@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jle    14ea <eslib_file_read_full+0x36a>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
cmp    -0x38(%rbp),%rax
ja     14d9 <eslib_file_read_full+0x359>
jmp    158e <eslib_file_read_full+0x40e>
movslq -0x3c(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    152c <eslib_file_read_full+0x3ac>
cmpl   $0x0,-0x3c(%rbp)
jge    1513 <eslib_file_read_full+0x393>
mov    0x2abd(%rip),%rax
mov    (%rax),%rax
mov    0x2aab(%rip),%rcx
cmp    (%rcx),%rax
je     1513 <eslib_file_read_full+0x393>
jmp    158e <eslib_file_read_full+0x40e>
cmpl   $0x0,-0x3c(%rbp)
jne    1522 <eslib_file_read_full+0x3a2>
jmp    1531 <eslib_file_read_full+0x3b1>
jmp    1527 <eslib_file_read_full+0x3a7>
jmp    152c <eslib_file_read_full+0x3ac>
jmp    14a2 <eslib_file_read_full+0x322>
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1566 <eslib_file_read_full+0x3e6>
cmpq   $0x0,-0x48(%rbp)
jle    155c <eslib_file_read_full+0x3dc>
mov    -0x48(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1561 <eslib_file_read_full+0x3e1>
jmp    158e <eslib_file_read_full+0x40e>
jmp    1566 <eslib_file_read_full+0x3e6>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
mov    0x2a7b(%rip),%rax
mov    (%rax),%rcx
mov    0x2a39(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    15b1 <eslib_file_read_full+0x431>
mov    -0x4c(%rbp),%edi
call   1050 <close@plt>
mov    0x2a2b(%rip),%rax
mov    (%rax),%rcx
mov    0x2a11(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eslib_file_read_full>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e13(%rip),%r14
movq   $0x0,(%r14)
movq   $0x0,(%rcx)
test   %rdx,%rdx
je     1216 <eslib_file_read_full+0x86>
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e05(%rip),%rax
mov    0x2dc6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1225 <eslib_file_read_full+0x95>
mov    %eax,%r13d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
test   %rax,%rax
je     1255 <eslib_file_read_full+0xc5>
mov    (%r14),%rdi
call   10a0 <strerror@plt>
lea    0xe0c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%edi
call   1060 <close@plt>
jmp    1241 <eslib_file_read_full+0xb1>
mov    0x2d8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
jmp    1241 <eslib_file_read_full+0xb1>
mov    (%r14),%rdi
call   10a0 <strerror@plt>
lea    0xdcc(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%edi
call   1080 <S_ISREG@plt>
test   %eax,%eax
je     12ed <eslib_file_read_full+0x15d>
xor    %r14d,%r14d
jmp    128f <eslib_file_read_full+0xff>
nopl   0x0(%rax,%rax,1)
mov    0x2d41(%rip),%rcx
mov    (%rcx),%rdi
mov    0x2d2f(%rip),%rcx
cmp    (%rcx),%rdi
jne    137d <eslib_file_read_full+0x1ed>
cmp    %rbx,%r14
jae    12b1 <eslib_file_read_full+0x121>
lea    (%r15,%r14,1),%rsi
mov    %rbx,%rdx
sub    %r14,%rdx
mov    %r13d,%edi
call   1070 <read@plt>
test   %eax,%eax
js     1270 <eslib_file_read_full+0xe0>
je     12b1 <eslib_file_read_full+0x121>
mov    %eax,%ecx
add    %rcx,%r14
cmp    %rbx,%r14
jb     128f <eslib_file_read_full+0xff>
cmp    %rbx,%r14
jne    130b <eslib_file_read_full+0x17b>
lea    0xf(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1311 <eslib_file_read_full+0x181>
mov    0x2cd4(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2cd2(%rip),%rdx
cmp    %rcx,(%rdx)
je     12c0 <eslib_file_read_full+0x130>
jmp    1311 <eslib_file_read_full+0x181>
lea    0xd33(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
jmp    120c <eslib_file_read_full+0x7c>
ja     120c <eslib_file_read_full+0x7c>
test   %eax,%eax
jle    1364 <eslib_file_read_full+0x1d4>
mov    %eax,%r12d
add    %r14,%r12
cmp    %r14,%r12
jbe    120c <eslib_file_read_full+0x7c>
mov    0x2cad(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
test   %rax,%rax
js     139b <eslib_file_read_full+0x20b>
mov    %rax,%r12
mov    0x2c72(%rip),%r14
je     13d4 <eslib_file_read_full+0x244>
mov    %r12,0x0(%rbp)
mov    %r13d,%edi
call   1060 <close@plt>
mov    0x2c91(%rip),%rax
jmp    121d <eslib_file_read_full+0x8d>
jne    120c <eslib_file_read_full+0x7c>
mov    %r13d,%edi
call   1060 <close@plt>
mov    %r14,0x0(%rbp)
xor    %eax,%eax
jmp    1246 <eslib_file_read_full+0xb6>
call   10a0 <strerror@plt>
lea    0xc90(%rip),%rdi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    120c <eslib_file_read_full+0x7c>
mov    0x2c16(%rip),%r14
mov    %r13d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <read@plt>
test   %eax,%eax
jg     13c7 <eslib_file_read_full+0x237>
jns    134c <eslib_file_read_full+0x1bc>
mov    (%r14),%rax
mov    0x2bf0(%rip),%rcx
cmp    (%rcx),%rax
je     13a2 <eslib_file_read_full+0x212>
jmp    13d4 <eslib_file_read_full+0x244>
mov    %eax,%eax
add    %r12,%rax
cmp    %r12,%rax
mov    %rax,%r12
ja     13a2 <eslib_file_read_full+0x212>
mov    %r13d,%edi
call   1060 <close@plt>
mov    0x2be5(%rip),%rax
jmp    121d <eslib_file_read_full+0x8d>

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str = [14 x i8] c"open(%s): %s\0A\00"
@.str.1 = [11 x i8] c"fstat: %s\0A\00"
@.str.2 = [44 x i8] c"file_read_full only supports regular files\0A\00"
@EMEDIUMTYPE = global i64 0
@EINTR = global i64 0
@.str.3 = [14 x i8] c"read(%s): %s\0A\00"
@SEEK_END = global i32 0
@EOVERFLOW = global i64 0
@ENOTSUP = global i64 0
define i32 @eslib_file_read_full(i8* %0, i8* %1, i64 %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64*
%10 = alloca %struct.stat
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca i8
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64* %3, i64** %9
store i64 0, i64* %11
store i32 -1, i32* %14
store i64 0, i64* @errno
%16 = load i64*, i64** %9
store i64 0, i64* %16
%17 = load i64, i64* %8
%18 = icmp ult i64 %17, 1
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = load i64*, i64** %9
%21 = icmp eq i64* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %4
%23 = load i64, i64* @EINVAL
store i64 %23, i64* @errno
store i32 -1, i32* %5
br label %207
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = load i32, i32* @O_RDONLY
%27 = load i32, i32* @O_CLOEXEC
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %25, i32 %28)
store i32 %29, i32* %14
%30 = load i32, i32* %14
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %24
%33 = load i8*, i8** %6
%34 = load i64, i64* @errno
%35 = call i8* @strerror(i64 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %35)
store i32 -1, i32* %5
br label %207
37: ; preds = %24
%38 = load i32, i32* %14
%39 = call i64 @fstat(i32 %38, %struct.stat* %10)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i64, i64* @errno
%43 = call i8* @strerror(i64 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %143
45: ; preds = %37
%46 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @S_ISREG(i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %45
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%52 = load i64, i64* @EMEDIUMTYPE
store i64 %52, i64* @errno
br label %143
53: ; preds = %45
store i32 -1, i32* %12
br label %54
54: ; preds = %92, %53
%55 = load i64, i64* %11
%56 = load i64, i64* %8
%57 = icmp ult i64 %55, %56
br i1 %57, label %58, label %93
58: ; preds = %54
%59 = load i32, i32* %14
%60 = load i8*, i8** %7
%61 = load i64, i64* %11
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = load i64, i64* %8
%64 = load i64, i64* %11
%65 = sub i64 %63, %64
%66 = call i32 @read(i32 %59, i8* %62, i64 %65)
store i32 %66, i32* %12
%67 = load i32, i32* %12
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %78
69: ; preds = %58
%70 = load i64, i64* @errno
%71 = load i64, i64* @EINTR
%72 = icmp ne i64 %70, %71
br i1 %72, label %73, label %78
73: ; preds = %69
%74 = load i8*, i8** %6
%75 = load i64, i64* @errno
%76 = call i8* @strerror(i64 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %74, i8* %76)
br label %143
78: ; preds = %69, %58
%79 = load i32, i32* %12
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load i32, i32* %12
%83 = sext i32 %82 to i64
%84 = load i64, i64* %11
%85 = add i64 %84, %83
store i64 %85, i64* %11
br label %91
86: ; preds = %78
%87 = load i32, i32* %12
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %86
br label %93
90: ; preds = %86
br label %91
91: ; preds = %90, %81
br label %92
92: ; preds = %91
br label %54
93: ; preds = %89, %54
%94 = load i64, i64* %11
%95 = load i64, i64* %8
%96 = icmp eq i64 %94, %95
br i1 %96, label %97, label %111
97: ; preds = %93
br label %98
98: ; preds = %108, %97
%99 = load i32, i32* %14
%100 = call i32 @read(i32 %99, i8* %15, i64 1)
store i32 %100, i32* %12
br label %101
101: ; preds = %98
%102 = load i32, i32* %12
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %108
104: ; preds = %101
%105 = load i64, i64* @errno
%106 = load i64, i64* @EINTR
%107 = icmp eq i64 %105, %106
br label %108
108: ; preds = %104, %101
%109 = phi i1 [ false, %101 ], [ %107, %104 ]
br i1 %109, label %98, label %110
110: ; preds = %108
br label %117
111: ; preds = %93
%112 = load i64, i64* %11
%113 = load i64, i64* %8
%114 = icmp ugt i64 %112, %113
br i1 %114, label %115, label %116
115: ; preds = %111
br label %143
116: ; preds = %111
br label %117
117: ; preds = %116, %110
%118 = load i32, i32* %12
%119 = icmp sgt i32 %118, 0
br i1 %119, label %120, label %133
120: ; preds = %117
%121 = load i64, i64* %11
%122 = load i32, i32* %12
%123 = sext i32 %122 to i64
%124 = add i64 %121, %123
%125 = load i64, i64* %11
%126 = icmp ule i64 %124, %125
br i1 %126, label %127, label %128
127: ; preds = %120
br label %143
128: ; preds = %120
%129 = load i32, i32* %12
%130 = sext i32 %129 to i64
%131 = load i64, i64* %11
%132 = add i64 %131, %130
store i64 %132, i64* %11
br label %146
133: ; preds = %117
%134 = load i32, i32* %12
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %137
136: ; preds = %133
br label %143
137: ; preds = %133
br label %138
138: ; preds = %137
%139 = load i32, i32* %14
%140 = call i32 @close(i32 %139)
%141 = load i64, i64* %11
%142 = load i64*, i64** %9
store i64 %141, i64* %142
store i32 0, i32* %5
br label %207
143: ; preds = %136, %127, %115, %73, %50, %41
%144 = load i32, i32* %14
%145 = call i32 @close(i32 %144)
store i32 -1, i32* %5
br label %207
146: ; preds = %128
%147 = load i32, i32* %14
%148 = load i32, i32* @SEEK_END
%149 = call i64 @lseek(i32 %147, i32 0, i32 %148)
store i64 %149, i64* %13
%150 = load i64, i64* %13
%151 = icmp slt i64 %150, 0
br i1 %151, label %152, label %191
152: ; preds = %146
br label %153
153: ; preds = %152, %187
%154 = load i32, i32* %14
%155 = load i8*, i8** %7
%156 = load i64, i64* %8
%157 = call i32 @read(i32 %154, i8* %155, i64 %156)
store i32 %157, i32* %12
%158 = load i32, i32* %12
%159 = icmp sgt i32 %158, 0
br i1 %159, label %160, label %173
160: ; preds = %153
%161 = load i64, i64* %11
%162 = load i32, i32* %12
%163 = sext i32 %162 to i64
%164 = add i64 %161, %163
%165 = load i64, i64* %11
%166 = icmp ule i64 %164, %165
br i1 %166, label %167, label %168
167: ; preds = %160
br label %203
168: ; preds = %160
%169 = load i32, i32* %12
%170 = sext i32 %169 to i64
%171 = load i64, i64* %11
%172 = add i64 %171, %170
store i64 %172, i64* %11
br label %187
173: ; preds = %153
%174 = load i32, i32* %12
%175 = icmp slt i32 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %173
%177 = load i64, i64* @errno
%178 = load i64, i64* @EINTR
%179 = icmp ne i64 %177, %178
br i1 %179, label %180, label %181
180: ; preds = %176
br label %203
181: ; preds = %176, %173
%182 = load i32, i32* %12
%183 = icmp eq i32 %182, 0
br i1 %183, label %184, label %185
184: ; preds = %181
br label %188
185: ; preds = %181
br label %186
186: ; preds = %185
br label %187
187: ; preds = %186, %168
br label %153
188: ; preds = %184
%189 = load i64, i64* %11
%190 = load i64*, i64** %9
store i64 %189, i64* %190
br label %199
191: ; preds = %146
%192 = load i64, i64* %13
%193 = icmp sgt i64 %192, 0
br i1 %193, label %194, label %197
194: ; preds = %191
%195 = load i64, i64* %13
%196 = load i64*, i64** %9
store i64 %195, i64* %196
br label %198
197: ; preds = %191
br label %203
198: ; preds = %194
br label %199
199: ; preds = %198, %188
%200 = load i32, i32* %14
%201 = call i32 @close(i32 %200)
%202 = load i64, i64* @EOVERFLOW
store i64 %202, i64* @errno
store i32 -1, i32* %5
br label %207
203: ; preds = %197, %180, %167
%204 = load i32, i32* %14
%205 = call i32 @close(i32 %204)
%206 = load i64, i64* @ENOTSUP
store i64 %206, i64* @errno
store i32 -1, i32* %5
br label %207
207: ; preds = %203, %199, %143, %138, %32, %22
%208 = load i32, i32* %5
ret i32 %208
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str = [14 x i8] c"open(%s): %s\0A\00"
@.str.1 = [11 x i8] c"fstat: %s\0A\00"
@EMEDIUMTYPE = global i64 0
@EINTR = global i64 0
@.str.3 = [14 x i8] c"read(%s): %s\0A\00"
@SEEK_END = global i32 0
@EOVERFLOW = global i64 0
@ENOTSUP = global i64 0
@str = [43 x i8] c"file_read_full only supports regular files\00"
define i32 @eslib_file_read_full(i8* %0, i8* nocapture %1, i64 %2, i64* nocapture writeonly %3) {
%5 = alloca %struct.stat
%6 = alloca i8
%7 = bitcast %struct.stat* %5 to i8*
store i64 0, i64* @errno
store i64 0, i64* %3
%8 = icmp eq i64 %2, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = load i64, i64* @EINVAL
store i64 %10, i64* @errno
br label %110
11: ; preds = %4
%12 = load i32, i32* @O_RDONLY
%13 = load i32, i32* @O_CLOEXEC
%14 = or i32 %13, %12
%15 = tail call i32 @open(i8* %0, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i64, i64* @errno
%19 = tail call i8* @strerror(i64 %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %19)
br label %110
21: ; preds = %11
%22 = call i64 @fstat(i32 %15, %struct.stat* %5)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i64, i64* @errno
%26 = tail call i8* @strerror(i64 %25)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %84
28: ; preds = %21
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%30 = load i32, i32* %29
%31 = tail call i32 @S_ISREG(i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%35 = load i64, i64* @EMEDIUMTYPE
store i64 %35, i64* @errno
br label %84
36: ; preds = %28, %54
%37 = phi i64 [ %55, %54 ], [ 0, %28 ]
%38 = getelementptr inbounds i8, i8* %1, i64 %37
%39 = sub i64 %2, %37
%40 = tail call i32 @read(i32 %15, i8* %38, i64 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %36
%43 = load i64, i64* @errno
%44 = load i64, i64* @EINTR
%45 = icmp eq i64 %43, %44
br i1 %45, label %54, label %46
46: ; preds = %42
%47 = tail call i8* @strerror(i64 %43)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %47)
br label %84
49: ; preds = %36
%50 = icmp eq i32 %40, 0
br i1 %50, label %57, label %51
51: ; preds = %49
%52 = zext i32 %40 to i64
%53 = add i64 %37, %52
br label %54
54: ; preds = %42, %51
%55 = phi i64 [ %53, %51 ], [ %37, %42 ]
%56 = icmp ult i64 %55, %2
br i1 %56, label %36, label %57
57: ; preds = %54, %49
%58 = phi i64 [ %55, %54 ], [ %37, %49 ]
%59 = icmp eq i64 %58, %2
br i1 %59, label %60, label %67
60: ; preds = %57, %60
%61 = call i32 @read(i32 %15, i8* %6, i64 1)
%62 = icmp eq i32 %61, -1
%63 = load i64, i64* @errno
%64 = load i64, i64* @EINTR
%65 = icmp eq i64 %63, %64
%66 = select i1 %62, i1 %65, i1 false
br i1 %66, label %60, label %69
67: ; preds = %57
%68 = icmp ugt i64 %58, %2
br i1 %68, label %84, label %69
69: ; preds = %60, %67
%70 = phi i32 [ %40, %67 ], [ %61, %60 ]
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %80
72: ; preds = %69
%73 = zext i32 %70 to i64
%74 = add i64 %58, %73
%75 = icmp ugt i64 %74, %58
br i1 %75, label %76, label %84
76: ; preds = %72
%77 = load i32, i32* @SEEK_END
%78 = tail call i64 @lseek(i32 %15, i32 0, i32 %77)
%79 = icmp slt i64 %78, 0
br i1 %79, label %93, label %101
80: ; preds = %69
%81 = icmp eq i32 %70, 0
br i1 %81, label %82, label %84
82: ; preds = %80
%83 = tail call i32 @close(i32 %15)
store i64 %58, i64* %3
br label %110
84: ; preds = %80, %72, %67, %46, %33, %24
%85 = tail call i32 @close(i32 %15)
br label %110
86: ; preds = %93, %97
%87 = tail call i32 @read(i32 %15, i8* %1, i64 %2)
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %95
89: ; preds = %86
%90 = zext i32 %87 to i64
%91 = add i64 %94, %90
%92 = icmp ugt i64 %91, %94
br i1 %92, label %93, label %107
93: ; preds = %76, %89
%94 = phi i64 [ %91, %89 ], [ %74, %76 ]
br label %86
95: ; preds = %86
%96 = icmp slt i32 %87, 0
br i1 %96, label %97, label %103
97: ; preds = %95
%98 = load i64, i64* @errno
%99 = load i64, i64* @EINTR
%100 = icmp eq i64 %98, %99
br i1 %100, label %86, label %107
101: ; preds = %76
%102 = icmp eq i64 %78, 0
br i1 %102, label %107, label %103
103: ; preds = %95, %101
%104 = phi i64 [ %78, %101 ], [ %94, %95 ]
store i64 %104, i64* %3
%105 = tail call i32 @close(i32 %15)
%106 = load i64, i64* @EOVERFLOW
store i64 %106, i64* @errno
br label %110
107: ; preds = %97, %89, %101
%108 = tail call i32 @close(i32 %15)
%109 = load i64, i64* @ENOTSUP
store i64 %109, i64* @errno
br label %110
110: ; preds = %107, %103, %84, %82, %17, %9
%111 = phi i32 [ -1, %9 ], [ -1, %17 ], [ -1, %84 ], [ -1, %107 ], [ -1, %103 ], [ 0, %82 ]
ret i32 %111
}