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

/* Variables and functions */
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 ((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     1138 <eeprom_write_word+0x28>
jmp    11e4 <eeprom_write_word+0xd4>
mov    -0x10(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1177 <eeprom_write_word+0x67>
movslq -0x10(%rbp),%rcx
mov    $0x14000000,%eax
mov    (%rax,%rcx,4),%eax
cmp    -0xc(%rbp),%eax
je     1172 <eeprom_write_word+0x62>
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    11e4 <eeprom_write_word+0xd4>
movslq -0x10(%rbp),%rcx
mov    $0x14000000,%eax
mov    (%rax,%rcx,4),%eax
cmp    -0xc(%rbp),%eax
je     11a2 <eeprom_write_word+0x92>
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     11df <eeprom_write_word+0xcf>
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    11e4 <eeprom_write_word+0xd4>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_write_word>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x7fe,%edi
jg     1177 <eeprom_write_word+0x67>
mov    %esi,%ebp
mov    $0x14000000,%r14d
mov    %rdi,%rbx
shl    $0x20,%rbx
movslq %edi,%rax
mov    %rbx,%rcx
sar    $0x1e,%rcx
mov    0x14000000(%rcx),%ecx
test   $0x1,%dil
jne    114b <eeprom_write_word+0x3b>
cmp    %ebp,%ecx
je     1177 <eeprom_write_word+0x67>
mov    %ebp,(%r14,%rax,4)
jmp    1184 <eeprom_write_word+0x74>
cmp    %ebp,%ecx
je     115a <eeprom_write_word+0x4a>
mov    %ebp,(%r14,%rax,4)
xor    %eax,%eax
call   1030 <flexram_wait@plt>
movabs $0x100000000,%rax
add    %rax,%rbx
mov    %rbx,%rax
sar    $0x1e,%rax
sar    $0x8,%ebp
cmp    %ebp,(%r14,%rax,1)
jne    117c <eeprom_write_word+0x6c>
pop    %rbx
pop    %r14
pop    %rbp
ret
sar    $0x20,%rbx
mov    %ebp,(%r14,%rbx,4)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
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 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 %60
11: ; preds = %2
%12 = load i32, i32* %5
%13 = and i32 %12, 1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %4
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %25
store i32 %23, i32* %26
%27 = call i32 (...) @flexram_wait()
br label %28
28: ; preds = %22, %15
br label %60
29: ; preds = %11
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %4
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %42
36: ; preds = %29
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %39
store i32 %37, i32* %40
%41 = call i32 (...) @flexram_wait()
br label %42
42: ; preds = %36, %29
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %4
%49 = ashr i32 %48, 8
%50 = icmp ne i32 %47, %49
br i1 %50, label %51, label %59
51: ; preds = %42
%52 = load i32, i32* %4
%53 = ashr i32 %52, 8
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* inttoptr (i64 335544320 to i32*), i64 %56
store i32 %53, i32* %57
%58 = call i32 (...) @flexram_wait()
br label %59
59: ; preds = %51, %42
br label %60
60: ; preds = %10, %59, %28
ret void
}

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