#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*/ allocfile(char *, unsigned long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
size_t fread(void *, int, size_t, int /*<<< orphan*/ *);
int __mp_readalloc(char *s, unsigned long n, void *a, size_t l) {
  FILE *f;
  int r;
  r = 0;
  if ((f = fopen(allocfile(s, n), "rb")) != NULL) {
    if (fread(a, sizeof(char), l, f) == l)
      r = 1;
    fclose(f);
  }
  return r;
}


x86 assembly (clang, -O0):
<__mp_readalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <allocfile@plt>
mov    %eax,%edi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11b8 <__mp_readalloc+0x78>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x20(%rbp),%rax
jne    11af <__mp_readalloc+0x6f>
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mp_readalloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
call   1030 <allocfile@plt>
lea    0xea7(%rip),%rsi
mov    %eax,%edi
call   1060 <fopen@plt>
test   %rax,%rax
je     118e <__mp_readalloc+0x4e>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <fread@plt>
xor    %ebp,%ebp
cmp    %r15,%rax
sete   %bpl
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1190 <__mp_readalloc+0x50>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @__mp_readalloc(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = call i32 @allocfile(i8* %11, i64 %12)
%14 = call i32* @fopen(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %9
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %27
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = load i64, i64* %8
%19 = load i32*, i32** %9
%20 = call i64 @fread(i8* %17, i32 1, i64 %18, i32* %19)
%21 = load i64, i64* %8
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1, i32* %10
br label %24
24: ; preds = %23, %16
%25 = load i32*, i32** %9
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %24, %4
%28 = load i32, i32* %10
ret i32 %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @__mp_readalloc(i8* %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = tail call i32 @allocfile(i8* %0, i64 %1)
%6 = tail call i32* @fopen(i32 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i64 @fread(i8* %2, i32 1, i64 %3, i32* %6)
%10 = icmp eq i64 %9, %3
%11 = zext i1 %10 to i32
%12 = tail call i32 @fclose(i32* %6)
br label %13
13: ; preds = %8, %4
%14 = phi i32 [ %11, %8 ], [ 0, %4 ]
ret i32 %14
}