// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_node.c
// Function: btree_node_dirty
struct node *
btree_node_dirty(struct btree * T, struct node * N)
{
	struct node * N_dirty;
	size_t i;

	/* Sanity check the node. */
	assert(node_present(N));
	assert(N->state == NODE_STATE_CLEAN);
	assert(pool_rec_lockcount(T->P, N) > 0);

	/* Notify the cleaner. */
	btree_cleaning_notify_dirtying(T->cstate, N);

	/* If we are not a root and p_dirty is clean, recurse up the tree. */
	if ((N->root == 0) &&
	    (N->p_dirty->state == NODE_STATE_CLEAN) &&
	    (btree_node_dirty(T, N->p_dirty) == NULL))
		goto err0;

	/* Allocate a new dirty node. */
	if ((N_dirty = btree_node_mknode(T, N->type, N->height, N->nkeys,
	    NULL, NULL, NULL)) == NULL)
		goto err0;

	/* Copy more node data. */
	N_dirty->root = N->root;
	N_dirty->mlen_t = N->mlen_t;
	N_dirty->mlen_n = N->mlen_n;
	N_dirty->p_dirty = N->p_dirty;

	/* The old node is now SHADOW. */
	N->state = NODE_STATE_SHADOW;
	N->p_dirty = NULL;
	btree_node_lock(T, N);

	/* The new node is dirty. */
	N_dirty->oldestncleaf = (uint64_t)(-1);
	N_dirty->p_shadow = NULL;

	/* Leaf or parent? */
	if (N->type == NODE_TYPE_LEAF) {
		/* Duplicate key-value pairs. */
		if (IMALLOC(N_dirty->u.pairs, N->nkeys, struct kvpair_const))
			goto err1;
		memcpy(N_dirty->u.pairs, N->u.pairs,
		    N->nkeys * sizeof(struct kvpair_const));
	} else {
		/* Duplicate keys. */
		if (IMALLOC(N_dirty->u.keys, N->nkeys,
		    const struct kvldskey *))
			goto err1;
		memcpy(N_dirty->u.keys, N->u.keys,
		    N->nkeys * sizeof(const struct kvldskey *));

		/* Copy child vector. */
		if (IMALLOC(N_dirty->v.children, N->nkeys + 1, struct node *))
			goto err2;
		memcpy(N_dirty->v.children, N->v.children,
		    (N->nkeys + 1) * sizeof(struct node *));

		/* Tell children (if any) about their new dirty parent. */
		for (i = 0; i <= N_dirty->nkeys; i++) {
			if (node_hasplock(N_dirty->v.children[i]))
				btree_node_unlock(T, N);
			N_dirty->v.children[i]->p_dirty = N_dirty;
			if (node_hasplock(N_dirty->v.children[i]))
				btree_node_lock(T, N_dirty);
		}
	}

	/* Update the dirty tree structure. */
	if (N_dirty->root == 0) {
		for (i = 0; i <= N_dirty->p_dirty->nkeys; i++)
			if (N_dirty->p_dirty->v.children[i] == N)
				N_dirty->p_dirty->v.children[i] = N_dirty;
	} else {
		btree_node_unlock(T, T->root_dirty);
		T->root_dirty = N_dirty;
		btree_node_lock(T, T->root_dirty);
	}

	/* Success! */
	return (N_dirty);

err2:
	free(N_dirty->u.keys);
err1:
	pool_rec_free(T->P, N_dirty);
	node_free(N_dirty);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movb 0x1c(%rsi), %al
testb $0x2, %al
jne 0x9326
testb $0xc, %al
jne 0x9345
movq %rsi, %r15
movq %rdi, %r14
movq 0x30(%rdi), %rdi
callq 0x107ac
testq %rax, %rax
je 0x9364
movq 0x40(%r14), %rdi
movq %r15, %rsi
callq 0x7096
movb 0x1c(%r15), %al
testb $0x10, %al
jne 0x8fca
movq 0x28(%r15), %rsi
testb $0xc, 0x1c(%rsi)
jne 0x8fca
movq %r14, %rdi
callq 0x8f61
testq %rax, %rax
je 0x91db
movb 0x1c(%r15), %al
andb $0x3, %al
movzbl %al, %esi
movsbl 0x1d(%r15), %edx
movq 0x38(%r15), %rcx
movq $0x0, (%rsp)
xorl %ebx, %ebx
movq %r14, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x8a48
testq %rax, %rax
je 0x92f5
movq %rax, %r12
movq %rax, %rbx
movb 0x1c(%r15), %al
andb $0x10, %al
movb 0x1c(%r12), %cl
andb $-0x11, %cl
orb %al, %cl
movb %cl, 0x1c(%r12)
movb 0x1e(%r15), %al
movb %al, 0x1e(%r12)
movb 0x1f(%r15), %al
movb %al, 0x1f(%r12)
movq 0x28(%r15), %rax
movq %rax, 0x28(%r12)
movb 0x1c(%r15), %al
andb $-0xd, %al
orb $0x4, %al
movb %al, 0x1c(%r15)
movq $0x0, 0x28(%r15)
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x9066
movq %r15, %rsi
callq 0x1070f
movq $-0x1, 0x10(%rbx)
movq $0x0, 0x20(%rbx)
movb 0x1c(%r15), %al
andb $0x3, %al
movq 0x38(%r15), %rdi
cmpb $0x1, %al
jne 0x90bd
testq %rdi, %rdi
je 0x90a1
movq %rdi, %rax
shrq $0x3c, %rax
je 0x9126
callq 0x20a0
movl $0xc, (%rax)
movq $0x0, 0x40(%rbx)
cmpq $0x0, 0x38(%r15)
jne 0x91c7
xorl %edx, %edx
xorl %edi, %edi
jmp 0x9147
testq %rdi, %rdi
je 0x90da
movq %rdi, %rax
shrq $0x3d, %rax
je 0x9155
callq 0x20a0
movl $0xc, (%rax)
leaq 0x40(%r12), %rbp
movq $0x0, 0x40(%rbx)
cmpq $0x0, 0x38(%r15)
jne 0x91c7
movl $0x1, %r13d
shlq $0x3, %r13
movq %r13, %rdi
callq 0x22a0
addq $0x48, %r12
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x91b7
movq 0x38(%r15), %rcx
leaq 0x8(,%rcx,8), %rdx
jmp 0x91e6
shlq $0x4, %rdi
callq 0x22a0
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x90a9
movq %rax, %rdi
movq 0x38(%r15), %rdx
shlq $0x4, %rdx
movq 0x40(%r15), %rsi
callq 0x2280
jmp 0x927b
shlq $0x3, %rdi
callq 0x22a0
leaq 0x40(%r12), %rbp
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x90e7
movq 0x38(%r15), %r13
movq 0x40(%r15), %rsi
leaq (,%r13,8), %rdx
movq %rax, %rdi
callq 0x2280
incq %r13
je 0x91ab
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %r13
jbe 0x90f8
callq 0x20a0
movl $0xc, (%rax)
addq $0x48, %r12
movq $0x0, 0x48(%rbx)
cmpq $-0x1, 0x38(%r15)
je 0x91e2
movq (%rbp), %rdi
callq 0x2040
movq 0x30(%r14), %rdi
movq %rbx, %rsi
callq 0x10770
movq %rbx, %rdi
callq 0xab9b
xorl %ebx, %ebx
jmp 0x92f5
xorl %edx, %edx
xorl %eax, %eax
movq 0x48(%r15), %rsi
movq %rax, %rdi
callq 0x2280
xorl %r13d, %r13d
movq (%r12), %rax
movq (%rax,%r13,8), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
cmpb $0x2, %al
je 0x922e
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9307
decq %rcx
movq %rcx, (%rax)
jne 0x922e
movq %r15, %rsi
callq 0x107ea
movq 0x48(%rbx), %rax
movq (%rax,%r13,8), %rax
movq %rbx, 0x28(%rax)
movq 0x48(%rbx), %rax
movq (%rax,%r13,8), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
cmpb $0x2, %al
je 0x926e
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x926e
movq %rbx, %rsi
callq 0x1070f
incq %r13
cmpq 0x38(%rbx), %r13
jbe 0x91f5
testb $0x10, 0x1c(%rbx)
jne 0x92a4
movq 0x28(%rbx), %rcx
xorl %eax, %eax
movq 0x48(%rcx), %rdx
cmpq %r15, (%rdx,%rax,8)
jne 0x9299
movq %rbx, (%rdx,%rax,8)
movq 0x28(%rbx), %rcx
incq %rax
cmpq 0x38(%rcx), %rax
jbe 0x9287
jmp 0x92f5
movq 0x28(%r14), %rsi
movq 0x30(%r14), %rdi
testq %rsi, %rsi
je 0x92d2
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9307
decq %rcx
movq %rcx, (%rax)
jne 0x92d2
callq 0x107ea
movq 0x30(%r14), %rdi
movq %rbx, 0x28(%r14)
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x92f5
movq %rbx, %rsi
callq 0x1070f
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb342(%rip), %rdi      # 0x14650
leaq 0xb361(%rip), %rsi      # 0x14676
leaq 0xb373(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
leaq 0xbddd(%rip), %rdi      # 0x1510a
leaq 0xbced(%rip), %rsi      # 0x15021
leaq 0xbddf(%rip), %rcx      # 0x1511a
movl $0x1c8, %edx            # imm = 0x1C8
callq 0x21c0
leaq 0xbe0b(%rip), %rdi      # 0x15157
leaq 0xbcce(%rip), %rsi      # 0x15021
leaq 0xbdc0(%rip), %rcx      # 0x1511a
movl $0x1c9, %edx            # imm = 0x1C9
callq 0x21c0
leaq 0xbe09(%rip), %rdi      # 0x15174
leaq 0xbcaf(%rip), %rsi      # 0x15021
leaq 0xbda1(%rip), %rcx      # 0x1511a
movl $0x1ca, %edx            # imm = 0x1CA
callq 0x21c0