#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 scalar_t__ uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ calloc(size_t, size_t);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
size_t fread(scalar_t__ *, size_t, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int hvec_read(const char *file_in, uint16_t **data, int *n) {
  size_t s = sizeof(uint16_t), i = 0, nn;
  int j;
  uint16_t N = 0;
  FILE *fid = fopen(file_in, "rb");
  if (fid == NULL)
    return EXIT_FAILURE;
  i = fread(&N, s, 1, fid);
  if (i != 1)
    return EXIT_FAILURE;
  *n = (int)N;
  nn = (size_t)*n;
  *data = (uint16_t *)calloc(nn, s);
  if ((*data) == NULL) {
    fprintf(stderr, "Can't allocate memory while reading file %s\n", file_in);
    return EXIT_FAILURE;
  }
  i = fread(*data, s, nn, fid);
  if (i != nn)
    return EXIT_FAILURE;
  j = fclose(fid);
  if (j != 0)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<hvec_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11ac <hvec_read+0x5c>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b6 <hvec_read+0x166>
mov    -0x28(%rbp),%rsi
mov    -0x50(%rbp),%rcx
lea    -0x48(%rbp),%rdi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x1,-0x30(%rbp)
je     11e2 <hvec_read+0x92>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b6 <hvec_read+0x166>
mov    -0x48(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1248 <hvec_read+0xf8>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdd1(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b6 <hvec_read+0x166>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x50(%rbp),%rcx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1283 <hvec_read+0x133>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b6 <hvec_read+0x166>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     12aa <hvec_read+0x15a>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b6 <hvec_read+0x166>
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hvec_read>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    0x2e56(%rip),%r13
test   %rax,%rax
je     121a <hvec_read+0xca>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%rax
jne    121a <hvec_read+0xca>
mov    0x8(%rsp),%rax
mov    %eax,(%r12)
movslq %eax,%r12
mov    $0x8,%esi
mov    %r12,%rdi
call   1050 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11f9 <hvec_read+0xa9>
mov    $0x8,%esi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r12,%rax
jne    121a <hvec_read+0xca>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %eax,%eax
jne    1213 <hvec_read+0xc3>
mov    0x2dd9(%rip),%r13
jmp    121a <hvec_read+0xca>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
jmp    121a <hvec_read+0xca>
mov    0x2dbe(%rip),%r13
mov    0x0(%r13),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [45 x i8] c"Can't allocate memory while reading file %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @hvec_read(i8* %0, i64** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64**
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
%13 = alloca i32*
store i8* %0, i8** %5
store i64** %1, i64*** %6
store i32* %2, i32** %7
store i64 8, i64* %8
store i64 0, i64* %9
store i64 0, i64* %12
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %13
%16 = load i32*, i32** %13
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %4
br label %69
20: ; preds = %3
%21 = load i64, i64* %8
%22 = load i32*, i32** %13
%23 = call i64 @fread(i64* %12, i64 %21, i64 1, i32* %22)
store i64 %23, i64* %9
%24 = load i64, i64* %9
%25 = icmp ne i64 %24, 1
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %4
br label %69
28: ; preds = %20
%29 = load i64, i64* %12
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %7
store i32 %30, i32* %31
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = sext i32 %33 to i64
store i64 %34, i64* %10
%35 = load i64, i64* %10
%36 = load i64, i64* %8
%37 = call i64 @calloc(i64 %35, i64 %36)
%38 = inttoptr i64 %37 to i64*
%39 = load i64**, i64*** %6
store i64* %38, i64** %39
%40 = load i64**, i64*** %6
%41 = load i64*, i64** %40
%42 = icmp eq i64* %41, null
br i1 %42, label %43, label %48
43: ; preds = %28
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %5
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %4
br label %69
48: ; preds = %28
%49 = load i64**, i64*** %6
%50 = load i64*, i64** %49
%51 = load i64, i64* %8
%52 = load i64, i64* %10
%53 = load i32*, i32** %13
%54 = call i64 @fread(i64* %50, i64 %51, i64 %52, i32* %53)
store i64 %54, i64* %9
%55 = load i64, i64* %9
%56 = load i64, i64* %10
%57 = icmp ne i64 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %48
%59 = load i32, i32* @EXIT_FAILURE
store i32 %59, i32* %4
br label %69
60: ; preds = %48
%61 = load i32*, i32** %13
%62 = call i32 @fclose(i32* %61)
store i32 %62, i32* %11
%63 = load i32, i32* %11
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = load i32, i32* @EXIT_FAILURE
store i32 %66, i32* %4
br label %69
67: ; preds = %60
%68 = load i32, i32* @EXIT_SUCCESS
store i32 %68, i32* %4
br label %69
69: ; preds = %67, %65, %58, %43, %26, %18
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [45 x i8] c"Can't allocate memory while reading file %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @hvec_read(i8* %0, i64** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = call i64 @fread(i64* %4, i64 8, i64 1, i32* %6)
%10 = icmp eq i64 %9, 1
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i64, i64* %4
%13 = trunc i64 %12 to i32
store i32 %13, i32* %2
%14 = shl i64 %12, 32
%15 = ashr exact i64 %14, 32
%16 = tail call i64 @calloc(i64 %15, i64 8)
%17 = inttoptr i64 %16 to i64*
store i64* %17, i64** %1
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %29
22: ; preds = %11
%23 = tail call i64 @fread(i64* %17, i64 8, i64 %15, i32* %6)
%24 = icmp eq i64 %23, %15
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = tail call i32 @fclose(i32* %6)
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %29
29: ; preds = %25, %22, %8, %3, %19
%30 = phi i32* [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %3 ], [ @EXIT_FAILURE, %8 ], [ @EXIT_FAILURE, %22 ], [ %28, %25 ]
%31 = load i32, i32* %30
ret i32 %31
}