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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
bool load_image(const char *name, uint8_t *image_data) {
  FILE *f;
  int read;
  f = fopen(name, "rb");
  if (f == NULL) {
    return false;
  }
  read = fread(image_data, 3, 4 * 100 * 80, f);
  fclose(f);
  return (read == 4 * 100 * 80);
}


x86 assembly (clang, -O0):
<load_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <load_image+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <load_image+0x70>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x3,%esi
mov    $0x7d00,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x7d00,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_image>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1177 <load_image+0x47>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x3,%esi
mov    $0x7d00,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
cmp    $0x7d00,%ebp
sete   %al
jmp    1179 <load_image+0x49>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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