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


x86 assembly (clang, -O0):
<ivecs_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    11c9 <ivecs_new_read+0x79>
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)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <ivecs_new_read+0xa1>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0xffffffff,%ecx
call   1050 <ivecs_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):
<ivecs_new_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <ivecs_new_read+0x4d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    $0xffffffff,%ecx
call   1050 <ivecs_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,(%r15)
movq   $0x0,(%r14)
mov    $0xffffffff,%eax
jmp    1194 <ivecs_new_read+0x44>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"ivecs_new_read: could not open %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @ivecs_new_read(i8* %0, i32* %1, i32** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32**
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32** %2, i32*** %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 %21, 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
%20 = load i32**, i32*** %7
store i32* null, i32** %20
store i32 -1, i32* %4
br label %29
21: ; preds = %3
%22 = load i32*, i32** %9
%23 = load i32*, i32** %6
%24 = load i32**, i32*** %7
%25 = call i32 @ivecs_new_fread_max(i32* %22, i32* %23, i32** %24, i32 -1)
store i32 %25, i32* %8
%26 = load i32*, i32** %9
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* %8
store i32 %28, i32* %4
br label %29
29: ; preds = %21, %14
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"ivecs_new_read: could not open %s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @ivecs_new_read(i8* %0, i32* %1, i32** %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
store i32* null, i32** %2
br label %13
10: ; preds = %3
%11 = tail call i32 @ivecs_new_fread_max(i32* %4, i32* %1, i32** %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
}