// File: /workspace/github_cpp_makefile_star2_O3/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 0x2a6a
movq %rsi, %r15
movq 0x10(%rsi), %rdi
callq 0x22f0
movl %eax, %r14d
movq 0x18(%r15), %rdi
callq 0x22f0
movl %eax, %ebx
movq 0x20(%r15), %rdi
callq 0x22f0
movl %eax, %ebp
movq 0x8(%r15), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x2ada
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 0x2f78
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 %r14d, %edx
callq 0x49a4
leaq 0x98(%rsp), %rdi
callq 0x4100
movl %eax, %r14d
leaq 0x10(%rsp), %rdi
callq 0x4a82
addl %ebx, %ebp
movl %ebp, 0xc(%rsp)
cmpl %ebp, %ebx
jae 0x26c4
movl %r14d, %r12d
leaq 0x70(%rsp), %r15
movq 0x697d(%rip), %r13      # 0x8fd8
movq %r15, %rdi
movl %r14d, %esi
callq 0x2bdc
testl %r14d, %r14d
je 0x2685
xorl %ebp, %ebp
movq 0x78(%rsp), %rsi
addq %rbp, %rsi
movq %r13, %rdi
callq 0x2280
incq %rbp
cmpq %rbp, %r12
jne 0x266d
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x4aaa
movl %eax, %ebp
testl %eax, %eax
jne 0x295f
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
movq %r15, %rdx
callq 0x4baa
movl %eax, %ebp
testl %eax, %eax
jne 0x29bf
movq %r15, %rdi
callq 0x2d7e
incl %ebx
cmpl 0xc(%rsp), %ebx
jne 0x265b
leaq 0x10(%rsp), %rdi
callq 0x4a0c
movq 0x691b(%rip), %rdi      # 0x8ff0
leaq 0x39c3(%rip), %rsi      # 0x609f
movl $0x24, %edx
callq 0x2210
movq 0x6903(%rip), %rdi      # 0x8ff0
leaq 0x39d0(%rip), %rsi      # 0x60c4
movl $0x12, %edx
callq 0x2210
movl 0x58(%rsp), %esi
movq 0x68e7(%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 0x68b1(%rip), %rdi      # 0x8ff0
leaq 0x3991(%rip), %rsi      # 0x60d7
movl $0x12, %edx
callq 0x2210
movl 0x5c(%rsp), %esi
movq 0x6895(%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 0x685f(%rip), %rdi      # 0x8ff0
leaq 0x3952(%rip), %rsi      # 0x60ea
movl $0x12, %edx
callq 0x2210
movl 0x60(%rsp), %esi
movq 0x6843(%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 0x680d(%rip), %rdi      # 0x8ff0
leaq 0x3913(%rip), %rsi      # 0x60fd
movl $0x12, %edx
callq 0x2210
movl 0x68(%rsp), %esi
movq 0x67f1(%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 0x67bb(%rip), %rdi      # 0x8ff0
leaq 0x38d4(%rip), %rsi      # 0x6110
movl $0x12, %edx
callq 0x2210
movl 0x64(%rsp), %esi
movq 0x679f(%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 0x6769(%rip), %rdi      # 0x8ff0
leaq 0x3895(%rip), %rsi      # 0x6123
movl $0x12, %edx
callq 0x2210
movl 0x6c(%rsp), %esi
movq 0x674d(%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 0x66fd(%rip), %rdi      # 0x8ff0
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x66e9(%rip), %rdi      # 0x8ff0
leaq 0x3828(%rip), %rsi      # 0x6136
movl $0x12, %edx
callq 0x2210
leaq 0x10(%rsp), %rdi
callq 0x4aa4
movq 0x66c7(%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 %ebx, %ebx
movq %rax, %rdi
callq 0x2110
jmp 0x2a3f
movq 0x668a(%rip), %rdi      # 0x8ff0
leaq 0x36d8(%rip), %rsi      # 0x6045
movl $0x6, %edx
callq 0x2210
movq 0x6672(%rip), %rdi      # 0x8ff0
movl %ebp, %esi
callq 0x2350
movq %rax, %r14
leaq 0x36bd(%rip), %rsi      # 0x604c
movl $0x35, %edx
movq %rax, %rdi
callq 0x2210
movl %ebx, %esi
movq %r14, %rdi
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
jmp 0x2a1d
movq 0x662a(%rip), %rdi      # 0x8ff0
leaq 0x3678(%rip), %rsi      # 0x6045
movl $0x6, %edx
callq 0x2210
movq 0x6612(%rip), %rdi      # 0x8ff0
movl %ebp, %esi
callq 0x2350
movq %rax, %r14
leaq 0x3693(%rip), %rsi      # 0x6082
movl $0x1c, %edx
movq %rax, %rdi
callq 0x2210
movl %ebx, %esi
movq %r14, %rdi
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
leaq 0x70(%rsp), %rdi
callq 0x2d7e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rdi
callq 0x49d4
leaq 0x98(%rsp), %rdi
callq 0x3518
movl %ebx, %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 0x2ac5
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ad2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x2ad2
movq %rax, %rbx
jmp 0x2ad2
jmp 0x2aae
jmp 0x2aa9
jmp 0x2aae
movq %rax, %rbx
jmp 0x2abb
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2d7e
leaq 0x10(%rsp), %rdi
callq 0x49d4
leaq 0x98(%rsp), %rdi
callq 0x3518
movq %rbx, %rdi
callq 0x2360