// File: jstaursky[P]hutch/src/Sleigh/memstate.cc
// Function: MemoryBank::setPage(unsigned long, unsigned char const*, int, int)
void MemoryBank::setPage(uintb addr,const uint1 *val,int4 skip,int4 size)
  
{  // Default implementation just iterates using insert
   // 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 {
    ptr = (uint1 *)&curval;
    int4 sz = wordsize;
    if (startalign < addr) {
      ptr += (addr-startalign);
      sz = wordsize - (addr-startalign);
    }
    if (startalign + wordsize > endaddr)
      sz -= (startalign + wordsize - endaddr);
    if (sz != wordsize) {
      curval = find(startalign); // Part of word is copied from underlying
      memcpy(ptr,val,sz);	 // Rest is taken from -val-
    }
    else
      curval = *((const uintb *)val); // -val- supplies entire word
    if (bswap)
      curval = byte_swap(curval,wordsize);
    insert(startalign,curval);
    val += 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 0x164cf6
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), %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 0x164d63
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 0x164d9b
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 (%rsp), %rcx
movl 0xc(%rsp), %eax
cmpl 0x8(%rcx), %eax
je 0x164dd2
movq (%rsp), %rdi
movq 0x30(%rsp), %rsi
movq (%rdi), %rax
callq *0x8(%rax)
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rdi
movq 0x50(%rsp), %rsi
movslq 0xc(%rsp), %rdx
callq 0xd68e0
jmp 0x164ddf
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
testb $0x1, 0x1f(%rsp)
je 0x164dfc
movq (%rsp), %rax
movq 0x20(%rsp), %rdi
movl 0x8(%rax), %esi
callq 0xd0ce0
movq %rax, 0x20(%rsp)
movq (%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq (%rdi), %rax
callq *(%rax)
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 0x164d15
addq $0x68, %rsp
retq
nopw (%rax,%rax)