// File: /workspace/github_cpp_makefile_star2_O3/harry830622[P]floorplanner/src/b_star_tree.cpp
// Function: BStarTree::Delete(int)
void BStarTree::Delete(int deleted_node_id) {
  Node& deleted_node = node(deleted_node_id);

  int child_id = -1;
  if (deleted_node.left_child_id_ != -1 && deleted_node.right_child_id_ != -1) {
    child_id = deleted_node.left_child_id_;
    int current_node_id = child_id;
    while (left_child_id(current_node_id) != -1 &&
           right_child_id(current_node_id) != -1) {
      current_node_id = left_child_id(current_node_id);
    }
    if (right_child_id(current_node_id) != -1) {
      Node& current_node = node(current_node_id);
      current_node.left_child_id_ = current_node.right_child_id_;
      current_node.right_child_id_ = -1;
    }
    while (current_node_id != deleted_node_id) {
      Node& current_node = node(current_node_id);
      Node& current_parent = node(current_node.parent_id_);
      Node& current_parent_right_child = node(current_parent.right_child_id_);
      current_node.right_child_id_ = current_parent.right_child_id_;
      current_parent_right_child.parent_id_ = current_node_id;
      current_node_id = current_node.parent_id_;
    }
  } else if (deleted_node.left_child_id_ != -1) {
    child_id = deleted_node.left_child_id_;
  } else if (deleted_node.right_child_id_ != -1) {
    child_id = deleted_node.right_child_id_;
  }

  if (child_id != -1) {
    node(child_id).parent_id_ = deleted_node.parent_id_;
  }

  if (deleted_node.parent_id_ == -1) {
    root_id_ = child_id;
  } else {
    Node& parent = node(deleted_node.parent_id_);
    if (parent.left_child_id_ == deleted_node_id) {
      parent.left_child_id_ = child_id;
    } else {
      parent.right_child_id_ = child_id;
    }
  }

  deleted_node.parent_id_ = -1;
  deleted_node.left_child_id_ = -1;
  deleted_node.right_child_id_ = -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movslq %esi, %rsi
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %rsi, %rdx
jbe 0x7aa8
movq %rdi, %r14
shlq $0x4, %rsi
leaq (%rax,%rsi), %r12
movl 0x4(%rax,%rsi), %ebp
movl 0x8(%rax,%rsi), %ecx
cmpl $-0x1, %ebp
sete %sil
cmpl $-0x1, %ecx
sete %dil
orb %sil, %dil
je 0x793b
cmpl $-0x1, %ebp
jne 0x7a2d
movl %ecx, %ebp
jmp 0x7a19
movq %r14, %rdi
movl %ebp, %esi
callq 0x725c
movl %ebp, %r15d
cmpl $-0x1, %eax
je 0x797d
movl %ebp, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x728c
cmpl $-0x1, %eax
je 0x797d
movq %r14, %rdi
movl %r15d, %esi
callq 0x725c
movl %eax, %r15d
movq %r14, %rdi
movl %eax, %esi
callq 0x725c
cmpl $-0x1, %eax
jne 0x7950
movq %r14, %rdi
movl %r15d, %esi
callq 0x728c
cmpl $-0x1, %eax
je 0x79bc
movslq %r15d, %rsi
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %rsi, %rdx
jbe 0x7aa8
shlq $0x4, %rsi
movl 0x8(%rax,%rsi), %ecx
movl %ecx, 0x4(%rax,%rsi)
movl $0xffffffff, 0x8(%rax,%rsi) # imm = 0xFFFFFFFF
cmpl %ebx, %r15d
je 0x7a19
movq 0x8(%r14), %rcx
movq 0x10(%r14), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
movslq %r15d, %rsi
cmpq %rsi, %rdx
jbe 0x7aa8
shlq $0x4, %rsi
movslq (%rcx,%rsi), %rax
cmpq %rax, %rdx
jbe 0x7a9c
shlq $0x4, %rax
movl 0x8(%rcx,%rax), %eax
cltq
cmpq %rax, %rdx
jbe 0x7a9c
addq %rcx, %rsi
movq %rax, %rdi
shlq $0x4, %rdi
movl %eax, 0x8(%rsi)
movl %r15d, (%rcx,%rdi)
movl (%rsi), %r15d
cmpl %ebx, %r15d
jne 0x79d0
cmpl $-0x1, %ebp
je 0x7a42
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movslq %ebp, %rsi
cmpq %rsi, %rdx
jbe 0x7aa8
movl (%r12), %ecx
shlq $0x4, %rsi
movl %ecx, (%rax,%rsi)
jmp 0x7a4b
movl (%r12), %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
je 0x7a7a
movslq %ecx, %rsi
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
cmpq %rsi, %rdx
jbe 0x7aa8
shlq $0x4, %rsi
leaq (%rax,%rsi), %rcx
cmpl %ebx, 0x4(%rax,%rsi)
jne 0x7a7f
movl %ebp, 0x4(%rcx)
jmp 0x7a82
movl %ebp, (%r14)
jmp 0x7a82
movl %ebp, 0x8(%rcx)
movq $-0x1, (%r12)
movl $0xffffffff, 0x8(%r12)  # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19692(%rip), %rdi     # 0x21135
movq %rax, %rsi
jmp 0x7aaf
leaq 0x19686(%rip), %rdi     # 0x21135
xorl %eax, %eax
callq 0x6530