// File: /workspace/github_c_makefile_star2_O1/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 %rsi, %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, (%rsp)
jne 0x15033
movq 0x40(%rdi), %rbx
movl 0x4(%rbx), %eax
cmpl 0x8(%rbx), %eax
jne 0x14fb3
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rax
incq %rcx
movq %rcx, 0x10(%rbx)
cmpq %rax, %rcx
jne 0x14f90
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x1, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x18(%rbx)
movq 0x20(%rbx), %rdi
shlq $0x3, %rsi
callq 0x21d0
movq %rax, 0x20(%rbx)
movslq 0x8(%rbx), %rdi
movslq (%rbx), %rsi
callq 0x2130
movq 0x10(%rbx), %rcx
movq 0x20(%rbx), %rdx
movq %rax, (%rdx,%rcx,8)
movl $0x0, 0x4(%rbx)
movq (%rsp), %rdi
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
movslq 0x4(%rbx), %rax
leal 0x1(%rax), %edx
movl %edx, 0x4(%rbx)
movslq (%rbx), %rdx
imulq %rax, %rdx
leaq (%rcx,%rdx), %rbx
movq 0x8(%rcx,%rdx), %rax
andq %r14, %rax
addq %rbp, %rax
incq %rax
movq %rax, 0x8(%rcx,%rdx)
movq 0x38(%rdi), %rsi
movq %rsi, (%rcx,%rdx)
movups 0x8(%rdi), %xmm0
movups 0x18(%rdi), %xmm1
movups 0x28(%rdi), %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 0x1500f
movq %rax, 0x8(%rbx)
movq %rbx, 0x38(%rdi)
movq %rbx, %r15
movq 0x8(%r15), %rax
shrq $0x36, %rax
andl $0x1ff, %eax            # imm = 0x1FF
leal -0x1(%rax), %ecx
cmpl %r12d, %ecx
je 0x15069
leaq 0x80(%rbx), %rdi
leaq 0x40(%rbx), %rsi
notl %r12d
addl %r12d, %eax
movslq %eax, %rdx
shlq $0x6, %rdx
callq 0x2210
movq (%rsp), %rdi
movq 0x8(%r15), %rax
leaq (%rax,%rbp), %rcx
incq %rcx
movabsq $0x7fc0000000000000, %rdx # imm = 0x7FC0000000000000
andq %rcx, %rdx
andq %r14, %rax
orq %rdx, %rax
movq %rax, 0x8(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x40(%rbx)
movq 0x8(%r15), %rax
shrq $0x3f, %rax
movq 0x40(%rdi,%rax,8), %r12
movl 0x4(%r12), %eax
cmpl 0x8(%r12), %eax
jne 0x1511f
movq 0x10(%r12), %rcx
movq 0x18(%r12), %rax
incq %rcx
movq %rcx, 0x10(%r12)
cmpq %rax, %rcx
jne 0x150f6
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x1, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x18(%r12)
movq 0x20(%r12), %rdi
shlq $0x3, %rsi
callq 0x21d0
movq %rax, 0x20(%r12)
movslq 0x8(%r12), %rdi
movslq (%r12), %rsi
callq 0x2130
movq 0x10(%r12), %rcx
movq 0x20(%r12), %rdx
movq %rax, (%rdx,%rcx,8)
movl $0x0, 0x4(%r12)
movq (%rsp), %rdi
movq 0x20(%r12), %rax
movq 0x10(%r12), %rcx
movq (%rax,%rcx,8), %rdx
movl 0x4(%r12), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%r12)
imull (%r12), %eax
cltq
leaq (%rdx,%rax), %r12
movq %r12, 0x40(%rbx)
cmpq $0x0, 0x8(%r15)
movq (%rbx), %r15
js 0x1522c
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movl (%rdi), %eax
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
andq %r14, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%r15)
shll $0x6, %esi
addq %r15, %rsi
movl (%rdi), %eax
sarl %eax
movslq %eax, %rdx
shlq $0x6, %rdx
movq %r12, %rdi
callq 0x2180
movq (%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 0x15243
movq 0x10(%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 0x151fd
incq %rcx
movq 0x8(%r12), %rdx
shrq $0x36, %rdx
andl $0x1ff, %edx            # imm = 0x1FF
addq $0x40, %rax
cmpq %rdx, %rcx
jb 0x151fb
jmp 0x15243
movq %r15, %rdi
movq %r12, %rsi
callq 0x15fa8
leaq 0x50(%rbx), %rsi
movq %r12, %rdi
callq 0x15ffd
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 0x15248
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