// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/kvlds/dispatch_mr.c
// Function: batch_run
static int
batch_run(struct batch * B)
{
	struct req_cookie * req;
	struct proto_kvlds_request * R;
	struct node * leaf;
	size_t i;
	struct kvpair_const * pos;
	const struct kvldskey * val;
	int op;

	/* Prepare leaves for mutation. */
	for (i = 0; i < B->ndirty; i++)
		if (btree_mutate_mutable(B->dirties[i]))
			goto err0;

	/* Handle requests in order. */
	for (i = 0; i < B->nreqs; i++) {
		req = B->reqs[i];
		R = req->R;
		leaf = req->leaf;

		/* If this node isn't dirty, we're not doing anything. */
		if (leaf->state != NODE_STATE_DIRTY)
			continue;

		/* Look for the relevant key within the node. */
		pos = btree_mutate_find(leaf, R->key);
		val = pos->v;

		/* Figure out what we need to do (if anything). */
		op = OP_NONE;
		switch (R->type) {
		case PROTO_KVLDS_SET:
			/* Add or modify as required. */
			op = OP_ADD;
			break;
		case PROTO_KVLDS_CAS:
			/*
			 * Operation only has effect if key exists and is
			 * associated with the right value.
			 */
			if ((val != NULL) &&
			    (kvldskey_cmp(R->oval, val) == 0))
				op = OP_MODIFY;
			break;
		case PROTO_KVLDS_ADD:
			/* Operation only has effect if key doesn't exist. */
			if (val == NULL)
				op = OP_ADD;
			break;
		case PROTO_KVLDS_MODIFY:
			/* Operation only has effect if key exists. */
			if (val != NULL)
				op = OP_MODIFY;
			break;
		case PROTO_KVLDS_DELETE:
			/* Operation only has effect if key exists. */
			if (val != NULL)
				op = OP_DELETE;
			break;
		case PROTO_KVLDS_CAD:
			/*
			 * Operation only has effect if key exists and is
			 * associated with the right value.
			 */
			if ((val != NULL) &&
			    (kvldskey_cmp(R->oval, val) == 0))
				op = OP_DELETE;
			break;
		}

		/* Actually perform the operation (if required). */
		switch (op) {
		case OP_ADD:
			/*
			 * If the key is not present, add the pair.  (Note
			 * that the key might be present even if there is no
			 * value associated with it, since at this point a
			 * deleted key-value pair is represented as a value
			 * of NULL.)
			 */
			if (pos->k == NULL) {
				if (btree_mutate_add(leaf, pos,
				    R->key, R->value))
					goto err0;
				break;
			}

			/* Otherwise, fall through to the MODIFY path. */
			/* FALLTHROUGH */
		case OP_MODIFY:
			/* Modify the key. */
			pos->v = R->value;
			break;
		case OP_DELETE:
			/* Delete the key. */
			pos->v = NULL;
			break;
		}

		/* Record if we did something. */
		if (op != OP_NONE)
			req->opdone = 1;
	}

	/* We're not going to mutate leaves any more. */
	for (i = 0; i < B->ndirty; i++)
		if (btree_mutate_immutable(B->dirties[i]))
			goto err0;
	free(B->dirties);

	/* Success! */
	return (0);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x5d51
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xb780
cmpl $0x0, %eax
je 0x5d41
jmp 0x5f7a
jmp 0x5d43
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5d14
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x5f22
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%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
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x2, %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x2, %eax
je 0x5daf
jmp 0x5f11
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0xb880
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
addl $0xfffffef0, %eax       # imm = 0xFFFFFEF0
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x11, %eax
ja 0x5e8b
movq -0x50(%rbp), %rax
leaq 0x18bf3(%rip), %rcx     # 0x1e9f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x44(%rbp)
jmp 0x5e8b
cmpq $0x0, -0x40(%rbp)
je 0x5e33
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x18660
cmpl $0x0, %eax
jne 0x5e33
movl $0x1, -0x44(%rbp)
jmp 0x5e8b
cmpq $0x0, -0x40(%rbp)
jne 0x5e43
movl $0x0, -0x44(%rbp)
jmp 0x5e8b
cmpq $0x0, -0x40(%rbp)
je 0x5e53
movl $0x1, -0x44(%rbp)
jmp 0x5e8b
cmpq $0x0, -0x40(%rbp)
je 0x5e63
movl $0x2, -0x44(%rbp)
jmp 0x5e8b
cmpq $0x0, -0x40(%rbp)
je 0x5e89
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x18660
cmpl $0x0, %eax
jne 0x5e89
movl $0x2, -0x44(%rbp)
jmp 0x5e8b
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0x5eab
jmp 0x5e97
movl -0x54(%rbp), %eax
subl $0x1, %eax
je 0x5ee0
jmp 0x5ea1
movl -0x54(%rbp), %eax
subl $0x2, %eax
je 0x5ef2
jmp 0x5efe
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x5ede
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
callq 0xb8d0
cmpl $0x0, %eax
je 0x5edc
jmp 0x5f7a
jmp 0x5efe
jmp 0x5ee0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x5efe
movq -0x38(%rbp), %rax
movq $0x0, 0x8(%rax)
cmpl $-0x1, -0x44(%rbp)
je 0x5f0f
movq -0x18(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0x5f11
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5d59
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x5f64
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xb960
cmpl $0x0, %eax
je 0x5f54
jmp 0x5f7a
jmp 0x5f56
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x5f2a
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0x5f81
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)