// File: /workspace/github_cpp_makefile_star2_O1/cpottamus[P]btree_lab/writebuffer.cc
// Function: main
int main(int argc, char *argv[])
{
  if (argc<5) { 
    usage();
    exit(-1);
  }
  SIZE_T cachesize=atoi(argv[2]);
  SIZE_T blocknum=atoi(argv[3]);
  SIZE_T numblocks=atoi(argv[4]);

  DiskSystem disk(argv[1]);
  BufferCache cache(&disk,cachesize);

  SIZE_T blocksize = disk.GetBlockSize();

  cache.Attach();

  for (unsigned i=blocknum;i<(blocknum+numblocks);i++) { 
    Block block(blocksize);
    ERROR_T rc;
    for (unsigned j=0;j<blocksize;j++) { 
      cin >> block.data[j];
    }
    rc=cache.NotifyAllocateBlock(i);
    if (rc!=ERROR_NOERROR) { 
      cerr << "Error " << rc <<" occured when notifying cache of allocation of block "<< i << endl;
      return -1;
    }
    rc=cache.WriteBlock(i,block);
    if (rc!=ERROR_NOERROR) { 
      cerr << "Error " << rc <<" occured when writing block "<< i << endl;
      return -1;
    }
  }

  cache.Detach();

  cerr << "Your data was successfully written.\n";

  cerr << "numallocs       = "<<cache.GetNumAllocs()<<endl;
  cerr << "numdeallocs     = "<<cache.GetNumDeallocs()<<endl;
  cerr << "numreads        = "<<cache.GetNumReads()<<endl;
  cerr << "numdiskreads    = "<<cache.GetNumDiskReads()<<endl;
  cerr << "numwrites       = "<<cache.GetNumWrites()<<endl;
  cerr << "numdiskwrites   = "<<cache.GetNumDiskWrites()<<endl;
  cerr << endl;

  cerr << "total time      = "<<cache.GetCurrentTime()<<endl;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
cmpl $0x4, %edi
jle 0x2aa4
movq %rsi, %r14
movq 0x10(%rsi), %rdi
callq 0x22f0
movl %eax, %ebx
movq 0x18(%r14), %rdi
callq 0x22f0
movl %eax, %ebp
movq 0x20(%r14), %rdi
callq 0x22f0
movl %eax, %r13d
movq 0x8(%r14), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x2b12
subq $0x8, %rsp
xorl %eax, %eax
leaq 0xa0(%rsp), %rdi
leaq 0x18(%rsp), %rsi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rax
pushq %rax
pushq %rax
callq 0x2fc8
addq $0x20, %rsp
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2613
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl %ebx, %edx
callq 0x49bc
leaq 0x98(%rsp), %rdi
callq 0x4152
movl %eax, %ebx
leaq 0x10(%rsp), %rdi
callq 0x4ab4
addl %ebp, %r13d
xorl %r12d, %r12d
cmpl %r13d, %ebp
setb %r15b
jae 0x27d7
movl %ebp, %r14d
movl %r13d, %eax
movq %rax, 0x8(%rsp)
movl %ebx, 0x4(%rsp)
movl %ebx, %ebx
xorl %r12d, %r12d
movq 0x696a(%rip), %rbp      # 0x8fd8
leaq 0x70(%rsp), %rdi
movl 0x4(%rsp), %r13d
movl %r13d, %esi
callq 0x2c0c
testl %r13d, %r13d
je 0x26a0
xorl %r13d, %r13d
movq 0x78(%rsp), %rsi
addq %r13, %rsi
movq %rbp, %rdi
callq 0x2280
incq %r13
cmpq %r13, %rbx
jne 0x2688
leaq 0x10(%rsp), %rdi
movl %r14d, %esi
callq 0x4adc
movl %eax, %r13d
testl %eax, %eax
je 0x2716
movl $0x6, %edx
movq 0x6930(%rip), %rdi      # 0x8ff0
leaq 0x397e(%rip), %rsi      # 0x6045
callq 0x2210
movq 0x691d(%rip), %rdi      # 0x8ff0
movl %r13d, %esi
callq 0x2350
movq %rax, %r12
movl $0x35, %edx
movq %rax, %rdi
leaq 0x395f(%rip), %rsi      # 0x604c
callq 0x2210
movq %r12, %rdi
movq %r14, %rsi
callq 0x2100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2180
jmp 0x2793
leaq 0x10(%rsp), %rdi
movl %r14d, %esi
leaq 0x70(%rsp), %rdx
callq 0x4be8
movl %eax, %r13d
testl %eax, %eax
je 0x27d2
movl $0x6, %edx
movq 0x68b1(%rip), %rdi      # 0x8ff0
leaq 0x38ff(%rip), %rsi      # 0x6045
callq 0x2210
movq 0x689e(%rip), %rdi      # 0x8ff0
movl %r13d, %esi
callq 0x2350
movq %rax, %r12
movl $0x1c, %edx
movq %rax, %rdi
leaq 0x3916(%rip), %rsi      # 0x6082
callq 0x2210
movq %r12, %rdi
movq %r14, %rsi
callq 0x2100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
leaq 0x70(%rsp), %rdi
callq 0x2dae
testb %r13b, %r13b
je 0x27d7
incq %r14
cmpq 0x8(%rsp), %r14
setb %r15b
jne 0x266e
jmp 0x27d7
movb $0x1, %r13b
jmp 0x27af
testb $0x1, %r15b
jne 0x2a78
leaq 0x10(%rsp), %rdi
callq 0x4a24
movq 0x67fe(%rip), %rdi      # 0x8ff0
leaq 0x38a6(%rip), %rsi      # 0x609f
movl $0x24, %edx
callq 0x2210
movq 0x67e6(%rip), %rdi      # 0x8ff0
leaq 0x38b3(%rip), %rsi      # 0x60c4
movl $0x12, %edx
callq 0x2210
movl 0x58(%rsp), %esi
movq 0x67ca(%rip), %rdi      # 0x8ff0
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x6794(%rip), %rdi      # 0x8ff0
leaq 0x3874(%rip), %rsi      # 0x60d7
movl $0x12, %edx
callq 0x2210
movl 0x5c(%rsp), %esi
movq 0x6778(%rip), %rdi      # 0x8ff0
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x6742(%rip), %rdi      # 0x8ff0
leaq 0x3835(%rip), %rsi      # 0x60ea
movl $0x12, %edx
callq 0x2210
movl 0x60(%rsp), %esi
movq 0x6726(%rip), %rdi      # 0x8ff0
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x66f0(%rip), %rdi      # 0x8ff0
leaq 0x37f6(%rip), %rsi      # 0x60fd
movl $0x12, %edx
callq 0x2210
movl 0x68(%rsp), %esi
movq 0x66d4(%rip), %rdi      # 0x8ff0
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x669e(%rip), %rdi      # 0x8ff0
leaq 0x37b7(%rip), %rsi      # 0x6110
movl $0x12, %edx
callq 0x2210
movl 0x64(%rsp), %esi
movq 0x6682(%rip), %rdi      # 0x8ff0
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x664c(%rip), %rdi      # 0x8ff0
leaq 0x3778(%rip), %rsi      # 0x6123
movl $0x12, %edx
callq 0x2210
movl 0x6c(%rsp), %esi
movq 0x6630(%rip), %rbx      # 0x8ff0
movq %rbx, %rdi
callq 0x2100
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x65e0(%rip), %rdi      # 0x8ff0
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x65cc(%rip), %rdi      # 0x8ff0
leaq 0x370b(%rip), %rsi      # 0x6136
movl $0x12, %edx
callq 0x2210
leaq 0x10(%rsp), %rdi
callq 0x4ad6
movq 0x65aa(%rip), %rdi      # 0x8ff0
callq 0x2310
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
xorl %r12d, %r12d
movq %rax, %rdi
callq 0x2110
leaq 0x10(%rsp), %rdi
callq 0x49ec
leaq 0x98(%rsp), %rdi
callq 0x3568
movl %r12d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x255c
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2250
movq %rax, %rbx
jmp 0x2afd
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b0a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x2b0a
movq %rax, %rbx
jmp 0x2b0a
jmp 0x2adf
movq %rax, %rbx
jmp 0x2af3
jmp 0x2ae6
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2dae
leaq 0x10(%rsp), %rdi
callq 0x49ec
leaq 0x98(%rsp), %rdi
callq 0x3568
movq %rbx, %rdi
callq 0x2360