#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 *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sp_init_screen_mark();
int memdmp_read(unsigned char *startpt_p, int length, char *filename_p) {
  FILE *ifile_p;
  ifile_p = fopen(filename_p, "rb");
  if (ifile_p == NULL) {
    return 0;
  }
  fread(startpt_p, 1, length, ifile_p);
  fclose(ifile_p);
  sp_init_screen_mark();
  return 1;
}


x86 assembly (clang, -O0):
<memdmp_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117e <memdmp_read+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11aa <memdmp_read+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x0,%al
call   1040 <sp_init_screen_mark@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memdmp_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xeac(%rip),%rsi
mov    %rdx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     118d <memdmp_read+0x4d>
mov    %rax,%rbp
mov    $0x1,%ebx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1040 <sp_init_screen_mark@plt>
jmp    118f <memdmp_read+0x4f>
xor    %ebx,%ebx
mov    %ebx,%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 @memdmp_read(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%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 = load i32*, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 0, i32* %4
br label %22
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = load i32*, i32** %8
%18 = call i32 @fread(i8* %15, i32 1, i32 %16, i32* %17)
%19 = load i32*, i32** %8
%20 = call i32 @fclose(i32* %19)
%21 = call i32 (...) @sp_init_screen_mark()
store i32 1, i32* %4
br label %22
22: ; preds = %14, %13
%23 = load i32, i32* %4
ret i32 %23
}

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