#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(double *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int read_bin_iopsy(const char *fname, double *data, const int ndata) {
  FILE *fp;
  time_t start, end;
  const int CHUNKSIZE = 1024;
  int nchunks = 1024 * 1024 * 128 / CHUNKSIZE;
  assert(fp);
  start = time(NULL);
  for (int i = 0; i < nchunks; i++) {
    int chunk = (i * 13 % nchunks);
    int start = chunk * CHUNKSIZE;
    fp = fopen(fname, "rb");
    fseek(fp, start * sizeof(double), SEEK_SET);
    fread(&(data[start]), sizeof(double), CHUNKSIZE, fp);
    fclose(fp);
  }
  end = time(NULL);
  return (int)(end - start);
}


x86 assembly (clang, -O0):
<read_bin_iopsy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x400,-0x34(%rbp)
movl   $0x20000,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1227 <read_bin_iopsy+0xc7>
imul   $0xd,-0x3c(%rbp),%eax
cltd
idivl  -0x38(%rbp)
mov    %edx,-0x40(%rbp)
mov    -0x40(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x8,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    119e <read_bin_iopsy+0x3e>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_bin_iopsy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r13
call   1050 <assert@plt>
xor    %r12d,%r12d
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,(%rsp)
mov    0x2e55(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12d,%ebp
and    $0x7fffc00,%ebp
mov    %r13,%rdi
lea    0xe5d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %ebp,%esi
shl    $0x3,%esi
mov    (%r14),%edx
mov    %rax,%rdi
call   1070 <fseek@plt>
lea    (%r15,%rbp,8),%rdi
mov    $0x8,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x3400,%r12d
cmp    $0x68000000,%r12d
jne    1190 <read_bin_iopsy+0x30>
xor    %edi,%edi
call   1060 <time@plt>
sub    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @read_bin_iopsy(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 1024, i32* %10
store i32 131072, i32* %11
%15 = load i32*, i32** %7
%16 = call i32 @assert(i32* %15)
%17 = call i64 @time(i32* null)
store i64 %17, i64* %8
store i32 0, i32* %12
br label %18
18: ; preds = %46, %3
%19 = load i32, i32* %12
%20 = load i32, i32* %11
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load i32, i32* %12
%24 = mul nsw i32 %23, 13
%25 = load i32, i32* %11
%26 = srem i32 %24, %25
store i32 %26, i32* %13
%27 = load i32, i32* %13
%28 = mul nsw i32 %27, 1024
store i32 %28, i32* %14
%29 = load i8*, i8** %4
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = load i32, i32* %14
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 8
%35 = trunc i64 %34 to i32
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %31, i32 %35, i32 %36)
%38 = load double*, double** %5
%39 = load i32, i32* %14
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load i32*, i32** %7
%43 = call i32 @fread(double* %41, i32 8, i32 1024, i32* %42)
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %22
%47 = load i32, i32* %12
%48 = add nsw i32 %47, 1
store i32 %48, i32* %12
br label %18
49: ; preds = %18
%50 = call i64 @time(i32* null)
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = load i64, i64* %8
%53 = sub nsw i64 %51, %52
%54 = trunc i64 %53 to i32
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @read_bin_iopsy(i8* nocapture %0, double* nocapture %1, i32 %2) {
%4 = tail call i32 @assert(i32* undef)
%5 = tail call i64 @time(i32* null)
br label %10
6: ; preds = %10
%7 = tail call i64 @time(i32* null)
%8 = sub nsw i64 %7, %5
%9 = trunc i64 %8 to i32
ret i32 %9
10: ; preds = %3, %10
%11 = phi i32 [ 0, %3 ], [ %22, %10 ]
%12 = mul nuw nsw i32 %11, 13312
%13 = and i32 %12, 134216704
%14 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = zext i32 %13 to i64
%16 = shl nuw nsw i32 %13, 3
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @fseek(i32* %14, i32 %16, i32 %17)
%19 = getelementptr inbounds double, double* %1, i64 %15
%20 = tail call i32 @fread(double* %19, i32 8, i32 1024, i32* %14)
%21 = tail call i32 @fclose(i32* %14)
%22 = add nuw nsw i32 %11, 1
%23 = icmp eq i32 %22, 131072
br i1 %23, label %6, label %10
}