#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 */

/* Variables and functions */
int /*<<< orphan*/ exec_read_cmd(void *, int, int, unsigned int *);
int /*<<< orphan*/ exec_write_cmd(void *, int, int, int);
void PEX_8111Read(void *info, int addr, int *data) {
  if (addr < 0x1000) {
    exec_read_cmd(info, addr, 4, (unsigned int *)data);
  } else if (addr >= 0x1000 && addr <= 0x1FFF) {
    exec_write_cmd(info, 0x84, 4, addr);
    exec_read_cmd(info, 0x88, 4, (unsigned int *)data);
  }
}


x86 assembly (clang, -O0):
<PEX_8111Read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1000,-0xc(%rbp)
jge    115a <PEX_8111Read+0x3a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x4,%edx
call   1030 <exec_read_cmd@plt>
jmp    11a6 <PEX_8111Read+0x86>
cmpl   $0x1000,-0xc(%rbp)
jl     11a1 <PEX_8111Read+0x81>
cmpl   $0x1fff,-0xc(%rbp)
jg     11a1 <PEX_8111Read+0x81>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x84,%esi
mov    $0x4,%edx
call   1040 <exec_write_cmd@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x88,%esi
mov    $0x4,%edx
call   1030 <exec_read_cmd@plt>
jmp    11a6 <PEX_8111Read+0x86>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PEX_8111Read>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ecx
mov    %rdi,%rbx
cmp    $0x1000,%esi
jl     1153 <PEX_8111Read+0x33>
cmp    $0x1fff,%ecx
ja     116c <PEX_8111Read+0x4c>
mov    %rbx,%rdi
mov    $0x84,%esi
mov    $0x4,%edx
call   1040 <exec_write_cmd@plt>
mov    $0x88,%ecx
mov    %rbx,%rdi
mov    %ecx,%esi
mov    $0x4,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <exec_read_cmd@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @PEX_8111Read(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 4096
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = load i32*, i32** %6
%13 = call i32 @exec_read_cmd(i8* %10, i32 %11, i32 4, i32* %12)
br label %28
14: ; preds = %3
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 4096
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp sle i32 %18, 8191
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = call i32 @exec_write_cmd(i8* %21, i32 132, i32 4, i32 %22)
%24 = load i8*, i8** %4
%25 = load i32*, i32** %6
%26 = call i32 @exec_read_cmd(i8* %24, i32 136, i32 4, i32* %25)
br label %27
27: ; preds = %20, %17, %14
br label %28
28: ; preds = %27, %9
ret void
}

LLVM IR (-O2):
define void @PEX_8111Read(i8* %0, i32 %1, i32* %2) {
%4 = icmp slt i32 %1, 4096
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = icmp ult i32 %1, 8192
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = tail call i32 @exec_write_cmd(i8* %0, i32 132, i32 4, i32 %1)
br label %9
9: ; preds = %3, %7
%10 = phi i32 [ 136, %7 ], [ %1, %3 ]
%11 = tail call i32 @exec_read_cmd(i8* %0, i32 %10, i32 4, i32* %2)
br label %12
12: ; preds = %9, %5
ret void
}