#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 */
struct edid1_info {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(struct edid1_info *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(struct edid1_info *);
struct edid1_info *malloc(int);
struct edid1_info *load_edid(const char *filename) {
  FILE *fd = NULL;
  size_t read = 0;
  struct edid1_info *edid = NULL;
  if (!filename) {
    return NULL;
  }
  fd = fopen(filename, "rb");
  if (fd == NULL) {
    return NULL;
  }
  edid = malloc(0x80);
  if (!edid)
    return NULL;
  read = fread(edid, sizeof(unsigned char), 0x80, fd);
  if (read != 0x80) {
    free(edid);
    return NULL;
  }
  return edid;
}


x86 assembly (clang, -O0):
<load_edid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <load_edid+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    1215 <load_edid+0xd5>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <load_edid+0x68>
movq   $0x0,-0x8(%rbp)
jmp    1215 <load_edid+0xd5>
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <load_edid+0x8e>
movq   $0x0,-0x8(%rbp)
jmp    1215 <load_edid+0xd5>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x80,-0x20(%rbp)
je     120d <load_edid+0xcd>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1215 <load_edid+0xd5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_edid>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1194 <load_edid+0x54>
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1194 <load_edid+0x54>
mov    %rax,%r14
mov    $0x80,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1194 <load_edid+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0x80,%rax
je     1196 <load_edid+0x56>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.edid1_info = type { i32 }
@.str = [3 x i8] c"rb\00"
define noalias %struct.edid1_info* @load_edid(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%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 %14, label %6
6: ; preds = %3
%7 = tail call %struct.edid1_info* @malloc(i32 128)
%8 = icmp eq %struct.edid1_info* %7, null
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = tail call i64 @fread(%struct.edid1_info* %7, i32 1, i32 128, i32* %4)
%11 = icmp eq i64 %10, 128
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @free(%struct.edid1_info* %7)
br label %14
14: ; preds = %9, %6, %3, %1, %12
%15 = phi %struct.edid1_info* [ null, %12 ], [ null, %1 ], [ null, %3 ], [ null, %6 ], [ %7, %9 ]
ret %struct.edid1_info* %15
}