// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a3e
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 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x2ab0
subq $0x8, %rsp
xorl %eax, %eax
leaq 0xb0(%rsp), %rdi
leaq 0x28(%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 0x2f68
addq $0x20, %rsp
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2606
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl %r14d, %edx
callq 0x495c
leaq 0xa8(%rsp), %rdi
callq 0x40f2
movl %eax, 0xc(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x4a54
addl %ebx, %ebp
xorl %r12d, %r12d
cmpl %ebp, %ebx
setb 0xa(%rsp)
jae 0x2770
movl %ebx, %r14d
movl %ebp, %eax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
leaq 0x80(%rsp), %rbx
movq 0x696c(%rip), %r13      # 0x8fd0
leaq 0xb(%rsp), %rbp
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x2bac
leaq 0x20(%rsp), %rdi
movl %r14d, %esi
movq %rbx, %r15
movq %rbx, %rdx
callq 0x4aa4
movl %eax, %ebx
testl %eax, %eax
je 0x2708
movl $0x6, %edx
movq 0x6956(%rip), %rdi      # 0x8ff0
leaq 0x39a3(%rip), %rsi      # 0x6044
callq 0x2210
movq 0x6943(%rip), %rdi      # 0x8ff0
movl %ebx, %esi
callq 0x2340
movq %rax, %r12
movl $0x1c, %edx
movq %rax, %rdi
leaq 0x3985(%rip), %rsi      # 0x604b
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
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2110
jmp 0x274e
cmpl $0x0, 0x90(%rsp)
je 0x274e
movq %r12, 0x10(%rsp)
xorl %r12d, %r12d
movq 0x88(%rsp), %rax
movb (%rax,%r12), %al
movb %al, 0xb(%rsp)
movl $0x1, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2210
incq %r12
movl 0x90(%rsp), %eax
cmpq %rax, %r12
jb 0x271a
movq 0x10(%rsp), %r12
movq %r15, %rdi
callq 0x2d4e
testl %ebx, %ebx
jne 0x2770
incq %r14
cmpq 0x18(%rsp), %r14
setb 0xa(%rsp)
movq %r15, %rbx
jne 0x2669
testb $0x1, 0xa(%rsp)
jne 0x2a12
leaq 0x20(%rsp), %rdi
callq 0x49c4
movq 0x6864(%rip), %rdi      # 0x8ff0
leaq 0x38d5(%rip), %rsi      # 0x6068
movl $0x21, %edx
callq 0x2210
movq 0x684c(%rip), %rdi      # 0x8ff0
leaq 0x38df(%rip), %rsi      # 0x608a
movl $0x12, %edx
callq 0x2210
movl 0x68(%rsp), %esi
movq 0x6830(%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 0x67fa(%rip), %rdi      # 0x8ff0
leaq 0x38a0(%rip), %rsi      # 0x609d
movl $0x12, %edx
callq 0x2210
movl 0x6c(%rsp), %esi
movq 0x67de(%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 0x67a8(%rip), %rdi      # 0x8ff0
leaq 0x3861(%rip), %rsi      # 0x60b0
movl $0x12, %edx
callq 0x2210
movl 0x70(%rsp), %esi
movq 0x678c(%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 0x6756(%rip), %rdi      # 0x8ff0
leaq 0x3822(%rip), %rsi      # 0x60c3
movl $0x12, %edx
callq 0x2210
movl 0x78(%rsp), %esi
movq 0x673a(%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 0x6704(%rip), %rdi      # 0x8ff0
leaq 0x37e3(%rip), %rsi      # 0x60d6
movl $0x12, %edx
callq 0x2210
movl 0x74(%rsp), %esi
movq 0x66e8(%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 0x66b2(%rip), %rdi      # 0x8ff0
leaq 0x37a4(%rip), %rsi      # 0x60e9
movl $0x12, %edx
callq 0x2210
movl 0x7c(%rsp), %esi
movq 0x6696(%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 0x6646(%rip), %rdi      # 0x8ff0
callq 0x2040
movq %rax, %rdi
callq 0x2110
movq 0x6632(%rip), %rdi      # 0x8ff0
leaq 0x3737(%rip), %rsi      # 0x60fc
movl $0x12, %edx
callq 0x2210
leaq 0x20(%rsp), %rdi
callq 0x4a76
movq 0x6610(%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 %r12d, %r12d
movq %rax, %rdi
callq 0x2110
leaq 0x20(%rsp), %rdi
callq 0x498c
leaq 0xa8(%rsp), %rdi
callq 0x3508
movl %r12d, %eax
addq $0x128, %rsp            # imm = 0x128
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 0x2a9a
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2aa7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x2aa7
movq %rax, %rbx
jmp 0x2aa7
jmp 0x2a79
movq %rax, %rbx
jmp 0x2a90
jmp 0x2a80
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2d4e
leaq 0x20(%rsp), %rdi
callq 0x498c
leaq 0xa8(%rsp), %rdi
callq 0x3508
movq %rbx, %rdi
callq 0x2350
nop