#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(float *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ nrerror(char *);
void fread_vector(char *filename, float *v, long nl, long nh) {
  long ncol = nh - nl + 1, nread;
  FILE *f;
  f = fopen(filename, "rb");
  if (f == NULL)
    nrerror("Can't open file in fread_vector");
  nread = fread(v + nl, sizeof(float), ncol, f);
  if (nread != ncol)
    nrerror("fread_fvector can't read the whole vector");
  fclose(f);
}


x86 assembly (clang, -O0):
<fread_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1193 <fread_vector+0x53>
lea    0xe75(%rip),%rdi
call   1040 <nrerror@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11d2 <fread_vector+0x92>
lea    0xe56(%rip),%rdi
call   1040 <nrerror@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_vector>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
sub    %rdx,%rbx
add    $0x1,%rbx
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1178 <fread_vector+0x38>
lea    0xe90(%rip),%rdi
call   1040 <nrerror@plt>
lea    (%r12,%r15,4),%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    %rbx,%rax
je     119d <fread_vector+0x5d>
lea    0xe8b(%rip),%rdi
call   1040 <nrerror@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [32 x i8] c"Can't open file in fread_vector\00"
@.str.2 = [42 x i8] c"fread_fvector can't read the whole vector\00"
define void @fread_vector(i8* %0, float* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32*
store i8* %0, i8** %5
store float* %1, float** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%12 = load i64, i64* %8
%13 = load i64, i64* %7
%14 = sub nsw i64 %12, %13
%15 = add nsw i64 %14, 1
store i64 %15, i64* %9
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %4
%23 = load float*, float** %6
%24 = load i64, i64* %7
%25 = getelementptr inbounds float, float* %23, i64 %24
%26 = load i64, i64* %9
%27 = load i32*, i32** %11
%28 = call i64 @fread(float* %25, i32 4, i64 %26, i32* %27)
store i64 %28, i64* %10
%29 = load i64, i64* %10
%30 = load i64, i64* %9
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = call i32 @nrerror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %22
%35 = load i32*, i32** %11
%36 = call i32 @fclose(i32* %35)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [32 x i8] c"Can't open file in fread_vector\00"
@.str.2 = [42 x i8] c"fread_fvector can't read the whole vector\00"
define void @fread_vector(i8* nocapture %0, float* nocapture %1, i64 %2, i64 %3) {
%5 = sub nsw i64 %3, %2
%6 = add nsw i64 %5, 1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = getelementptr inbounds float, float* %1, i64 %2
%13 = tail call i64 @fread(float* %12, i32 4, i64 %6, i32* %7)
%14 = icmp eq i64 %13, %6
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @nrerror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = tail call i32 @fclose(i32* %7)
ret void
}