#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 int32_t;

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


x86 assembly (clang, -O0):
<store_word>:
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_word+0x3d>
cmpl   $0xffffffff,-0x4(%rbp)
ja     117d <store_word+0x3d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <reg_write_word@plt>
jmp    1210 <store_word+0xd0>
mov    -0x4(%rbp),%eax
and    $0xdfffffff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x9fc00000,-0x4(%rbp)
jb     11b2 <store_word+0x72>
cmpl   $0x9fe00000,-0x4(%rbp)
jae    11b2 <store_word+0x72>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <flash_write@plt>
jmp    1210 <store_word+0xd0>
cmpl   $0x80000000,-0x4(%rbp)
jb     11f9 <store_word+0xb9>
cmpl   $0x82000000,-0x4(%rbp)
jae    11f9 <store_word+0xb9>
mov    -0x8(%rbp),%edi
call   1040 <htonl@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    1210 <store_word+0xd0>
jmp    11fe <store_word+0xbe>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_word>:
push   %rbp
push   %rbx
push   %rax
cmp    $0xfffe0000,%edi
jb     1156 <store_word+0x16>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <reg_write_word@plt>
mov    %edi,%ebp
and    $0xdfffffff,%ebp
and    $0xdfe00000,%edi
cmp    $0x9fc00000,%edi
jne    1179 <store_word+0x39>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <flash_write@plt>
cmp    $0x81ffffff,%ebp
jg     11a6 <store_word+0x66>
mov    %rdx,%rbx
mov    %esi,%edi
call   1040 <htonl@plt>
movslq %ebp,%rcx
lea    (%rbx,%rcx,4),%rcx
movabs $0xfffffffe00000000,%rdx
ff ff ff
mov    %eax,(%rdx,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe53(%rip),%rdi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"can't write 0x%08x to 0x%x\0A\00"
define void @store_word(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 %47
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 %47
28: ; preds = %22, %17
%29 = load i32, i32* %5
%30 = icmp uge i32 %29, -2147483648
br i1 %30, label %31, label %42
31: ; preds = %28
%32 = load i32, i32* %5
%33 = icmp ult i32 %32, -2113929216
br i1 %33, label %34, label %42
34: ; preds = %31
%35 = load i32, i32* %6
%36 = call i32 @htonl(i32 %35)
%37 = load i32*, i32** %7
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = getelementptr inbounds i32, i32* %40, i64 -2147483648
store i32 %36, i32* %41
br label %47
42: ; preds = %31, %28
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = load i32, i32* %5
%46 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %45)
br label %47
47: ; preds = %43, %34, %25, %14
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"can't write 0x%08x to 0x%x\0A\00"
define void @store_word(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_word(i32 %0, i32 %1)
br label %21
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 %21
12: ; preds = %7
%13 = icmp slt i32 %8, -2113929216
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = tail call i32 @htonl(i32 %1)
%16 = sext i32 %8 to i64
%17 = getelementptr inbounds i32, i32* %2, i64 %16
%18 = getelementptr inbounds i32, i32* %17, i64 -2147483648
store i32 %15, i32* %18
br label %21
19: ; preds = %12
%20 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %8)
br label %21
21: ; preds = %19, %14, %11, %6
ret void
}