// File: cpottamus[P]btree_lab/btree.cc
// Function: PrintNode(std::ostream&, unsigned int, BTreeNode&, BTreeDisplayType)
static ERROR_T PrintNode(ostream &os, SIZE_T nodenum, BTreeNode &b, BTreeDisplayType dt)
{
  KEY_T key;
  VALUE_T value;
  SIZE_T ptr;
  SIZE_T offset;
  ERROR_T rc;
  unsigned i;

  if (dt==BTREE_DEPTH_DOT) { 
    os << nodenum << " [ label=\""<<nodenum<<": ";
  } else if (dt==BTREE_DEPTH) {
    os << nodenum << ": ";
  } else {
  }

  switch (b.info.nodetype) { 
    case BTREE_ROOT_NODE:
    case BTREE_INTERIOR_NODE:
    if (dt==BTREE_SORTED_KEYVAL) {
    } else {
      if (dt==BTREE_DEPTH_DOT) { 
      } else { 
       os << "Interior: ";
     }
     for (offset=0;offset<=b.info.numkeys;offset++) { 
       rc=b.GetPtr(offset,ptr);
       if (rc) { return rc; }
       os << "*" << ptr << " ";
	// Last pointer
       if (offset==b.info.numkeys) break;
       rc=b.GetKey(offset,key);
       if (rc) {  return rc; }
       for (i=0;i<b.info.keysize;i++) { 
         os << key.data[i];
       }
       os << " ";
     }
   }
   break;
   case BTREE_LEAF_NODE:
   if (dt==BTREE_DEPTH_DOT || dt==BTREE_SORTED_KEYVAL) { 
   } else {
    os << "Leaf: ";
  }
  for (offset=0;offset<b.info.numkeys;offset++) { 
    if (offset==0) { 
	// special case for first pointer
     rc=b.GetPtr(offset,ptr);
     if (rc) { return rc; }
     if (dt!=BTREE_SORTED_KEYVAL) { 
       os << "*" << ptr << " ";
     }
   }
   if (dt==BTREE_SORTED_KEYVAL) { 
     os << "(";
   }
   rc=b.GetKey(offset,key);
   if (rc) {  return rc; }
   for (i=0;i<b.info.keysize;i++) { 
     os << key.data[i];
   }
   if (dt==BTREE_SORTED_KEYVAL) { 
     os << ",";
   } else {
     os << " ";
   }
   rc=b.GetVal(offset,value);
   if (rc) {  return rc; }
   for (i=0;i<b.info.valuesize;i++) { 
     os << value.data[i];
   }
   if (dt==BTREE_SORTED_KEYVAL) { 
     os << ")\n";
} else {
	os << " ";
}
}
break;
default:
if (dt==BTREE_DEPTH_DOT) { 
  os << "Unknown("<<b.info.nodetype<<")";
} else {
  os << "Unsupported Node Type " << b.info.nodetype ;
}
}
if (dt==BTREE_DEPTH_DOT) { 
  os << "\" ]";
}
return ERROR_NOERROR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x43e0
leaq -0x78(%rbp), %rdi
callq 0x43e0
jmp 0xce4d
cmpl $0x1, -0x24(%rbp)
jne 0xcee8
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x3320
movq %rax, -0xa0(%rbp)
jmp 0xce6c
movq -0xa0(%rbp), %rdi
leaq 0x3a55(%rip), %rsi      # 0x108cf
callq 0x31f0
movq %rax, -0xa8(%rbp)
jmp 0xce88
movq -0xa8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x3320
movq %rax, -0xb0(%rbp)
jmp 0xcea0
movq -0xb0(%rbp), %rdi
leaq 0x3a3b(%rip), %rsi      # 0x108e9
callq 0x31f0
jmp 0xceb5
jmp 0xcf1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xd450
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x46e0
jmp 0xd450
cmpl $0x0, -0x24(%rbp)
jne 0xcf1a
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x3320
movq %rax, -0xb8(%rbp)
jmp 0xcf03
movq -0xb8(%rbp), %rdi
leaq 0x39d8(%rip), %rsi      # 0x108e9
callq 0x31f0
jmp 0xcf18
jmp 0xcf1c
jmp 0xcf1c
jmp 0xcf1e
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xbc(%rbp)
addl $-0x2, %eax
subl $0x2, %eax
jb 0xcf48
jmp 0xcf34
movl -0xbc(%rbp), %eax
subl $0x4, %eax
je 0xd0f0
jmp 0xd385
cmpl $0x2, -0x24(%rbp)
jne 0xcf53
jmp 0xd0eb
cmpl $0x1, -0x24(%rbp)
jne 0xcf5b
jmp 0xcf6f
movq -0x10(%rbp), %rdi
leaq 0x3974(%rip), %rsi      # 0x108da
callq 0x31f0
jmp 0xcf6d
jmp 0xcf6f
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
ja 0xd0e9
movq -0x20(%rbp), %rdi
movl -0x8c(%rbp), %esi
leaq -0x88(%rbp), %rdx
callq 0xf650
movl %eax, -0xc0(%rbp)
jmp 0xcfaa
movl -0xc0(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0xcfd7
movl -0x90(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xd432
movq -0x10(%rbp), %rdi
leaq 0x35f7(%rip), %rsi      # 0x105d9
callq 0x31f0
movq %rax, -0xc8(%rbp)
jmp 0xcff0
movq -0xc8(%rbp), %rdi
movl -0x88(%rbp), %esi
callq 0x3320
movq %rax, -0xd0(%rbp)
jmp 0xd00b
movq -0xd0(%rbp), %rdi
leaq 0x366b(%rip), %rsi      # 0x10684
callq 0x31f0
jmp 0xd020
movl -0x8c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0xd034
jmp 0xd0e9
movq -0x20(%rbp), %rdi
movl -0x8c(%rbp), %esi
leaq -0x50(%rbp), %rdx
callq 0xf5d0
movl %eax, -0xd4(%rbp)
jmp 0xd04f
movl -0xd4(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0xd07c
movl -0x90(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xd432
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xd0c1
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movl -0x94(%rbp), %ecx
movzbl (%rax,%rcx), %esi
callq 0x3370
jmp 0xd0ae
jmp 0xd0b0
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xd086
movq -0x10(%rbp), %rdi
leaq 0x35b8(%rip), %rsi      # 0x10684
callq 0x31f0
jmp 0xd0d3
jmp 0xd0d5
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0xcf79
jmp 0xd0eb
jmp 0xd407
cmpl $0x1, -0x24(%rbp)
je 0xd0fc
cmpl $0x2, -0x24(%rbp)
jne 0xd0fe
jmp 0xd112
movq -0x10(%rbp), %rdi
leaq 0x37dc(%rip), %rsi      # 0x108e5
callq 0x31f0
jmp 0xd110
jmp 0xd112
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0xd380
cmpl $0x0, -0x8c(%rbp)
jne 0xd1da
movq -0x20(%rbp), %rdi
movl -0x8c(%rbp), %esi
leaq -0x88(%rbp), %rdx
callq 0xf650
movl %eax, -0xd8(%rbp)
jmp 0xd15a
movl -0xd8(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0xd187
movl -0x90(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xd432
cmpl $0x2, -0x24(%rbp)
je 0xd1d8
movq -0x10(%rbp), %rdi
leaq 0x3441(%rip), %rsi      # 0x105d9
callq 0x31f0
movq %rax, -0xe0(%rbp)
jmp 0xd1a6
movq -0xe0(%rbp), %rdi
movl -0x88(%rbp), %esi
callq 0x3320
movq %rax, -0xe8(%rbp)
jmp 0xd1c1
movq -0xe8(%rbp), %rdi
leaq 0x34b5(%rip), %rsi      # 0x10684
callq 0x31f0
jmp 0xd1d6
jmp 0xd1d8
jmp 0xd1da
cmpl $0x2, -0x24(%rbp)
jne 0xd1f4
movq -0x10(%rbp), %rdi
leaq 0x3982(%rip), %rsi      # 0x10b6d
callq 0x31f0
jmp 0xd1f2
jmp 0xd1f4
movq -0x20(%rbp), %rdi
movl -0x8c(%rbp), %esi
leaq -0x50(%rbp), %rdx
callq 0xf5d0
movl %eax, -0xec(%rbp)
jmp 0xd20f
movl -0xec(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0xd23c
movl -0x90(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xd432
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xd281
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movl -0x94(%rbp), %ecx
movzbl (%rax,%rcx), %esi
callq 0x3370
jmp 0xd26e
jmp 0xd270
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xd246
cmpl $0x2, -0x24(%rbp)
jne 0xd29b
movq -0x10(%rbp), %rdi
leaq 0x365a(%rip), %rsi      # 0x108ec
callq 0x31f0
jmp 0xd299
jmp 0xd2af
movq -0x10(%rbp), %rdi
leaq 0x33de(%rip), %rsi      # 0x10684
callq 0x31f0
jmp 0xd2ad
jmp 0xd2af
movq -0x20(%rbp), %rdi
movl -0x8c(%rbp), %esi
leaq -0x78(%rbp), %rdx
callq 0xf6a0
movl %eax, -0xf0(%rbp)
jmp 0xd2ca
movl -0xf0(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0xd2f7
movl -0x90(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xd432
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xd33c
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rax
movl -0x94(%rbp), %ecx
movzbl (%rax,%rcx), %esi
callq 0x3370
jmp 0xd329
jmp 0xd32b
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xd301
cmpl $0x2, -0x24(%rbp)
jne 0xd356
movq -0x10(%rbp), %rdi
leaq 0x35a1(%rip), %rsi      # 0x108ee
callq 0x31f0
jmp 0xd354
jmp 0xd36a
movq -0x10(%rbp), %rdi
leaq 0x3323(%rip), %rsi      # 0x10684
callq 0x31f0
jmp 0xd368
jmp 0xd36a
jmp 0xd36c
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0xd11c
jmp 0xd407
cmpl $0x1, -0x24(%rbp)
jne 0xd3d6
movq -0x10(%rbp), %rdi
leaq 0x355b(%rip), %rsi      # 0x108f1
callq 0x31f0
movq %rax, -0xf8(%rbp)
jmp 0xd3a4
movq -0xf8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
callq 0x33f0
movq %rax, -0x100(%rbp)
jmp 0xd3bf
movq -0x100(%rbp), %rdi
leaq 0x3390(%rip), %rsi      # 0x1075d
callq 0x31f0
jmp 0xd3d4
jmp 0xd405
movq -0x10(%rbp), %rdi
leaq 0x33d1(%rip), %rsi      # 0x107b2
callq 0x31f0
movq %rax, -0x108(%rbp)
jmp 0xd3ef
movq -0x108(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
callq 0x33f0
jmp 0xd403
jmp 0xd405
jmp 0xd407
cmpl $0x1, -0x24(%rbp)
jne 0xd421
movq -0x10(%rbp), %rdi
leaq 0x34e2(%rip), %rsi      # 0x108fa
callq 0x31f0
jmp 0xd41f
jmp 0xd421
movl $0x0, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x46e0
leaq -0x50(%rbp), %rdi
callq 0x46e0
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x46e0
movq -0x80(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)