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

  if (inoffblock+numblock > numblocks) { 
    cerr << "DiskSystem::Write: Attempt to write 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++) { 
    if (!IsBlockAllocated(inoffblock+i)) { 
      if (PRINT_DISKSYSTEM_ALLOCATION_ERRORS) {
	cerr <<"DiskSystem::Write: writing unallocated block "<<(i+inoffblock)<<endl;
      }
    }
    if (mywrite(datafilefd,offset+(inoffblock+i)*blocksize,blocks[i].data,blocksize)!=blocksize) {  
      cerr << "DiskSystem::Write: mywrite has failed"<<endl;
      return ERROR_IMPLBUG;
    }
  }

  return ERROR_NOERROR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %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, -0x38(%rbp)
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
cmpl 0x4c(%rcx), %eax
jbe 0x6192
movq 0x10ed1(%rip), %rdi     # 0x16ff0
leaq 0xa30c(%rip), %rsi      # 0x10432
callq 0x31f0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x3320
movq %rax, %rdi
leaq 0xa2ab(%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 0xa290(%rip), %rsi      # 0x103f0
callq 0x31f0
movq %rax, %rdi
movq -0x38(%rbp), %rax
movl 0x4c(%rax), %esi
subl $0x1, %esi
callq 0x3320
movq %rax, %rdi
movq 0x10e3f(%rip), %rsi     # 0x16fc0
callq 0x3240
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x6262
movq -0x38(%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 0x625b
movq -0x38(%rbp), %rdi
movl -0x14(%rbp), %esi
addl -0x2c(%rbp), %esi
callq 0x60a0
testb $0x1, %al
jne 0x61d1
jmp 0x61d1
movq -0x38(%rbp), %rdx
movq 0x10(%rdx), %rax
movq %rax, -0x48(%rbp)
movl 0x48(%rdx), %eax
movl -0x14(%rbp), %ecx
addl -0x2c(%rbp), %ecx
imull 0x50(%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x6960
movq -0x48(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq 0x8(%rcx), %rdx
movl 0x50(%rax), %ecx
callq 0x5a50
movq -0x38(%rbp), %rcx
cmpl 0x50(%rcx), %eax
je 0x624b
movq 0x10dc9(%rip), %rdi     # 0x16ff0
leaq 0xa230(%rip), %rsi      # 0x1045e
callq 0x31f0
movq %rax, %rdi
movq 0x10d83(%rip), %rsi     # 0x16fc0
callq 0x3240
movl $0xfffffff5, -0x4(%rbp) # imm = 0xFFFFFFF5
jmp 0x6262
jmp 0x624d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x61b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)