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

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


x86 assembly (clang, -O0):
<eeprom_write_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x10(%rbp)
cmpl   $0x7ff,-0x10(%rbp)
jl     1148 <eeprom_write_word+0x28>
jmp    1212 <eeprom_write_word+0xf2>
mov    $0x40020001,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1162 <eeprom_write_word+0x42>
mov    $0x0,%al
call   1040 <eeprom_initialize@plt>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11a3 <eeprom_write_word+0x83>
movslq -0x10(%rbp),%rcx
mov    $0x14000000,%eax
mov    (%rax,%rcx,4),%eax
mov    -0xc(%rbp),%ecx
cmp    %ecx,%eax
je     119e <eeprom_write_word+0x7e>
mov    -0xc(%rbp),%edx
movslq -0x10(%rbp),%rcx
mov    $0x14000000,%eax
mov    %edx,(%rax,%rcx,4)
mov    $0x0,%al
call   1030 <flexram_wait@plt>
jmp    1212 <eeprom_write_word+0xf2>
movslq -0x10(%rbp),%rcx
mov    $0x14000000,%eax
mov    (%rax,%rcx,4),%eax
mov    -0xc(%rbp),%ecx
cmp    %ecx,%eax
je     11d0 <eeprom_write_word+0xb0>
mov    -0xc(%rbp),%edx
movslq -0x10(%rbp),%rcx
mov    $0x14000000,%eax
mov    %edx,(%rax,%rcx,4)
mov    $0x0,%al
call   1030 <flexram_wait@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x14000000,%eax
mov    (%rax,%rcx,4),%eax
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
cmp    %ecx,%eax
je     120d <eeprom_write_word+0xed>
mov    -0xc(%rbp),%edx
sar    $0x8,%edx
mov    -0x10(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
mov    $0x14000000,%eax
mov    %edx,(%rax,%rcx,4)
mov    $0x0,%al
call   1030 <flexram_wait@plt>
jmp    1212 <eeprom_write_word+0xf2>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_write_word>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
cmp    $0x7fe,%ebx
jg     11b4 <eeprom_write_word+0x94>
mov    0x40020001,%eax
test   $0x1,%al
jne    114a <eeprom_write_word+0x2a>
xor    %eax,%eax
call   1040 <eeprom_initialize@plt>
mov    $0x14000000,%r14d
mov    %rbx,%r15
shl    $0x20,%r15
movslq %ebx,%rax
mov    %r15,%rcx
sar    $0x1e,%rcx
mov    0x14000000(%rcx),%ecx
mov    0xc(%rsp),%edx
test   $0x1,%bl
jne    117e <eeprom_write_word+0x5e>
cmp    %edx,%ecx
je     11b4 <eeprom_write_word+0x94>
mov    0xc(%rsp),%ecx
mov    %ecx,(%r14,%rax,4)
jmp    11cd <eeprom_write_word+0xad>
cmp    %edx,%ecx
je     1191 <eeprom_write_word+0x71>
mov    0xc(%rsp),%ecx
mov    %ecx,(%r14,%rax,4)
xor    %eax,%eax
call   1030 <flexram_wait@plt>
movabs $0x100000000,%rax
add    %rax,%r15
mov    %r15,%rax
sar    $0x1e,%rax
mov    (%r14,%rax,1),%eax
mov    0xc(%rsp),%ecx
sar    $0x8,%ecx
cmp    %ecx,%eax
jne    11be <eeprom_write_word+0x9e>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
sar    $0x20,%r15
mov    0xc(%rsp),%eax
sar    $0x8,%eax
mov    %eax,(%r14,%r15,4)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <flexram_wait@plt>

LLVM IR (-O0):
define void @eeprom_write_word(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store volatile i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = ptrtoint i32* %6 to i32
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 2047
br i1 %9, label %10, label %11
10: ; preds = %2
br label %66
11: ; preds = %2
%12 = load volatile i32, i32* inttoptr (i64 1073872897 to i32*)
%13 = and i32 %12, 1
%14 = icmp ne i32 %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 = and i32 %18, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %23
%25 = load volatile i32, i32* %24
%26 = load volatile i32, i32* %4
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load volatile i32, i32* %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %31
store volatile i32 %29, i32* %32
%33 = call i32 (...) @flexram_wait()
br label %34
34: ; preds = %28, %21
br label %66
35: ; preds = %17
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %37
%39 = load volatile i32, i32* %38
%40 = load volatile i32, i32* %4
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %35
%43 = load volatile i32, i32* %4
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %45
store volatile i32 %43, i32* %46
%47 = call i32 (...) @flexram_wait()
br label %48
48: ; preds = %42, %35
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %51
%53 = load volatile i32, i32* %52
%54 = load volatile i32, i32* %4
%55 = ashr i32 %54, 8
%56 = icmp ne i32 %53, %55
br i1 %56, label %57, label %65
57: ; preds = %48
%58 = load volatile i32, i32* %4
%59 = ashr i32 %58, 8
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %62
store volatile i32 %59, i32* %63
%64 = call i32 (...) @flexram_wait()
br label %65
65: ; preds = %57, %48
br label %66
66: ; preds = %10, %65, %34
ret void
}

LLVM IR (-O2):
define void @eeprom_write_word(i32* %0, i32 %1) {
%3 = alloca i32
store volatile i32 %1, i32* %3
%4 = ptrtoint i32* %0 to i64
%5 = trunc i64 %4 to i32
%6 = icmp sgt i32 %5, 2046
br i1 %6, label %42, label %7
7: ; preds = %2
%8 = load volatile i32, i32* inttoptr (i64 1073872897 to i32*)
%9 = and i32 %8, 1
%10 = icmp eq i32 %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 = and i32 %5, 1
%15 = icmp eq i32 %14, 0
%16 = shl i64 %4, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %17
%19 = load volatile i32, i32* %18
%20 = load volatile i32, i32* %3
%21 = icmp eq i32 %19, %20
br i1 %15, label %22, label %25
22: ; preds = %13
br i1 %21, label %42, label %23
23: ; preds = %22
%24 = load volatile i32, i32* %3
store volatile i32 %24, i32* %18
br label %40
25: ; preds = %13
br i1 %21, label %29, label %26
26: ; preds = %25
%27 = load volatile i32, i32* %3
store volatile i32 %27, i32* %18
%28 = tail call i32 (...) @flexram_wait()
br label %29
29: ; preds = %26, %25
%30 = add i64 %16, 4294967296
%31 = ashr exact i64 %30, 32
%32 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %31
%33 = load volatile i32, i32* %32
%34 = load volatile i32, i32* %3
%35 = ashr i32 %34, 8
%36 = icmp eq i32 %33, %35
br i1 %36, label %42, label %37
37: ; preds = %29
%38 = load volatile i32, i32* %3
%39 = ashr i32 %38, 8
store volatile i32 %39, i32* %32
br label %40
40: ; preds = %37, %23
%41 = tail call i32 (...) @flexram_wait()
br label %42
42: ; preds = %40, %22, %29, %2
ret void
}