#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*/ assert_file_exist(char *);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int feat_readfile(char *featfile, float *feats, int D, int maxframes) {
  assert_file_exist(featfile);
  FILE *fptr = fopen(featfile, "r");
  if (NULL == fptr)
    fatal("Feature file does not exist!\n");
  int c = 0;
  while (!feof(fptr) && c < maxframes * D) {
    fscanf(fptr, "%f", &feats[c]);
    c++;
  }
  if (feof(fptr))
    c--;
  fclose(fptr);
  if (c % D != 0)
    fatal("Incorrect feature geometry!\n");
  return c / D;
}


x86 assembly (clang, -O0):
<feat_readfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert_file_exist@plt>
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11ab <feat_readfile+0x4b>
lea    0xe5c(%rip),%rdi
call   1080 <fatal@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
jne    11df <feat_readfile+0x7f>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x14(%rbp),%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11ef <feat_readfile+0x8f>
jmp    121c <feat_readfile+0xbc>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe17(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <feat_readfile+0x52>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1238 <feat_readfile+0xd8>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
je     125d <feat_readfile+0xfd>
lea    0xdcb(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x14(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feat_readfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <assert_file_exist@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    119f <feat_readfile+0x3f>
lea    0xe68(%rip),%rdi
call   1080 <fatal@plt>
mov    %r15,%rdi
call   1060 <feof@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11f8 <feat_readfile+0x98>
imul   %r14d,%r12d
test   %r12d,%r12d
jle    11f8 <feat_readfile+0x98>
mov    %r12d,%r13d
xor    %ebx,%ebx
lea    0xe5d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11f8 <feat_readfile+0x98>
add    $0x4,%rbp
cmp    %r13,%rbx
jb     11d0 <feat_readfile+0x70>
mov    %r15,%rdi
call   1060 <feof@plt>
cmp    $0x1,%rax
adc    $0xffffffff,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
cltd
idiv   %r14d
mov    %eax,%ebx
test   %edx,%edx
je     1227 <feat_readfile+0xc7>
lea    0xe01(%rip),%rdi
call   1080 <fatal@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [30 x i8] c"Feature file does not exist!\0A\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [29 x i8] c"Incorrect feature geometry!\0A\00"
define i32 @feat_readfile(i8* %0, float* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %5
store float* %1, float** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 @assert_file_exist(i8* %11)
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* null, %15
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = call i32 @fatal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %4
store i32 0, i32* %10
br label %20
20: ; preds = %32, %19
%21 = load i32*, i32** %9
%22 = call i64 @feof(i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = load i32, i32* %10
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = mul nsw i32 %26, %27
%29 = icmp slt i32 %25, %28
br label %30
30: ; preds = %24, %20
%31 = phi i1 [ false, %20 ], [ %29, %24 ]
br i1 %31, label %32, label %41
32: ; preds = %30
%33 = load i32*, i32** %9
%34 = load float*, float** %6
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float, float* %34, i64 %36
%38 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %37)
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %20
41: ; preds = %30
%42 = load i32*, i32** %9
%43 = call i64 @feof(i32* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %10
%47 = add nsw i32 %46, -1
store i32 %47, i32* %10
br label %48
48: ; preds = %45, %41
%49 = load i32*, i32** %9
%50 = call i32 @fclose(i32* %49)
%51 = load i32, i32* %10
%52 = load i32, i32* %7
%53 = srem i32 %51, %52
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = call i32 @fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
%58 = load i32, i32* %10
%59 = load i32, i32* %7
%60 = sdiv i32 %58, %59
ret i32 %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [30 x i8] c"Feature file does not exist!\0A\00"
@.str.2 = [3 x i8] c"%f\00"
@.str.3 = [29 x i8] c"Incorrect feature geometry!\0A\00"
define i32 @feat_readfile(i8* %0, float* %1, i32 %2, i32 %3) {
%5 = tail call i32 @assert_file_exist(i8* %0)
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = tail call i64 @feof(i32* %6)
%12 = icmp eq i64 %11, 0
%13 = mul nsw i32 %3, %2
%14 = icmp sgt i32 %13, 0
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %16, label %29
16: ; preds = %10
%17 = zext i32 %13 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %22, %18 ]
%20 = getelementptr inbounds float, float* %1, i64 %19
%21 = tail call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float* %20)
%22 = add nuw nsw i64 %19, 1
%23 = tail call i64 @feof(i32* %6)
%24 = icmp eq i64 %23, 0
%25 = icmp ult i64 %22, %17
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %18, label %27
27: ; preds = %18
%28 = trunc i64 %22 to i32
br label %29
29: ; preds = %27, %10
%30 = phi i32 [ 0, %10 ], [ %28, %27 ]
%31 = tail call i64 @feof(i32* %6)
%32 = icmp ne i64 %31, 0
%33 = sext i1 %32 to i32
%34 = add nsw i32 %30, %33
%35 = tail call i32 @fclose(i32* %6)
%36 = srem i32 %34, %2
%37 = sdiv i32 %34, %2
%38 = icmp eq i32 %36, 0
br i1 %38, label %41, label %39
39: ; preds = %29
%40 = tail call i32 @fatal(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %29
ret i32 %37
}