#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 */
int /*<<< orphan*/ fatal(char *);
int lenchars_file(char *);
scalar_t__ readchars_file2(char *, int, int *);
int readdim_file(char *);
float *readfeats_file2(char *fn, int fA, int fB, int *N, int *D) {
  int nbytes = lenchars_file(fn) - sizeof(int);
  int nfloats = nbytes / sizeof(float);
  *D = readdim_file(fn);
  if (nfloats % *D != 0)
    fatal("ERROR: Feature dimension inconsistent with file\n");
  int nframes = nfloats / (*D);
  if (fA == -1)
    fA = 0;
  if (fA >= nframes) {
    fatal("ERROR: fA is larger than total number of frames\n");
  }
  if (fB == -1)
    fB = nframes - 1;
  if (fB < fA) {
    fatal("ERROR: fB is less than fA\n");
  }
  *N = fB - fA + 1;
  int nbytesread = (*N) * (*D) * sizeof(float);
  return (float *)readchars_file2(fn, fA * (*D) * sizeof(float), &nbytesread);
}


x86 assembly (clang, -O0):
<readfeats_file2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <lenchars_file@plt>
cltq
sub    $0x4,%rax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <readdim_file@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cltd
idivl  (%rcx)
cmp    $0x0,%edx
je     11a7 <readfeats_file2+0x67>
lea    0xe5e(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c5 <readfeats_file2+0x85>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jl     11dd <readfeats_file2+0x9d>
lea    0xe59(%rip),%rdi
call   1060 <fatal@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    11f0 <readfeats_file2+0xb0>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1208 <readfeats_file2+0xc8>
lea    0xe5f(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    -0x20(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1040 <readchars_file2@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readfeats_file2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,0x10(%rsp)
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r13
call   1050 <lenchars_file@plt>
mov    %eax,%ebp
add    $0xfffffffc,%ebp
sar    $0x2,%ebp
mov    %r13,%rdi
call   1030 <readdim_file@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
mov    %ebp,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     1190 <readfeats_file2+0x50>
lea    0xe78(%rip),%rdi
call   1060 <fatal@plt>
mov    (%r14),%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%r15d
xor    %ebp,%ebp
cmp    $0xffffffff,%ebx
cmovne %ebx,%ebp
cmp    %eax,%ebp
jl     11b0 <readfeats_file2+0x70>
lea    0xe86(%rip),%rdi
call   1060 <fatal@plt>
add    $0xffffffff,%r15d
cmp    $0xffffffff,%r12d
cmovne %r12d,%r15d
sub    %ebp,%r15d
jge    11cd <readfeats_file2+0x8d>
lea    0xe9a(%rip),%rdi
call   1060 <fatal@plt>
add    $0x1,%r15d
mov    0x10(%rsp),%rax
mov    %r15d,(%rax)
mov    (%r14),%eax
imul   %eax,%r15d
shl    $0x2,%r15d
mov    %r15d,0xc(%rsp)
imul   %eax,%ebp
shl    $0x2,%ebp
lea    0xc(%rsp),%rdx
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <readchars_file2@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"ERROR: Feature dimension inconsistent with file\0A\00"
@.str.1 = [49 x i8] c"ERROR: fA is larger than total number of frames\0A\00"
@.str.2 = [27 x i8] c"ERROR: fB is less than fA\0A\00"
define float* @readfeats_file2(i8* %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%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 i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%15 = load i8*, i8** %6
%16 = call i32 @lenchars_file(i8* %15)
%17 = sext i32 %16 to i64
%18 = sub i64 %17, 4
%19 = trunc i64 %18 to i32
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = sext i32 %20 to i64
%22 = udiv i64 %21, 4
%23 = trunc i64 %22 to i32
store i32 %23, i32* %12
%24 = load i8*, i8** %6
%25 = call i32 @readdim_file(i8* %24)
%26 = load i32*, i32** %10
store i32 %25, i32* %26
%27 = load i32, i32* %12
%28 = load i32*, i32** %10
%29 = load i32, i32* %28
%30 = srem i32 %27, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %5
%33 = call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %5
%35 = load i32, i32* %12
%36 = load i32*, i32** %10
%37 = load i32, i32* %36
%38 = sdiv i32 %35, %37
store i32 %38, i32* %13
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %42
41: ; preds = %34
store i32 0, i32* %7
br label %42
42: ; preds = %41, %34
%43 = load i32, i32* %7
%44 = load i32, i32* %13
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* %13
%53 = sub nsw i32 %52, 1
store i32 %53, i32* %8
br label %54
54: ; preds = %51, %48
%55 = load i32, i32* %8
%56 = load i32, i32* %7
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
%61 = load i32, i32* %8
%62 = load i32, i32* %7
%63 = sub nsw i32 %61, %62
%64 = add nsw i32 %63, 1
%65 = load i32*, i32** %9
store i32 %64, i32* %65
%66 = load i32*, i32** %9
%67 = load i32, i32* %66
%68 = load i32*, i32** %10
%69 = load i32, i32* %68
%70 = mul nsw i32 %67, %69
%71 = sext i32 %70 to i64
%72 = mul i64 %71, 4
%73 = trunc i64 %72 to i32
store i32 %73, i32* %14
%74 = load i8*, i8** %6
%75 = load i32, i32* %7
%76 = load i32*, i32** %10
%77 = load i32, i32* %76
%78 = mul nsw i32 %75, %77
%79 = sext i32 %78 to i64
%80 = mul i64 %79, 4
%81 = trunc i64 %80 to i32
%82 = call i64 @readchars_file2(i8* %74, i32 %81, i32* %14)
%83 = inttoptr i64 %82 to float*
ret float* %83
}

LLVM IR (-O2):
@.str = [49 x i8] c"ERROR: Feature dimension inconsistent with file\0A\00"
@.str.1 = [49 x i8] c"ERROR: fA is larger than total number of frames\0A\00"
@.str.2 = [27 x i8] c"ERROR: fB is less than fA\0A\00"
define float* @readfeats_file2(i8* %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture %4) {
%6 = alloca i32
%7 = tail call i32 @lenchars_file(i8* %0)
%8 = add i32 %7, -4
%9 = ashr i32 %8, 2
%10 = tail call i32 @readdim_file(i8* %0)
store i32 %10, i32* %4
%11 = srem i32 %9, %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = tail call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %4
br label %16
16: ; preds = %13, %5
%17 = phi i32 [ %15, %13 ], [ %10, %5 ]
%18 = sdiv i32 %9, %17
%19 = icmp eq i32 %1, -1
%20 = select i1 %19, i32 0, i32 %1
%21 = icmp slt i32 %20, %18
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = tail call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = icmp eq i32 %2, -1
%26 = add nsw i32 %18, -1
%27 = select i1 %25, i32 %26, i32 %2
%28 = icmp slt i32 %27, %20
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = sub nsw i32 %27, %20
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
%34 = bitcast i32* %6 to i8*
%35 = load i32, i32* %4
%36 = shl i32 %33, 2
%37 = mul i32 %36, %35
store i32 %37, i32* %6
%38 = shl i32 %20, 2
%39 = mul i32 %38, %35
%40 = call i64 @readchars_file2(i8* %0, i32 %39, i32* %6)
%41 = inttoptr i64 %40 to float*
ret float* %41
}