// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/kvlds/dispatch_mr.c
// Function: batch_dirty
static int
batch_dirty(struct batch * B)
{
	struct req_cookie * req;
	struct proto_kvlds_request * R;
	struct nodepair * shadowdirty;
	size_t Nsd;
	size_t i;
	struct kvpair_const * kv;

	/* Allocate array to hold (shadow node, dirty node) pairs. */
	if (IMALLOC(shadowdirty, B->nreqs, struct nodepair))
		goto err0;
	Nsd = 0;

	/* Dirty leaves which will need to be modified. */
	for (i = 0; i < B->nreqs; i++) {
		req = B->reqs[i];
		R = req->R;

		/* If the node has already been dirtied, move on. */
		if (req->leaf->state != NODE_STATE_CLEAN)
			continue;

		/* Look for the relevant key within the node. */
		kv = btree_find_kvpair(req->leaf, R->key);

		/* If this request doesn't do anything, move on. */
		switch (R->type) {
		case PROTO_KVLDS_SET:
			/*
			 * Operation has effect if the key doesn't exist OR
			 * if the value is different; we don't bother
			 * optimizing this case.
			 */
			break;
		case PROTO_KVLDS_ADD:
			/* Operation only has effect if key doesn't exist. */
			if (kv != NULL)
				continue;
			break;
		case PROTO_KVLDS_MODIFY:
		case PROTO_KVLDS_DELETE:
			/* Operation only has effect if key exists. */
			if (kv == NULL)
				continue;
			break;
		case PROTO_KVLDS_CAS:
		case PROTO_KVLDS_CAD:
			/*
			 * Operation only has effect if key exists and is
			 * associated with the right value.
			 */
			if (kv == NULL)
				continue;
			if (kvldskey_cmp(R->oval, kv->v))
				continue;
			break;
		}

		/* Dirty the node. */
		shadowdirty[Nsd].shadow = req->leaf;
		if ((shadowdirty[Nsd].dirty =
		    btree_node_dirty(B->T, req->leaf)) == NULL)
			goto err1;
		Nsd += 1;
	}

	/* Release locks on the clean or shadow nodes. */
	for (i = 0; i < B->nreqs; i++)
		btree_node_unlock(B->T, B->reqs[i]->leaf);

	/* Sort the shadow/dirty pairs if we have any. */
	if (Nsd > 0)
		qsort(shadowdirty, Nsd, sizeof(struct nodepair), compar_snp);

	/* Translate shadow node pointers to dirty node pointers. */
	for (i = 0; i < B->nreqs; i++)
		B->reqs[i]->leaf =
		    finddirty(shadowdirty, Nsd, B->reqs[i]->leaf);

	/* Create a list of dirty leaves for future reference. */
	if ((B->ndirty = Nsd) > 0) {
		if (IMALLOC(B->dirties, B->ndirty, struct node *))
			goto err1;
		for (i = 0; i < B->ndirty; i++)
			B->dirties[i] = shadowdirty[i].dirty;
	} else {
		/* No dirty leaves. */
		B->dirties = NULL;
	}

	/* Free the shadow/dirty pairs. */
	free(shadowdirty);

	/* Tell the cleaner to dirty nodes now if it wants. */
	if (btree_cleaning_clean(B->T->cstate))
		goto err0;

	/* Success! */
	return (0);

err1:
	free(shadowdirty);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x10, %esi
callq 0x5510
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x5a08
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jbe 0x5a08
jmp 0x5ce1
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x5b59
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb 0x1c(%rax), %al
shrb $0x2, %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x5a66
jmp 0x5b48
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xacc0
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
addl $0xfffffef0, %eax       # imm = 0xFFFFFEF0
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x11, %eax
ja 0x5aef
movq -0x48(%rbp), %rax
leaq 0x18f07(%rip), %rcx     # 0x1e9a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x5aef
cmpq $0x0, -0x40(%rbp)
je 0x5ab8
jmp 0x5b48
jmp 0x5aef
cmpq $0x0, -0x40(%rbp)
jne 0x5ac6
jmp 0x5b48
jmp 0x5aef
cmpq $0x0, -0x40(%rbp)
jne 0x5ad1
jmp 0x5b48
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x18660
cmpl $0x0, %eax
je 0x5aed
jmp 0x5b48
jmp 0x5aef
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xc5a0
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x5b3c
jmp 0x5cd8
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5a18
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x5b9e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rsi
callq 0x6220
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5b61
cmpq $0x0, -0x30(%rbp)
jbe 0x5bbe
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x10, %edx
leaq 0x697(%rip), %rcx       # 0x6250
callq 0x20e0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x5c1a
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdx
callq 0x62b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5bc6
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rax, 0x40(%rcx)
cmpq $0x0, %rax
jbe 0x5ca2
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x8, %esi
callq 0x5510
movq -0x10(%rbp), %rcx
movq %rax, 0x38(%rcx)
cmpq $0x0, %rax
jne 0x5c59
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jbe 0x5c59
jmp 0x5cd8
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x5ca0
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x5c61
jmp 0x5cae
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rdi
callq 0x96f0
cmpl $0x0, %eax
je 0x5ccf
jmp 0x5ce1
movl $0x0, -0x4(%rbp)
jmp 0x5ce8
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)