// File: /workspace/github_cpp_makefile_star2_O2/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 $0x198, %rsp            # imm = 0x198
cmpl $0x5, %edi
jne 0x2697
movq %rsi, %rbx
movq 0x8(%rsi), %r15
movq 0x10(%rsi), %rdi
callq 0x2300
movl %eax, %ebp
movq 0x18(%rbx), %r14
movq 0x20(%rbx), %rbx
leaq 0x20(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq %r15, %rsi
callq 0x29d2
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2dec
leaq 0x20(%rsp), %rdi
callq 0x20b0
leaq 0x20(%rsp), %rdi
leaq 0x118(%rsp), %rsi
movl %ebp, %edx
callq 0x43b0
leaq 0xd0(%rsp), %rdi
leaq 0x20(%rsp), %rcx
pushq $0x1
popq %r8
xorl %esi, %esi
xorl %edx, %edx
callq 0x4e5c
leaq 0x20(%rsp), %rdi
callq 0x4492
movl %eax, %ebp
testl %eax, %eax
je 0x26a4
movq 0xa96a(%rip), %rdi      # 0xcff0
leaq 0x59a9(%rip), %rsi      # 0x8036
callq 0x21b0
jmp 0x27d5
callq 0x25ac
pushq $-0x1
popq %rbx
jmp 0x280e
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x50d2
movl %eax, %ebp
testl %eax, %eax
je 0x26d3
movq 0xa92e(%rip), %rdi      # 0xcff0
leaq 0x5994(%rip), %rsi      # 0x805d
callq 0x21b0
jmp 0x27d5
movq 0xa916(%rip), %rdi      # 0xcff0
leaq 0x59a1(%rip), %rsi      # 0x8082
callq 0x21b0
movq %rax, %rdi
callq 0x20c0
leaq 0xa8(%rsp), %rdi
movq %r14, %rsi
callq 0x2bcc
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x2bcc
leaq 0xd0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0x65e8
movl %eax, %ebx
leaq 0x80(%rsp), %rdi
callq 0x2c4e
leaq 0xa8(%rsp), %rdi
callq 0x2c4e
testl %ebx, %ebx
je 0x2772
movq 0xa89e(%rip), %rdi      # 0xcff0
leaq 0x5939(%rip), %rsi      # 0x8092
callq 0x21b0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
jmp 0x2785
movq 0xa877(%rip), %rdi      # 0xcff0
leaq 0x5933(%rip), %rsi      # 0x80b3
callq 0x21b0
leaq 0xd0(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x52e2
movl %eax, %ebp
testl %eax, %eax
je 0x27b2
movq 0xa84c(%rip), %rdi      # 0xcff0
leaq 0x591a(%rip), %rsi      # 0x80c5
callq 0x21b0
jmp 0x27d5
leaq 0x20(%rsp), %rdi
callq 0x4410
movl %eax, %ebp
testl %eax, %eax
je 0x281e
movq 0xa827(%rip), %rdi      # 0xcff0
leaq 0x591b(%rip), %rsi      # 0x80eb
callq 0x21b0
movq %rax, %rdi
movl %ebp, %esi
callq 0x2370
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
leaq 0xd0(%rsp), %rdi
callq 0x4f38
leaq 0x20(%rsp), %rdi
callq 0x43dc
leaq 0x118(%rsp), %rdi
callq 0x31fa
movl %ebx, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xa7cb(%rip), %rdi      # 0xcff0
leaq 0x58e5(%rip), %rsi      # 0x8111
callq 0x21b0
movq 0xa7b8(%rip), %rdi      # 0xcff0
leaq 0x58eb(%rip), %rsi      # 0x812a
callq 0x21b0
movl 0x68(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa791(%rip), %rdi      # 0xcff0
leaq 0x58d7(%rip), %rsi      # 0x813d
callq 0x21b0
movl 0x6c(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa76a(%rip), %rdi      # 0xcff0
leaq 0x58c3(%rip), %rsi      # 0x8150
callq 0x21b0
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa743(%rip), %rdi      # 0xcff0
leaq 0x58af(%rip), %rsi      # 0x8163
callq 0x21b0
movl 0x78(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa71c(%rip), %rdi      # 0xcff0
leaq 0x589b(%rip), %rsi      # 0x8176
callq 0x21b0
movl 0x74(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa6f5(%rip), %rdi      # 0xcff0
leaq 0x5887(%rip), %rsi      # 0x8189
callq 0x21b0
movl 0x7c(%rsp), %esi
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20c0
movq 0xa6ce(%rip), %rdi      # 0xcff0
callq 0x20c0
movq 0xa6c2(%rip), %rdi      # 0xcff0
leaq 0x5867(%rip), %rsi      # 0x819c
callq 0x21b0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x44b4
movq %rbx, %rdi
callq 0x2320
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20c0
jmp 0x27ea
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2c4e
jmp 0x2973
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x2c4e
jmp 0x29a5
jmp 0x29a2
movq %rax, %rbx
jmp 0x29b2
movq %rax, %rbx
jmp 0x29bc
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20b0
jmp 0x29c9
movq %rax, %rbx
jmp 0x29c9
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x4f38
leaq 0x20(%rsp), %rdi
callq 0x43dc
leaq 0x118(%rsp), %rdi
callq 0x31fa
movq %rbx, %rdi
callq 0x2380
nop