#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
int save_filter_taps(const char *file, float *taps, int len) {
  FILE *out;
  if ((out = fopen(file, "wb")) == NULL) {
    printf("error opening file: %s\n", file);
    perror("1");
    return -1;
  }
  if (fwrite(taps, sizeof(float), len, out) < len) {
    printf("error writing file: %s\n", file);
    perror("2");
    return -1;
  }
  if (fclose(out) != 0) {
    printf("Error on closing filter file: %s\n", file);
    perror("3");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<save_filter_taps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a9 <save_filter_taps+0x59>
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <save_filter_taps+0xe1>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
call   1070 <fwrite@plt>
cmp    -0x1c(%rbp),%eax
jge    11ef <save_filter_taps+0x9f>
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <save_filter_taps+0xe1>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     122a <save_filter_taps+0xda>
mov    -0x10(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <save_filter_taps+0xe1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_filter_taps>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe9a(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a6 <save_filter_taps+0x56>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
cmp    %ebp,%eax
jl     11b6 <save_filter_taps+0x66>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11c6 <save_filter_taps+0x76>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6e(%rip),%rbp
lea    0xe4f(%rip),%rdi
jmp    11d4 <save_filter_taps+0x84>
lea    0xe78(%rip),%rbp
lea    0xe59(%rip),%rdi
jmp    11d4 <save_filter_taps+0x84>
lea    0xe8c(%rip),%rbp
lea    0xe63(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    119b <save_filter_taps+0x4b>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [24 x i8] c"error opening file: %s\0A\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [24 x i8] c"error writing file: %s\0A\00"
@.str.4 = [2 x i8] c"2\00"
@.str.5 = [34 x i8] c"Error on closing filter file: %s\0A\00"
@.str.6 = [2 x i8] c"3\00"
define i32 @save_filter_taps(i8* %0, float* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %5
store float* %1, float** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %36
16: ; preds = %3
%17 = load float*, float** %6
%18 = load i32, i32* %7
%19 = load i32*, i32** %8
%20 = call i32 @fwrite(float* %17, i32 4, i32 %18, i32* %19)
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
br label %36
27: ; preds = %16
%28 = load i32*, i32** %8
%29 = call i64 @fclose(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %32)
%34 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
br label %36
35: ; preds = %27
store i32 0, i32* %4
br label %36
36: ; preds = %35, %31, %23, %12
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [24 x i8] c"error opening file: %s\0A\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [24 x i8] c"error writing file: %s\0A\00"
@.str.4 = [2 x i8] c"2\00"
@.str.5 = [34 x i8] c"Error on closing filter file: %s\0A\00"
@.str.6 = [2 x i8] c"3\00"
define i32 @save_filter_taps(i8* %0, float* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i32 @fwrite(float* %1, i32 4, i32 %2, i32* %4)
%8 = icmp slt i32 %7, %2
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 @fclose(i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9, %6, %3
%13 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), %6 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), %9 ]
%14 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), %9 ]
%15 = tail call i32 @printf(i8* %13, i8* %0)
%16 = tail call i32 @perror(i8* %14)
br label %17
17: ; preds = %12, %9
%18 = phi i32 [ 0, %9 ], [ -1, %12 ]
ret i32 %18
}