// File: cpottamus[P]btree_lab/disksystem.cc
// Function: DiskSystem::Read(unsigned int, unsigned int, std::vector<Block, std::allocator<Block>>&, double&)
ERROR_T DiskSystem::Read(const SIZE_T   inoffblock,
			 const SIZE_T   numblock,
			 vector<Block> &blocks,
			 double        &reqtime)
{
  reqtime=0;

  if (inoffblock+numblock > numblocks) { 
    cerr << "DiskSystem::Read: Attempt to read blocks "<<inoffblock<<" to "<<(inoffblock+numblock-1)<<", but maxmimum block is only "<<(numblocks-1)<<endl;
    return ERROR_NOSPACE;
  }

  reqtime=ModelAccess(inoffblock,numblock);

  for (SIZE_T i=0;i<numblock;i++) { 
    Block b(blocksize);
    if (!IsBlockAllocated(inoffblock+i)) { 
      if (PRINT_DISKSYSTEM_ALLOCATION_ERRORS) {
	cerr <<"DiskSystem::Read: reading unallocated block "<<(i+inoffblock)<<endl;
      }
    }
    if (myread(datafilefd,offset+(inoffblock+i)*blocksize,b.data,blocksize,true)!=blocksize) { 
      cerr << "DiskSystem::Read: myread has failed"<<endl;
      return ERROR_IMPLBUG;
    }
    blocks.push_back(b);
  }

  return ERROR_NOERROR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
cmpl 0x4c(%rcx), %eax
jbe 0x5f55
movq 0x1110e(%rip), %rdi     # 0x16ff0
leaq 0xa4d8(%rip), %rsi      # 0x103c1
callq 0x31f0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x3320
movq %rax, %rdi
leaq 0xa4e8(%rip), %rsi      # 0x103eb
callq 0x31f0
movq %rax, %rdi
movl -0x14(%rbp), %esi
addl -0x18(%rbp), %esi
subl $0x1, %esi
callq 0x3320
movq %rax, %rdi
leaq 0xa4cd(%rip), %rsi      # 0x103f0
callq 0x31f0
movq %rax, %rdi
movq -0x70(%rbp), %rax
movl 0x4c(%rax), %esi
subl $0x1, %esi
callq 0x3320
movq %rax, %rdi
movq 0x1107c(%rip), %rsi     # 0x16fc0
callq 0x3240
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x6081
movq -0x70(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movq (%rdi), %rax
callq *(%rax)
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x607a
movq -0x70(%rbp), %rax
movl 0x50(%rax), %esi
leaq -0x58(%rbp), %rdi
callq 0x4420
movq -0x70(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x2c(%rbp), %eax
addl %eax, %esi
callq 0x60a0
movb %al, -0x71(%rbp)
jmp 0x5fa5
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x5fca
jmp 0x5fae
jmp 0x5fca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x46e0
jmp 0x608d
movq -0x70(%rbp), %rcx
movq 0x10(%rcx), %rdi
movl 0x48(%rcx), %esi
movl -0x14(%rbp), %eax
movl -0x2c(%rbp), %edx
addl %edx, %eax
movl 0x50(%rcx), %ecx
imull %ecx, %eax
addl %eax, %esi
movq -0x50(%rbp), %rdx
movl $0x1, %r8d
callq 0x5ba0
movl %eax, -0x78(%rbp)
jmp 0x5ff9
movl -0x78(%rbp), %eax
movq -0x70(%rbp), %rcx
cmpl 0x50(%rcx), %eax
je 0x6040
movq 0x10fe4(%rip), %rdi     # 0x16ff0
leaq 0xa3fb(%rip), %rsi      # 0x1040e
callq 0x31f0
movq %rax, -0x80(%rbp)
jmp 0x601e
movq -0x80(%rbp), %rdi
movq 0x10f97(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x6030
movl $0xfffffff5, -0x4(%rbp) # imm = 0xFFFFFFF5
movl $0x1, -0x68(%rbp)
jmp 0x6056
movq -0x20(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x68f0
jmp 0x604f
movl $0x0, -0x68(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x46e0
movl -0x68(%rbp), %eax
testl %eax, %eax
je 0x606a
jmp 0x6068
jmp 0x6081
jmp 0x606c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x5f73
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)