// File: cpottamus[P]btree_lab/btree_delete.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;
    if ((rc=btree.Delete(KEY_T(key)))!=ERROR_NOERROR) { 
      cerr <<"Can't delete from index due to error "<<rc<<endl;
    } else {
      cerr <<"Delete 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
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
je 0x3750
callq 0x3700
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3f26
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x33a0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x3410
movq -0x1c8(%rbp), %rsi
movq -0x1c0(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0x3f40
jmp 0x37b2
movq %rsp, %rax
movl $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
xorl %r9d, %r9d
xorps %xmm2, %xmm2
movl %r9d, %edx
movl %r9d, %ecx
movl %r9d, %r8d
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x49b0
jmp 0x37f3
leaq -0xc8(%rbp), %rdi
callq 0x3120
leaq -0xc9(%rbp), %rdi
callq 0x3270
movl -0x1c(%rbp), %edx
leaq -0x140(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7720
jmp 0x3823
leaq -0x188(%rbp), %rdi
xorl %edx, %edx
leaq -0x140(%rbp), %rcx
movl $0x1, %r8d
movl %edx, %esi
callq 0x9c20
jmp 0x3842
leaq -0x140(%rbp), %rdi
callq 0x78e0
movl %eax, -0x1cc(%rbp)
jmp 0x3856
movl -0x1cc(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3955
movq 0x1377e(%rip), %rdi     # 0x16ff0
leaq 0xc7b7(%rip), %rsi      # 0x10030
callq 0x31f0
movq %rax, -0x1d8(%rbp)
jmp 0x3887
movq -0x1d8(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x1e0(%rbp)
jmp 0x38a2
movq -0x1e0(%rbp), %rdi
movq 0x13710(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x38b7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3eda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x38ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3120
leaq -0xc9(%rbp), %rdi
callq 0x3270
jmp 0x3f32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x3f18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x3f0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x3f00
leaq -0x188(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x9ff0
movl %eax, -0x1e4(%rbp)
jmp 0x396d
movl -0x1e4(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x39e0
movq 0x1366b(%rip), %rdi     # 0x16ff0
leaq 0xc6cb(%rip), %rsi      # 0x10057
callq 0x31f0
movq %rax, -0x1f0(%rbp)
jmp 0x399a
movq -0x1f0(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x1f8(%rbp)
jmp 0x39b5
movq -0x1f8(%rbp), %rdi
movq 0x135fd(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x39ca
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3eda
movq 0x13609(%rip), %rdi     # 0x16ff0
leaq 0xc68e(%rip), %rsi      # 0x1007c
callq 0x31f0
movq %rax, -0x200(%rbp)
jmp 0x39fc
movq -0x200(%rbp), %rdi
movq 0x135b6(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3a11
movq -0x28(%rbp), %rsi
leaq -0x1b8(%rbp), %rdi
callq 0x4590
jmp 0x3a23
leaq -0x188(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xca30
movl %eax, -0x204(%rbp)
jmp 0x3a3e
movl -0x204(%rbp), %eax
movl %eax, -0x18c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x4650
movl -0x204(%rbp), %eax
cmpl $0x0, %eax
je 0x3ad2
movq 0x13588(%rip), %rdi     # 0x16ff0
leaq 0xc61d(%rip), %rsi      # 0x1008c
callq 0x31f0
movq %rax, -0x210(%rbp)
jmp 0x3a7d
movq -0x210(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x218(%rbp)
jmp 0x3a98
movq -0x218(%rbp), %rdi
movq 0x1351a(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3aad
jmp 0x3ae9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x4650
jmp 0x3f00
movq 0x13517(%rip), %rdi     # 0x16ff0
leaq 0xc5d2(%rip), %rsi      # 0x100b2
callq 0x31f0
jmp 0x3ae7
jmp 0x3ae9
leaq -0x188(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xa3d0
movl %eax, -0x21c(%rbp)
jmp 0x3b01
movl -0x21c(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3b74
movq 0x134d7(%rip), %rdi     # 0x16ff0
leaq 0xc5a4(%rip), %rsi      # 0x100c4
callq 0x31f0
movq %rax, -0x228(%rbp)
jmp 0x3b2e
movq -0x228(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x230(%rbp)
jmp 0x3b49
movq -0x230(%rbp), %rdi
movq 0x13469(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3b5e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3eda
leaq -0x140(%rbp), %rdi
callq 0x77f0
movl %eax, -0x234(%rbp)
jmp 0x3b88
movl -0x234(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3bfb
movq 0x13450(%rip), %rdi     # 0x16ff0
leaq 0xc543(%rip), %rsi      # 0x100ea
callq 0x31f0
movq %rax, -0x240(%rbp)
jmp 0x3bb5
movq -0x240(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x248(%rbp)
jmp 0x3bd0
movq -0x248(%rbp), %rdi
movq 0x133e2(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3be5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3eda
movq 0x133ee(%rip), %rdi     # 0x16ff0
leaq 0xc507(%rip), %rsi      # 0x10110
callq 0x31f0
jmp 0x3c10
movq 0x133d9(%rip), %rdi     # 0x16ff0
leaq 0xc50b(%rip), %rsi      # 0x10129
callq 0x31f0
movq %rax, -0x250(%rbp)
jmp 0x3c2c
leaq -0x140(%rbp), %rdi
callq 0x3ff0
movl %eax, -0x254(%rbp)
jmp 0x3c40
movl -0x254(%rbp), %esi
movq -0x250(%rbp), %rdi
callq 0x3320
movq %rax, -0x260(%rbp)
jmp 0x3c5b
movq -0x260(%rbp), %rdi
movq 0x13357(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3c70
movq 0x13379(%rip), %rdi     # 0x16ff0
leaq 0xc4be(%rip), %rsi      # 0x1013c
callq 0x31f0
movq %rax, -0x268(%rbp)
jmp 0x3c8c
leaq -0x140(%rbp), %rdi
callq 0x4010
movl %eax, -0x26c(%rbp)
jmp 0x3ca0
movl -0x26c(%rbp), %esi
movq -0x268(%rbp), %rdi
callq 0x3320
movq %rax, -0x278(%rbp)
jmp 0x3cbb
movq -0x278(%rbp), %rdi
movq 0x132f7(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3cd0
movq 0x13319(%rip), %rdi     # 0x16ff0
leaq 0xc471(%rip), %rsi      # 0x1014f
callq 0x31f0
movq %rax, -0x280(%rbp)
jmp 0x3cec
leaq -0x140(%rbp), %rdi
callq 0x4030
movl %eax, -0x284(%rbp)
jmp 0x3d00
movl -0x284(%rbp), %esi
movq -0x280(%rbp), %rdi
callq 0x3320
movq %rax, -0x290(%rbp)
jmp 0x3d1b
movq -0x290(%rbp), %rdi
movq 0x13297(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3d30
movq 0x132b9(%rip), %rdi     # 0x16ff0
leaq 0xc424(%rip), %rsi      # 0x10162
callq 0x31f0
movq %rax, -0x298(%rbp)
jmp 0x3d4c
leaq -0x140(%rbp), %rdi
callq 0x4050
movl %eax, -0x29c(%rbp)
jmp 0x3d60
movl -0x29c(%rbp), %esi
movq -0x298(%rbp), %rdi
callq 0x3320
movq %rax, -0x2a8(%rbp)
jmp 0x3d7b
movq -0x2a8(%rbp), %rdi
movq 0x13237(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3d90
movq 0x13259(%rip), %rdi     # 0x16ff0
leaq 0xc3d7(%rip), %rsi      # 0x10175
callq 0x31f0
movq %rax, -0x2b0(%rbp)
jmp 0x3dac
leaq -0x140(%rbp), %rdi
callq 0x4070
movl %eax, -0x2b4(%rbp)
jmp 0x3dc0
movl -0x2b4(%rbp), %esi
movq -0x2b0(%rbp), %rdi
callq 0x3320
movq %rax, -0x2c0(%rbp)
jmp 0x3ddb
movq -0x2c0(%rbp), %rdi
movq 0x131d7(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3df0
movq 0x131f9(%rip), %rdi     # 0x16ff0
leaq 0xc38a(%rip), %rsi      # 0x10188
callq 0x31f0
movq %rax, -0x2c8(%rbp)
jmp 0x3e0c
leaq -0x140(%rbp), %rdi
callq 0x4090
movl %eax, -0x2cc(%rbp)
jmp 0x3e20
movl -0x2cc(%rbp), %esi
movq -0x2c8(%rbp), %rdi
callq 0x3320
movq %rax, -0x2d8(%rbp)
jmp 0x3e3b
movq -0x2d8(%rbp), %rdi
movq 0x13177(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3e50
movq 0x13199(%rip), %rdi     # 0x16ff0
movq 0x13162(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3e65
movq 0x13184(%rip), %rdi     # 0x16ff0
leaq 0xc328(%rip), %rsi      # 0x1019b
callq 0x31f0
movq %rax, -0x2e0(%rbp)
jmp 0x3e81
leaq -0x140(%rbp), %rdi
callq 0x7970
movsd %xmm0, -0x2e8(%rbp)
jmp 0x3e97
movsd -0x2e8(%rbp), %xmm0
movq -0x2e0(%rbp), %rdi
callq 0x3440
movq %rax, -0x2f0(%rbp)
jmp 0x3eb4
movq -0x2f0(%rbp), %rdi
movq 0x130fe(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3ec9
movl $0x0, -0x4(%rbp)
movl $0x1, -0x190(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x9d70
leaq -0x140(%rbp), %rdi
callq 0x7790
leaq -0xa8(%rbp), %rdi
callq 0x5220
jmp 0x3f26
leaq -0x188(%rbp), %rdi
callq 0x9d70
leaq -0x140(%rbp), %rdi
callq 0x7790
leaq -0xa8(%rbp), %rdi
callq 0x5220
jmp 0x3f32
movl -0x4(%rbp), %eax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0xd8(%rbp), %rdi
callq 0x3400
nop