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

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

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

  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;
    VALUE_T val;
    if ((rc=btree.Lookup(KEY_T(key),val))!=ERROR_NOERROR) { 
      cerr <<"Lookup failed: error "<<rc<<endl;
    } else {
      cerr <<"Lookup succeeded\n";
      cout << val;
    }
    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 %r14
pushq %rbx
subq $0x1a0, %rsp            # imm = 0x1A0
cmpl $0x4, %edi
jne 0x268e
movq %rsi, %rbx
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %rdi
callq 0x2300
movl %eax, %ebp
movq 0x18(%rbx), %rbx
leaq 0x28(%rsp), %rdi
leaq 0xd8(%rsp), %rdx
movq %r14, %rsi
callq 0x29f2
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x120(%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 0x2e0c
leaq 0x28(%rsp), %rdi
callq 0x20b0
leaq 0x28(%rsp), %rdi
leaq 0x120(%rsp), %rsi
movl %ebp, %edx
callq 0x43d0
leaq 0xd8(%rsp), %rdi
leaq 0x28(%rsp), %rcx
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
callq 0x4e7c
leaq 0x28(%rsp), %rdi
callq 0x44b2
movl %eax, %ebp
testl %eax, %eax
je 0x2698
movq 0xa970(%rip), %rdi      # 0xcff0
leaq 0x59a9(%rip), %rsi      # 0x8030
callq 0x21b0
jmp 0x26c2
callq 0x25ac
pushq $-0x1
popq %rbx
jmp 0x26fb
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x50f2
movl %eax, %ebp
testl %eax, %eax
je 0x2709
movq 0xa93a(%rip), %rdi      # 0xcff0
leaq 0x599a(%rip), %rsi      # 0x8057
callq 0x21b0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
leaq 0xd8(%rsp), %rdi
callq 0x4f58
leaq 0x28(%rsp), %rdi
callq 0x43fc
leaq 0x120(%rsp), %rdi
callq 0x321a
movl %ebx, %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbx
popq %r14
popq %rbp
retq
movq 0xa8e0(%rip), %rdi      # 0xcff0
leaq 0x5965(%rip), %rsi      # 0x807c
callq 0x21b0
movq %rax, %rdi
callq 0x20c0
leaq 0x88(%rsp), %rdi
callq 0x2ac4
leaq 0xb0(%rsp), %rdi
movq %rbx, %rsi
callq 0x2bec
leaq 0xd8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x54fe
movl %eax, %ebx
leaq 0xb0(%rsp), %rdi
callq 0x2c6e
testl %ebx, %ebx
je 0x2798
movq 0xa878(%rip), %rdi      # 0xcff0
leaq 0x590d(%rip), %rsi      # 0x808c
callq 0x21b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
jmp 0x27bf
movq 0xa851(%rip), %rdi      # 0xcff0
leaq 0x58fc(%rip), %rsi      # 0x80a2
callq 0x21b0
movq 0xa81e(%rip), %rsi      # 0xcfd0
leaq 0x88(%rsp), %rdi
callq 0x2d16
leaq 0xd8(%rsp), %rdi
leaq 0x24(%rsp), %rsi
callq 0x5302
movl %eax, %ebx
testl %eax, %eax
je 0x27ec
movq 0xa812(%rip), %rdi      # 0xcff0
leaq 0x58cf(%rip), %rsi      # 0x80b4
callq 0x21b0
jmp 0x280f
leaq 0x28(%rsp), %rdi
callq 0x4430
movl %eax, %ebx
testl %eax, %eax
je 0x2836
movq 0xa7ed(%rip), %rdi      # 0xcff0
leaq 0x58d0(%rip), %rsi      # 0x80da
callq 0x21b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
leaq 0x88(%rsp), %rdi
callq 0x2c6e
jmp 0x26d7
movq 0xa7b3(%rip), %rdi      # 0xcff0
leaq 0x58bc(%rip), %rsi      # 0x8100
callq 0x21b0
movq 0xa7a0(%rip), %rdi      # 0xcff0
leaq 0x58c2(%rip), %rsi      # 0x8119
callq 0x21b0
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa779(%rip), %rdi      # 0xcff0
leaq 0x58ae(%rip), %rsi      # 0x812c
callq 0x21b0
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa752(%rip), %rdi      # 0xcff0
leaq 0x589a(%rip), %rsi      # 0x813f
callq 0x21b0
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa72b(%rip), %rdi      # 0xcff0
leaq 0x5886(%rip), %rsi      # 0x8152
callq 0x21b0
movl 0x80(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa701(%rip), %rdi      # 0xcff0
leaq 0x586f(%rip), %rsi      # 0x8165
callq 0x21b0
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa6da(%rip), %rdi      # 0xcff0
leaq 0x585b(%rip), %rsi      # 0x8178
callq 0x21b0
movl 0x84(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa6b0(%rip), %rdi      # 0xcff0
callq 0x20c0
movq 0xa6a4(%rip), %rdi      # 0xcff0
leaq 0x5838(%rip), %rsi      # 0x818b
callq 0x21b0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x44d4
movq %rbx, %rdi
callq 0x2320
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x2824
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2c6e
jmp 0x29b3
jmp 0x29b0
jmp 0x29c2
movq %rax, %rbx
jmp 0x29d2
movq %rax, %rbx
jmp 0x29dc
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20b0
jmp 0x29e9
movq %rax, %rbx
jmp 0x29e9
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2c6e
jmp 0x29c5
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x4f58
leaq 0x28(%rsp), %rdi
callq 0x43fc
leaq 0x120(%rsp), %rdi
callq 0x321a
movq %rbx, %rdi
callq 0x2380
nop