// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rdx, %rbx
movq %rsi, %r12
movabsq $-0x40000000000000, %r13 # imm = 0xFFC0000000000000
movabsq $-0x7fc0000000000001, %r14 # imm = 0x803FFFFFFFFFFFFF
movabsq $0x3fffffffffffff, %rbp # imm = 0x3FFFFFFFFFFFFF
movq %rdx, %r15
subq %rsi, %r15
shrq $0x6, %r15
testq %rsi, %rsi
jne 0x12a8c
movq %rdi, %rbx
movq 0x40(%rdi), %rdi
callq 0x12611
movq %rbx, %rdi
movq %rax, %rbx
movq 0x8(%rax), %rax
andq %r14, %rax
addq %rbp, %rax
incq %rax
movq %rax, 0x8(%rbx)
movq 0x38(%rdi), %rcx
movq %rcx, (%rbx)
movups 0x8(%rdi), %xmm0
movups 0x18(%rdi), %xmm1
movups 0x28(%rdi), %xmm2
movups %xmm2, 0x30(%rbx)
movups %xmm1, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
pushq $0x2
popq %rcx
cmpq $0x8, %rcx
je 0x12a81
movq (%rbx,%rcx,8), %rdx
addq %rax, %rdx
andq %rbp, %rdx
andq %r13, %rax
orq %rdx, %rax
incq %rcx
jmp 0x12a66
movq %rax, 0x8(%rbx)
movq %rbx, 0x38(%rdi)
movq %rbx, %r12
movq 0x8(%r12), %rax
movq %rax, %rcx
shrq $0x36, %rcx
andl $0x1ff, %ecx            # imm = 0x1FF
leal -0x1(%rcx), %edx
cmpl %r15d, %edx
movq %rdi, (%rsp)
je 0x12ad0
leaq 0x80(%rbx), %rdi
leaq 0x40(%rbx), %rsi
notl %r15d
addl %r15d, %ecx
movslq %ecx, %rdx
shlq $0x6, %rdx
callq 0x2200
movq (%rsp), %rdi
movq 0x8(%r12), %rax
leaq (%rax,%rbp), %rcx
incq %rcx
movabsq $0x7fc0000000000000, %rdx # imm = 0x7FC0000000000000
andq %rcx, %rdx
andq %r14, %rax
orq %rdx, %rax
movq %rax, 0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
movq 0x8(%r12), %rax
shrq $0x3f, %rax
movq 0x40(%rdi,%rax,8), %rdi
callq 0x12611
movq %rax, %r15
movq %rax, 0x40(%rbx)
cmpq $0x0, 0x8(%r12)
movq (%rbx), %r12
js 0x12bee
movq (%rsp), %rcx
movl (%rcx), %eax
movq %rcx, %rdx
shrl %eax
movq 0x8(%r12), %rcx
movq %rcx, %rsi
shrq $0x36, %rsi
subl %eax, %esi
movl $0x1ff, %eax            # imm = 0x1FF
andl %eax, %esi
movq %rsi, %rax
shlq $0x36, %rax
andq %r14, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%r12)
shll $0x6, %esi
addq %r12, %rsi
movl (%rdx), %eax
sarl %eax
movslq %eax, %rdx
shlq $0x6, %rdx
movq %r15, %rdi
callq 0x2170
movq (%rsp), %rax
movl (%rax), %eax
shrl %eax
movl $0x1ff, %ecx            # imm = 0x1FF
andl %ecx, %eax
shlq $0x36, %rax
andq 0x8(%r15), %r14
orq %rax, %r14
movq %r14, 0x8(%r15)
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
incq %rax
andq 0x8(%r12), %rax
btrq $0x3f, %r14
orq %rax, %r14
movq %r14, 0x8(%r15)
movq %r15, %rax
addq $0x10, %rax
xorl %ecx, %ecx
shrq $0x36, %r14
andl $0x1ff, %r14d           # imm = 0x1FF
cmpq %r14, %rcx
jae 0x12c05
xorl %edx, %edx
cmpq $0x6, %rdx
je 0x12be1
movq (%rax,%rdx,8), %rsi
addq %rsi, 0x50(%rbx,%rdx,8)
incq %rdx
jmp 0x12bcd
incq %rcx
movq 0x8(%r15), %r14
addq $0x40, %rax
jmp 0x12bbb
movq %r12, %rdi
movq %r15, %rsi
callq 0x1354c
leaq 0x50(%rbx), %rsi
movq %r15, %rdi
callq 0x135a1
pushq $0x2
popq %rax
cmpq $0x8, %rax
je 0x12c31
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
jmp 0x12c08
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 $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq