#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*/ fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void writefeats_file(char *fn, float *feats, int D, int nframes) {
  FILE *fd = fopen(fn, "w");
  if (fd == NULL) {
    perror("Unable to open output file for writing");
  } else {
    fwrite(feats, D * nframes, sizeof(float), fd);
    fclose(fd);
  }
}


x86 assembly (clang, -O0):
<writefeats_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <writefeats_file+0x46>
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
jmp    11a8 <writefeats_file+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x4,%edx
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writefeats_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r14
lea    0xeaa(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     118b <writefeats_file+0x4b>
mov    %rax,%rbp
imul   %r15d,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe70(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [39 x i8] c"Unable to open output file for writing\00"
define void @writefeats_file(i8* %0, float* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %5
store float* %1, float** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %25
16: ; preds = %4
%17 = load float*, float** %6
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = mul nsw i32 %18, %19
%21 = load i32*, i32** %9
%22 = call i32 @fwrite(float* %17, i32 %20, i32 4, i32* %21)
%23 = load i32*, i32** %9
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %16, %14
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [39 x i8] c"Unable to open output file for writing\00"
define void @writefeats_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 eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %13
9: ; preds = %4
%10 = mul nsw i32 %3, %2
%11 = tail call i32 @fwrite(float* %1, i32 %10, i32 4, i32* %5)
%12 = tail call i32 @fclose(i32* %5)
br label %13
13: ; preds = %9, %7
ret void
}