// File: cpottamus[P]btree_lab/btree_display.cc
// Function: main
int main(int argc, char **argv)
{
  char *filestem;
  bool dot;
  SIZE_T cachesize;
  SIZE_T superblocknum;

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

  filestem=argv[1];
  cachesize=atoi(argv[2]);
  dot=argv[3][0]=='d' || argv[3][0]=='D';

  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.Display(cout, dot ? BTREE_DEPTH_DOT : BTREE_DEPTH))!=ERROR_NOERROR) { 
      cerr <<"Display failed: error "<<rc<<endl;
    } else {
      cerr <<"Display 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 0x3f51
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x33a0
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x64, %ecx
movb %al, -0x1b9(%rbp)
je 0x379b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %eax
cmpl $0x44, %eax
sete %al
movb %al, -0x1b9(%rbp)
movb -0x1b9(%rbp), %al
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x3410
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0x3f70
jmp 0x37e0
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 0x49e0
jmp 0x3821
leaq -0xc8(%rbp), %rdi
callq 0x3120
leaq -0xc9(%rbp), %rdi
callq 0x3270
movl -0x20(%rbp), %edx
leaq -0x140(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7750
jmp 0x3851
leaq -0x188(%rbp), %rdi
xorl %edx, %edx
leaq -0x140(%rbp), %rcx
movl $0x1, %r8d
movl %edx, %esi
callq 0x9c50
jmp 0x3870
leaq -0x140(%rbp), %rdi
callq 0x7910
movl %eax, -0x1d4(%rbp)
jmp 0x3884
movl -0x1d4(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3983
movq 0x13750(%rip), %rdi     # 0x16ff0
leaq 0xc791(%rip), %rsi      # 0x10038
callq 0x31f0
movq %rax, -0x1e0(%rbp)
jmp 0x38b5
movq -0x1e0(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x1e8(%rbp)
jmp 0x38d0
movq -0x1e8(%rbp), %rdi
movq 0x136e2(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x38e5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3f05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x392d
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 0x3f5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x3f43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x3f37
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x3f2b
leaq -0x188(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa020
movl %eax, -0x1ec(%rbp)
jmp 0x399b
movl -0x1ec(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3a0e
movq 0x1363d(%rip), %rdi     # 0x16ff0
leaq 0xc6a5(%rip), %rsi      # 0x1005f
callq 0x31f0
movq %rax, -0x1f8(%rbp)
jmp 0x39c8
movq -0x1f8(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x200(%rbp)
jmp 0x39e3
movq -0x200(%rbp), %rdi
movq 0x135cf(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x39f8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3f05
movq 0x135db(%rip), %rdi     # 0x16ff0
leaq 0xc668(%rip), %rsi      # 0x10084
callq 0x31f0
movq %rax, -0x208(%rbp)
jmp 0x3a2a
movq -0x208(%rbp), %rdi
movq 0x13588(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3a3f
leaq -0x1b8(%rbp), %rdi
callq 0x4380
jmp 0x3a4d
movzbl -0x19(%rbp), %edx
andl $0x1, %edx
movq 0x13575(%rip), %rsi     # 0x16fd0
leaq -0x188(%rbp), %rdi
callq 0xd410
movl %eax, -0x20c(%rbp)
jmp 0x3a6f
movl -0x20c(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3af1
movq 0x13569(%rip), %rdi     # 0x16ff0
leaq 0xc606(%rip), %rsi      # 0x10094
callq 0x31f0
movq %rax, -0x218(%rbp)
jmp 0x3a9c
movq -0x218(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x220(%rbp)
jmp 0x3ab7
movq -0x220(%rbp), %rdi
movq 0x134fb(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3acc
jmp 0x3b08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x4680
jmp 0x3f2b
movq 0x134f8(%rip), %rdi     # 0x16ff0
leaq 0xc5ac(%rip), %rsi      # 0x100ab
callq 0x31f0
jmp 0x3b06
jmp 0x3b08
leaq -0x188(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0xa400
movl %eax, -0x224(%rbp)
jmp 0x3b20
movl -0x224(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3b93
movq 0x134b8(%rip), %rdi     # 0x16ff0
leaq 0xc57f(%rip), %rsi      # 0x100be
callq 0x31f0
movq %rax, -0x230(%rbp)
jmp 0x3b4d
movq -0x230(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x238(%rbp)
jmp 0x3b68
movq -0x238(%rbp), %rdi
movq 0x1344a(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3b7d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3ef9
leaq -0x140(%rbp), %rdi
callq 0x7820
movl %eax, -0x23c(%rbp)
jmp 0x3ba7
movl -0x23c(%rbp), %eax
movl %eax, -0x18c(%rbp)
cmpl $0x0, %eax
je 0x3c1a
movq 0x13431(%rip), %rdi     # 0x16ff0
leaq 0xc51e(%rip), %rsi      # 0x100e4
callq 0x31f0
movq %rax, -0x248(%rbp)
jmp 0x3bd4
movq -0x248(%rbp), %rdi
movl -0x18c(%rbp), %esi
callq 0x33f0
movq %rax, -0x250(%rbp)
jmp 0x3bef
movq -0x250(%rbp), %rdi
movq 0x133c3(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3c04
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x190(%rbp)
jmp 0x3ef9
movq 0x133cf(%rip), %rdi     # 0x16ff0
leaq 0xc4e2(%rip), %rsi      # 0x1010a
callq 0x31f0
jmp 0x3c2f
movq 0x133ba(%rip), %rdi     # 0x16ff0
leaq 0xc4e6(%rip), %rsi      # 0x10123
callq 0x31f0
movq %rax, -0x258(%rbp)
jmp 0x3c4b
leaq -0x140(%rbp), %rdi
callq 0x4020
movl %eax, -0x25c(%rbp)
jmp 0x3c5f
movl -0x25c(%rbp), %esi
movq -0x258(%rbp), %rdi
callq 0x3320
movq %rax, -0x268(%rbp)
jmp 0x3c7a
movq -0x268(%rbp), %rdi
movq 0x13338(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3c8f
movq 0x1335a(%rip), %rdi     # 0x16ff0
leaq 0xc499(%rip), %rsi      # 0x10136
callq 0x31f0
movq %rax, -0x270(%rbp)
jmp 0x3cab
leaq -0x140(%rbp), %rdi
callq 0x4040
movl %eax, -0x274(%rbp)
jmp 0x3cbf
movl -0x274(%rbp), %esi
movq -0x270(%rbp), %rdi
callq 0x3320
movq %rax, -0x280(%rbp)
jmp 0x3cda
movq -0x280(%rbp), %rdi
movq 0x132d8(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3cef
movq 0x132fa(%rip), %rdi     # 0x16ff0
leaq 0xc44c(%rip), %rsi      # 0x10149
callq 0x31f0
movq %rax, -0x288(%rbp)
jmp 0x3d0b
leaq -0x140(%rbp), %rdi
callq 0x4060
movl %eax, -0x28c(%rbp)
jmp 0x3d1f
movl -0x28c(%rbp), %esi
movq -0x288(%rbp), %rdi
callq 0x3320
movq %rax, -0x298(%rbp)
jmp 0x3d3a
movq -0x298(%rbp), %rdi
movq 0x13278(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3d4f
movq 0x1329a(%rip), %rdi     # 0x16ff0
leaq 0xc3ff(%rip), %rsi      # 0x1015c
callq 0x31f0
movq %rax, -0x2a0(%rbp)
jmp 0x3d6b
leaq -0x140(%rbp), %rdi
callq 0x4080
movl %eax, -0x2a4(%rbp)
jmp 0x3d7f
movl -0x2a4(%rbp), %esi
movq -0x2a0(%rbp), %rdi
callq 0x3320
movq %rax, -0x2b0(%rbp)
jmp 0x3d9a
movq -0x2b0(%rbp), %rdi
movq 0x13218(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3daf
movq 0x1323a(%rip), %rdi     # 0x16ff0
leaq 0xc3b2(%rip), %rsi      # 0x1016f
callq 0x31f0
movq %rax, -0x2b8(%rbp)
jmp 0x3dcb
leaq -0x140(%rbp), %rdi
callq 0x40a0
movl %eax, -0x2bc(%rbp)
jmp 0x3ddf
movl -0x2bc(%rbp), %esi
movq -0x2b8(%rbp), %rdi
callq 0x3320
movq %rax, -0x2c8(%rbp)
jmp 0x3dfa
movq -0x2c8(%rbp), %rdi
movq 0x131b8(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3e0f
movq 0x131da(%rip), %rdi     # 0x16ff0
leaq 0xc365(%rip), %rsi      # 0x10182
callq 0x31f0
movq %rax, -0x2d0(%rbp)
jmp 0x3e2b
leaq -0x140(%rbp), %rdi
callq 0x40c0
movl %eax, -0x2d4(%rbp)
jmp 0x3e3f
movl -0x2d4(%rbp), %esi
movq -0x2d0(%rbp), %rdi
callq 0x3320
movq %rax, -0x2e0(%rbp)
jmp 0x3e5a
movq -0x2e0(%rbp), %rdi
movq 0x13158(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3e6f
movq 0x1317a(%rip), %rdi     # 0x16ff0
movq 0x13143(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3e84
movq 0x13165(%rip), %rdi     # 0x16ff0
leaq 0xc303(%rip), %rsi      # 0x10195
callq 0x31f0
movq %rax, -0x2e8(%rbp)
jmp 0x3ea0
leaq -0x140(%rbp), %rdi
callq 0x79a0
movsd %xmm0, -0x2f0(%rbp)
jmp 0x3eb6
movsd -0x2f0(%rbp), %xmm0
movq -0x2e8(%rbp), %rdi
callq 0x3440
movq %rax, -0x2f8(%rbp)
jmp 0x3ed3
movq -0x2f8(%rbp), %rdi
movq 0x130df(%rip), %rsi     # 0x16fc0
callq 0x3240
jmp 0x3ee8
movl $0x0, -0x4(%rbp)
movl $0x1, -0x190(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x4680
leaq -0x188(%rbp), %rdi
callq 0x9da0
leaq -0x140(%rbp), %rdi
callq 0x77c0
leaq -0xa8(%rbp), %rdi
callq 0x5250
jmp 0x3f51
leaq -0x188(%rbp), %rdi
callq 0x9da0
leaq -0x140(%rbp), %rdi
callq 0x77c0
leaq -0xa8(%rbp), %rdi
callq 0x5250
jmp 0x3f5d
movl -0x4(%rbp), %eax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0xd8(%rbp), %rdi
callq 0x3400
nopl (%rax)