// File: /workspace/github_cpp_makefile_star2_O1/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 $0x130, %rsp            # imm = 0x130
cmpl $0x5, %edi
jne 0x2704
movq %rsi, %r15
movq 0x8(%rsi), %r12
movq 0x10(%rsi), %rdi
callq 0x22f0
movl %eax, %r14d
movq 0x18(%r15), %rdi
callq 0x22f0
movl %eax, %ebx
movq 0x20(%r15), %rdi
callq 0x22f0
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
movq %r12, %rsi
callq 0x2a88
subq $0x8, %rsp
xorl %eax, %eax
leaq 0xb8(%rsp), %rdi
leaq 0x10(%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 0x2b58
addq $0x20, %rsp
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2684
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21e0
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl %r14d, %edx
callq 0x454c
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rcx
movl %ebx, %esi
movl %ebp, %edx
movl $0x1, %r8d
callq 0x5028
leaq 0x8(%rsp), %rdi
callq 0x4644
movl %eax, %ebx
testl %eax, %eax
je 0x2726
movq 0xb927(%rip), %rdi      # 0xdff0
leaq 0x696c(%rip), %rsi      # 0x903c
movl $0x26, %edx
callq 0x2230
movq 0xb90f(%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 0x281b
movq 0xb8e5(%rip), %rdi      # 0xdff0
leaq 0x68f2(%rip), %rsi      # 0x9004
movl $0x37, %edx
callq 0x2230
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x2854
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x52b6
movl %eax, %ebx
testl %eax, %eax
je 0x277f
movq 0xb8ac(%rip), %rdi      # 0xdff0
leaq 0x6918(%rip), %rsi      # 0x9063
movl $0x31, %edx
callq 0x2230
movq 0xb894(%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 0x281b
movq 0xb86a(%rip), %rbx      # 0xdff0
leaq 0x6908(%rip), %rsi      # 0x9095
movl $0xe, %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 0xb838(%rip), %rdi      # 0xdff0
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x68(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x54d2
movl %eax, %ebx
testl %eax, %eax
je 0x2866
movq 0xb80b(%rip), %rdi      # 0xdff0
leaq 0x68b8(%rip), %rsi      # 0x90a4
movl $0x25, %edx
callq 0x2230
movq 0xb7f3(%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 0x68(%rsp), %rdi
callq 0x5104
leaq 0x8(%rsp), %rdi
callq 0x457c
leaq 0xb0(%rsp), %rdi
callq 0x30f8
movl %ebx, %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rdi
callq 0x45b4
movl %eax, %ebx
testl %eax, %eax
je 0x28ab
movq 0xb773(%rip), %rdi      # 0xdff0
leaq 0x6846(%rip), %rsi      # 0x90ca
movl $0x25, %edx
callq 0x2230
movq 0xb75b(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20c0
jmp 0x2833
movq 0xb73e(%rip), %rdi      # 0xdff0
leaq 0x6837(%rip), %rsi      # 0x90f0
movl $0x18, %edx
callq 0x2230
movq 0xb726(%rip), %rdi      # 0xdff0
leaq 0x6838(%rip), %rsi      # 0x9109
movl $0x12, %edx
callq 0x2230
movl 0x50(%rsp), %esi
movq 0xb70a(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb6f6(%rip), %rdi      # 0xdff0
leaq 0x681b(%rip), %rsi      # 0x911c
movl $0x12, %edx
callq 0x2230
movl 0x54(%rsp), %esi
movq 0xb6da(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb6c6(%rip), %rdi      # 0xdff0
leaq 0x67fe(%rip), %rsi      # 0x912f
movl $0x12, %edx
callq 0x2230
movl 0x58(%rsp), %esi
movq 0xb6aa(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb696(%rip), %rdi      # 0xdff0
leaq 0x67e1(%rip), %rsi      # 0x9142
movl $0x12, %edx
callq 0x2230
movl 0x60(%rsp), %esi
movq 0xb67a(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb666(%rip), %rdi      # 0xdff0
leaq 0x67c4(%rip), %rsi      # 0x9155
movl $0x12, %edx
callq 0x2230
movl 0x5c(%rsp), %esi
movq 0xb64a(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb636(%rip), %rdi      # 0xdff0
leaq 0x67a7(%rip), %rsi      # 0x9168
movl $0x12, %edx
callq 0x2230
movl 0x64(%rsp), %esi
movq 0xb61a(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb606(%rip), %rdi      # 0xdff0
callq 0x20c0
movq 0xb5fa(%rip), %rdi      # 0xdff0
leaq 0x677e(%rip), %rsi      # 0x917b
movl $0x12, %edx
callq 0x2230
leaq 0x8(%rsp), %rdi
callq 0x4666
movq 0xb5d8(%rip), %rdi      # 0xdff0
callq 0x2310
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x2833
movq %rax, %rbx
jmp 0x2a68
movq %rax, %rbx
jmp 0x2a72
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a7f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x2a7f
movq %rax, %rbx
jmp 0x2a7f
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5104
leaq 0x8(%rsp), %rdi
callq 0x457c
leaq 0xb0(%rsp), %rdi
callq 0x30f8
movq %rbx, %rdi
callq 0x2370
nop