#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 */
size_t min(size_t, size_t);
int /*<<< orphan*/ read_block_1(int, char *, size_t);
void read_block(int fd, char *block, size_t block_size) {
  size_t read = 0, max_length = 0x1000000;
  do {
    size_t size = min(max_length, block_size);
    read_block_1(fd, block + read, size);
    read += size;
    block_size -= size;
  } while (block_size > 0);
}


x86 assembly (clang, -O0):
<read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1000000,-0x28(%rbp)
01
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <min@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <read_block_1@plt>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
ja     1143 <read_block+0x23>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_block>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1000000,%edi
mov    %rbx,%rsi
call   1030 <min@plt>
mov    %rax,%r12
lea    (%r14,%rbp,1),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
call   1040 <read_block_1@plt>
add    %r12,%rbp
sub    %r12,%rbx
jne    1140 <read_block+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @read_block(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 16777216, i64* %8
br label %10
10: ; preds = %26, %3
%11 = load i64, i64* %8
%12 = load i64, i64* %6
%13 = call i64 @min(i64 %11, i64 %12)
store i64 %13, i64* %9
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i64, i64* %7
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i64, i64* %9
%19 = call i32 @read_block_1(i32 %14, i8* %17, i64 %18)
%20 = load i64, i64* %9
%21 = load i64, i64* %7
%22 = add i64 %21, %20
store i64 %22, i64* %7
%23 = load i64, i64* %9
%24 = load i64, i64* %6
%25 = sub i64 %24, %23
store i64 %25, i64* %6
br label %26
26: ; preds = %10
%27 = load i64, i64* %6
%28 = icmp ugt i64 %27, 0
br i1 %28, label %10, label %29
29: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @read_block(i32 %0, i8* %1, i64 %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ 0, %3 ], [ %10, %4 ]
%6 = phi i64 [ %2, %3 ], [ %11, %4 ]
%7 = tail call i64 @min(i64 16777216, i64 %6)
%8 = getelementptr inbounds i8, i8* %1, i64 %5
%9 = tail call i32 @read_block_1(i32 %0, i8* %8, i64 %7)
%10 = add i64 %7, %5
%11 = sub i64 %6, %7
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4
ret void
}