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

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

  filestem=argv[1];
  cachesize=atoi(argv[2]);
  keysize=atoi(argv[3]);
  valuesize=atoi(argv[4]);

  DiskSystem disk(filestem);
  BufferCache cache(&disk,cachesize);
  BTreeIndex btree(keysize,valuesize,&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,true))!=ERROR_NOERROR) { 
    cerr << "Can't attach to index with creation due to error "<<rc<<endl;
    return -1;
  } else {
    cerr << "Index created!"<<endl;
    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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x150, %rsp            # imm = 0x150
cmpl $0x5, %edi
jne 0x26a9
movq %rsi, %r15
movq 0x8(%rsi), %r12
movq 0x10(%rsi), %rdi
callq 0x2300
movl %eax, %r14d
movq 0x18(%r15), %rdi
callq 0x2300
movl %eax, %ebx
movq 0x20(%r15), %rdi
callq 0x2300
movl %eax, %ebp
leaq 0x28(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq %r12, %rsi
callq 0x292c
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0xd0(%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
callq 0x2a00
leaq 0x28(%rsp), %rdi
callq 0x20b0
leaq 0x28(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movl %r14d, %edx
callq 0x3fc4
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rcx
pushq $0x1
popq %r8
movl %ebx, %esi
movl %ebp, %edx
callq 0x4a70
leaq 0x28(%rsp), %rdi
callq 0x40a6
movl %eax, %ebx
testl %eax, %eax
je 0x26b6
movq 0xa958(%rip), %rdi      # 0xcff0
leaq 0x599d(%rip), %rsi      # 0x803c
callq 0x21b0
jmp 0x274e
callq 0x25ac
pushq $-0x1
popq %rbx
jmp 0x2787
leaq 0x88(%rsp), %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x4ce6
movl %eax, %ebx
testl %eax, %eax
je 0x26e3
movq 0xa91b(%rip), %rdi      # 0xcff0
leaq 0x5987(%rip), %rsi      # 0x8063
callq 0x21b0
jmp 0x274e
movq 0xa906(%rip), %rdi      # 0xcff0
leaq 0x59a4(%rip), %rsi      # 0x8095
callq 0x21b0
movq %rax, %rdi
callq 0x20c0
leaq 0x88(%rsp), %rdi
leaq 0x24(%rsp), %rsi
callq 0x4ef6
movl %eax, %ebx
testl %eax, %eax
je 0x272b
movq 0xa8d3(%rip), %rdi      # 0xcff0
leaq 0x5980(%rip), %rsi      # 0x80a4
callq 0x21b0
jmp 0x274e
leaq 0x28(%rsp), %rdi
callq 0x4024
movl %eax, %ebx
testl %eax, %eax
je 0x2799
movq 0xa8ae(%rip), %rdi      # 0xcff0
leaq 0x5981(%rip), %rsi      # 0x80ca
callq 0x21b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
leaq 0x88(%rsp), %rdi
callq 0x4b4c
leaq 0x28(%rsp), %rdi
callq 0x3ff0
leaq 0xd0(%rsp), %rdi
callq 0x2e0e
movl %ebx, %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xa850(%rip), %rdi      # 0xcff0
leaq 0x5949(%rip), %rsi      # 0x80f0
callq 0x21b0
movq 0xa83d(%rip), %rdi      # 0xcff0
leaq 0x594f(%rip), %rsi      # 0x8109
callq 0x21b0
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa816(%rip), %rdi      # 0xcff0
leaq 0x593b(%rip), %rsi      # 0x811c
callq 0x21b0
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa7ef(%rip), %rdi      # 0xcff0
leaq 0x5927(%rip), %rsi      # 0x812f
callq 0x21b0
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa7c8(%rip), %rdi      # 0xcff0
leaq 0x5913(%rip), %rsi      # 0x8142
callq 0x21b0
movl 0x80(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa79e(%rip), %rdi      # 0xcff0
leaq 0x58fc(%rip), %rsi      # 0x8155
callq 0x21b0
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa777(%rip), %rdi      # 0xcff0
leaq 0x58e8(%rip), %rsi      # 0x8168
callq 0x21b0
movl 0x84(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa74d(%rip), %rdi      # 0xcff0
callq 0x20c0
movq 0xa741(%rip), %rdi      # 0xcff0
leaq 0x58c5(%rip), %rsi      # 0x817b
callq 0x21b0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x40c8
movq %rbx, %rdi
callq 0x2320
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x2763
movq %rax, %rbx
jmp 0x290d
movq %rax, %rbx
jmp 0x2917
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20b0
jmp 0x2924
movq %rax, %rbx
jmp 0x2924
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4b4c
leaq 0x28(%rsp), %rdi
callq 0x3ff0
leaq 0xd0(%rsp), %rdi
callq 0x2e0e
movq %rbx, %rdi
callq 0x2380