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

/* Variables and functions */
int /*<<< orphan*/ load(int /*<<< orphan*/ *, unsigned char *, unsigned long);
int /*<<< orphan*/ load_chunk(int /*<<< orphan*/ *, unsigned char *,
                              unsigned long);
int /*<<< orphan*/ my_srand(unsigned long);
void load_file(FILE *fh, unsigned char *ptr, unsigned long filesz) {
  unsigned long chunksz;
  my_srand(filesz);
  for (chunksz = (2048 * 1024); chunksz >= 32; chunksz >>= 1)
    while (filesz >= chunksz) {
      load_chunk(fh, ptr, chunksz);
      filesz -= chunksz;
      ptr += chunksz;
    }
  if (filesz)
    load(fh, ptr, filesz);
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <my_srand@plt>
movq   $0x200000,-0x20(%rbp)
cmpq   $0x20,-0x20(%rbp)
jb     11ba <load_file+0x8a>
jmp    1165 <load_file+0x35>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     11a4 <load_file+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <load_chunk@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1165 <load_file+0x35>
jmp    11a9 <load_file+0x79>
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1155 <load_file+0x25>
cmpq   $0x0,-0x18(%rbp)
je     11d6 <load_file+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <load@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <my_srand@plt>
mov    $0x200000,%r12d
jmp    1174 <load_file+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <load_chunk@plt>
sub    %r12,%r14
add    %r12,%rbx
cmp    %r12,%r14
jae    1160 <load_file+0x30>
mov    %r12,%rax
shr    %rax
cmp    $0x3f,%r12
mov    %rax,%r12
ja     1174 <load_file+0x44>
test   %r14,%r14
je     11a6 <load_file+0x76>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <load@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @load_file(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = call i32 @my_srand(i64 %8)
store i64 2097152, i64* %7
br label %10
10: ; preds = %30, %3
%11 = load i64, i64* %7
%12 = icmp uge i64 %11, 32
br i1 %12, label %13, label %33
13: ; preds = %10
br label %14
14: ; preds = %18, %13
%15 = load i64, i64* %6
%16 = load i64, i64* %7
%17 = icmp uge i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i8*, i8** %5
%21 = load i64, i64* %7
%22 = call i32 @load_chunk(i32* %19, i8* %20, i64 %21)
%23 = load i64, i64* %7
%24 = load i64, i64* %6
%25 = sub i64 %24, %23
store i64 %25, i64* %6
%26 = load i64, i64* %7
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 %26
store i8* %28, i8** %5
br label %14
29: ; preds = %14
br label %30
30: ; preds = %29
%31 = load i64, i64* %7
%32 = lshr i64 %31, 1
store i64 %32, i64* %7
br label %10
33: ; preds = %10
%34 = load i64, i64* %6
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32*, i32** %4
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = call i32 @load(i32* %37, i8* %38, i64 %39)
br label %41
41: ; preds = %36, %33
ret void
}

LLVM IR (-O2):
define void @load_file(i32* %0, i8* %1, i64 %2) {
%4 = tail call i32 @my_srand(i64 %2)
br label %5
5: ; preds = %3, %17
%6 = phi i64 [ 2097152, %3 ], [ %20, %17 ]
%7 = phi i64 [ %2, %3 ], [ %19, %17 ]
%8 = phi i8* [ %1, %3 ], [ %18, %17 ]
%9 = icmp ult i64 %7, %6
br i1 %9, label %17, label %10
10: ; preds = %5, %10
%11 = phi i64 [ %14, %10 ], [ %7, %5 ]
%12 = phi i8* [ %15, %10 ], [ %8, %5 ]
%13 = tail call i32 @load_chunk(i32* %0, i8* %12, i64 %6)
%14 = sub i64 %11, %6
%15 = getelementptr inbounds i8, i8* %12, i64 %6
%16 = icmp ult i64 %14, %6
br i1 %16, label %17, label %10
17: ; preds = %10, %5
%18 = phi i8* [ %8, %5 ], [ %15, %10 ]
%19 = phi i64 [ %7, %5 ], [ %14, %10 ]
%20 = lshr i64 %6, 1
%21 = icmp ugt i64 %6, 63
br i1 %21, label %5, label %22
22: ; preds = %17
%23 = icmp eq i64 %19, 0
br i1 %23, label %26, label %24
24: ; preds = %22
%25 = tail call i32 @load(i32* %0, i8* %18, i64 %19)
br label %26
26: ; preds = %24, %22
ret void
}