#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 /*<<< orphan*/ int32_t;

/* Variables and functions */
int32_t *get_address(uint32_t vaddr, int8_t *ram, int8_t *flash) {
  if (vaddr >= 0xfffe0000 && vaddr <= 0xffffffff)
    return 0;
  else
    vaddr = vaddr & ~0x20000000;
  if (vaddr >= 0x9fc00000 && vaddr < 0x9fe00000)
    return (int32_t *)(flash + (vaddr - 0x9fc00000));
  else if (vaddr >= 0x80000000 && vaddr < 0x82000000)
    return (int32_t *)(ram + (vaddr - 0x80000000));
  return 0;
}


x86 assembly (clang, -O0):
<get_address>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0xfffe0000,-0xc(%rbp)
jb     1133 <get_address+0x33>
cmpl   $0xffffffff,-0xc(%rbp)
ja     1133 <get_address+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11bd <get_address+0xbd>
mov    -0xc(%rbp),%eax
and    $0xdfffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x9fc00000,-0xc(%rbp)
jb     1177 <get_address+0x77>
cmpl   $0x9fe00000,-0xc(%rbp)
jae    1177 <get_address+0x77>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x9fc00000,%ecx
mov    %ecx,%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11bd <get_address+0xbd>
cmpl   $0x80000000,-0xc(%rbp)
jb     11b0 <get_address+0xb0>
cmpl   $0x82000000,-0xc(%rbp)
jae    11b0 <get_address+0xb0>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x80000000,%ecx
mov    %ecx,%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11bd <get_address+0xbd>
jmp    11b5 <get_address+0xb5>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_address>:
cmp    $0xfffdffff,%edi
ja     1138 <get_address+0x38>
mov    %edi,%eax
and    $0xdfffffff,%eax
and    $0xdfe00000,%edi
cmp    $0x9fc00000,%edi
jne    1127 <get_address+0x27>
add    $0x60400000,%eax
lea    (%rdx,%rax,4),%rax
ret
cmp    $0x81ffffff,%eax
jg     1138 <get_address+0x38>
xor    $0x80000000,%eax
lea    (%rsi,%rax,4),%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32* @get_address(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%8 = load i32, i32* %5
%9 = icmp uge i32 %8, -131072
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* %5
%12 = icmp ule i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %10
store i32* null, i32** %4
br label %43
14: ; preds = %10, %3
%15 = load i32, i32* %5
%16 = and i32 %15, -536870913
store i32 %16, i32* %5
br label %17
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp uge i32 %18, -1614807040
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32, i32* %5
%22 = icmp ult i32 %21, -1612709888
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32*, i32** %7
%25 = load i32, i32* %5
%26 = sub i32 %25, -1614807040
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
store i32* %28, i32** %4
br label %43
29: ; preds = %20, %17
%30 = load i32, i32* %5
%31 = icmp uge i32 %30, -2147483648
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i32, i32* %5
%34 = icmp ult i32 %33, -2113929216
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i32*, i32** %6
%37 = load i32, i32* %5
%38 = sub i32 %37, -2147483648
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %36, i64 %39
store i32* %40, i32** %4
br label %43
41: ; preds = %32, %29
br label %42
42: ; preds = %41
store i32* null, i32** %4
br label %43
43: ; preds = %42, %35, %23, %13
%44 = load i32*, i32** %4
ret i32* %44
}

LLVM IR (-O2):
define i32* @get_address(i32 %0, i32* readnone %1, i32* readnone %2) {
%4 = icmp ugt i32 %0, -131073
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = and i32 %0, -536870913
%7 = and i32 %0, -538968064
%8 = icmp eq i32 %7, -1614807040
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = add i32 %6, 1614807040
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %2, i64 %11
br label %19
13: ; preds = %5
%14 = icmp slt i32 %6, -2113929216
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = xor i32 %6, -2147483648
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %1, i64 %17
br label %19
19: ; preds = %13, %3, %15, %9
%20 = phi i32* [ %12, %9 ], [ %18, %15 ], [ null, %3 ], [ null, %13 ]
ret i32* %20
}