#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 */

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int readall(int fd, char *buf, int maxCount) {
  int count = 0;
  while (1) {
    if (count + 100 > maxCount) {
      fprintf(stderr, "Environment file is too large.\n");
      return -1;
    }
    int numRead = read(fd, buf + count, 100);
    if (numRead == 0)
      return count;
    if (numRead > 0)
      count += numRead;
    if (numRead < 0 && errno != EAGAIN && errno != EINVAL)
      return -1;
  }
}


x86 assembly (clang, -O0):
<readall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x64,%eax
cmp    -0x14(%rbp),%eax
jle    1169 <readall+0x49>
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <readall+0xdb>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    $0x64,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1199 <readall+0x79>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <readall+0xdb>
cmpl   $0x0,-0x1c(%rbp)
jle    11ac <readall+0x8c>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f6 <readall+0xd6>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    0x2df9(%rip),%rcx
cmp    (%rcx),%rax
je     11f6 <readall+0xd6>
mov    0x2e01(%rip),%rax
mov    (%rax),%rax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
je     11f6 <readall+0xd6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <readall+0xdb>
jmp    1139 <readall+0x19>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readall>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x64,%edx
jge    115b <readall+0x3b>
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
mov    0x2e6c(%rip),%r12
mov    0x2e4d(%rip),%r13
jmp    118f <readall+0x6f>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
js     11b0 <readall+0x90>
add    %ebp,%ecx
lea    0x64(%rcx),%eax
mov    %ecx,%ebp
cmp    %ebx,%eax
jg     1130 <readall+0x10>
mov    %ebp,%esi
add    %r14,%rsi
mov    %r15d,%edi
mov    $0x64,%edx
call   1030 <read@plt>
test   %eax,%eax
je     114a <readall+0x2a>
mov    %eax,%ecx
jns    1180 <readall+0x60>
xor    %ecx,%ecx
jmp    1180 <readall+0x60>
nopl   (%rax)
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1184 <readall+0x64>
mov    0x2e0f(%rip),%rdx
cmp    (%rdx),%rax
je     1184 <readall+0x64>
jmp    1145 <readall+0x25>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Environment file is too large.\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EINVAL = global i64 0
define i32 @readall(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %3, %48
%11 = load i32, i32* %8
%12 = add nsw i32 %11, 100
%13 = load i32, i32* %7
%14 = icmp sgt i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %49
18: ; preds = %10
%19 = load i32, i32* %5
%20 = load i8*, i8** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i32 @read(i32 %19, i8* %23, i32 100)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = load i32, i32* %8
store i32 %28, i32* %4
br label %49
29: ; preds = %18
%30 = load i32, i32* %9
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = add nsw i32 %34, %33
store i32 %35, i32* %8
br label %36
36: ; preds = %32, %29
%37 = load i32, i32* %9
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = load i64, i64* @errno
%41 = load i64, i64* @EAGAIN
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i64, i64* @errno
%45 = load i64, i64* @EINVAL
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 -1, i32* %4
br label %49
48: ; preds = %43, %39, %36
br label %10
49: ; preds = %47, %27, %15
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Environment file is too large.\0A\00"
@errno = global i64 0
@EAGAIN = global i64 0
@EINVAL = global i64 0
define i32 @readall(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp slt i32 %2, 100
br i1 %4, label %5, label %8
5: ; preds = %26, %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %29
8: ; preds = %3, %26
%9 = phi i32 [ %17, %26 ], [ 0, %3 ]
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = tail call i32 @read(i32 %0, i8* %11, i32 100)
%13 = icmp eq i32 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %8
%15 = icmp sgt i32 %12, 0
%16 = select i1 %15, i32 %12, i32 0
%17 = add nuw nsw i32 %16, %9
%18 = icmp slt i32 %12, 0
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i64, i64* @errno
%21 = load i64, i64* @EAGAIN
%22 = icmp eq i64 %20, %21
%23 = load i64, i64* @EINVAL
%24 = icmp eq i64 %20, %23
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %29
26: ; preds = %14, %19
%27 = add nuw nsw i32 %17, 100
%28 = icmp sgt i32 %27, %2
br i1 %28, label %5, label %8
29: ; preds = %19, %8, %5
%30 = phi i32 [ -1, %5 ], [ %9, %8 ], [ -1, %19 ]
ret i32 %30
}