// File: /workspace/github_cpp_makefile_star2_O1/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 $0x138, %rsp            # imm = 0x138
cmpl $0x3, %edi
jne 0x26e4
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %rdi
callq 0x22f0
movl %eax, %ebx
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0x2ada
subq $0x8, %rsp
xorl %eax, %eax
leaq 0xc0(%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 0x2ba8
addq $0x20, %rsp
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2665
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21e0
leaq 0x10(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
movl %ebx, %edx
callq 0x459c
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
movl $0x1, %r8d
callq 0x5078
leaq 0x10(%rsp), %rdi
callq 0x4694
movl %eax, %ebx
testl %eax, %eax
je 0x2706
movq 0xb947(%rip), %rdi      # 0xdff0
leaq 0x697a(%rip), %rsi      # 0x902a
movl $0x26, %edx
callq 0x2230
movq 0xb92f(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
jmp 0x2872
movq 0xb905(%rip), %rdi      # 0xdff0
leaq 0x6912(%rip), %rsi      # 0x9004
movl $0x25, %edx
callq 0x2230
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x28ab
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5306
movl %eax, %ebx
testl %eax, %eax
je 0x275c
movq 0xb8cf(%rip), %rdi      # 0xdff0
leaq 0x6929(%rip), %rsi      # 0x9051
movl $0x24, %edx
callq 0x2230
movq 0xb8b7(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
jmp 0x2872
movq 0xb88d(%rip), %rbx      # 0xdff0
leaq 0x690c(%rip), %rsi      # 0x9076
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq 0xb85b(%rip), %rdi      # 0xdff0
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x70(%rsp), %rdi
callq 0x710e
movl %eax, %ebx
testl %eax, %eax
je 0x2804
movq 0xb837(%rip), %rdi      # 0xdff0
leaq 0x68c6(%rip), %rsi      # 0x9086
movl $0x15, %edx
callq 0x2230
movq 0xb81f(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
jmp 0x281c
movq 0xb7e5(%rip), %rdi      # 0xdff0
leaq 0x688a(%rip), %rsi      # 0x909c
movl $0x16, %edx
callq 0x2230
leaq 0x70(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x5522
movl %eax, %ebx
testl %eax, %eax
je 0x28b8
movq 0xb7b4(%rip), %rdi      # 0xdff0
leaq 0x6870(%rip), %rsi      # 0x90b3
movl $0x25, %edx
callq 0x2230
movq 0xb79c(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2130
leaq 0x70(%rsp), %rdi
callq 0x5154
leaq 0x10(%rsp), %rdi
callq 0x45cc
leaq 0xb8(%rsp), %rdi
callq 0x3148
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r14
retq
leaq 0x10(%rsp), %rdi
callq 0x4604
movl %eax, %ebx
testl %eax, %eax
je 0x28fd
movq 0xb721(%rip), %rdi      # 0xdff0
leaq 0x6803(%rip), %rsi      # 0x90d9
movl $0x25, %edx
callq 0x2230
movq 0xb709(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20c0
jmp 0x288a
movq 0xb6ec(%rip), %rdi      # 0xdff0
leaq 0x67f4(%rip), %rsi      # 0x90ff
movl $0x18, %edx
callq 0x2230
movq 0xb6d4(%rip), %rdi      # 0xdff0
leaq 0x67f5(%rip), %rsi      # 0x9118
movl $0x12, %edx
callq 0x2230
movl 0x58(%rsp), %esi
movq 0xb6b8(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb6a4(%rip), %rdi      # 0xdff0
leaq 0x67d8(%rip), %rsi      # 0x912b
movl $0x12, %edx
callq 0x2230
movl 0x5c(%rsp), %esi
movq 0xb688(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb674(%rip), %rdi      # 0xdff0
leaq 0x67bb(%rip), %rsi      # 0x913e
movl $0x12, %edx
callq 0x2230
movl 0x60(%rsp), %esi
movq 0xb658(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb644(%rip), %rdi      # 0xdff0
leaq 0x679e(%rip), %rsi      # 0x9151
movl $0x12, %edx
callq 0x2230
movl 0x68(%rsp), %esi
movq 0xb628(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb614(%rip), %rdi      # 0xdff0
leaq 0x6781(%rip), %rsi      # 0x9164
movl $0x12, %edx
callq 0x2230
movl 0x64(%rsp), %esi
movq 0xb5f8(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb5e4(%rip), %rdi      # 0xdff0
leaq 0x6764(%rip), %rsi      # 0x9177
movl $0x12, %edx
callq 0x2230
movl 0x6c(%rsp), %esi
movq 0xb5c8(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb5b4(%rip), %rdi      # 0xdff0
callq 0x20c0
movq 0xb5a8(%rip), %rdi      # 0xdff0
leaq 0x673b(%rip), %rsi      # 0x918a
movl $0x12, %edx
callq 0x2230
leaq 0x10(%rsp), %rdi
callq 0x46b6
movq 0xb586(%rip), %rdi      # 0xdff0
callq 0x2310
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x288a
movq %rax, %rbx
jmp 0x2aba
movq %rax, %rbx
jmp 0x2ac4
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ad1
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x2ad1
movq %rax, %rbx
jmp 0x2ad1
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5154
leaq 0x10(%rsp), %rdi
callq 0x45cc
leaq 0xb8(%rsp), %rdi
callq 0x3148
movq %rbx, %rdi
callq 0x2370
nop