// File: /workspace/github_cpp_makefile_star2_O2/cpottamus[P]btree_lab/btree_sane.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
    if ((rc=btree.SanityCheck())!=ERROR_NOERROR) { 
      cerr <<"Sanity failed: error "<<rc<<endl;
    } else {
      cerr <<"Sanity check succeded\n";
    }
    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 %r14
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
cmpl $0x3, %edi
jne 0x2689
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %rdi
callq 0x2300
movl %eax, %ebx
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rdx
movq %r14, %rsi
callq 0x2950
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0xc8(%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 0x2a24
leaq 0x20(%rsp), %rdi
callq 0x20b0
leaq 0x20(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
movl %ebx, %edx
callq 0x3fe8
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rcx
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
callq 0x4a94
leaq 0x20(%rsp), %rdi
callq 0x40ca
movl %eax, %ebx
testl %eax, %eax
je 0x2696
movq 0xa978(%rip), %rdi      # 0xcff0
leaq 0x59ab(%rip), %rsi      # 0x802a
callq 0x21b0
jmp 0x277d
callq 0x25ac
pushq $-0x1
popq %rbx
jmp 0x27b6
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4d0a
movl %eax, %ebx
testl %eax, %eax
je 0x26c5
movq 0xa93c(%rip), %rdi      # 0xcff0
leaq 0x5996(%rip), %rsi      # 0x8051
callq 0x21b0
jmp 0x277d
movq 0xa924(%rip), %rdi      # 0xcff0
leaq 0x59a3(%rip), %rsi      # 0x8076
callq 0x21b0
movq %rax, %rdi
callq 0x20c0
leaq 0x80(%rsp), %rdi
callq 0x67ea
movl %eax, %ebx
testl %eax, %eax
je 0x271a
movq 0xa8f6(%rip), %rdi      # 0xcff0
leaq 0x5985(%rip), %rsi      # 0x8086
callq 0x21b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
jmp 0x272d
movq 0xa8cf(%rip), %rdi      # 0xcff0
leaq 0x5974(%rip), %rsi      # 0x809c
callq 0x21b0
leaq 0x80(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x4f1a
movl %eax, %ebx
testl %eax, %eax
je 0x275a
movq 0xa8a4(%rip), %rdi      # 0xcff0
leaq 0x5960(%rip), %rsi      # 0x80b3
callq 0x21b0
jmp 0x277d
leaq 0x20(%rsp), %rdi
callq 0x4048
movl %eax, %ebx
testl %eax, %eax
je 0x27c3
movq 0xa87f(%rip), %rdi      # 0xcff0
leaq 0x5961(%rip), %rsi      # 0x80d9
callq 0x21b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
leaq 0x80(%rsp), %rdi
callq 0x4b70
leaq 0x20(%rsp), %rdi
callq 0x4014
leaq 0xc8(%rsp), %rdi
callq 0x2e32
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
retq
movq 0xa826(%rip), %rdi      # 0xcff0
leaq 0x592e(%rip), %rsi      # 0x80ff
callq 0x21b0
movq 0xa813(%rip), %rdi      # 0xcff0
leaq 0x5934(%rip), %rsi      # 0x8118
callq 0x21b0
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa7ec(%rip), %rdi      # 0xcff0
leaq 0x5920(%rip), %rsi      # 0x812b
callq 0x21b0
movl 0x6c(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa7c5(%rip), %rdi      # 0xcff0
leaq 0x590c(%rip), %rsi      # 0x813e
callq 0x21b0
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa79e(%rip), %rdi      # 0xcff0
leaq 0x58f8(%rip), %rsi      # 0x8151
callq 0x21b0
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa777(%rip), %rdi      # 0xcff0
leaq 0x58e4(%rip), %rsi      # 0x8164
callq 0x21b0
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa750(%rip), %rdi      # 0xcff0
leaq 0x58d0(%rip), %rsi      # 0x8177
callq 0x21b0
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa729(%rip), %rdi      # 0xcff0
callq 0x20c0
movq 0xa71d(%rip), %rdi      # 0xcff0
leaq 0x58b0(%rip), %rsi      # 0x818a
callq 0x21b0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x40ec
movq %rbx, %rdi
callq 0x2320
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x2792
movq %rax, %rbx
jmp 0x2931
movq %rax, %rbx
jmp 0x293b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20b0
jmp 0x2948
movq %rax, %rbx
jmp 0x2948
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x4b70
leaq 0x20(%rsp), %rdi
callq 0x4014
leaq 0xc8(%rsp), %rdi
callq 0x2e32
movq %rbx, %rdi
callq 0x2380