#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_file(char *, int, int *);
float *readfeats_file(char *fn, int D, int *fA, int *fB, int *N) {
  int nbytes = lenchars_file(fn);
  int nfloats = nbytes / sizeof(float);
  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_file(fn, (*fA) * D * sizeof(float), &nbytesread);
}


x86 assembly (clang, -O0):
<readfeats_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <lenchars_file@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
je     117e <readfeats_file+0x4e>
lea    0xe87(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x30(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    119f <readfeats_file+0x6f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x34(%rbp),%eax
jl     11ba <readfeats_file+0x8a>
lea    0xe7c(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11d3 <readfeats_file+0xa3>
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11f1 <readfeats_file+0xc1>
lea    0xe76(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
sub    (%rax),%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
lea    -0x38(%rbp),%rdx
call   1030 <readchars_file@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readfeats_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%r13
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <lenchars_file@plt>
sar    $0x2,%eax
cltd
idiv   %ebx
mov    %eax,%ebp
test   %edx,%edx
je     1166 <readfeats_file+0x36>
lea    0xe9f(%rip),%rdi
call   1050 <fatal@plt>
mov    (%r15),%eax
cmp    $0xffffffff,%eax
je     11df <readfeats_file+0xaf>
cmp    %ebp,%eax
jl     117e <readfeats_file+0x4e>
lea    0xeb8(%rip),%rdi
call   1050 <fatal@plt>
mov    0x0(%r13),%eax
cmp    $0xffffffff,%eax
jne    1190 <readfeats_file+0x60>
add    $0xffffffff,%ebp
mov    %ebp,0x0(%r13)
mov    %ebp,%eax
mov    (%r15),%ecx
cmp    %ecx,%eax
jge    11aa <readfeats_file+0x7a>
lea    0xec4(%rip),%rdi
call   1050 <fatal@plt>
mov    0x0(%r13),%eax
mov    (%r15),%ecx
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%r12)
shl    $0x2,%ebx
imul   %ebx,%eax
mov    %eax,0x4(%rsp)
imul   (%r15),%ebx
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <readchars_file@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movl   $0x0,(%r15)
xor    %eax,%eax
cmp    %ebp,%eax
jge    1172 <readfeats_file+0x42>
jmp    117e <readfeats_file+0x4e>

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_file(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)
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = sext i32 %17 to i64
%19 = udiv i64 %18, 4
%20 = trunc i64 %19 to i32
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = load i32, i32* %7
%23 = srem i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %5
%26 = call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %5
%28 = load i32, i32* %12
%29 = load i32, i32* %7
%30 = sdiv i32 %28, %29
store i32 %30, i32* %13
%31 = load i32*, i32** %8
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i32*, i32** %8
store i32 0, i32* %35
br label %36
36: ; preds = %34, %27
%37 = load i32*, i32** %8
%38 = load i32, i32* %37
%39 = load i32, i32* %13
%40 = icmp sge i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = load i32*, i32** %9
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load i32, i32* %13
%49 = sub nsw i32 %48, 1
%50 = load i32*, i32** %9
store i32 %49, i32* %50
br label %51
51: ; preds = %47, %43
%52 = load i32*, i32** %9
%53 = load i32, i32* %52
%54 = load i32*, i32** %8
%55 = load i32, i32* %54
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57, %51
%60 = load i32*, i32** %9
%61 = load i32, i32* %60
%62 = load i32*, i32** %8
%63 = load i32, i32* %62
%64 = sub nsw i32 %61, %63
%65 = add nsw i32 %64, 1
%66 = load i32*, i32** %10
store i32 %65, i32* %66
%67 = load i32*, i32** %10
%68 = load i32, i32* %67
%69 = load i32, i32* %7
%70 = mul nsw i32 %68, %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** %8
%76 = load i32, i32* %75
%77 = load i32, i32* %7
%78 = mul nsw i32 %76, %77
%79 = sext i32 %78 to i64
%80 = mul i64 %79, 4
%81 = trunc i64 %80 to i32
%82 = call i64 @readchars_file(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_file(i8* %0, i32 %1, i32* nocapture %2, i32* nocapture %3, i32* nocapture writeonly %4) {
%6 = alloca i32
%7 = tail call i32 @lenchars_file(i8* %0)
%8 = ashr i32 %7, 2
%9 = srem i32 %8, %1
%10 = sdiv i32 %8, %1
%11 = icmp eq i32 %9, 0
br i1 %11, label %14, label %12
12: ; preds = %5
%13 = tail call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %5
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %2
br label %18
18: ; preds = %17, %14
%19 = phi i32 [ 0, %17 ], [ %15, %14 ]
%20 = icmp slt i32 %19, %10
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = add nsw i32 %10, -1
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %23
%29 = phi i32 [ %27, %26 ], [ %24, %23 ]
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = tail call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %3
%35 = load i32, i32* %2
br label %36
36: ; preds = %32, %28
%37 = phi i32 [ %35, %32 ], [ %30, %28 ]
%38 = phi i32 [ %34, %32 ], [ %29, %28 ]
%39 = sub nsw i32 %38, %37
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
%41 = bitcast i32* %6 to i8*
%42 = shl i32 %1, 2
%43 = mul i32 %42, %40
store i32 %43, i32* %6
%44 = load i32, i32* %2
%45 = mul i32 %42, %44
%46 = call i64 @readchars_file(i8* %0, i32 %45, i32* %6)
%47 = inttoptr i64 %46 to float*
ret float* %47
}