#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 */
int /*<<< orphan*/ exit(int);
int ntohl(int);
int32_t get_instruction(uint32_t address, int8_t *ram, int8_t *flash) {
  int32_t instruction = 0x0;
  if (address >= 0x80000000 && address < 0x82000000)
    instruction = *(int32_t *)(ram + address - 0x80000000);
  else if (address >= 0x9fc00000 && address < 0x9fe00000)
    instruction = *(int32_t *)(flash + address - 0x9fc00000);
  else
    exit(1);
  instruction = ntohl(instruction);
  return instruction;
}


x86 assembly (clang, -O0):
<get_instruction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x80000000,-0x4(%rbp)
jb     117a <get_instruction+0x5a>
cmpl   $0x82000000,-0x4(%rbp)
jae    117a <get_instruction+0x5a>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movabs $0xfffffffe00000000,%rcx
ff ff ff
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c9 <get_instruction+0xa9>
cmpl   $0x9fc00000,-0x4(%rbp)
jb     11ba <get_instruction+0x9a>
cmpl   $0x9fe00000,-0x4(%rbp)
jae    11ba <get_instruction+0x9a>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movabs $0xfffffffd81000000,%rcx
ff ff ff
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c4 <get_instruction+0xa4>
mov    $0x1,%edi
call   1030 <exit@plt>
jmp    11c9 <get_instruction+0xa9>
mov    -0x1c(%rbp),%edi
call   1040 <ntohl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_instruction>:
push   %rax
mov    $0xffffffff80000000,%rax
cmp    $0x82000000,%edi
jl     114b <get_instruction+0x2b>
mov    %edi,%eax
and    $0xffe00000,%eax
cmp    $0x9fc00000,%eax
jne    115b <get_instruction+0x3b>
movabs $0xffffffff60400000,%rax
ff ff ff
mov    %rdx,%rsi
movslq %edi,%rcx
lea    (%rsi,%rcx,4),%rcx
mov    (%rcx,%rax,4),%edi
pop    %rax
jmp    1040 <ntohl@plt>
mov    $0x1,%edi
call   1030 <exit@plt>

LLVM IR (-O0):
define i32 @get_instruction(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp uge i32 %8, -2147483648
br i1 %9, label %10, label %20
10: ; preds = %3
%11 = load i32, i32* %4
%12 = icmp ult i32 %11, -2113929216
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32*, i32** %5
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = getelementptr inbounds i32, i32* %17, i64 -2147483648
%19 = load i32, i32* %18
store i32 %19, i32* %7
br label %36
20: ; preds = %10, %3
%21 = load i32, i32* %4
%22 = icmp uge i32 %21, -1614807040
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp ult i32 %24, -1612709888
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32*, i32** %6
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = getelementptr inbounds i32, i32* %30, i64 -2680160256
%32 = load i32, i32* %31
store i32 %32, i32* %7
br label %35
33: ; preds = %23, %20
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
br label %36
36: ; preds = %35, %13
%37 = load i32, i32* %7
%38 = call i32 @ntohl(i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
define i32 @get_instruction(i32 %0, i32* nocapture %1, i32* nocapture %2) {
%4 = icmp slt i32 %0, -2113929216
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = and i32 %0, -2097152
%7 = icmp eq i32 %6, -1614807040
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %5, %3
%11 = phi i32* [ %1, %3 ], [ %2, %5 ]
%12 = phi i64 [ -2147483648, %3 ], [ -2680160256, %5 ]
%13 = sext i32 %0 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
%15 = getelementptr inbounds i32, i32* %14, i64 %12
%16 = load i32, i32* %15
%17 = tail call i32 @ntohl(i32 %16)
ret i32 %17
}