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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ calloc(size_t, size_t);
size_t 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 hvec32_read(const char *file_in, uint32_t **data, int *n) {
  size_t s = sizeof(uint32_t), i = 0, nn;
  uint32_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 = (uint32_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;
  i = fclose(fid);
  if (i != 0)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<hvec32_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,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11ac <hvec32_read+0x5c>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <hvec32_read+0x165>
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%rdi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x1,-0x30(%rbp)
je     11e2 <hvec32_read+0x92>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <hvec32_read+0x165>
mov    -0x40(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%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    1245 <hvec32_read+0xf5>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdd4(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <hvec32_read+0x165>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x48(%rbp),%rcx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     1280 <hvec32_read+0x130>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <hvec32_read+0x165>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12a9 <hvec32_read+0x159>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <hvec32_read+0x165>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hvec32_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,(%rsp)
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    0x2e59(%rip),%rbp
test   %rax,%rax
je     1212 <hvec32_read+0xc2>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%rax
jne    1212 <hvec32_read+0xc2>
mov    (%rsp),%r13
mov    %r13d,(%r12)
mov    $0x8,%esi
mov    %r13,%rdi
call   1050 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11f1 <hvec32_read+0xa1>
mov    $0x8,%esi
mov    %rax,%rdi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r13,%rax
jne    1212 <hvec32_read+0xc2>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    120b <hvec32_read+0xbb>
mov    0x2de1(%rip),%rbp
jmp    1212 <hvec32_read+0xc2>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
jmp    1212 <hvec32_read+0xc2>
mov    0x2dc6(%rip),%rbp
mov    0x0(%rbp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 @hvec32_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 i64
%12 = 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* %11
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %4
br label %66
19: ; preds = %3
%20 = load i64, i64* %8
%21 = load i32*, i32** %12
%22 = call i64 @fread(i64* %11, i64 %20, i64 1, i32* %21)
store i64 %22, i64* %9
%23 = load i64, i64* %9
%24 = icmp ne i64 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %4
br label %66
27: ; preds = %19
%28 = load i64, i64* %11
%29 = trunc i64 %28 to i32
%30 = load i32*, i32** %7
store i32 %29, i32* %30
%31 = load i64, i64* %11
store i64 %31, i64* %10
%32 = load i64, i64* %10
%33 = load i64, i64* %8
%34 = call i64 @calloc(i64 %32, i64 %33)
%35 = inttoptr i64 %34 to i64*
%36 = load i64**, i64*** %6
store i64* %35, i64** %36
%37 = load i64**, i64*** %6
%38 = load i64*, i64** %37
%39 = icmp eq i64* %38, null
br i1 %39, label %40, label %45
40: ; preds = %27
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %5
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %4
br label %66
45: ; preds = %27
%46 = load i64**, i64*** %6
%47 = load i64*, i64** %46
%48 = load i64, i64* %8
%49 = load i64, i64* %10
%50 = load i32*, i32** %12
%51 = call i64 @fread(i64* %47, i64 %48, i64 %49, i32* %50)
store i64 %51, i64* %9
%52 = load i64, i64* %9
%53 = load i64, i64* %10
%54 = icmp ne i64 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %45
%56 = load i32, i32* @EXIT_FAILURE
store i32 %56, i32* %4
br label %66
57: ; preds = %45
%58 = load i32*, i32** %12
%59 = call i64 @fclose(i32* %58)
store i64 %59, i64* %9
%60 = load i64, i64* %9
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = load i32, i32* @EXIT_FAILURE
store i32 %63, i32* %4
br label %66
64: ; preds = %57
%65 = load i32, i32* @EXIT_SUCCESS
store i32 %65, i32* %4
br label %66
66: ; preds = %64, %62, %55, %40, %25, %17
%67 = load i32, i32* %4
ret i32 %67
}

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 @hvec32_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 %27, 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 %27
11: ; preds = %8
%12 = load i64, i64* %4
%13 = trunc i64 %12 to i32
store i32 %13, i32* %2
%14 = tail call i64 @calloc(i64 %12, i64 8)
%15 = inttoptr i64 %14 to i64*
store i64* %15, i64** %1
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
20: ; preds = %11
%21 = tail call i64 @fread(i64* %15, i64 8, i64 %12, i32* %6)
%22 = icmp eq i64 %21, %12
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i64 @fclose(i32* %6)
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %27
27: ; preds = %23, %20, %8, %3, %17
%28 = phi i32* [ @EXIT_FAILURE, %17 ], [ @EXIT_FAILURE, %3 ], [ @EXIT_FAILURE, %8 ], [ @EXIT_FAILURE, %20 ], [ %26, %23 ]
%29 = load i32, i32* %28
ret i32 %29
}