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

  DiskSystem disk(argv[2]);
  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;
    rc=cache.ReadBlock(i,block);
    if (rc!=ERROR_NOERROR) { 
      cerr << "Error " << rc <<" occured when reading block "<< i << endl;
      return -1;
    }
    for (SIZE_T j=0;j<block.length;j++) { 
      cout << block.data[j];
    }
  }

  cache.Detach();

  cerr << "Your data was successfully read.\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 0x286d
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x2300
movl %eax, %ebp
movq 0x18(%r14), %rdi
callq 0x2300
movl %eax, %ebx
movq 0x20(%r14), %rdi
callq 0x2300
movl %eax, %r15d
movq 0x10(%r14), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x28cc
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 0x2ce8
leaq 0x20(%rsp), %rdi
callq 0x20b0
leaq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl %ebp, %edx
callq 0x42ac
movl %r15d, %r14d
leaq 0xa8(%rsp), %rdi
callq 0x3bb4
movl %eax, %r15d
leaq 0x20(%rsp), %rdi
callq 0x438e
addl %ebx, %r14d
xorl %r12d, %r12d
movq 0x59a1(%rip), %r13      # 0x7fd0
movl %r15d, 0x1c(%rsp)
cmpl %r14d, %ebx
jae 0x26fb
leaq 0x80(%rsp), %rbp
movq %rbp, %rdi
movl %r15d, %esi
callq 0x29c6
leaq 0x20(%rsp), %rdi
movl %ebx, %esi
movq %rbp, %rdx
callq 0x43da
movl %eax, %ebp
testl %eax, %eax
je 0x26ab
movq 0x5984(%rip), %rdi      # 0x7ff0
leaq 0x29d1(%rip), %rsi      # 0x5044
callq 0x21a0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2360
movq %rax, %rdi
leaq 0x29bf(%rip), %rsi      # 0x504b
callq 0x21a0
movl %ebx, %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rax
movl %eax, %r12d
jmp 0x26df
movl %r14d, %r15d
xorl %r14d, %r14d
movl 0x90(%rsp), %eax
cmpq %rax, %r14
jae 0x26d7
movq 0x88(%rsp), %rax
movsbl (%rax,%r14), %esi
movq %r13, %rdi
callq 0x2230
incq %r14
jmp 0x26b1
movl %r15d, %r14d
movl 0x1c(%rsp), %r15d
leaq 0x80(%rsp), %rdi
callq 0x2b4a
incl %ebx
testl %ebp, %ebp
je 0x2634
jmp 0x2841
leaq 0x20(%rsp), %rdi
callq 0x430c
movq 0x58e4(%rip), %rdi      # 0x7ff0
leaq 0x2955(%rip), %rsi      # 0x5068
callq 0x21a0
movq 0x58d1(%rip), %rdi      # 0x7ff0
leaq 0x2964(%rip), %rsi      # 0x508a
callq 0x21a0
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x58aa(%rip), %rdi      # 0x7ff0
leaq 0x2950(%rip), %rsi      # 0x509d
callq 0x21a0
movl 0x6c(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x5883(%rip), %rdi      # 0x7ff0
leaq 0x293c(%rip), %rsi      # 0x50b0
callq 0x21a0
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x585c(%rip), %rdi      # 0x7ff0
leaq 0x2928(%rip), %rsi      # 0x50c3
callq 0x21a0
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x5835(%rip), %rdi      # 0x7ff0
leaq 0x2914(%rip), %rsi      # 0x50d6
callq 0x21a0
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x580e(%rip), %rdi      # 0x7ff0
leaq 0x2900(%rip), %rsi      # 0x50e9
callq 0x21a0
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
movq 0x57e7(%rip), %rdi      # 0x7ff0
callq 0x20c0
movq 0x57db(%rip), %rdi      # 0x7ff0
leaq 0x28e0(%rip), %rsi      # 0x50fc
callq 0x21a0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x43b0
movq %rbx, %rdi
callq 0x2320
xorl %r12d, %r12d
movq %rax, %rdi
callq 0x20c0
leaq 0x20(%rsp), %rdi
callq 0x42d8
leaq 0xa8(%rsp), %rdi
callq 0x30f6
movl %r12d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x254c
pushq $-0x1
popq %rdi
callq 0x2260
movq %rax, %rbx
jmp 0x28b6
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20b0
jmp 0x28c3
movq %rax, %rbx
jmp 0x28c3
jmp 0x2895
movq %rax, %rbx
jmp 0x28ac
jmp 0x289c
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2b4a
leaq 0x20(%rsp), %rdi
callq 0x42d8
leaq 0xa8(%rsp), %rdi
callq 0x30f6
movq %rbx, %rdi
callq 0x2370
nop