// File: /workspace/github_cpp_makefile_star2_O1/jstaursky[P]hutch/src/Sleigh/loadimage.cc
// Function: RawLoadImage::loadFill(unsigned char*, int, Address const&)
void RawLoadImage::loadFill(uint1 *ptr,int4 size,const Address &addr)

{
  uintb curaddr = addr.getOffset();
  uintb offset = 0;
  uintb readsize;

  curaddr -= vma;		// Get relative offset of first byte
  while(size>0) {
    if (curaddr >= filesize) {
      if (offset == 0)		// Initial address not within file
	break;
      memset(ptr+offset,0,size); // Fill out the rest of the buffer with 0
      return;
    }
    readsize = size;
    if (curaddr + readsize > filesize) // Adjust to biggest possible read
      readsize = filesize - curaddr;
    thefile->seekg(curaddr);
    thefile->read((char *)(ptr+offset),readsize);
    offset += readsize;
    size -= readsize;
    curaddr += readsize;
  }
  if (size > 0) {
    ostringstream errmsg;
    errmsg << "Unable to load " << dec << size << " bytes at " << addr.getShortcut();
    addr.printRaw(errmsg);
    throw DataUnavailError(errmsg.str());
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rcx, 0x8(%rsp)
testl %edx, %edx
jle 0x71151
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movq 0x8(%rsp), %rax
movq 0x8(%rax), %r12
subq 0x28(%rdi), %r12
xorl %ebx, %ebx
movq 0x38(%r15), %rax
movq %rax, %r13
subq %r12, %r13
jbe 0x71163
movl %ebp, %ecx
leaq (%r12,%rcx), %rdx
cmpq %rax, %rdx
cmovbeq %rcx, %r13
movq 0x30(%r15), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x40ec0
movq 0x30(%r15), %rdi
leaq (%r14,%rbx), %rsi
movq %r13, %rdx
callq 0x40e80
addq %r13, %rbx
subl %r13d, %ebp
addq %r13, %r12
testl %ebp, %ebp
jg 0x7110d
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x71188
addq %rbx, %r14
movl %ebp, %edx
movq %r14, %rdi
xorl %esi, %esi
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fca0
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x41110
leaq 0x1077d(%rip), %rsi     # 0x81919
movl $0xf, %edx
movq %r14, %rdi
callq 0x40b80
leaq 0x30(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl 0x48(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x48(%rsp,%rax)
movl %ebp, %esi
callq 0x41da0
movq %rax, %r14
leaq 0x10755(%rip), %rsi     # 0x81929
movl $0xa, %edx
movq %rax, %rdi
callq 0x40b80
movq 0x8(%rsp), %rax
movq (%rax), %rax
movb 0x30(%rax), %al
leaq 0x10(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r14, %rdi
callq 0x40b80
leaq 0x30(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x407e0
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x418b0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x31ca4(%rip), %rsi     # 0xa2ee8
movq 0x319ed(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x71279
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x40870
jmp 0x71279
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x7128b
movq %rbx, %rdi
callq 0x40080
jmp 0x7128b
movq %rax, %r14
movq 0x31aee(%rip), %rsi     # 0xa2d80
leaq 0x30(%rsp), %rdi
callq 0x3fc30
leaq 0xa0(%rsp), %rdi
callq 0x3f730
movq %r14, %rdi
callq 0x41f00
nop