// File: /workspace/github_cpp_makefile_star2_O1/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 $0x180, %rsp            # imm = 0x180
cmpl $0x4, %edi
jne 0x26ef
movq %rsi, %rbx
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %rdi
callq 0x22f0
movl %eax, %ebp
movq 0x18(%rbx), %rbx
leaq 0x8(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
movq %r14, %rsi
callq 0x2b84
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x108(%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 0x303c
addq $0x20, %rsp
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2670
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21e0
leaq 0x8(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movl %ebp, %edx
callq 0x4a30
leaq 0xb8(%rsp), %rdi
leaq 0x8(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
movl $0x1, %r8d
callq 0x550c
leaq 0x8(%rsp), %rdi
callq 0x4b28
movl %eax, %ebp
testl %eax, %eax
je 0x2711
movq 0xb939(%rip), %rdi      # 0xdff0
leaq 0x6972(%rip), %rsi      # 0x9030
movl $0x26, %edx
callq 0x2230
movq 0xb921(%rip), %rdi      # 0xdff0
movl %ebp, %esi
callq 0x2360
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
jmp 0x2769
movq 0xb8fa(%rip), %rdi      # 0xdff0
leaq 0x6907(%rip), %rsi      # 0x9004
movl $0x2b, %edx
callq 0x2230
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x27a5
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x579a
movl %eax, %ebp
testl %eax, %eax
je 0x27b3
movq 0xb8bd(%rip), %rdi      # 0xdff0
leaq 0x691d(%rip), %rsi      # 0x9057
movl $0x24, %edx
callq 0x2230
movq 0xb8a5(%rip), %rdi      # 0xdff0
movl %ebp, %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 0xb8(%rsp), %rdi
callq 0x55e8
leaq 0x8(%rsp), %rdi
callq 0x4a60
leaq 0x100(%rsp), %rdi
callq 0x35dc
movl %ebx, %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r14
popq %rbp
retq
movq 0xb836(%rip), %r14      # 0xdff0
leaq 0x68bb(%rip), %rsi      # 0x907c
movl $0xf, %edx
movq %r14, %rdi
callq 0x2230
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq 0xb804(%rip), %rdi      # 0xdff0
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x68(%rsp), %rdi
callq 0x2c54
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0x2d96
leaq 0xb8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x5bcc
movl %eax, %ebx
leaq 0x90(%rsp), %rdi
callq 0x2e22
testl %ebx, %ebx
je 0x2892
movq 0xb7a9(%rip), %rdi      # 0xdff0
leaq 0x683e(%rip), %rsi      # 0x908c
movl $0x15, %edx
callq 0x2230
movq 0xb791(%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 0x28bb
movq 0xb757(%rip), %rdi      # 0xdff0
leaq 0x6802(%rip), %rsi      # 0x90a2
movl $0x11, %edx
callq 0x2230
movq 0xb71f(%rip), %rsi      # 0xdfd0
leaq 0x68(%rsp), %rdi
callq 0x2f06
leaq 0xb8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x59b6
movl %eax, %ebx
testl %eax, %eax
je 0x292d
movq 0xb716(%rip), %rdi      # 0xdff0
leaq 0x67d3(%rip), %rsi      # 0x90b4
movl $0x25, %edx
callq 0x2230
movq 0xb6fe(%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
jmp 0x2af1
leaq 0x8(%rsp), %rdi
callq 0x4a98
movl %eax, %ebx
testl %eax, %eax
je 0x2975
movq 0xb6ac(%rip), %rdi      # 0xdff0
leaq 0x678f(%rip), %rsi      # 0x90da
movl $0x25, %edx
callq 0x2230
movq 0xb694(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20c0
jmp 0x2af1
movq 0xb674(%rip), %rdi      # 0xdff0
leaq 0x677d(%rip), %rsi      # 0x9100
movl $0x18, %edx
callq 0x2230
movq 0xb65c(%rip), %rdi      # 0xdff0
leaq 0x677e(%rip), %rsi      # 0x9119
movl $0x12, %edx
callq 0x2230
movl 0x50(%rsp), %esi
movq 0xb640(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb62c(%rip), %rdi      # 0xdff0
leaq 0x6761(%rip), %rsi      # 0x912c
movl $0x12, %edx
callq 0x2230
movl 0x54(%rsp), %esi
movq 0xb610(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb5fc(%rip), %rdi      # 0xdff0
leaq 0x6744(%rip), %rsi      # 0x913f
movl $0x12, %edx
callq 0x2230
movl 0x58(%rsp), %esi
movq 0xb5e0(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb5cc(%rip), %rdi      # 0xdff0
leaq 0x6727(%rip), %rsi      # 0x9152
movl $0x12, %edx
callq 0x2230
movl 0x60(%rsp), %esi
movq 0xb5b0(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb59c(%rip), %rdi      # 0xdff0
leaq 0x670a(%rip), %rsi      # 0x9165
movl $0x12, %edx
callq 0x2230
movl 0x5c(%rsp), %esi
movq 0xb580(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb56c(%rip), %rdi      # 0xdff0
leaq 0x66ed(%rip), %rsi      # 0x9178
movl $0x12, %edx
callq 0x2230
movl 0x64(%rsp), %esi
movq 0xb550(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb53c(%rip), %rdi      # 0xdff0
callq 0x20c0
movq 0xb530(%rip), %rdi      # 0xdff0
leaq 0x66c4(%rip), %rsi      # 0x918b
movl $0x12, %edx
callq 0x2230
leaq 0x8(%rsp), %rdi
callq 0x4b4a
movq 0xb50e(%rip), %rdi      # 0xdff0
callq 0x2310
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
leaq 0x68(%rsp), %rdi
callq 0x2e22
jmp 0x2781
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x2e22
jmp 0x2b48
jmp 0x2b45
jmp 0x2b54
movq %rax, %rbx
jmp 0x2b64
movq %rax, %rbx
jmp 0x2b6e
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b7b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x2b7b
movq %rax, %rbx
jmp 0x2b7b
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x2e22
jmp 0x2b57
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x55e8
leaq 0x8(%rsp), %rdi
callq 0x4a60
leaq 0x100(%rsp), %rdi
callq 0x35dc
movq %rbx, %rdi
callq 0x2370
nop