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

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


x86 assembly (clang, -O0):
<store_byte>:
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     116d <store_byte+0x3d>
cmpl   $0xffffffff,-0x4(%rbp)
ja     116d <store_byte+0x3d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <reg_write_byte@plt>
jmp    1228 <store_byte+0xf8>
mov    -0x4(%rbp),%eax
and    $0xdfffffff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x9fc00000,-0x4(%rbp)
jb     11a2 <store_byte+0x72>
cmpl   $0x9fe00000,-0x4(%rbp)
jae    11a2 <store_byte+0x72>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <flash_write@plt>
jmp    1228 <store_byte+0xf8>
cmpl   $0x9fc00000,-0x4(%rbp)
jb     11cc <store_byte+0x9c>
cmpl   $0x9fe00000,-0x4(%rbp)
jae    11cc <store_byte+0x9c>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <flash_write@plt>
jmp    1228 <store_byte+0xf8>
cmpl   $0x80000000,-0x4(%rbp)
jb     120c <store_byte+0xdc>
cmpl   $0x82000000,-0x4(%rbp)
jae    120c <store_byte+0xdc>
mov    -0x8(%rbp),%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    1228 <store_byte+0xf8>
jmp    1211 <store_byte+0xe1>
jmp    1216 <store_byte+0xe6>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xddd(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_byte>:
cmp    $0xfffe0000,%edi
jb     113d <store_byte+0xd>
jmp    1040 <reg_write_byte@plt>
mov    %edi,%eax
and    $0xdfffffff,%eax
and    $0xdfe00000,%edi
cmp    $0x9fc00000,%edi
jne    1159 <store_byte+0x29>
mov    %eax,%edi
jmp    1050 <flash_write@plt>
cmp    $0x81ffffff,%eax
jg     1174 <store_byte+0x44>
cltq
lea    (%rdx,%rax,4),%rax
movabs $0xfffffffe00000000,%rcx
ff ff ff
mov    %esi,(%rcx,%rax,1)
ret
lea    0xe85(%rip),%rdi
mov    %eax,%edx
jmp    1030 <printf@plt>

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

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