// File: cpottamus[P]btree_lab/btree_show.cc
// Function: main
int main(int argc, char **argv)
{
  char *filestem;
  SIZE_T cachesize;
  SIZE_T superblocknum;

  if (argc!=3) { 
    usage();
    return -1;
  }

  filestem=argv[1];
  cachesize=atoi(argv[2]);

  DiskSystem disk(filestem);
  BufferCache cache(&disk,cachesize);
  BTreeIndex btree(0,0,&cache);
  
  ERROR_T rc;


  if ((rc=cache.Attach())!=ERROR_NOERROR) { 
    cerr << "Can't attach buffer cache due to error"<<rc<<endl;
    return -1;
  }

  if ((rc=btree.Attach(0))!=ERROR_NOERROR) { 
    cerr << "Can't attach to index  due to error "<<rc<<endl;
    return -1;
  } else {
    cerr << "Index attached!"<<endl;
    // Your Implementation should do the right thing here
    cout << btree;
    if ((rc=btree.Detach(superblocknum))!=ERROR_NOERROR) { 
      cerr <<"Can't detach from index due to error "<<rc<<endl;
      return -1;
    }
    if ((rc=cache.Detach())!=ERROR_NOERROR) { 
      cerr <<"Can't detach from cache due to error "<<rc<<endl;
      return -1;
    }
    cerr << "Performance statistics:\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
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
je 0x3750
callq 0x3700
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e57
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x33a0
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x3410
movq -0x198(%rbp), %rsi
movq -0x190(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x3e70
jmp 0x37a6
movq %rsp, %rax
movl $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %r9d, %r9d
xorps %xmm2, %xmm2
movl %r9d, %edx
movl %r9d, %ecx
movl %r9d, %r8d
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x42b0
jmp 0x37e7
leaq -0xc0(%rbp), %rdi
callq 0x3120
leaq -0xc1(%rbp), %rdi
callq 0x3270
movl -0x1c(%rbp), %edx
leaq -0x138(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x7020
jmp 0x3817
leaq -0x180(%rbp), %rdi
xorl %edx, %edx
leaq -0x138(%rbp), %rcx
movl $0x1, %r8d
movl %edx, %esi
callq 0x9520
jmp 0x3836
leaq -0x138(%rbp), %rdi
callq 0x71e0
movl %eax, -0x19c(%rbp)
jmp 0x384a
movl -0x19c(%rbp), %eax
movl %eax, -0x184(%rbp)
cmpl $0x0, %eax
je 0x3955
movq 0x1378a(%rip), %rdi     # 0x16ff0
leaq 0xc7bd(%rip), %rsi      # 0x1002a
callq 0x31f0
movq %rax, -0x1a8(%rbp)
jmp 0x387b
movq -0x1a8(%rbp), %rdi
movl -0x184(%rbp), %esi
callq 0x33f0
movq %rax, -0x1b0(%rbp)
jmp 0x3896
movq -0x1b0(%rbp), %rdi
movq 0x1371c(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x38ab
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x188(%rbp)
jmp 0x3e17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x38f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3120
leaq -0xc1(%rbp), %rdi
callq 0x3270
jmp 0x3e63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x3e49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x3e3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x9670
jmp 0x3e3d
leaq -0x180(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x98f0
movl %eax, -0x1b4(%rbp)
jmp 0x396d
movl -0x1b4(%rbp), %eax
movl %eax, -0x184(%rbp)
cmpl $0x0, %eax
je 0x39e0
movq 0x1366b(%rip), %rdi     # 0x16ff0
leaq 0xc6c5(%rip), %rsi      # 0x10051
callq 0x31f0
movq %rax, -0x1c0(%rbp)
jmp 0x399a
movq -0x1c0(%rbp), %rdi
movl -0x184(%rbp), %esi
callq 0x33f0
movq %rax, -0x1c8(%rbp)
jmp 0x39b5
movq -0x1c8(%rbp), %rdi
movq 0x135fd(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x39ca
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x188(%rbp)
jmp 0x3e17
movq 0x13609(%rip), %rdi     # 0x16ff0
leaq 0xc688(%rip), %rsi      # 0x10076
callq 0x31f0
movq %rax, -0x1d0(%rbp)
jmp 0x39fc
movq -0x1d0(%rbp), %rdi
movq 0x135b6(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3a11
movq 0x135b8(%rip), %rdi     # 0x16fd0
leaq -0x180(%rbp), %rsi
callq 0x3f20
jmp 0x3a26
leaq -0x180(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x9cd0
movl %eax, -0x1d4(%rbp)
jmp 0x3a3e
movl -0x1d4(%rbp), %eax
movl %eax, -0x184(%rbp)
cmpl $0x0, %eax
je 0x3ab1
movq 0x1359a(%rip), %rdi     # 0x16ff0
leaq 0xc629(%rip), %rsi      # 0x10086
callq 0x31f0
movq %rax, -0x1e0(%rbp)
jmp 0x3a6b
movq -0x1e0(%rbp), %rdi
movl -0x184(%rbp), %esi
callq 0x33f0
movq %rax, -0x1e8(%rbp)
jmp 0x3a86
movq -0x1e8(%rbp), %rdi
movq 0x1352c(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3a9b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x188(%rbp)
jmp 0x3e17
leaq -0x138(%rbp), %rdi
callq 0x70f0
movl %eax, -0x1ec(%rbp)
jmp 0x3ac5
movl -0x1ec(%rbp), %eax
movl %eax, -0x184(%rbp)
cmpl $0x0, %eax
je 0x3b38
movq 0x13513(%rip), %rdi     # 0x16ff0
leaq 0xc5c8(%rip), %rsi      # 0x100ac
callq 0x31f0
movq %rax, -0x1f8(%rbp)
jmp 0x3af2
movq -0x1f8(%rbp), %rdi
movl -0x184(%rbp), %esi
callq 0x33f0
movq %rax, -0x200(%rbp)
jmp 0x3b0d
movq -0x200(%rbp), %rdi
movq 0x134a5(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3b22
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x188(%rbp)
jmp 0x3e17
movq 0x134b1(%rip), %rdi     # 0x16ff0
leaq 0xc58c(%rip), %rsi      # 0x100d2
callq 0x31f0
jmp 0x3b4d
movq 0x1349c(%rip), %rdi     # 0x16ff0
leaq 0xc590(%rip), %rsi      # 0x100eb
callq 0x31f0
movq %rax, -0x208(%rbp)
jmp 0x3b69
leaq -0x138(%rbp), %rdi
callq 0x3f50
movl %eax, -0x20c(%rbp)
jmp 0x3b7d
movl -0x20c(%rbp), %esi
movq -0x208(%rbp), %rdi
callq 0x3320
movq %rax, -0x218(%rbp)
jmp 0x3b98
movq -0x218(%rbp), %rdi
movq 0x1341a(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3bad
movq 0x1343c(%rip), %rdi     # 0x16ff0
leaq 0xc543(%rip), %rsi      # 0x100fe
callq 0x31f0
movq %rax, -0x220(%rbp)
jmp 0x3bc9
leaq -0x138(%rbp), %rdi
callq 0x3f70
movl %eax, -0x224(%rbp)
jmp 0x3bdd
movl -0x224(%rbp), %esi
movq -0x220(%rbp), %rdi
callq 0x3320
movq %rax, -0x230(%rbp)
jmp 0x3bf8
movq -0x230(%rbp), %rdi
movq 0x133ba(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3c0d
movq 0x133dc(%rip), %rdi     # 0x16ff0
leaq 0xc4f6(%rip), %rsi      # 0x10111
callq 0x31f0
movq %rax, -0x238(%rbp)
jmp 0x3c29
leaq -0x138(%rbp), %rdi
callq 0x3f90
movl %eax, -0x23c(%rbp)
jmp 0x3c3d
movl -0x23c(%rbp), %esi
movq -0x238(%rbp), %rdi
callq 0x3320
movq %rax, -0x248(%rbp)
jmp 0x3c58
movq -0x248(%rbp), %rdi
movq 0x1335a(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3c6d
movq 0x1337c(%rip), %rdi     # 0x16ff0
leaq 0xc4a9(%rip), %rsi      # 0x10124
callq 0x31f0
movq %rax, -0x250(%rbp)
jmp 0x3c89
leaq -0x138(%rbp), %rdi
callq 0x3fb0
movl %eax, -0x254(%rbp)
jmp 0x3c9d
movl -0x254(%rbp), %esi
movq -0x250(%rbp), %rdi
callq 0x3320
movq %rax, -0x260(%rbp)
jmp 0x3cb8
movq -0x260(%rbp), %rdi
movq 0x132fa(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3ccd
movq 0x1331c(%rip), %rdi     # 0x16ff0
leaq 0xc45c(%rip), %rsi      # 0x10137
callq 0x31f0
movq %rax, -0x268(%rbp)
jmp 0x3ce9
leaq -0x138(%rbp), %rdi
callq 0x3fd0
movl %eax, -0x26c(%rbp)
jmp 0x3cfd
movl -0x26c(%rbp), %esi
movq -0x268(%rbp), %rdi
callq 0x3320
movq %rax, -0x278(%rbp)
jmp 0x3d18
movq -0x278(%rbp), %rdi
movq 0x1329a(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3d2d
movq 0x132bc(%rip), %rdi     # 0x16ff0
leaq 0xc40f(%rip), %rsi      # 0x1014a
callq 0x31f0
movq %rax, -0x280(%rbp)
jmp 0x3d49
leaq -0x138(%rbp), %rdi
callq 0x3ff0
movl %eax, -0x284(%rbp)
jmp 0x3d5d
movl -0x284(%rbp), %esi
movq -0x280(%rbp), %rdi
callq 0x3320
movq %rax, -0x290(%rbp)
jmp 0x3d78
movq -0x290(%rbp), %rdi
movq 0x1323a(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3d8d
movq 0x1325c(%rip), %rdi     # 0x16ff0
movq 0x13225(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3da2
movq 0x13247(%rip), %rdi     # 0x16ff0
leaq 0xc3ad(%rip), %rsi      # 0x1015d
callq 0x31f0
movq %rax, -0x298(%rbp)
jmp 0x3dbe
leaq -0x138(%rbp), %rdi
callq 0x7270
movsd %xmm0, -0x2a0(%rbp)
jmp 0x3dd4
movsd -0x2a0(%rbp), %xmm0
movq -0x298(%rbp), %rdi
callq 0x3440
movq %rax, -0x2a8(%rbp)
jmp 0x3df1
movq -0x2a8(%rbp), %rdi
movq 0x131c1(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3e06
movl $0x0, -0x4(%rbp)
movl $0x1, -0x188(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x9670
leaq -0x138(%rbp), %rdi
callq 0x7090
leaq -0xa0(%rbp), %rdi
callq 0x4b20
jmp 0x3e57
leaq -0x138(%rbp), %rdi
callq 0x7090
leaq -0xa0(%rbp), %rdi
callq 0x4b20
jmp 0x3e63
movl -0x4(%rbp), %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
movq -0xd0(%rbp), %rdi
callq 0x3400
nop