#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 scalar_t__ volatile uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ eeprom_initialize();
int /*<<< orphan*/ flexram_wait();
void eeprom_write_byte(uint8_t *addr, uint8_t value) {
  uint32_t offset = (uint32_t)addr;
  if (offset >= 2048)
    return;
  if (!((*(volatile uint8_t *)0x40020001) & ((uint8_t)0x01)))
    eeprom_initialize();
  if (((uint8_t *)0x14000000)[offset] != value) {
    ((uint8_t *)0x14000000)[offset] = value;
    flexram_wait();
  }
}


x86 assembly (clang, -O0):
<eeprom_write_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x14(%rbp)
cmpl   $0x800,-0x14(%rbp)
jl     1149 <eeprom_write_byte+0x29>
jmp    1198 <eeprom_write_byte+0x78>
mov    $0x40020001,%eax
mov    (%rax),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1166 <eeprom_write_byte+0x46>
mov    $0x0,%al
call   1040 <eeprom_initialize@plt>
movslq -0x14(%rbp),%rcx
mov    $0x14000000,%eax
mov    (%rax,%rcx,8),%rax
mov    -0x10(%rbp),%rcx
cmp    %rcx,%rax
je     1198 <eeprom_write_byte+0x78>
mov    -0x10(%rbp),%rdx
movslq -0x14(%rbp),%rcx
mov    $0x14000000,%eax
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   1030 <flexram_wait@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_write_byte>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsi,0x8(%rsp)
cmp    $0x7ff,%ebx
jg     115a <eeprom_write_byte+0x3a>
mov    0x40020001,%rax
40
test   $0x1,%al
jne    1148 <eeprom_write_byte+0x28>
xor    %eax,%eax
call   1040 <eeprom_initialize@plt>
movslq %ebx,%rax
mov    0x14000000(,%rax,8),%rcx
14
cmp    0x8(%rsp),%rcx
jne    1160 <eeprom_write_byte+0x40>
add    $0x10,%rsp
pop    %rbx
ret
lea    0x14000000(,%rax,8),%rax
14
mov    0x8(%rsp),%rcx
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1030 <flexram_wait@plt>

LLVM IR (-O0):
define void @eeprom_write_byte(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i32
store i64* %0, i64** %3
store volatile i64 %1, i64* %4
%6 = load i64*, i64** %3
%7 = ptrtoint i64* %6 to i32
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 2048
br i1 %9, label %10, label %11
10: ; preds = %2
br label %30
11: ; preds = %2
%12 = load volatile i64, i64* inttoptr (i64 1073872897 to i64*)
%13 = and i64 %12, 1
%14 = icmp ne i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 (...) @eeprom_initialize()
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* inttoptr (i64 335544320 to i64*), i64 %19
%21 = load volatile i64, i64* %20
%22 = load volatile i64, i64* %4
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load volatile i64, i64* %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i64, i64* inttoptr (i64 335544320 to i64*), i64 %27
store volatile i64 %25, i64* %28
%29 = call i32 (...) @flexram_wait()
br label %30
30: ; preds = %10, %24, %17
ret void
}

LLVM IR (-O2):
define void @eeprom_write_byte(i64* %0, i64 %1) {
%3 = alloca i64
store volatile i64 %1, i64* %3
%4 = ptrtoint i64* %0 to i64
%5 = trunc i64 %4 to i32
%6 = icmp sgt i32 %5, 2047
br i1 %6, label %23, label %7
7: ; preds = %2
%8 = load volatile i64, i64* inttoptr (i64 1073872897 to i64*)
%9 = and i64 %8, 1
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 (...) @eeprom_initialize()
br label %13
13: ; preds = %11, %7
%14 = shl i64 %4, 32
%15 = ashr exact i64 %14, 32
%16 = getelementptr inbounds i64, i64* inttoptr (i64 335544320 to i64*), i64 %15
%17 = load volatile i64, i64* %16
%18 = load volatile i64, i64* %3
%19 = icmp eq i64 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = load volatile i64, i64* %3
store volatile i64 %21, i64* %16
%22 = tail call i32 (...) @flexram_wait()
br label %23
23: ; preds = %13, %20, %2
ret void
}