// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0xca10
cmpl $0x0, %eax
je 0xc5c0
jmp 0xc5df
leaq 0x12f58(%rip), %rdi     # 0x1f51f
leaq 0x12e68(%rip), %rsi     # 0x1f436
movl $0x1c8, %edx            # imm = 0x1C8
leaq 0x12f55(%rip), %rcx     # 0x1f52f
callq 0x21d0
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x2, %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xc5f5
jmp 0xc614
leaq 0x12f70(%rip), %rdi     # 0x1f56c
leaq 0x12e33(%rip), %rsi     # 0x1f436
movl $0x1c9, %edx            # imm = 0x1C9
leaq 0x12f20(%rip), %rcx     # 0x1f52f
callq 0x21d0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x19140
cmpq $0x0, %rax
jbe 0xc62d
jmp 0xc64c
leaq 0x12f55(%rip), %rdi     # 0x1f589
leaq 0x12dfb(%rip), %rsi     # 0x1f436
movl $0x1ca, %edx            # imm = 0x1CA
leaq 0x12ee8(%rip), %rcx     # 0x1f52f
callq 0x21d0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x94f0
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xc6a5
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movb 0x1c(%rax), %al
shrb $0x2, %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xc6a5
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0xc5a0
cmpq $0x0, %rax
jne 0xc6a5
jmp 0xc9f6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
movzbl %al, %esi
movq -0x18(%rbp), %rax
movsbl 0x1d(%rax), %edx
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
movq $0x0, (%rsp)
callq 0xbe40
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0xc6e9
jmp 0xc9f6
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x20(%rbp), %rax
movb %cl, %dl
movb 0x1c(%rax), %cl
andb $0x1, %dl
shlb $0x4, %dl
andb $-0x11, %cl
orb %dl, %cl
movb %cl, 0x1c(%rax)
movq -0x18(%rbp), %rax
movb 0x1e(%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, 0x1e(%rax)
movq -0x18(%rbp), %rax
movb 0x1f(%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, 0x1f(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %cl
andb $-0xd, %cl
orb $0x4, %cl
movb %cl, 0x1c(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc570
movq -0x20(%rbp), %rax
movq $-0x1, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xc7e3
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movl $0x10, %esi
callq 0xca50
movq -0x20(%rbp), %rcx
movq %rax, 0x40(%rcx)
cmpq $0x0, %rax
jne 0xc7bd
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jbe 0xc7bd
jmp 0xc9dc
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdx
shlq $0x4, %rdx
callq 0x2280
jmp 0xc925
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movl $0x8, %esi
callq 0xca50
movq -0x20(%rbp), %rcx
movq %rax, 0x40(%rcx)
cmpq $0x0, %rax
jne 0xc813
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jbe 0xc813
jmp 0xc9dc
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdx
shlq $0x3, %rdx
callq 0x2280
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
addq $0x1, %rdi
movl $0x8, %esi
callq 0xca50
movq -0x20(%rbp), %rcx
movq %rax, 0x48(%rcx)
cmpq $0x0, %rax
jne 0xc86f
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
addq $0x1, %rax
cmpq $0x0, %rax
jbe 0xc86f
jmp 0xc9cf
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdx
addq $0x1, %rdx
shlq $0x3, %rdx
callq 0x2280
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x38(%rcx), %rax
ja 0xc923
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xcaf0
cmpl $0x0, %eax
je 0xc8d1
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xcb20
movq -0x20(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xcaf0
cmpl $0x0, %eax
je 0xc910
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xc570
jmp 0xc912
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xc89c
jmp 0xc925
movq -0x20(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xc997
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpq 0x38(%rcx), %rax
ja 0xc995
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x18(%rbp), %rax
jne 0xc985
movq -0x20(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xc987
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xc941
jmp 0xc9c5
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0xcb20
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0xc570
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc9fe
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x190c0
movq -0x20(%rbp), %rdi
callq 0xfb50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)