// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq %rsi, %r8
movq %rdi, %r15
movq (%rdi), %rbp
testq %rbp, %rbp
jne 0x62f2
movq 0x10(%r15), %rbp
movq 0xa8(%rbp), %rax
movq %rax, 0x10(%r15)
leaq 0x20(%rbp), %rdi
movl $0x90, %edx
xorl %esi, %esi
movq %r8, %r14
callq 0x3140
movq %r14, %r8
movq %rbp, (%r15)
movq %rbp, 0x8(%r15)
cmpq $0x0, 0x60(%rbp)
je 0x6343
xorl %ecx, %ecx
movl $0x7, %eax
cmpl %eax, %ecx
jg 0x6333
leal (%rcx,%rax), %esi
movl %esi, %edx
shrl $0x1f, %edx
addl %esi, %edx
sarl %edx
movslq %edx, %rsi
cmpq $0x0, 0x20(%rbp,%rsi,8)
je 0x632d
movl (%rbp,%rsi,4), %esi
cmpl %ebx, %esi
jg 0x632d
incl %edx
movl %edx, %ecx
cmpl %ebx, %esi
jne 0x6300
jmp 0x633c
decl %edx
movl %edx, %eax
jmp 0x6300
cltq
movq 0x68(%rbp,%rax,8), %rbp
jmp 0x62f2
xorl %eax, %eax
jmp 0x6613
movl $0x8, %r14d
leal -0x1(%r14), %eax
cmpq $0x0, 0x20(%rbp,%rax,8)
jne 0x635d
decl %r14d
jne 0x6349
xorl %r14d, %r14d
leal -0x1(%r14), %ecx
xorl %edx, %edx
xorl %eax, %eax
cmpl %ecx, %edx
jg 0x638c
leal (%rcx,%rdx), %esi
shrl %esi
movl (%rbp,%rsi,4), %edi
cmpl %ebx, %edi
jle 0x637f
leal -0x1(%rsi), %ecx
cmpl %esi, %edx
jl 0x6369
jmp 0x638c
incl %esi
movl %esi, %edx
cmpl %ebx, %edi
jne 0x6365
jmp 0x6613
cmpl $0x8, %r14d
jne 0x65b7
movq %r15, 0x10(%rsp)
xorl %eax, %eax
movl %ebx, %r15d
movq %r8, %rcx
xorl %edx, %edx
movq %rax, 0x8(%rsp)
movq %rdx, %r14
movq %rcx, (%rsp)
movq %rbp, %r12
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %r13
movq 0xa8(%r13), %rax
movq %rax, 0x10(%rcx)
leaq 0x20(%r13), %rdi
movl $0x90, %edx
xorl %esi, %esi
callq 0x3140
movq 0xa8(%rbp), %rax
movq %rax, 0xa8(%r13)
xorl %eax, %eax
movl 0x10(%r12,%rax), %ecx
movl %ecx, (%r13,%rax)
movq 0x40(%r12,%rax,2), %rcx
movq %rcx, 0x20(%r13,%rax,2)
movq 0x88(%r12,%rax,2), %rdx
movq %rdx, 0x68(%r13,%rax,2)
testq %rdx, %rdx
je 0x641a
movq %r13, 0xa8(%rdx)
movq 0x20(%r13,%rax,2), %rcx
movq %r13, 0x8(%rcx)
movq $0x0, 0x40(%r12,%rax,2)
addq $0x4, %rax
cmpq $0x10, %rax
jne 0x63e8
movl 0xc(%r12), %ebx
cmpl %ebx, %r15d
jge 0x6494
movq 0x38(%r12), %r8
movq 0x80(%r12), %rax
movq %rax, 0x60(%r13)
testq %rax, %rax
je 0x6458
movq %r13, 0xa8(%rax)
movl $0x10, %eax
movl -0x38(%r12,%rax,4), %ecx
cmpl %ecx, %r15d
jge 0x64d5
movl %ecx, -0x34(%r12,%rax,4)
movq -0x50(%r12,%rax,8), %rcx
movq -0x8(%r12,%rax,8), %rdx
movq %rdx, (%r12,%rax,8)
movq %rcx, -0x48(%r12,%rax,8)
leaq -0x1(%rax), %rcx
addq $-0xd, %rax
cmpq $0x1, %rax
movq %rcx, %rax
ja 0x645d
xorl %eax, %eax
jmp 0x64d8
movl (%r13), %ebx
cmpl %ebx, %r15d
movq %r14, %rsi
jge 0x64fc
movq %rsi, 0x80(%r12)
movq 0x8(%rsp), %r14
movq %r14, 0x60(%r13)
testq %rsi, %rsi
movq (%rsp), %r8
je 0x64c1
movq %r12, 0xa8(%rsi)
testq %r14, %r14
je 0x64cd
movq %r13, 0xa8(%r14)
movl %r15d, %ebx
jmp 0x6575
addl $-0xd, %eax
cltq
movl %r15d, (%r12,%rax,4)
movq (%rsp), %rcx
movq %rcx, 0x20(%r12,%rax,8)
movq %r12, 0x8(%rcx)
movq %r14, 0x60(%r12,%rax,8)
movq 0x8(%rsp), %rcx
movq %rcx, 0x68(%r12,%rax,8)
jmp 0x6575
movq 0x20(%r13), %r8
xorl %eax, %eax
movl 0x4(%r13,%rax,4), %ecx
cmpl %r15d, %ecx
jge 0x6537
movl %ecx, (%r13,%rax,4)
movq 0x28(%r13,%rax,8), %rcx
movq 0x68(%r13,%rax,8), %rdx
movq %rdx, 0x60(%r13,%rax,8)
movq %rcx, 0x20(%r13,%rax,8)
leaq 0x1(%rax), %rcx
movq %rcx, %rax
cmpq $0x3, %rcx
jne 0x6502
movl $0x3, %eax
movl %eax, %eax
movl %r15d, (%r13,%rax,4)
movq (%rsp), %rcx
movq %rcx, 0x20(%r13,%rax,8)
movq %r13, 0x8(%rcx)
movq %rsi, 0x60(%r13,%rax,8)
movq 0x8(%rsp), %r14
movq %r14, 0x68(%r13,%rax,8)
movq %r14, %rax
testq %rsi, %rsi
je 0x6569
movq %r13, 0xa8(%rsi)
testq %rax, %rax
je 0x6575
movq %r13, 0xa8(%rax)
movq 0xa8(%r12), %rbp
testq %rbp, %rbp
je 0x6622
movl $0x8, %r14d
leal -0x1(%r14), %eax
cmpq $0x0, 0x20(%rbp,%rax,8)
jne 0x659f
decl %r14d
jne 0x658c
jmp 0x65f4
movl %ebx, %r15d
movq %r8, %rcx
movq %r13, %rax
movq %r12, %rdx
cmpl $0x8, %r14d
je 0x63a5
jmp 0x65bd
xorl %r12d, %r12d
xorl %r13d, %r13d
testl %r14d, %r14d
jle 0x65f7
movl %r14d, %r14d
movl -0x4(%rbp,%r14,4), %eax
cmpl %ebx, %eax
jl 0x65f7
movl %eax, (%rbp,%r14,4)
movq 0x18(%rbp,%r14,8), %rax
movq 0x60(%rbp,%r14,8), %rcx
movq %rax, 0x20(%rbp,%r14,8)
movq %rcx, 0x68(%rbp,%r14,8)
decq %r14
leaq 0x1(%r14), %rax
cmpq $0x1, %rax
ja 0x65c5
xorl %r14d, %r14d
movslq %r14d, %rax
movl %ebx, (%rbp,%rax,4)
movq %r8, 0x20(%rbp,%rax,8)
movq %r12, 0x60(%rbp,%rax,8)
movq %r13, 0x68(%rbp,%rax,8)
movq %rbp, 0x8(%r8)
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r15
movq 0x10(%r15), %rbp
movq 0xa8(%rbp), %rax
movq %rax, 0x10(%r15)
leaq 0x20(%rbp), %rdi
xorl %r14d, %r14d
movl $0x90, %edx
xorl %esi, %esi
movq %r8, (%rsp)
callq 0x3140
movq (%rsp), %r8
movq %rbp, (%r15)
movq %rbp, 0xa8(%r12)
movq %rbp, 0xa8(%r13)
jmp 0x65f7
nop