// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movb 0x1c(%rsi), %al
testb $0x2, %al
jne 0x9370
testb $0xc, %al
jne 0x938f
movq %rsi, %r14
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
callq 0x10847
testq %rax, %rax
je 0x93ae
movq 0x40(%rbx), %rdi
movq %r14, %rsi
callq 0x70e9
testb $0x10, 0x1c(%r14)
jne 0x9053
movq 0x28(%r14), %rsi
testb $0xc, 0x1c(%rsi)
jne 0x9053
movq %rbx, %rdi
callq 0x8fed
testq %rax, %rax
je 0x933d
movzbl 0x1c(%r14), %esi
andl $0x3, %esi
movsbl 0x1d(%r14), %edx
movq 0x38(%r14), %rcx
movq $0x0, (%rsp)
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x8ac8
testq %rax, %rax
je 0x9340
movq %rax, %r15
movb 0x1c(%r14), %al
andb $0x10, %al
movb 0x1c(%r15), %cl
andb $-0x11, %cl
orb %al, %cl
movb %cl, 0x1c(%r15)
movb 0x1e(%r14), %al
movb %al, 0x1e(%r15)
movb 0x1f(%r14), %al
movb %al, 0x1f(%r15)
movq 0x28(%r14), %rax
movq %rax, 0x28(%r15)
movb 0x1c(%r14), %al
andb $-0xd, %al
orb $0x4, %al
movb %al, 0x1c(%r14)
movq $0x0, 0x28(%r14)
testq %r14, %r14
je 0x90f0
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x90f0
movq %r14, %rsi
callq 0x107a3
movq $-0x1, 0x10(%r15)
movq $0x0, 0x20(%r15)
movb 0x1c(%r14), %al
andb $0x3, %al
movq 0x38(%r14), %rdi
cmpb $0x1, %al
jne 0x912b
testq %rdi, %rdi
je 0x9127
movq %rdi, %rax
shrq $0x3c, %rax
je 0x914e
callq 0x20a0
movl $0xc, (%rax)
xorl %edi, %edi
jmp 0x915a
movabsq $0x1fffffffffffffff, %r13 # imm = 0x1FFFFFFFFFFFFFFF
testq %rdi, %rdi
je 0x914a
cmpq %r13, %rdi
jbe 0x9186
callq 0x20a0
movl $0xc, (%rax)
xorl %edi, %edi
jmp 0x9192
shlq $0x4, %rdi
callq 0x22a0
movq %rax, %rdi
movq %rdi, 0x40(%r15)
testq %rdi, %rdi
je 0x9179
movq 0x38(%r14), %rdx
movq 0x40(%r14), %rsi
shlq $0x4, %rdx
callq 0x2280
jmp 0x9295
cmpq $0x0, 0x38(%r14)
jne 0x9329
jmp 0x9163
shlq $0x3, %rdi
callq 0x22a0
movq %rax, %rdi
movq %rdi, 0x40(%r15)
testq %rdi, %rdi
je 0x91c9
movq 0x38(%r14), %r12
movq 0x40(%r14), %rsi
leaq (,%r12,8), %rdx
callq 0x2280
incq %r12
je 0x91c5
cmpq %r13, %r12
jbe 0x91d6
callq 0x20a0
movl $0xc, (%rax)
xorl %edi, %edi
jmp 0x91e5
cmpq $0x0, 0x38(%r14)
jne 0x9329
jmp 0x919b
shlq $0x3, %r12
movq %r12, %rdi
callq 0x22a0
movq %rax, %rdi
movq %rdi, 0x48(%r15)
testq %rdi, %rdi
je 0x9315
movq 0x38(%r14), %rax
movq 0x48(%r14), %rsi
leaq 0x8(,%rax,8), %rdx
callq 0x2280
xorl %r12d, %r12d
testq %r14, %r14
je 0x9248
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
cmpb $0x2, %al
je 0x9248
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9351
decq %rcx
movq %rcx, (%rax)
jne 0x9248
movq %r14, %rsi
callq 0x10885
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rax
movq %r15, 0x28(%rax)
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
cmpb $0x2, %al
je 0x9288
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x9288
movq %r15, %rsi
callq 0x107a3
incq %r12
cmpq 0x38(%r15), %r12
jbe 0x920a
testb $0x10, 0x1c(%r15)
jne 0x92bf
movq 0x28(%r15), %rcx
xorl %eax, %eax
movq 0x48(%rcx), %rcx
cmpq %r14, (%rcx,%rax,8)
jne 0x92b0
movq %r15, (%rcx,%rax,8)
incq %rax
movq 0x28(%r15), %rcx
cmpq 0x38(%rcx), %rax
jbe 0x92a2
jmp 0x9310
movq 0x28(%rbx), %rsi
testq %rsi, %rsi
je 0x92e9
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9351
decq %rcx
movq %rcx, (%rax)
jne 0x92e9
callq 0x10885
movq %r15, 0x28(%rbx)
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x9310
movq %r15, %rsi
callq 0x107a3
movq %r15, %r12
jmp 0x9340
cmpq $-0x1, 0x38(%r14)
je 0x91f2
movq 0x40(%r15), %rdi
callq 0x2040
movq 0x30(%rbx), %rdi
movq %r15, %rsi
callq 0x1080b
movq %r15, %rdi
callq 0xace6
xorl %r12d, %r12d
movq %r12, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xb328(%rip), %rdi      # 0x14680
leaq 0xb347(%rip), %rsi      # 0x146a6
leaq 0xb359(%rip), %rcx      # 0x146bf
movl $0x88, %edx
callq 0x21c0
leaq 0xbdd8(%rip), %rdi      # 0x1514f
leaq 0xbce8(%rip), %rsi      # 0x15066
leaq 0xbdda(%rip), %rcx      # 0x1515f
movl $0x1c8, %edx            # imm = 0x1C8
callq 0x21c0
leaq 0xbe06(%rip), %rdi      # 0x1519c
leaq 0xbcc9(%rip), %rsi      # 0x15066
leaq 0xbdbb(%rip), %rcx      # 0x1515f
movl $0x1c9, %edx            # imm = 0x1C9
callq 0x21c0
leaq 0xbe04(%rip), %rdi      # 0x151b9
leaq 0xbcaa(%rip), %rsi      # 0x15066
leaq 0xbd9c(%rip), %rcx      # 0x1515f
movl $0x1ca, %edx            # imm = 0x1CA
callq 0x21c0