#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*/ *eeprom_create_empty_file();
int /*<<< orphan*/ *fopen(char *, char *);
FILE *eeprom_fp() {
  static FILE *EEPROM_FP = NULL;
  static int tried = 0;
  if (!EEPROM_FP && !tried) {
    tried = 1;
    EEPROM_FP = fopen("EEPROM.DAT", "r+b");
    if (!EEPROM_FP) {
      EEPROM_FP = eeprom_create_empty_file();
    }
  }
  return EEPROM_FP;
}


x86 assembly (clang, -O0):
<eeprom_fp>:
push   %rbp
mov    %rsp,%rbp
cmpq   $0x0,0x2f0c(%rip)
jne    1184 <eeprom_fp+0x64>
cmpl   $0x0,0x2f07(%rip)
jne    1184 <eeprom_fp+0x64>
movl   $0x1,0x2ef7(%rip)
lea    0xeb0(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,0x2ed5(%rip)
cmpq   $0x0,0x2ecd(%rip)
jne    117f <eeprom_fp+0x5f>
mov    $0x0,%al
call   1040 <eeprom_create_empty_file@plt>
mov    %rax,0x2eb9(%rip)
jmp    1184 <eeprom_fp+0x64>
mov    0x2ead(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_fp>:
push   %rax
mov    0x2f10(%rip),%rax
test   %rax,%rax
jne    115c <eeprom_fp+0x3c>
testb  $0x1,0x2f0c(%rip)
jne    115c <eeprom_fp+0x3c>
movb   $0x1,0x2f03(%rip)
lea    0xebc(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,0x2ee1(%rip)
test   %rax,%rax
je     115e <eeprom_fp+0x3e>
pop    %rcx
ret
xor    %eax,%eax
call   1040 <eeprom_create_empty_file@plt>
mov    %rax,0x2ecc(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@eeprom_fp.EEPROM_FP = internal global i32* null
@eeprom_fp.tried = internal global i32 0
@.str = [11 x i8] c"EEPROM.DAT\00"
@.str.1 = [4 x i8] c"r+b\00"
define i32* @eeprom_fp() {
%1 = load i32*, i32** @eeprom_fp.EEPROM_FP
%2 = icmp ne i32* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = load i32, i32* @eeprom_fp.tried
%5 = icmp ne i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
store i32 1, i32* @eeprom_fp.tried
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** @eeprom_fp.EEPROM_FP
%8 = load i32*, i32** @eeprom_fp.EEPROM_FP
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = call i32* (...) @eeprom_create_empty_file()
store i32* %11, i32** @eeprom_fp.EEPROM_FP
br label %12
12: ; preds = %10, %6
br label %13
13: ; preds = %12, %3, %0
%14 = load i32*, i32** @eeprom_fp.EEPROM_FP
ret i32* %14
}

LLVM IR (-O2):
@eeprom_fp.EEPROM_FP = internal unnamed_addr global i32* null
@eeprom_fp.tried = internal unnamed_addr global i1 false
@.str = [11 x i8] c"EEPROM.DAT\00"
@.str.1 = [4 x i8] c"r+b\00"
define i32* @eeprom_fp() {
%1 = load i32*, i32** @eeprom_fp.EEPROM_FP
%2 = icmp ne i32* %1, null
%3 = load i1, i1* @eeprom_fp.tried
%4 = select i1 %2, i1 true, i1 %3
br i1 %4, label %10, label %5
5: ; preds = %0
store i1 true, i1* @eeprom_fp.tried
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** @eeprom_fp.EEPROM_FP
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32* (...) @eeprom_create_empty_file()
store i32* %9, i32** @eeprom_fp.EEPROM_FP
br label %10
10: ; preds = %5, %8, %0
%11 = phi i32* [ %6, %5 ], [ %9, %8 ], [ %1, %0 ]
ret i32* %11
}