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

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

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

  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;
    if ((rc=btree.Update(KEY_T(key),VALUE_T(value)))!=ERROR_NOERROR) { 
      cerr <<"Can't update index due to error "<<rc<<endl;
    } else {
      cerr <<"Update succeeded\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 %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
cmpl $0x5, %edi
jne 0x26f8
movq %rsi, %rbx
movq 0x8(%rsi), %r15
movq 0x10(%rsi), %rdi
callq 0x22f0
movl %eax, %ebp
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %rbx
leaq 0x10(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
movq %r15, %rsi
callq 0x2b64
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x110(%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 0x3000
addq $0x20, %rsp
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2676
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21e0
leaq 0x10(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movl %ebp, %edx
callq 0x4a2c
leaq 0xc0(%rsp), %rdi
leaq 0x10(%rsp), %rcx
xorl %esi, %esi
xorl %edx, %edx
movl $0x1, %r8d
callq 0x54c8
leaq 0x10(%rsp), %rdi
callq 0x4b0a
movl %eax, %ebp
testl %eax, %eax
je 0x271a
movq 0xb933(%rip), %rdi      # 0xdff0
leaq 0x6972(%rip), %rsi      # 0x9036
movl $0x26, %edx
callq 0x2230
movq 0xb91b(%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 0x28d0
movq 0xb8f1(%rip), %rdi      # 0xdff0
leaq 0x68fe(%rip), %rsi      # 0x9004
movl $0x31, %edx
callq 0x2230
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x290c
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5756
movl %eax, %ebp
testl %eax, %eax
je 0x2773
movq 0xb8b8(%rip), %rdi      # 0xdff0
leaq 0x691e(%rip), %rsi      # 0x905d
movl $0x24, %edx
callq 0x2230
movq 0xb8a0(%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 0x28d0
movq 0xb876(%rip), %r15      # 0xdff0
leaq 0x6901(%rip), %rsi      # 0x9082
movl $0xf, %edx
movq %r15, %rdi
callq 0x2230
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq 0xb844(%rip), %rdi      # 0xdff0
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0x2d7a
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x2d7a
leaq 0xc0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x6dca
movl %eax, %ebx
leaq 0x70(%rsp), %rdi
callq 0x2e06
leaq 0x98(%rsp), %rdi
callq 0x2e06
testl %ebx, %ebx
je 0x285f
movq 0xb7dc(%rip), %rdi      # 0xdff0
leaq 0x6877(%rip), %rsi      # 0x9092
movl $0x20, %edx
callq 0x2230
movq 0xb7c4(%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 0x2877
movq 0xb78a(%rip), %rdi      # 0xdff0
leaq 0x6846(%rip), %rsi      # 0x90b3
movl $0x11, %edx
callq 0x2230
leaq 0xc0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x5978
movl %eax, %ebx
testl %eax, %eax
je 0x291c
movq 0xb756(%rip), %rdi      # 0xdff0
leaq 0x6824(%rip), %rsi      # 0x90c5
movl $0x25, %edx
callq 0x2230
movq 0xb73e(%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 0xc0(%rsp), %rdi
callq 0x55a4
leaq 0x10(%rsp), %rdi
callq 0x4a5c
leaq 0x108(%rsp), %rdi
callq 0x35a0
movl %ebx, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdi
callq 0x4a94
movl %eax, %ebx
testl %eax, %eax
je 0x2961
movq 0xb6bd(%rip), %rdi      # 0xdff0
leaq 0x67b1(%rip), %rsi      # 0x90eb
movl $0x25, %edx
callq 0x2230
movq 0xb6a5(%rip), %rdi      # 0xdff0
movl %ebx, %esi
callq 0x2360
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20c0
jmp 0x28e8
movq 0xb688(%rip), %rdi      # 0xdff0
leaq 0x67a2(%rip), %rsi      # 0x9111
movl $0x18, %edx
callq 0x2230
movq 0xb670(%rip), %rdi      # 0xdff0
leaq 0x67a3(%rip), %rsi      # 0x912a
movl $0x12, %edx
callq 0x2230
movl 0x58(%rsp), %esi
movq 0xb654(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb640(%rip), %rdi      # 0xdff0
leaq 0x6786(%rip), %rsi      # 0x913d
movl $0x12, %edx
callq 0x2230
movl 0x5c(%rsp), %esi
movq 0xb624(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb610(%rip), %rdi      # 0xdff0
leaq 0x6769(%rip), %rsi      # 0x9150
movl $0x12, %edx
callq 0x2230
movl 0x60(%rsp), %esi
movq 0xb5f4(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb5e0(%rip), %rdi      # 0xdff0
leaq 0x674c(%rip), %rsi      # 0x9163
movl $0x12, %edx
callq 0x2230
movl 0x68(%rsp), %esi
movq 0xb5c4(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb5b0(%rip), %rdi      # 0xdff0
leaq 0x672f(%rip), %rsi      # 0x9176
movl $0x12, %edx
callq 0x2230
movl 0x64(%rsp), %esi
movq 0xb594(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb580(%rip), %rdi      # 0xdff0
leaq 0x6712(%rip), %rsi      # 0x9189
movl $0x12, %edx
callq 0x2230
movl 0x6c(%rsp), %esi
movq 0xb564(%rip), %rdi      # 0xdff0
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xb550(%rip), %rdi      # 0xdff0
callq 0x20c0
movq 0xb544(%rip), %rdi      # 0xdff0
leaq 0x66e9(%rip), %rsi      # 0x919c
movl $0x12, %edx
callq 0x2230
leaq 0x10(%rsp), %rdi
callq 0x4b2c
movq 0xb522(%rip), %rdi      # 0xdff0
callq 0x2310
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x28e8
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2e06
jmp 0x2af4
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2e06
jmp 0x2b37
jmp 0x2b34
movq %rax, %rbx
jmp 0x2b44
movq %rax, %rbx
jmp 0x2b4e
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2b5b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x2b5b
movq %rax, %rbx
jmp 0x2b5b
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x55a4
leaq 0x10(%rsp), %rdi
callq 0x4a5c
leaq 0x108(%rsp), %rdi
callq 0x35a0
movq %rbx, %rdi
callq 0x2370
nop