// File: /workspace/github_cpp_makefile_star2_O2/davmac314[P]dinit/src/../dasynq/include/dasynq/btree_set.h
// Function: dasynq::btree_set<void*, int, std::less<int>, 8>::insert(dasynq::btree_set<void*, int, std::less<int>, 8>::heapnode&, int)
bool insert(handle_t & hndl, P pval = P()) noexcept
    {
        if (root_sept == nullptr) {
            root_sept = alloc_sept();
            left_sept = root_sept;
        }

        septnode * srch_sept = root_sept;

        while (! srch_sept->is_leaf()) {
            int min = 0;
            int max = N - 1;
            while (min <= max) {
                int i = (min + max) / 2;

                if (srch_sept->hn_p[i] == nullptr || pval < srch_sept->prio[i]) {
                    max = i - 1;
                }
                else if (srch_sept->prio[i] == pval) {
                    // Already present
                    return false;
                }
                else {
                    min = i + 1;
                }
            }

            // go up to the right:
            srch_sept = srch_sept->children[max + 1];
        }

        // We got to a leaf: does it have space?
        // First check if already present
        int children = srch_sept->num_vals();

        {
            int min = 0;
            int max = children - 1;
            while (min <= max) {
                int i = (min + max) / 2;

                if (pval < srch_sept->prio[i]) {
                    max = i - 1;
                }
                else if (srch_sept->prio[i] == pval) {
                    // Already present
                    return false;
                }
                else {
                    min = i + 1;
                }
            }
        }

        septnode * left_down = nullptr; // left node going down
        septnode * right_down = nullptr; // right node going down

        handle_t * hndl_p = &hndl;

        while (children == N) {
            // split and push value towards root
            septnode * new_sibling = alloc_sept();
            new_sibling->parent = srch_sept->parent;

            // create new sibling to the right:
            for (int i = N/2; i < N; i++) {
                new_sibling->prio[i - N/2] = srch_sept->prio[i];  // new[0] = old[4]
                new_sibling->hn_p[i - N/2] = srch_sept->hn_p[i];
                new_sibling->children[i - N/2 + 1] = srch_sept->children[i + 1];
                if (new_sibling->children[i - N/2 + 1]) new_sibling->children[i - N/2 + 1]->parent = new_sibling;
                new_sibling->hn_p[i - N/2]->parent = new_sibling;
                srch_sept->hn_p[i] = nullptr;
            }
            // Note that new_sibling->children[0] has not yet been set.

            if (pval < srch_sept->prio[N/2 - 1])  {
                auto o_prio = srch_sept->prio[N/2 - 1];
                auto o_hidx = srch_sept->hn_p[N/2 - 1];

                new_sibling->children[0] = srch_sept->children[N/2];
                if (new_sibling->children[0]) new_sibling->children[0]->parent = new_sibling;

                int i = N/2 - 1;
                for ( ; i > 0 && pval < srch_sept->prio[i - 1]; i--) {
                    srch_sept->prio[i] = srch_sept->prio[i - 1];
                    srch_sept->children[i+1] = srch_sept->children[i];
                    srch_sept->hn_p[i] = srch_sept->hn_p[i - 1];
                }
                srch_sept->prio[i] = pval;
                srch_sept->hn_p[i] = hndl_p;
                hndl_p->parent = srch_sept;
                srch_sept->children[i] = left_down;
                srch_sept->children[i+1] = right_down;
                hndl_p = o_hidx;
                pval = o_prio;
            }
            else if (pval < new_sibling->prio[0]) {
                // new value is right in the middle
                srch_sept->children[N/2] = left_down;
                new_sibling->children[0] = right_down;
                if (left_down) left_down->parent = srch_sept;
                if (right_down) right_down->parent = new_sibling;
            }
            else {
                auto o_prio = new_sibling->prio[0];
                auto o_hidx = new_sibling->hn_p[0];
                int i = 0;
                for ( ; i < (N/2 - 1) && new_sibling->prio[i + 1] < pval; i++) {
                    new_sibling->prio[i] = new_sibling->prio[i + 1];
                    new_sibling->children[i] = new_sibling->children[i + 1];
                    new_sibling->hn_p[i] = new_sibling->hn_p[i + 1];
                }
                new_sibling->prio[i] = pval;
                new_sibling->hn_p[i] = hndl_p;
                hndl_p->parent = new_sibling;
                new_sibling->children[i] = left_down;
                new_sibling->children[i+1] = right_down;
                if (left_down) left_down->parent = new_sibling;
                if (right_down) right_down->parent = new_sibling;
                hndl_p = o_hidx;
                pval = o_prio;
            }

            left_down = srch_sept;
            right_down = new_sibling;

            srch_sept = srch_sept->parent;
            if (srch_sept == nullptr) {
                // Need new root node:
                srch_sept = alloc_sept();
                root_sept = srch_sept;
                left_down->parent = root_sept;
                right_down->parent = root_sept;
                children = 0;
            }
            else {
                children = srch_sept->num_vals();
            }
        }

        // Insert into non-full node:
        int inspos;
        for (inspos = children; inspos > 0; inspos--) {
            if (srch_sept->prio[inspos - 1] < pval) {
                break;
            }

            srch_sept->prio[inspos] = srch_sept->prio[inspos-1];
            srch_sept->hn_p[inspos] = srch_sept->hn_p[inspos-1];
            srch_sept->children[inspos+1] = srch_sept->children[inspos];
        }

        srch_sept->prio[inspos] = pval;
        srch_sept->hn_p[inspos] = hndl_p;
        srch_sept->children[inspos] = left_down;
        srch_sept->children[inspos+1] = right_down;
        hndl_p->parent = srch_sept;
        return true;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r13
movq (%rdi), %rbx
testq %rbx, %rbx
jne 0x5fcd
movq %r13, %rdi
callq 0x62e2
movq %rax, %rbx
movq %rax, (%r13)
movq %rax, 0x8(%r13)
pushq $0x7
popq %rcx
pushq $0x2
popq %rsi
cmpq $0x0, 0x60(%rbx)
je 0x602b
xorl %r8d, %r8d
movl %ecx, %edi
cmpl %edi, %r8d
jg 0x600e
leal (%r8,%rdi), %eax
cltd
idivl %esi
movslq %eax, %rdx
cmpq $0x0, 0x20(%rbx,%rdx,8)
je 0x6008
movl (%rbx,%rdx,4), %edx
cmpl %ebp, %edx
jg 0x6008
incl %eax
movl %eax, %r8d
cmpl %ebp, %edx
jne 0x5fdf
jmp 0x6018
decl %eax
movl %eax, %edi
jmp 0x5fdf
movslq %edi, %rax
movq 0x68(%rbx,%rax,8), %rbx
jmp 0x5fd3
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x58f4
movl %eax, %edx
decl %edx
xorl %esi, %esi
xorl %ecx, %ecx
cmpl %edx, %esi
jg 0x605e
leal (%rdx,%rsi), %edi
shrl %edi
movl (%rbx,%rdi,4), %r8d
cmpl %ebp, %r8d
jle 0x6053
decl %edi
movl %edi, %edx
jmp 0x603b
incl %edi
movl %edi, %esi
cmpl %ebp, %r8d
jne 0x603b
jmp 0x601a
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq %r13, 0x10(%rsp)
cmpl $0x8, %eax
jne 0x627c
movq %r13, %rdi
callq 0x62e2
movq %rax, %r12
movq 0xa8(%rbx), %rax
movq %rax, 0xa8(%r12)
xorl %eax, %eax
cmpq $0x10, %rax
je 0x60df
movl 0x10(%rbx,%rax), %ecx
movl %ecx, (%r12,%rax)
movq 0x40(%rbx,%rax,2), %rcx
movq %rcx, 0x20(%r12,%rax,2)
movq 0x88(%rbx,%rax,2), %rdx
movq %rdx, 0x68(%r12,%rax,2)
testq %rdx, %rdx
je 0x60cf
movq %r12, 0xa8(%rdx)
movq 0x20(%r12,%rax,2), %rcx
movq %r12, 0x8(%rcx)
andq $0x0, 0x40(%rbx,%rax,2)
addq $0x4, %rax
jmp 0x6099
movl 0xc(%rbx), %r14d
cmpl %r14d, %ebp
jge 0x6138
movq %r15, %rsi
movq 0x38(%rbx), %r15
movq 0x80(%rbx), %rax
movq %rax, 0x60(%r12)
testq %rax, %rax
je 0x6107
movq %r12, 0xa8(%rax)
pushq $0x10
popq %rax
cmpq $0xd, %rax
je 0x6176
movl -0x38(%rbx,%rax,4), %ecx
cmpl %ecx, %ebp
jge 0x61b0
movl %ecx, -0x34(%rbx,%rax,4)
movq -0x50(%rbx,%rax,8), %rcx
movq -0x8(%rbx,%rax,8), %rdx
movq %rdx, (%rbx,%rax,8)
movq %rcx, -0x48(%rbx,%rax,8)
decq %rax
jmp 0x610a
movl (%r12), %r14d
cmpl %r14d, %ebp
jge 0x617a
movq (%rsp), %rcx
movq %rcx, 0x80(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0x60(%r12)
testq %rcx, %rcx
je 0x6162
movq %rbx, 0xa8(%rcx)
testq %rax, %rax
je 0x616e
movq %r12, 0xa8(%rax)
movl %ebp, %r14d
jmp 0x6216
xorl %eax, %eax
jmp 0x61b3
movq %r15, %rsi
movq 0x20(%r12), %r15
xorl %eax, %eax
cmpq $0x3, %rax
je 0x61d6
movl 0x4(%r12,%rax,4), %ecx
cmpl %ebp, %ecx
jge 0x61d9
movl %ecx, (%r12,%rax,4)
movq 0x28(%r12,%rax,8), %rcx
movq 0x68(%r12,%rax,8), %rdx
movq %rdx, 0x60(%r12,%rax,8)
movq %rcx, 0x20(%r12,%rax,8)
incq %rax
jmp 0x6184
addl $-0xd, %eax
cltq
movl %ebp, (%rbx,%rax,4)
movq %rsi, 0x20(%rbx,%rax,8)
movq %rbx, 0x8(%rsi)
movq (%rsp), %rcx
movq %rcx, 0x60(%rbx,%rax,8)
movq 0x8(%rsp), %rcx
movq %rcx, 0x68(%rbx,%rax,8)
jmp 0x6216
pushq $0x3
popq %rax
movl %eax, %eax
movl %ebp, (%r12,%rax,4)
movq %rsi, 0x20(%r12,%rax,8)
movq %r12, 0x8(%rsi)
movq (%rsp), %rdx
movq %rdx, 0x60(%r12,%rax,8)
movq 0x8(%rsp), %rcx
movq %rcx, 0x68(%r12,%rax,8)
movq %rcx, %rax
testq %rdx, %rdx
je 0x620a
movq %r12, 0xa8(%rdx)
testq %rax, %rax
je 0x6216
movq %r12, 0xa8(%rax)
movq 0xa8(%rbx), %r13
testq %r13, %r13
je 0x6243
movq %r13, %rdi
callq 0x58f4
movq %rbx, (%rsp)
movq %r12, 0x8(%rsp)
movq %r13, %rbx
movl %r14d, %ebp
movq 0x10(%rsp), %r13
jmp 0x6074
movq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x62e2
movq %rax, %rcx
movq %rax, (%r13)
movq %rax, 0xa8(%rbx)
movq %rax, 0xa8(%r12)
xorl %eax, %eax
movq %rbx, (%rsp)
movq %r12, 0x8(%rsp)
movq %rcx, %rbx
movl %r14d, %ebp
jmp 0x6074
movl %eax, %edx
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
movq (%rsp), %rdi
testl %edx, %edx
jle 0x62b3
movl -0x4(%rbx,%rdx,4), %eax
cmpl %ebp, %eax
jl 0x62b1
movl %eax, (%rbx,%rdx,4)
movq 0x18(%rbx,%rdx,8), %rax
movq 0x60(%rbx,%rdx,8), %rsi
movq %rax, 0x20(%rbx,%rdx,8)
movq %rsi, 0x68(%rbx,%rdx,8)
decq %rdx
jmp 0x6289
movl %edx, %ecx
movslq %ecx, %rax
movl %ebp, (%rbx,%rax,4)
movq %r15, 0x20(%rbx,%rax,8)
movq %rdi, 0x60(%rbx,%rax,8)
movq 0x8(%rsp), %rcx
movq %rcx, 0x68(%rbx,%rax,8)
movq %rbx, 0x8(%r15)
movb $0x1, %cl
jmp 0x601a
jmp 0x62da
movq %rax, %rdi
callq 0x42c3