// File: /workspace/github_cpp_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
cmpl $0x4, %edi
jle 0x28a5
movq %rsi, %r15
movq 0x10(%rsi), %rdi
callq 0x2310
movl %eax, %r14d
movq 0x18(%r15), %rdi
callq 0x2310
movl %eax, %ebx
movq 0x20(%r15), %rdi
callq 0x2310
movl %eax, 0x1c(%rsp)
movq 0x8(%r15), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x2904
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2d20
leaq 0x20(%rsp), %rdi
callq 0x20b0
leaq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl %r14d, %edx
callq 0x42e4
leaq 0xa8(%rsp), %rdi
callq 0x3bec
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x43c6
addl %ebx, 0x1c(%rsp)
movl 0x18(%rsp), %r14d
xorl %r12d, %r12d
leaq 0x80(%rsp), %r15
movq 0x598a(%rip), %r13      # 0x7fd8
cmpl 0x1c(%rsp), %ebx
jae 0x2733
movq %r15, %rdi
movl 0x18(%rsp), %esi
callq 0x29fe
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x2683
movq 0x88(%rsp), %rsi
addq %rbp, %rsi
movq %r13, %rdi
callq 0x2290
incq %rbp
jmp 0x2666
leaq 0x20(%rsp), %rdi
movl %ebx, %esi
callq 0x43ee
movl %eax, %ebp
testl %eax, %eax
je 0x26bb
movq 0x5954(%rip), %rdi      # 0x7ff0
leaq 0x29a2(%rip), %rsi      # 0x5045
callq 0x21a0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2370
leaq 0x2993(%rip), %rsi      # 0x504c
jmp 0x26f4
leaq 0x20(%rsp), %rdi
movl %ebx, %esi
movq %r15, %rdx
callq 0x44e2
movl %eax, %ebp
testl %eax, %eax
je 0x272e
movq 0x5919(%rip), %rdi      # 0x7ff0
leaq 0x2967(%rip), %rsi      # 0x5045
callq 0x21a0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2370
leaq 0x298e(%rip), %rsi      # 0x5082
movq %rax, %rdi
callq 0x21a0
movl %ebx, %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
xorl %ebp, %ebp
pushq $-0x1
popq %rax
movl %eax, %r12d
movq %r15, %rdi
callq 0x2b82
incl %ebx
testb %bpl, %bpl
jne 0x264e
jmp 0x2879
movb $0x1, %bpl
jmp 0x2716
leaq 0x20(%rsp), %rdi
callq 0x4344
movq 0x58ac(%rip), %rdi      # 0x7ff0
leaq 0x2954(%rip), %rsi      # 0x509f
callq 0x21a0
movq 0x5899(%rip), %rdi      # 0x7ff0
leaq 0x2966(%rip), %rsi      # 0x50c4
callq 0x21a0
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x5872(%rip), %rdi      # 0x7ff0
leaq 0x2952(%rip), %rsi      # 0x50d7
callq 0x21a0
movl 0x6c(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x584b(%rip), %rdi      # 0x7ff0
leaq 0x293e(%rip), %rsi      # 0x50ea
callq 0x21a0
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x5824(%rip), %rdi      # 0x7ff0
leaq 0x292a(%rip), %rsi      # 0x50fd
callq 0x21a0
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x57fd(%rip), %rdi      # 0x7ff0
leaq 0x2916(%rip), %rsi      # 0x5110
callq 0x21a0
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x57d6(%rip), %rdi      # 0x7ff0
leaq 0x2902(%rip), %rsi      # 0x5123
callq 0x21a0
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x57af(%rip), %rdi      # 0x7ff0
callq 0x20c0
movq 0x57a3(%rip), %rdi      # 0x7ff0
leaq 0x28e2(%rip), %rsi      # 0x5136
callq 0x21a0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x43e8
movq %rbx, %rdi
callq 0x2330
xorl %r12d, %r12d
movq %rax, %rdi
callq 0x20c0
leaq 0x20(%rsp), %rdi
callq 0x4310
leaq 0xa8(%rsp), %rdi
callq 0x312e
movl %r12d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x255c
pushq $-0x1
popq %rdi
callq 0x2260
movq %rax, %rbx
jmp 0x28ee
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20b0
jmp 0x28fb
movq %rax, %rbx
jmp 0x28fb
jmp 0x28cd
movq %rax, %rbx
jmp 0x28e4
jmp 0x28d4
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2b82
leaq 0x20(%rsp), %rdi
callq 0x4310
leaq 0xa8(%rsp), %rdi
callq 0x312e
movq %rbx, %rdi
callq 0x2380
nop