// File: /workspace/github_cpp_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
cmpl $0x4, %edi
jle 0x29fe
movq %rsi, %r15
movq 0x8(%rsi), %rdi
callq 0x22e0
movl %eax, %r14d
movq 0x18(%r15), %rdi
callq 0x22e0
movl %eax, %ebx
movq 0x20(%r15), %rdi
callq 0x22e0
movl %eax, %ebp
movq 0x10(%r15), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x2a6e
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 0x2f0c
addq $0x20, %rsp
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2603
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl %r14d, %edx
callq 0x4938
leaq 0x98(%rsp), %rdi
callq 0x4094
movl %eax, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x4a16
addl %ebx, %ebp
cmpl %ebp, %ebx
jae 0x26b8
movl %ebp, %r14d
leaq 0x70(%rsp), %r15
movq 0x6988(%rip), %r13      # 0x8fd0
leaq 0xb(%rsp), %r12
movq %r15, %rdi
movl 0xc(%rsp), %esi
callq 0x2b70
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
movq %r15, %rdx
callq 0x4a66
movl %eax, %ebp
testl %eax, %eax
jne 0x2953
cmpl $0x0, 0x80(%rsp)
je 0x26a9
xorl %ebp, %ebp
movq 0x78(%rsp), %rax
movb (%rax,%rbp), %al
movb %al, 0xb(%rsp)
movl $0x1, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x2210
incq %rbp
movl 0x80(%rsp), %eax
cmpq %rax, %rbp
jb 0x267e
movq %r15, %rdi
callq 0x2d12
incl %ebx
cmpl %r14d, %ebx
jne 0x264d
leaq 0x10(%rsp), %rdi
callq 0x49a0
movq 0x6927(%rip), %rdi      # 0x8ff0
leaq 0x3998(%rip), %rsi      # 0x6068
movl $0x21, %edx
callq 0x2210
movq 0x690f(%rip), %rdi      # 0x8ff0
leaq 0x39a2(%rip), %rsi      # 0x608a
movl $0x12, %edx
callq 0x2210
movl 0x58(%rsp), %esi
movq 0x68f3(%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 0x68bd(%rip), %rdi      # 0x8ff0
leaq 0x3963(%rip), %rsi      # 0x609d
movl $0x12, %edx
callq 0x2210
movl 0x5c(%rsp), %esi
movq 0x68a1(%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 0x686b(%rip), %rdi      # 0x8ff0
leaq 0x3924(%rip), %rsi      # 0x60b0
movl $0x12, %edx
callq 0x2210
movl 0x60(%rsp), %esi
movq 0x684f(%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 0x6819(%rip), %rdi      # 0x8ff0
leaq 0x38e5(%rip), %rsi      # 0x60c3
movl $0x12, %edx
callq 0x2210
movl 0x68(%rsp), %esi
movq 0x67fd(%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 0x67c7(%rip), %rdi      # 0x8ff0
leaq 0x38a6(%rip), %rsi      # 0x60d6
movl $0x12, %edx
callq 0x2210
movl 0x64(%rsp), %esi
movq 0x67ab(%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 0x6775(%rip), %rdi      # 0x8ff0
leaq 0x3867(%rip), %rsi      # 0x60e9
movl $0x12, %edx
callq 0x2210
movl 0x6c(%rsp), %esi
movq 0x6759(%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 0x6709(%rip), %rdi      # 0x8ff0
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x66f5(%rip), %rdi      # 0x8ff0
leaq 0x37fa(%rip), %rsi      # 0x60fc
movl $0x12, %edx
callq 0x2210
leaq 0x10(%rsp), %rdi
callq 0x4a38
movq 0x66d3(%rip), %rdi      # 0x8ff0
callq 0x2300
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 0x29d3
movq 0x6696(%rip), %rdi      # 0x8ff0
leaq 0x36e3(%rip), %rsi      # 0x6044
movl $0x6, %edx
callq 0x2210
movq 0x667e(%rip), %rdi      # 0x8ff0
movl %ebp, %esi
callq 0x2340
movq %rax, %r14
leaq 0x36c8(%rip), %rsi      # 0x604b
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 0x2d12
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rdi
callq 0x4968
leaq 0x98(%rsp), %rdi
callq 0x34ac
movl %ebx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x254c
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2250
movq %rax, %rbx
jmp 0x2a59
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a66
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x2a66
movq %rax, %rbx
jmp 0x2a66
jmp 0x2a42
jmp 0x2a3d
jmp 0x2a42
movq %rax, %rbx
jmp 0x2a4f
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2d12
leaq 0x10(%rsp), %rdi
callq 0x4968
leaq 0x98(%rsp), %rdi
callq 0x34ac
movq %rbx, %rdi
callq 0x2350