// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r14
callq 0x7d86
movq %rax, %rbx
movl 0x4(%rax), %r12d
movl 0x8(%rax), %eax
cmpl $-0x1, %r12d
sete %cl
cmpl $-0x1, %eax
sete %dl
orb %cl, %dl
je 0x7e1e
cmpl $-0x1, %r12d
jne 0x7ebf
movl %eax, %r12d
jmp 0x7eb9
movl %r12d, 0x4(%rsp)
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d56
cmpl $-0x1, %eax
je 0x7e53
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d62
cmpl $-0x1, %eax
je 0x7e53
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d56
movl %eax, %r12d
jmp 0x7e23
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d62
cmpl $-0x1, %eax
je 0x7eaf
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d86
movl 0x8(%rax), %ecx
movl %ecx, 0x4(%rax)
orl $-0x1, 0x8(%rax)
jmp 0x7eaf
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d86
movq %rax, %r13
movl (%rax), %esi
movq %r14, %rdi
callq 0x7d86
movq %rax, %r15
movl 0x8(%rax), %esi
movq %r14, %rdi
callq 0x7d86
movl 0x8(%r15), %ecx
movl %ecx, 0x8(%r13)
movl %r12d, (%rax)
movl (%r13), %r12d
cmpl %ebp, %r12d
jne 0x7e7a
movl 0x4(%rsp), %r12d
cmpl $-0x1, %r12d
je 0x7ed2
movl (%rbx), %r15d
movq %r14, %rdi
movl %r12d, %esi
callq 0x7d86
movl %r15d, (%rax)
jmp 0x7ed6
pushq $-0x1
popq %r12
movl (%rbx), %esi
cmpl $-0x1, %esi
je 0x7ef0
movq %r14, %rdi
callq 0x7d86
cmpl %ebp, 0x4(%rax)
jne 0x7ef5
movl %r12d, 0x4(%rax)
jmp 0x7ef9
movl %r12d, (%r14)
jmp 0x7ef9
movl %r12d, 0x8(%rax)
orq $-0x1, (%rbx)
orl $-0x1, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq