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


x86 assembly (clang, -O0):
<readfeats_file_d>:
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    $0x3,%rax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
je     117e <readfeats_file_d+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)
je     11a2 <readfeats_file_d+0x72>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11ac <readfeats_file_d+0x7c>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x34(%rbp),%eax
jl     11c7 <readfeats_file_d+0x97>
lea    0xe6f(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     11e8 <readfeats_file_d+0xb8>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11f4 <readfeats_file_d+0xc4>
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    1212 <readfeats_file_d+0xe2>
lea    0xe55(%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    $0x3,%rax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%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_d>:
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    $0x3,%eax
cltd
idiv   %ebx
mov    %eax,%ebp
test   %edx,%edx
je     1166 <readfeats_file_d+0x36>
lea    0xe9f(%rip),%rdi
call   1050 <fatal@plt>
mov    (%r15),%eax
test   %eax,%eax
js     11e2 <readfeats_file_d+0xb2>
cmp    %ebp,%eax
jl     117d <readfeats_file_d+0x4d>
lea    0xeb9(%rip),%rdi
call   1050 <fatal@plt>
mov    0x0(%r13),%eax
cmp    $0xffffffff,%eax
je     118a <readfeats_file_d+0x5a>
cmp    %ebp,%eax
jl     1193 <readfeats_file_d+0x63>
add    $0xffffffff,%ebp
mov    %ebp,0x0(%r13)
mov    %ebp,%eax
mov    (%r15),%ecx
cmp    %ecx,%eax
jge    11ad <readfeats_file_d+0x7d>
lea    0xec1(%rip),%rdi
call   1050 <fatal@plt>
mov    0x0(%r13),%eax
mov    (%r15),%ecx
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%r12)
shl    $0x3,%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    1171 <readfeats_file_d+0x41>
jmp    117d <readfeats_file_d+0x4d>

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 double* @readfeats_file_d(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, 8
%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 %38, label %34
34: ; preds = %27
%35 = load i32*, i32** %8
%36 = load i32, i32* %35
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34, %27
%39 = load i32*, i32** %8
store i32 0, i32* %39
br label %40
40: ; preds = %38, %34
%41 = load i32*, i32** %8
%42 = load i32, i32* %41
%43 = load i32, i32* %13
%44 = icmp sge i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @fatal(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
%48 = load i32*, i32** %9
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, -1
br i1 %50, label %57, label %51
51: ; preds = %47
%52 = load i32*, i32** %9
%53 = load i32, i32* %52
%54 = load i32, i32* %13
%55 = sub nsw i32 %54, 1
%56 = icmp sgt i32 %53, %55
br i1 %56, label %57, label %61
57: ; preds = %51, %47
%58 = load i32, i32* %13
%59 = sub nsw i32 %58, 1
%60 = load i32*, i32** %9
store i32 %59, i32* %60
br label %61
61: ; preds = %57, %51
%62 = load i32*, i32** %9
%63 = load i32, i32* %62
%64 = load i32*, i32** %8
%65 = load i32, i32* %64
%66 = icmp slt i32 %63, %65
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
%70 = load i32*, i32** %9
%71 = load i32, i32* %70
%72 = load i32*, i32** %8
%73 = load i32, i32* %72
%74 = sub nsw i32 %71, %73
%75 = add nsw i32 %74, 1
%76 = load i32*, i32** %10
store i32 %75, i32* %76
%77 = load i32*, i32** %10
%78 = load i32, i32* %77
%79 = load i32, i32* %7
%80 = mul nsw i32 %78, %79
%81 = sext i32 %80 to i64
%82 = mul i64 %81, 8
%83 = trunc i64 %82 to i32
store i32 %83, i32* %14
%84 = load i8*, i8** %6
%85 = load i32*, i32** %8
%86 = load i32, i32* %85
%87 = load i32, i32* %7
%88 = mul nsw i32 %86, %87
%89 = sext i32 %88 to i64
%90 = mul i64 %89, 8
%91 = trunc i64 %90 to i32
%92 = call i64 @readchars_file(i8* %84, i32 %91, i32* %14)
%93 = inttoptr i64 %92 to double*
ret double* %93
}

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 double* @readfeats_file_d(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, 3
%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 slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %2
br label %18
18: ; preds = %14, %17
%19 = phi i32 [ %15, %14 ], [ 0, %17 ]
%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 ne i32 %24, -1
%26 = icmp slt i32 %24, %10
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = add nsw i32 %10, -1
store i32 %29, i32* %3
br label %30
30: ; preds = %23, %28
%31 = phi i32 [ %24, %23 ], [ %29, %28 ]
%32 = load i32, i32* %2
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = tail call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %3
%37 = load i32, i32* %2
br label %38
38: ; preds = %34, %30
%39 = phi i32 [ %37, %34 ], [ %32, %30 ]
%40 = phi i32 [ %36, %34 ], [ %31, %30 ]
%41 = sub nsw i32 %40, %39
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
%43 = bitcast i32* %6 to i8*
%44 = shl i32 %1, 3
%45 = mul i32 %44, %42
store i32 %45, i32* %6
%46 = load i32, i32* %2
%47 = mul i32 %44, %46
%48 = call i64 @readchars_file(i8* %0, i32 %47, i32* %6)
%49 = inttoptr i64 %48 to double*
ret double* %49
}