#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 uint32_t;
typedef int /*<<< orphan*/ int8_t;
typedef int int16_t;

/* Variables and functions */
void flash_write(int, int);
int htons(int);
int /*<<< orphan*/ printf(char *, int, int);
void reg_write_short(int, int);
void store_short(uint32_t vaddr, int16_t val, int8_t *ram, int8_t *flash) {
  if (vaddr >= 0xfffe0000 && vaddr <= 0xffffffff)
    return reg_write_short(vaddr, val);
  vaddr = vaddr & ~0x20000000;
  if (vaddr >= 0x9fc00000 && vaddr < 0x9fe00000)
    return flash_write(vaddr, val);
  else if (vaddr >= 0x9a000000 && vaddr < 0x9f200000)
    return flash_write(vaddr, val);
  else if (vaddr >= 0x80000000 && vaddr < 0x82000000) {
    *(int16_t *)(ram + vaddr - 0x80000000) = htons(val);
    return;
  }
  printf("can't write 0x%04x to 0x%x\n", val, vaddr);
}


x86 assembly (clang, -O0):
<store_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0xfffe0000,-0x4(%rbp)
jb     117d <store_short+0x3d>
cmpl   $0xffffffff,-0x4(%rbp)
ja     117d <store_short+0x3d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <reg_write_short@plt>
jmp    123f <store_short+0xff>
mov    -0x4(%rbp),%eax
and    $0xdfffffff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x9fc00000,-0x4(%rbp)
jb     11b2 <store_short+0x72>
cmpl   $0x9fe00000,-0x4(%rbp)
jae    11b2 <store_short+0x72>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <flash_write@plt>
jmp    123f <store_short+0xff>
cmpl   $0x9a000000,-0x4(%rbp)
jb     11dc <store_short+0x9c>
cmpl   $0x9f200000,-0x4(%rbp)
jae    11dc <store_short+0x9c>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <flash_write@plt>
jmp    123f <store_short+0xff>
cmpl   $0x80000000,-0x4(%rbp)
jb     1223 <store_short+0xe3>
cmpl   $0x82000000,-0x4(%rbp)
jae    1223 <store_short+0xe3>
mov    -0x8(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rdx
shl    $0x2,%rdx
add    %rdx,%rax
movabs $0xfffffffe00000000,%rdx
ff ff ff
add    %rdx,%rax
mov    %ecx,(%rax)
jmp    123f <store_short+0xff>
jmp    1228 <store_short+0xe8>
jmp    122d <store_short+0xed>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xdc6(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_short>:
push   %r14
push   %rbx
push   %rax
cmp    $0xfffe0000,%edi
jb     1158 <store_short+0x18>
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <reg_write_short@plt>
mov    %edi,%ebx
and    $0xdfffffff,%ebx
and    $0xdfe00000,%edi
cmp    $0x9fc00000,%edi
je     117b <store_short+0x3b>
lea    0x66000000(%rbx),%eax
cmp    $0x51fffff,%eax
ja     1189 <store_short+0x49>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <flash_write@plt>
cmp    $0x81ffffff,%ebx
jg     11b7 <store_short+0x77>
mov    %rdx,%r14
mov    %esi,%edi
call   1040 <htons@plt>
movslq %ebx,%rcx
lea    (%r14,%rcx,4),%rcx
movabs $0xfffffffe00000000,%rdx
ff ff ff
mov    %eax,(%rdx,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe42(%rip),%rdi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"can't write 0x%04x to 0x%x\0A\00"
define void @store_short(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%9 = load i32, i32* %5
%10 = icmp uge i32 %9, -131072
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = load i32, i32* %5
%13 = icmp ule i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32, i32* %6
br label %57
17: ; preds = %11, %4
%18 = load i32, i32* %5
%19 = and i32 %18, -536870913
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp uge i32 %20, -1614807040
br i1 %21, label %22, label %28
22: ; preds = %17
%23 = load i32, i32* %5
%24 = icmp ult i32 %23, -1612709888
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %5
%27 = load i32, i32* %6
br label %57
28: ; preds = %22, %17
%29 = load i32, i32* %5
%30 = icmp uge i32 %29, -1711276032
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32, i32* %5
%33 = icmp ult i32 %32, -1625292800
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %5
%36 = load i32, i32* %6
br label %57
37: ; preds = %31, %28
%38 = load i32, i32* %5
%39 = icmp uge i32 %38, -2147483648
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i32, i32* %5
%42 = icmp ult i32 %41, -2113929216
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load i32, i32* %6
%45 = call i32 @htons(i32 %44)
%46 = load i32*, i32** %7
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = getelementptr inbounds i32, i32* %49, i64 -2147483648
store i32 %45, i32* %50
br label %57
51: ; preds = %40, %37
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
%54 = load i32, i32* %6
%55 = load i32, i32* %5
%56 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %54, i32 %55)
br label %57
57: ; preds = %53, %43, %34, %25, %14
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"can't write 0x%04x to 0x%x\0A\00"
define void @store_short(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture readnone %3) {
%5 = icmp ugt i32 %0, -131073
br i1 %5, label %6, label %7
6: ; preds = %4
tail call void @reg_write_short(i32 %0, i32 %1)
br label %25
7: ; preds = %4
%8 = and i32 %0, -536870913
%9 = and i32 %0, -538968064
%10 = icmp eq i32 %9, -1614807040
br i1 %10, label %11, label %12
11: ; preds = %7
tail call void @flash_write(i32 %8, i32 %1)
br label %25
12: ; preds = %7
%13 = add i32 %8, 1711276032
%14 = icmp ult i32 %13, 85983232
br i1 %14, label %15, label %16
15: ; preds = %12
tail call void @flash_write(i32 %8, i32 %1)
br label %25
16: ; preds = %12
%17 = icmp slt i32 %8, -2113929216
br i1 %17, label %18, label %23
18: ; preds = %16
%19 = tail call i32 @htons(i32 %1)
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds i32, i32* %2, i64 %20
%22 = getelementptr inbounds i32, i32* %21, i64 -2147483648
store i32 %19, i32* %22
br label %25
23: ; preds = %16
%24 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %8)
br label %25
25: ; preds = %23, %18, %15, %11, %6
ret void
}