#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__ calloc(size_t, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, size_t, int /*<<< orphan*/ *);
int Libres_read(char *path, size_t *len, unsigned int **arr) {
  FILE *fd_libres;
  if ((fd_libres = fopen(path, "rb"))) {
    fread((void *)len, 1, sizeof(size_t), fd_libres);
    *arr = (unsigned int *)calloc(*len, sizeof(unsigned int));
    fread((void *)*arr, sizeof(unsigned int), *len, fd_libres);
    fclose(fd_libres);
  } else {
    *len = 0;
    *arr = NULL;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<Libres_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    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11ce <Libres_read+0x8e>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11f0 <Libres_read+0xb0>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11f7 <Libres_read+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Libres_read>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a3 <Libres_read+0x63>
mov    %rax,%rbx
mov    $0x8,%edx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
mov    (%r15),%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,(%r14)
mov    (%r15),%rdx
mov    %rax,%rdi
mov    $0x4,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11b6 <Libres_read+0x76>
movq   $0x0,(%r15)
movq   $0x0,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @Libres_read(i8* %0, i64* %1, i32** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32**
%8 = alloca i32*
store i8* %0, i8** %5
store i64* %1, i64** %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 ne i32* %10, null
br i1 %11, label %12, label %31
12: ; preds = %3
%13 = load i64*, i64** %6
%14 = bitcast i64* %13 to i8*
%15 = load i32*, i32** %8
%16 = call i32 @fread(i8* %14, i32 1, i64 8, i32* %15)
%17 = load i64*, i64** %6
%18 = load i64, i64* %17
%19 = call i64 @calloc(i64 %18, i32 4)
%20 = inttoptr i64 %19 to i32*
%21 = load i32**, i32*** %7
store i32* %20, i32** %21
%22 = load i32**, i32*** %7
%23 = load i32*, i32** %22
%24 = bitcast i32* %23 to i8*
%25 = load i64*, i64** %6
%26 = load i64, i64* %25
%27 = load i32*, i32** %8
%28 = call i32 @fread(i8* %24, i32 4, i64 %26, i32* %27)
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
br label %34
31: ; preds = %3
%32 = load i64*, i64** %6
store i64 0, i64* %32
%33 = load i32**, i32*** %7
store i32* null, i32** %33
store i32 1, i32* %4
br label %35
34: ; preds = %12
store i32 0, i32* %4
br label %35
35: ; preds = %34, %31
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @Libres_read(i8* nocapture %0, i64* nocapture %1, i32** nocapture writeonly %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 %16, label %6
6: ; preds = %3
%7 = bitcast i64* %1 to i8*
%8 = tail call i32 @fread(i8* %7, i32 1, i64 8, i32* %4)
%9 = load i64, i64* %1
%10 = tail call i64 @calloc(i64 %9, i32 4)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %2
%12 = inttoptr i64 %10 to i8*
%13 = load i64, i64* %1
%14 = tail call i32 @fread(i8* %12, i32 4, i64 %13, i32* %4)
%15 = tail call i32 @fclose(i32* %4)
br label %17
16: ; preds = %3
store i64 0, i64* %1
store i32* null, i32** %2
br label %17
17: ; preds = %6, %16
%18 = phi i32 [ 0, %6 ], [ 1, %16 ]
ret i32 %18
}