// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, (%rax)
jne 0xa8e4
movq -0x98(%rbp), %rdi
callq 0xb030
movq %rax, -0xa0(%rbp)
jmp 0xa8cc
movq -0x98(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb070
xorb $-0x1, %al
testb $0x1, %al
jne 0xa906
jmp 0xa999
movl $0x0, -0x2c(%rbp)
movl $0x7, -0x30(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0xa97e
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpq $0x0, 0x20(%rax,%rcx,8)
je 0xa94d
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x34(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xa958
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xa97c
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
jne 0xa971
movb $0x0, -0x1(%rbp)
jmp 0xb016
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xa97c
jmp 0xa914
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x60(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0xa8f2
movq -0x28(%rbp), %rdi
callq 0x9470
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0xaa0f
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x44(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xa9e9
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xaa0d
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
jne 0xaa02
movb $0x0, -0x1(%rbp)
jmp 0xb016
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xaa0d
jmp 0xa9b5
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpl $0x8, -0x38(%rbp)
jne 0xaf05
movq -0x98(%rbp), %rdi
callq 0xb030
movq %rax, -0xa8(%rbp)
jmp 0xaa46
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq 0xa8(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0xa8(%rax)
movl $0x4, -0x6c(%rbp)
cmpl $0x8, -0x6c(%rbp)
jge 0xab4a
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movq -0x28(%rbp), %rax
movl -0x6c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x60(%rax,%rcx,8), %rdx
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x4, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x4, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq $0x0, 0x60(%rax,%rcx,8)
je 0xab11
movq -0x68(%rbp), %rcx
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %edx
subl $0x4, %edx
addl $0x1, %edx
movslq %edx, %rdx
movq 0x60(%rax,%rdx,8), %rax
movq %rcx, 0xa8(%rax)
movq -0x68(%rbp), %rcx
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %edx
subl $0x4, %edx
movslq %edx, %rdx
movq 0x20(%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq $0x0, 0x20(%rax,%rcx,8)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xaa6e
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xacaa
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movq 0x80(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x68(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0xaba1
movq -0x68(%rbp), %rcx
movq -0x68(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0xa8(%rax)
movl $0x3, -0x7c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x7c(%rbp)
movb %al, -0xa9(%rbp)
jle 0xabd2
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
movl -0x7c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
setl %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0xabde
jmp 0xac45
movq -0x28(%rbp), %rax
movl -0x7c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq 0x60(%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movl -0x7c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x28(%rbp), %rax
movl -0x7c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movl -0x7c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xaba8
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x60(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x58(%rbp), %rdx
movq -0x28(%rbp), %rax
movl -0x7c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x78(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xae7b
movl -0x1c(%rbp), %eax
movq -0x68(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xad01
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x60(%rax)
cmpq $0x0, -0x50(%rbp)
je 0xace6
movq -0x28(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0xa8(%rax)
cmpq $0x0, -0x58(%rbp)
je 0xacfc
movq -0x68(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0xa8(%rax)
jmp 0xae79
movq -0x68(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x80(%rbp)
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
xorl %eax, %eax
cmpl $0x3, -0x8c(%rbp)
movb %al, -0xaa(%rbp)
jge 0xad53
movq -0x68(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
setl %al
movb %al, -0xaa(%rbp)
movb -0xaa(%rbp), %al
testb $0x1, %al
jne 0xad5f
jmp 0xadde
movq -0x68(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x68(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x60(%rax,%rcx,8), %rdx
movq -0x68(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x68(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq -0x68(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0xad23
movl -0x1c(%rbp), %edx
movq -0x68(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rdx
movq -0x68(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x58(%rbp), %rdx
movq -0x68(%rbp), %rax
movl -0x8c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x60(%rax,%rcx,8)
cmpq $0x0, -0x50(%rbp)
je 0xae52
movq -0x68(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0xa8(%rax)
cmpq $0x0, -0x58(%rbp)
je 0xae68
movq -0x68(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xae7b
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xaef4
movq -0x98(%rbp), %rdi
callq 0xb030
movq %rax, -0xb8(%rbp)
jmp 0xaeb6
movq -0x98(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movq (%rax), %rdx
movq -0x50(%rbp), %rcx
movq %rdx, 0xa8(%rcx)
movq (%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0xa8(%rax)
movl $0x0, -0x38(%rbp)
jmp 0xaf00
movq -0x28(%rbp), %rdi
callq 0x9470
movl %eax, -0x38(%rbp)
jmp 0xaa27
movl -0x38(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
jle 0xafb4
movq -0x28(%rbp), %rax
movl -0x90(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
jge 0xaf35
jmp 0xafb4
movq -0x28(%rbp), %rax
movl -0x90(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x90(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movq 0x60(%rax,%rcx,8), %rdx
movq -0x28(%rbp), %rax
movl -0x90(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movl -0x90(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0xaf0e
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x60(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movq -0x50(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x90(%rbp), %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x58(%rbp), %rdx
movq -0x28(%rbp), %rax
movl -0x90(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0x52b0
nopl (%rax)