#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fvecs_new_fread_max(int /*<<< orphan*/ *, int *, float **, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int fvecs_new_read(const char *fname, int *d_out, float **vf_out) {
  int n;
  FILE *f = fopen(fname, "r");
  if (!f) {
    fprintf(stderr, "fvecs_new_read: could not open %s\n", fname);
    perror("");
    *d_out = -1;
    vf_out = NULL;
    return -1;
  }
  n = fvecs_new_fread_max(f, d_out, vf_out, -1);
  fclose(f);
  return n;
}


x86 assembly (clang, -O0):
<fvecs_new_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c6 <fvecs_new_read+0x76>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe81(%rip),%rdi
call   1070 <perror@plt>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <fvecs_new_read+0x9e>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0xffffffff,%ecx
call   1050 <fvecs_new_fread_max@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fvecs_new_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <fvecs_new_read+0x4d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1050 <fvecs_new_fread_max@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    %r12,%rdx
call   1040 <fprintf@plt>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,(%r14)
mov    $0xffffffff,%eax
jmp    1194 <fvecs_new_read+0x44>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"fvecs_new_read: could not open %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @fvecs_new_read(i8* %0, i32* %1, float** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca float**
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store float** %2, float*** %7
%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 ne i32* %12, null
br i1 %13, label %20, label %14
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32*, i32** %6
store i32 -1, i32* %19
store float** null, float*** %7
store i32 -1, i32* %4
br label %28
20: ; preds = %3
%21 = load i32*, i32** %9
%22 = load i32*, i32** %6
%23 = load float**, float*** %7
%24 = call i32 @fvecs_new_fread_max(i32* %21, i32* %22, float** %23, i32 -1)
store i32 %24, i32* %8
%25 = load i32*, i32** %9
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* %8
store i32 %27, i32* %4
br label %28
28: ; preds = %20, %14
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"fvecs_new_read: could not open %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @fvecs_new_read(i8* %0, i32* %1, float** %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %13
10: ; preds = %3
%11 = tail call i32 @fvecs_new_fread_max(i32* %4, i32* %1, float** %2, i32 -1)
%12 = tail call i32 @fclose(i32* %4)
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ %11, %10 ], [ -1, %6 ]
ret i32 %14
}