// File: /workspace/github_cpp_makefile_star2_O3/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 0x70ed3
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 0x70ee5
movl %ebp, %ecx
leaq (%r12,%rcx), %rdx
cmpq %rax, %rdx
cmovbeq %rcx, %r13
movq 0x30(%r15), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x40ed0
movq 0x30(%r15), %rdi
leaq (%r14,%rbx), %rsi
movq %r13, %rdx
callq 0x40e90
addq %r13, %rbx
subl %r13d, %ebp
addq %r13, %r12
testl %ebp, %ebp
jg 0x70e8f
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x70f0a
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 0x41120
leaq 0x109fb(%rip), %rsi     # 0x81919
movl $0xf, %edx
movq %r14, %rdi
callq 0x40b90
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 0x41db0
movq %rax, %r14
leaq 0x109d3(%rip), %rsi     # 0x81929
movl $0xa, %edx
movq %rax, %rdi
callq 0x40b90
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 0x40b90
leaq 0x30(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x407f0
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x418c0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x31f22(%rip), %rsi     # 0xa2ee8
movq 0x31c6b(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x70ff3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x40880
testb %bpl, %bpl
jne 0x70ffd
jmp 0x7100a
movq %rax, %r14
movq %rbx, %rdi
callq 0x40090
jmp 0x7100a
movq %rax, %r14
movq 0x31d6f(%rip), %rsi     # 0xa2d80
leaq 0x30(%rsp), %rdi
callq 0x3fc30
leaq 0xa0(%rsp), %rdi
callq 0x3f730
movq %r14, %rdi
callq 0x41f10