#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ lg(char *, ...);
int dload_bin(char *fname, double *vec, int M, int N1) {
  int m, n, N, s;
  FILE *fp;
  lg("Loading %s\n", fname);
  fp = fopen(fname, "rb");
  if (!fp) {
    lg("Cant open file\n");
    return 0;
  }
  fseek(fp, 0, SEEK_END);
  s = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  N = s / sizeof(double) / M;
  lg("N=%d\n", N);
  if (N * sizeof(double) * M != s) {
    lg("File size does not divide\n");
    exit(1);
  }
  if (N < 1 || N > N1) {
    lg("Bad N %d\n", N1);
    exit(1);
  }
  for (m = 0; m < M; m++) {
    n = fread(vec, sizeof(double), N, fp);
    if (N != n) {
      lg("Error %d %d\n", m, n);
      exit(1);
    }
    vec += N1;
  }
  fclose(fp);
  return N;
}


x86 assembly (clang, -O0):
<dload_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <lg@plt>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d1 <dload_bin+0x61>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <lg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1317 <dload_bin+0x1a7>
mov    -0x38(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
movslq -0x30(%rbp),%rax
shr    $0x3,%rax
movslq -0x1c(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <lg@plt>
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
movslq -0x1c(%rbp),%rcx
imul   %rcx,%rax
movslq -0x30(%rbp),%rcx
cmp    %rcx,%rax
je     125f <dload_bin+0xef>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <lg@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x1,-0x2c(%rbp)
jl     1275 <dload_bin+0x105>
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1290 <dload_bin+0x120>
mov    -0x20(%rbp),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <lg@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1308 <dload_bin+0x198>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x8,%esi
call   1030 <fread@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     12e5 <dload_bin+0x175>
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <lg@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1297 <dload_bin+0x127>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dload_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe72(%rip),%rdi
xor    %r13d,%r13d
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <lg@plt>
lea    0xe6a(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     120a <dload_bin+0x9a>
mov    %rax,%r12
mov    %r15d,0x4(%rsp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r12,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
movslq %ebp,%rbp
mov    %rbp,%rax
shr    $0x3,%rax
movslq %r14d,%r15
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
je     121d <dload_bin+0xad>
xor    %edx,%edx
div    %r15
mov    %rax,%r13
jmp    1225 <dload_bin+0xb5>
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1050 <lg@plt>
jmp    129b <dload_bin+0x12b>
xor    %edx,%edx
div    %r14d
mov    %eax,%r13d
lea    0xdf3(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <lg@plt>
movslq %r13d,%rax
imul   %r15,%rax
shl    $0x3,%rax
cmp    %rbp,%rax
jne    12c9 <dload_bin+0x159>
test   %r13d,%r13d
mov    0x4(%rsp),%esi
jle    12e1 <dload_bin+0x171>
cmp    %esi,%r13d
jg     12e1 <dload_bin+0x171>
test   %r14d,%r14d
jle    1293 <dload_bin+0x123>
movslq %esi,%r15
shl    $0x3,%r15
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r13d,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    %r13d,%eax
jne    12ad <dload_bin+0x13d>
add    $0x1,%ebp
add    %r15,%rbx
cmp    %ebp,%r14d
jne    1270 <dload_bin+0x100>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd96(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <lg@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd55(%rip),%rdi
xor    %eax,%eax
call   1050 <lg@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd58(%rip),%rdi
xor    %eax,%eax
call   1050 <lg@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Loading %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"Cant open file\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"N=%d\0A\00"
@.str.4 = [27 x i8] c"File size does not divide\0A\00"
@.str.5 = [10 x i8] c"Bad N %d\0A\00"
@.str.6 = [13 x i8] c"Error %d %d\0A\00"
define i32 @dload_bin(i8* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
store i8* %0, i8** %6
store double* %1, double** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%15 = load i8*, i8** %6
%16 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %6
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %14
%19 = load i32*, i32** %14
%20 = icmp ne i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %4
%22 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %94
23: ; preds = %4
%24 = load i32*, i32** %14
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %24, i32 0, i32 %25)
%27 = load i32*, i32** %14
%28 = call i32 @ftell(i32* %27)
store i32 %28, i32* %13
%29 = load i32*, i32** %14
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i32, i32* %13
%33 = sext i32 %32 to i64
%34 = udiv i64 %33, 8
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = udiv i64 %34, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 8
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = mul i64 %43, %45
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = icmp ne i64 %46, %48
br i1 %49, label %50, label %53
50: ; preds = %23
%51 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %23
%54 = load i32, i32* %12
%55 = icmp slt i32 %54, 1
br i1 %55, label %60, label %56
56: ; preds = %53
%57 = load i32, i32* %12
%58 = load i32, i32* %9
%59 = icmp sgt i32 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %56, %53
%61 = load i32, i32* %9
%62 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %56
store i32 0, i32* %10
br label %65
65: ; preds = %87, %64
%66 = load i32, i32* %10
%67 = load i32, i32* %8
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %90
69: ; preds = %65
%70 = load double*, double** %7
%71 = load i32, i32* %12
%72 = load i32*, i32** %14
%73 = call i32 @fread(double* %70, i32 8, i32 %71, i32* %72)
store i32 %73, i32* %11
%74 = load i32, i32* %12
%75 = load i32, i32* %11
%76 = icmp ne i32 %74, %75
br i1 %76, label %77, label %82
77: ; preds = %69
%78 = load i32, i32* %10
%79 = load i32, i32* %11
%80 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %78, i32 %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %69
%83 = load i32, i32* %9
%84 = load double*, double** %7
%85 = sext i32 %83 to i64
%86 = getelementptr inbounds double, double* %84, i64 %85
store double* %86, double** %7
br label %87
87: ; preds = %82
%88 = load i32, i32* %10
%89 = add nsw i32 %88, 1
store i32 %89, i32* %10
br label %65
90: ; preds = %65
%91 = load i32*, i32** %14
%92 = call i32 @fclose(i32* %91)
%93 = load i32, i32* %12
store i32 %93, i32* %5
br label %94
94: ; preds = %90, %21
%95 = load i32, i32* %5
ret i32 %95
}

LLVM IR (-O2):
@.str = [12 x i8] c"Loading %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [16 x i8] c"Cant open file\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [6 x i8] c"N=%d\0A\00"
@.str.4 = [27 x i8] c"File size does not divide\0A\00"
@.str.5 = [10 x i8] c"Bad N %d\0A\00"
@.str.6 = [13 x i8] c"Error %d %d\0A\00"
define i32 @dload_bin(i8* %0, double* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %54
10: ; preds = %4
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %6, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %6)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %6, i32 0, i32 %14)
%16 = sext i32 %13 to i64
%17 = lshr i64 %16, 3
%18 = sext i32 %2 to i64
%19 = udiv i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = shl i64 %19, 32
%23 = ashr exact i64 %22, 29
%24 = mul i64 %23, %18
%25 = icmp eq i64 %24, %16
br i1 %25, label %29, label %26
26: ; preds = %10
%27 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %10
%30 = icmp slt i32 %20, 1
%31 = icmp sgt i32 %20, %3
%32 = or i1 %30, %31
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = icmp sgt i32 %2, 0
br i1 %34, label %35, label %52
35: ; preds = %33
%36 = sext i32 %3 to i64
br label %40
37: ; preds = %29
%38 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %3)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %35, %48
%41 = phi double* [ %1, %35 ], [ %49, %48 ]
%42 = phi i32 [ 0, %35 ], [ %50, %48 ]
%43 = tail call i32 @fread(double* %41, i32 8, i32 %20, i32* %6)
%44 = icmp eq i32 %43, %20
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %42, i32 %43)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %40
%49 = getelementptr inbounds double, double* %41, i64 %36
%50 = add nuw nsw i32 %42, 1
%51 = icmp eq i32 %50, %2
br i1 %51, label %52, label %40
52: ; preds = %48, %33
%53 = tail call i32 @fclose(i32* %6)
br label %54
54: ; preds = %52, %8
%55 = phi i32 [ %20, %52 ], [ 0, %8 ]
ret i32 %55
}