// File: /workspace/github_c_makefile_star2_O2/mrkite[P]regs/docmaker/avl.cc
// Function: AVL::insertOnce(std::shared_ptr<AVLNode_>, unsigned int)
AVLNode AVL::insertOnce(AVLNode node, uint32_t key) {
  if (node == nullptr) {
    node = std::make_shared<AVLNode_>();
    node->key = key;
    node->left = nullptr;
    node->right = nullptr;
    node->down = nullptr;
    node->height = 1;
    node->matched = false;
    return node;
  }
  if (key < node->key) {
    node->left = insertOnce(node->left, key);
  } else if (key > node->key) {
    node->right = insertOnce(node->right, key);
  } else {  // key already exists
    return node;
  }
  node->height = 1 + max(Height(node->left), Height(node->right));
  int balance = getBalance(node);
  if (balance > 1 && key < node->left->key) {
    return rotateRight(node);
  }
  if (balance < -1 && key > node->right->key) {
    return rotateLeft(node);
  }
  if (balance > 1 && key > node->left->key) {
    node->left = rotateLeft(node->left);
    return rotateRight(node);
  }
  if (balance < -1 && key < node->right->key) {
    node->right = rotateRight(node->right);
    return rotateLeft(node);
  }
  return node;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdx), %rsi
testq %rsi, %rsi
je 0x5928
cmpl %ebp, (%rsi)
jbe 0x59c9
addq $0x8, %rsi
leaq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x60da
movq %rsp, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x58b8
movq (%r14), %rdi
addq $0x8, %rdi
movq %rsp, %rsi
callq 0x62fc
leaq 0x8(%rsp), %rdi
callq 0x5412
leaq 0x40(%rsp), %rdi
jmp 0x5a0e
movq %rsp, %r15
movq %r15, %rdi
callq 0x60bf
movq %r14, %rdi
movq %r15, %rsi
callq 0x62fc
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5412
movq (%r14), %rdi
movl %ebp, (%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
addq $0x8, %rdi
movq %rsp, %rsi
callq 0x62fc
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5412
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
movq (%r14), %rdi
addq $0x18, %rdi
movq %rsp, %rsi
callq 0x62fc
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5412
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
movq (%r14), %rdi
addq $0x28, %rdi
movq %rsp, %rsi
callq 0x62fc
leaq 0x8(%rsp), %rdi
callq 0x5412
movq (%r14), %rax
movl $0x1, 0x38(%rax)
movb $0x0, 0x3c(%rax)
jmp 0x5c77
jae 0x5b9f
addq $0x18, %rsi
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x60da
movq %rsp, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x58b8
movq (%r14), %rdi
addq $0x18, %rdi
movq %rsp, %rsi
callq 0x62fc
leaq 0x8(%rsp), %rdi
callq 0x5412
leaq 0x30(%rsp), %rdi
callq 0x5412
movq (%r14), %rsi
addq $0x8, %rsi
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
callq 0x60da
movq (%r15), %rax
xorl %r12d, %r12d
movl $0x0, %r13d
testq %rax, %rax
je 0x5a3f
movl 0x38(%rax), %r13d
movq (%r14), %rsi
addq $0x18, %rsi
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0x60da
movq (%r15), %rax
testq %rax, %rax
je 0x5a62
movl 0x38(%rax), %r12d
cmpl %r12d, %r13d
cmovgl %r13d, %r12d
incl %r12d
movq (%r14), %rax
movl %r12d, 0x38(%rax)
leaq 0xb0(%rsp), %rdi
callq 0x5412
leaq 0xc0(%rsp), %rdi
callq 0x5412
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x60da
movq (%r15), %rsi
testq %rsi, %rsi
je 0x5b0a
addq $0x8, %rsi
movq %rsp, %r15
movq %r15, %rdi
callq 0x60da
movq (%r15), %rax
xorl %r13d, %r13d
movl $0x0, %r12d
testq %rax, %rax
je 0x5ac9
movl 0x38(%rax), %r12d
movq 0x18(%rsp), %rsi
addq $0x18, %rsi
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
callq 0x60da
movq (%r15), %rax
testq %rax, %rax
je 0x5aee
movl 0x38(%rax), %r13d
subl %r13d, %r12d
leaq 0xd0(%rsp), %rdi
callq 0x5412
leaq 0x8(%rsp), %rdi
callq 0x5412
jmp 0x5b0d
xorl %r12d, %r12d
leaq 0x20(%rsp), %rdi
callq 0x5412
cmpl $0x2, %r12d
jl 0x5b57
movq (%r14), %rax
leaq 0x8(%rax), %rsi
movq 0x8(%rax), %rcx
cmpl %ebp, (%rcx)
jbe 0x5ba7
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x60da
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5cbf
leaq 0xa0(%rsp), %rdi
jmp 0x5c70
movq (%r14), %rax
cmpl $-0x2, %r12d
jg 0x5c77
leaq 0x18(%rax), %rsi
movq 0x18(%rax), %rcx
cmpl %ebp, (%rcx)
jae 0x5c10
leaq 0x88(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x60da
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5dfb
leaq 0x90(%rsp), %rdi
jmp 0x5c70
movq %rsi, (%rbx)
jmp 0x5c7a
jae 0x5c77
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x60da
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5dfb
movq (%r14), %rdi
addq $0x8, %rdi
movq %r12, %rsi
callq 0x62fc
leaq 0x8(%rsp), %rdi
callq 0x5412
leaq 0x80(%rsp), %rdi
callq 0x5412
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x60da
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5cbf
leaq 0x70(%rsp), %rdi
jmp 0x5c70
jbe 0x5c77
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x60da
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5cbf
movq (%r14), %rdi
addq $0x18, %rdi
movq %r12, %rsi
callq 0x62fc
leaq 0x8(%rsp), %rdi
callq 0x5412
leaq 0x60(%rsp), %rdi
callq 0x5412
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x60da
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5dfb
leaq 0x50(%rsp), %rdi
callq 0x5412
jmp 0x5c8b
movq %rax, (%rbx)
movq 0x8(%r14), %rax
andq $0x0, 0x8(%r14)
movq %rax, 0x8(%rbx)
andq $0x0, (%r14)
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x5cb2
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5412
movq %rbx, %rdi
callq 0x23a0