// File: jstaursky[P]hutch/src/Sleigh/memstate.cc
// Function: MemoryBank::getPage(unsigned long, unsigned char*, int, int) const
void MemoryBank::getPage(uintb addr,uint1 *res,int4 skip,int4 size) const

{ // Default implementation just iterates using find
  // but could be optimized
  uintb ptraddr = addr + skip;
  uintb endaddr = ptraddr + size;
  uintb startalign = ptraddr & ~((uintb)(wordsize-1));
  uintb endalign = endaddr & ~((uintb)(wordsize-1));
  if ((endaddr & ((uintb)(wordsize-1))) != 0)
    endalign += wordsize;

  uintb curval;
  bool bswap = ((HOST_ENDIAN==1) != space->isBigEndian());
  uint1 *ptr;
  do {
    curval = find(startalign);
    if (bswap)
      curval = byte_swap(curval,wordsize);
    ptr = (uint1 *)&curval;
    int4 sz = wordsize;
    if (startalign < addr) {
      ptr += (addr-startalign);
      sz = wordsize - (addr-startalign);
    }
    if (startalign + wordsize > endaddr)
      sz -= (startalign + wordsize -endaddr);
    memcpy(res,ptr,sz);
    res += sz;
    startalign += wordsize;
  } while(startalign != endalign);
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movl %ecx, 0x4c(%rsp)
movl %r8d, 0x48(%rsp)
movq 0x60(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x58(%rsp), %rax
movslq 0x4c(%rsp), %rdx
addq %rdx, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movslq 0x48(%rsp), %rdx
addq %rdx, %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
movl 0x8(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
xorq $-0x1, %rdx
andq %rdx, %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
movl 0x8(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
xorq $-0x1, %rdx
andq %rdx, %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x164b26
movq (%rsp), %rax
movslq 0x8(%rax), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
movq (%rsp), %rax
movq 0x10(%rax), %rdi
callq 0xddec0
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movb %al, 0x1f(%rsp)
movq (%rsp), %rdi
movq 0x30(%rsp), %rsi
movq (%rdi), %rax
callq *0x8(%rax)
movq %rax, 0x20(%rsp)
testb $0x1, 0x1f(%rsp)
je 0x164b76
movq (%rsp), %rax
movq 0x20(%rsp), %rdi
movl 0x8(%rax), %esi
callq 0xd0ce0
movq %rax, 0x20(%rsp)
movq (%rsp), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x58(%rsp), %rax
jae 0x164bc4
movq (%rsp), %rax
movq 0x58(%rsp), %rcx
subq 0x30(%rsp), %rcx
addq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movslq 0x8(%rax), %rax
movq 0x58(%rsp), %rcx
subq 0x30(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0xc(%rsp)
movq (%rsp), %rcx
movq 0x30(%rsp), %rax
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
cmpq 0x38(%rsp), %rax
jbe 0x164bfc
movq (%rsp), %rax
movq 0x30(%rsp), %rcx
movslq 0x8(%rax), %rax
addq %rax, %rcx
subq 0x38(%rsp), %rcx
movslq 0xc(%rsp), %rax
subq %rcx, %rax
movl %eax, 0xc(%rsp)
movq 0x50(%rsp), %rdi
movq 0x10(%rsp), %rsi
movslq 0xc(%rsp), %rdx
callq 0xd68e0
movq (%rsp), %rax
movl 0xc(%rsp), %edx
movq 0x50(%rsp), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x50(%rsp)
movslq 0x8(%rax), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x28(%rsp), %rax
jne 0x164b45
addq $0x68, %rsp
retq
nopl (%rax,%rax)