#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 *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void printfeats_file(char *fn, float *feats, int D, int nframes) {
  FILE *fd = fopen(fn, "w");
  for (int i = 0; i < nframes; i++) {
    for (int j = 0; j < D; j++) {
      fprintf(fd, "%e ", feats[i * D + j]);
    }
    fprintf(fd, "\n");
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<printfeats_file>:
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
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11da <printfeats_file+0xaa>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ba <printfeats_file+0x8a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5d(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1174 <printfeats_file+0x44>
mov    -0x20(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <printfeats_file+0x31>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printfeats_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,0x4(%rsp)
mov    %rsi,%rbx
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %r15d,%r15d
jle    11f2 <printfeats_file+0xb2>
movslq 0x4(%rsp),%rax
mov    %r15d,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r14d
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
lea    0xe6f(%rip),%r15
jmp    11bd <printfeats_file+0x7d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
add    0x10(%rsp),%rbx
cmp    0x8(%rsp),%r13
je     11f2 <printfeats_file+0xb2>
cmpl   $0x0,0x4(%rsp)
jle    11a0 <printfeats_file+0x60>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movss  (%rbx,%r12,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    11d0 <printfeats_file+0x90>
jmp    11a0 <printfeats_file+0x60>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%e \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @printfeats_file(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
%11 = alloca i32
store i8* %0, i8** %5
store float* %1, float** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
store i32 0, i32* %10
br label %14
14: ; preds = %42, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %45
18: ; preds = %14
store i32 0, i32* %11
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = load i32*, i32** %9
%25 = load float*, float** %6
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = mul nsw i32 %26, %27
%29 = load i32, i32* %11
%30 = add nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds float, float* %25, i64 %31
%33 = load float, float* %32
%34 = fpext float %33 to double
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %34)
br label %36
36: ; preds = %23
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %19
39: ; preds = %19
%40 = load i32*, i32** %9
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %14
45: ; preds = %14
%46 = load i32*, i32** %9
%47 = call i32 @fclose(i32* %46)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%e \00"
define void @printfeats_file(i8* nocapture %0, float* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = icmp sgt i32 %2, 0
%9 = sext i32 %2 to i64
%10 = zext i32 %3 to i64
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %7, %18
%13 = phi i64 [ 0, %7 ], [ %20, %18 ]
br i1 %8, label %14, label %18
14: ; preds = %12
%15 = mul nsw i64 %13, %9
br label %22
16: ; preds = %18, %4
%17 = tail call i32 @fclose(i32* %5)
ret void
18: ; preds = %22, %12
%19 = tail call i32 @fputc(i32 10, i32* %5)
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %16, label %12
22: ; preds = %14, %22
%23 = phi i64 [ 0, %14 ], [ %29, %22 ]
%24 = add nsw i64 %23, %15
%25 = getelementptr inbounds float, float* %1, i64 %24
%26 = load float, float* %25
%27 = fpext float %26 to double
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %18, label %22
}