// File: sgalkina[P]data_structures/src/tree_map.h
// Function: gtl::tree_map<int, int>::remove(gtl::tree_map<int, int>::Node*, int const&, bool&)
auto tree_map<K, V>::remove(Node * node, K const & key, bool & result) -> Node * {
  if (!node) {
    result = false;
    return nullptr;
  }
  if (key < node->key) {
    if (!is_red(node->left) && (!node->left || !is_red(node->left->left))) node = move_red_left(node);
    node->left = remove(node->left, key, result);
  } else {
    if (is_red(node->left)) node = node->rotate_right();
    if (key == node->key && !node->right) {
      Node * temp = node->left;
      node->left = nullptr;
      delete node;
      return temp;
    }
    if (!is_red(node->right) && (!node->right || !is_red(node->right->left))) node = move_red_right(node);
    if (key == node->key) {
      Node * min_right = min(node->right);
      node->value = min_right->value;
      node->key = min_right->key;
      node->right = delete_min(node->right);
    } else {
      node->right = remove(node->right, key, result);
    }
  }
  return fix_up(node);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0xa9f0
movq 0x20(%rsp), %rax
movb $0x0, (%rax)
movq $0x0, 0x40(%rsp)
jmp 0xac0b
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jge 0xaa84
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xa7b0
testb $0x1, %al
jne 0xaa56
movq 0x30(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0xaa42
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
callq 0xa7b0
testb $0x1, %al
jne 0xaa56
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0xac20
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0xa9b0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0xabf7
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xa7b0
testb $0x1, %al
jne 0xaa9d
jmp 0xaaac
movq 0x30(%rsp), %rdi
callq 0xa860
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jne 0xab13
movq 0x30(%rsp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xab13
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0x30(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0xab04
movq (%rsp), %rdi
callq 0xacb0
movq (%rsp), %rdi
callq 0x20f0
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0xac0b
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xa7b0
testb $0x1, %al
jne 0xab65
movq 0x30(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0xab51
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rsi
callq 0xa7b0
testb $0x1, %al
jne 0xab65
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0xad20
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq 0x30(%rsp), %rcx
cmpl (%rcx), %eax
jne 0xabcc
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xad90
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x4(%rax)
movq 0x10(%rsp), %rax
movl (%rax), %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0xae00
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xabf5
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
callq 0xa9b0
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0xabf7
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0xa6d0
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nop