#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 /*<<< orphan*/ SSL;

/* Variables and functions */
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int readall(SSL *ssl, char *buf) {
  int total = 0;
  int n;
  do {
    n = SSL_read(ssl, buf + total, 87380);
    total += n;
    if (n < 0 || total > 6291456) {
      fprintf(stderr, ("readall() error\n"));
      break;
    }
  } while (n != 0);
  return n < 0 ? n : 0;
}


x86 assembly (clang, -O0):
<readall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x15554,%edx
call   1030 <SSL_read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1173 <readall+0x53>
cmpl   $0x600000,-0x14(%rbp)
jle    118d <readall+0x6d>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
jmp    119c <readall+0x7c>
jmp    1192 <readall+0x72>
cmpl   $0x0,-0x18(%rbp)
jne    1137 <readall+0x17>
cmpl   $0x0,-0x18(%rbp)
jge    11b1 <readall+0x91>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11bb <readall+0x9b>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bb <readall+0x9b>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readall>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nop
movslq %ebx,%rsi
add    %r14,%rsi
mov    %r15,%rdi
mov    $0x15554,%edx
call   1030 <SSL_read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     115b <readall+0x3b>
add    %ebp,%ebx
cmp    $0x600001,%ebx
jge    115b <readall+0x3b>
test   %ebp,%ebp
jne    1130 <readall+0x10>
xor    %eax,%eax
jmp    1177 <readall+0x57>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebp,%eax
sar    $0x1f,%eax
and    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"readall() error\0A\00"
define i32 @readall(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %26, %2
%8 = load i32*, i32** %3
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = call i32 @SSL_read(i32* %8, i8* %12, i32 87380)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = add nsw i32 %15, %14
store i32 %16, i32* %5
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %7
%20 = load i32, i32* %5
%21 = icmp sgt i32 %20, 6291456
br i1 %21, label %22, label %25
22: ; preds = %19, %7
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %19
br label %26
26: ; preds = %25
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %7, label %29
29: ; preds = %26, %22
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i32, i32* %6
br label %35
34: ; preds = %29
br label %35
35: ; preds = %34, %32
%36 = phi i32 [ %33, %32 ], [ 0, %34 ]
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"readall() error\0A\00"
define i32 @readall(i32* %0, i8* %1) {
br label %3
3: ; preds = %16, %2
%4 = phi i32 [ 0, %2 ], [ %8, %16 ]
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
%7 = tail call i32 @SSL_read(i32* %0, i8* %6, i32 87380)
%8 = add nsw i32 %7, %4
%9 = icmp slt i32 %7, 0
%10 = icmp sgt i32 %8, 6291456
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = select i1 %9, i32 %7, i32 0
br label %18
16: ; preds = %3
%17 = icmp eq i32 %7, 0
br i1 %17, label %18, label %3
18: ; preds = %16, %12
%19 = phi i32 [ %15, %12 ], [ 0, %16 ]
ret i32 %19
}