// File: /workspace/github_c_makefile_star2_O3/lh3[P]fermi-lite/rope.c
// Function: split_node
static inline rpnode_t *split_node(rope_t *rope, rpnode_t *u, rpnode_t *v)
{ // split $v's child. $u is the first node in the bucket. $v and $u are in the same bucket. IMPORTANT: there is always enough room in $u
	int j, i = v - u;
	rpnode_t *w; // $w is the sibling of $v
	if (u == 0) { // only happens at the root; add a new root
		u = v = mp_alloc(rope->node);
		v->n = 1; v->p = rope->root; // the new root has the old root as the only child
		memcpy(v->c, rope->c, 48);
		for (j = 0; j < 6; ++j) v->l += v->c[j];
		rope->root = v;
	}
	if (i != u->n - 1) // then make room for a new node
		memmove(v + 2, v + 1, sizeof(rpnode_t) * (u->n - i - 1));
	++u->n; w = v + 1;
	memset(w, 0, sizeof(rpnode_t));
	w->p = mp_alloc(u->is_bottom? rope->leaf : rope->node);
	if (u->is_bottom) { // we are at the bottom level; $v->p is a string instead of a node
		uint8_t *p = (uint8_t*)v->p, *q = (uint8_t*)w->p;
		rle_split(p, q);
		rle_count(q, w->c);
	} else { // $v->p is a node, not a string
		rpnode_t *p = v->p, *q = w->p; // $v and $w are siblings and thus $p and $q are cousins
		p->n -= rope->max_nodes>>1;
		memcpy(q, p + p->n, sizeof(rpnode_t) * (rope->max_nodes>>1));
		q->n = rope->max_nodes>>1; // NB: this line must below memcpy() as $q->n and $q->is_bottom are modified by memcpy()
		q->is_bottom = p->is_bottom;
		for (i = 0; i < q->n; ++i)
			for (j = 0; j < 6; ++j)
				w->c[j] += q[i].c[j];
	}
	for (j = 0; j < 6; ++j) // compute $w->l and update $v->c
		w->l += w->c[j], v->c[j] -= w->c[j];
	v->l -= w->l; // update $v->c
	return v;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rdi, %r15
movabsq $-0x40000000000000, %r13 # imm = 0xFFC0000000000000
movabsq $-0x7fc0000000000001, %r14 # imm = 0x803FFFFFFFFFFFFF
movabsq $0x3fffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFF
movq %rdx, %r12
subq %rsi, %r12
shrq $0x6, %r12
testq %rsi, %rsi
movq %rdi, 0x10(%rsp)
jne 0x156d7
movq 0x40(%r15), %r15
movl 0x4(%r15), %eax
movq 0x10(%r15), %rbx
cmpl 0x8(%r15), %eax
jne 0x15627
incq %rbx
movq %rbx, 0x10(%r15)
cmpq 0x18(%r15), %rbx
jne 0x1562c
leaq (%rbx,%rbx), %rax
testq %rbx, %rbx
movl $0x1, %esi
cmovneq %rax, %rsi
movq %rsi, 0x18(%r15)
movq 0x20(%r15), %rdi
shlq $0x3, %rsi
callq 0x21c0
movq %rax, (%rsp)
movq %rax, 0x20(%r15)
movl 0x8(%r15), %eax
movq 0x10(%r15), %rbx
jmp 0x15634
movl (%r15), %r14d
jmp 0x1564c
movq 0x20(%r15), %rcx
movq %rcx, (%rsp)
movslq %eax, %rdi
movl (%r15), %r14d
movslq %r14d, %rsi
callq 0x2130
movq (%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
xorl %eax, %eax
movq 0x20(%r15), %rcx
movq (%rcx,%rbx,8), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x4(%r15)
imull %eax, %r14d
movslq %r14d, %rdx
leaq (%rcx,%rdx), %rbx
movq 0x8(%rcx,%rdx), %rax
movabsq $-0x7fc0000000000001, %r14 # imm = 0x803FFFFFFFFFFFFF
andq %r14, %rax
addq %rbp, %rax
incq %rax
movq %rax, 0x8(%rcx,%rdx)
movq 0x10(%rsp), %r15
movq 0x38(%r15), %rsi
movq %rsi, (%rcx,%rdx)
movups 0x8(%r15), %xmm0
movups 0x18(%r15), %xmm1
movups 0x28(%r15), %xmm2
movups %xmm0, 0x10(%rcx,%rdx)
movups %xmm1, 0x20(%rcx,%rdx)
movups %xmm2, 0x30(%rcx,%rdx)
movl $0x2, %ecx
movq (%rbx,%rcx,8), %rdx
addq %rax, %rdx
andq %rbp, %rdx
andq %r13, %rax
orq %rdx, %rax
incq %rcx
cmpq $0x8, %rcx
jne 0x156b3
movq %rax, 0x8(%rbx)
movq %rbx, 0x38(%r15)
movq %rbx, %rsi
movq 0x8(%rsi), %rax
movq %rax, %rcx
shrq $0x36, %rcx
andl $0x1ff, %ecx            # imm = 0x1FF
leal -0x1(%rcx), %edx
cmpl %r12d, %edx
movq %rsi, (%rsp)
je 0x15719
leaq 0x80(%rbx), %rdi
leaq 0x40(%rbx), %rsi
notl %r12d
addl %r12d, %ecx
movslq %ecx, %rdx
shlq $0x6, %rdx
callq 0x2200
movq (%rsp), %rsi
movq 0x8(%rsi), %rax
leaq (%rax,%rbp), %rcx
incq %rcx
movabsq $0x7fc0000000000000, %rdx # imm = 0x7FC0000000000000
andq %rcx, %rdx
andq %r14, %rax
orq %rdx, %rax
movq %rax, 0x8(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
movq 0x8(%rsi), %rax
shrq $0x3f, %rax
movq 0x40(%r15,%rax,8), %r12
movl 0x4(%r12), %eax
movq 0x10(%r12), %r14
cmpl 0x8(%r12), %eax
jne 0x157b0
incq %r14
movq %r14, 0x10(%r12)
cmpq 0x18(%r12), %r14
jne 0x157b6
leaq (%r14,%r14), %rax
testq %r14, %r14
movl $0x1, %esi
cmovneq %rax, %rsi
movq %rsi, 0x18(%r12)
movq 0x20(%r12), %rdi
shlq $0x3, %rsi
callq 0x21c0
movq %rax, 0x8(%rsp)
movq %rax, 0x20(%r12)
movl 0x8(%r12), %eax
movq 0x10(%r12), %r14
jmp 0x157c0
movl (%r12), %r15d
jmp 0x157de
movq 0x20(%r12), %rcx
movq %rcx, 0x8(%rsp)
movslq %eax, %rdi
movl (%r12), %r15d
movslq %r15d, %rsi
callq 0x2130
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
xorl %eax, %eax
movq (%rsp), %rsi
movq 0x20(%r12), %rcx
movq (%rcx,%r14,8), %rdx
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r12)
imull %eax, %r15d
movslq %r15d, %rax
leaq (%rdx,%rax), %r12
movq %r12, 0x40(%rbx)
cmpq $0x0, 0x8(%rsi)
movq (%rbx), %r15
js 0x158f2
movq %rax, 0x8(%rsp)
movq %rdx, (%rsp)
movq 0x10(%rsp), %rcx
movl (%rcx), %eax
movq %rcx, %rdx
shrl %eax
movq 0x8(%r15), %rcx
movq %rcx, %rsi
shrq $0x36, %rsi
subl %eax, %esi
movl $0x1ff, %eax            # imm = 0x1FF
andl %eax, %esi
movq %rsi, %rax
shlq $0x36, %rax
movabsq $-0x7fc0000000000001, %r14 # imm = 0x803FFFFFFFFFFFFF
andq %r14, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%r15)
shll $0x6, %esi
addq %r15, %rsi
movl (%rdx), %eax
sarl %eax
movslq %eax, %rdx
shlq $0x6, %rdx
movq %r12, %rdi
callq 0x2170
movq 0x10(%rsp), %rax
movl (%rax), %eax
shrl %eax
movl $0x1ff, %ecx            # imm = 0x1FF
andl %ecx, %eax
movq %rax, %rcx
shlq $0x36, %rcx
andq 0x8(%r12), %r14
orq %rcx, %r14
movq %r14, 0x8(%r12)
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
incq %rcx
andq 0x8(%r15), %rcx
btrq $0x3f, %r14
orq %rcx, %r14
movq %r14, 0x8(%r12)
testl %eax, %eax
je 0x15909
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
addq %rcx, %rax
addq $0x10, %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
addq %rsi, 0x50(%rbx,%rdx,8)
incq %rdx
cmpq $0x6, %rdx
jne 0x158c3
incq %rcx
movq 0x8(%r12), %rdx
shrq $0x36, %rdx
andl $0x1ff, %edx            # imm = 0x1FF
addq $0x40, %rax
cmpq %rdx, %rcx
jb 0x158c1
jmp 0x15909
movq %r15, %rdi
movq %r12, %rsi
callq 0x168ab
leaq 0x50(%rbx), %rsi
movq %r12, %rdi
callq 0x16900
movl $0x2, %eax
movq 0x40(%rbx,%rax,8), %rcx
movq 0x48(%rbx), %rdx
leaq (%rdx,%rcx), %rsi
andq %rbp, %rsi
andq %r13, %rdx
orq %rsi, %rdx
movq %rdx, 0x48(%rbx)
subq %rcx, (%rbx,%rax,8)
incq %rax
cmpq $0x8, %rax
jne 0x1590e
movq 0x8(%rbx), %rax
andq %rax, %r13
subq 0x48(%rbx), %rax
andq %rbp, %rax
orq %rax, %r13
movq %r13, 0x8(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq