// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/kvlds/dispatch.c
// Function: poke_mr
static int
poke_mr(struct dispatch_state * D)
{
	size_t concurrency = D->mr_concurrency;
	size_t pagesperop = (size_t)(D->T->root_dirty->height + 1);
	struct proto_kvlds_request ** reqs;
	struct requestq * RQ;
	size_t i;

	/* Sanity check. */
	assert(D->mr_qlen <= MAXREQS);

	/* Launch a batch of requests if possible. */
	if ((D->mr_inprogress == 0) &&
	    ((D->mr_timer_expired != 0) ||
	     (D->docleans != 0) ||
	     (D->mr_qlen >= D->mr_min_batch))) {
		/* Figure out how many requests will be in this batch. */
		if (D->mr_qlen * pagesperop > concurrency)
			D->mr_reqs = concurrency / pagesperop;
		else
			D->mr_reqs = D->mr_qlen;

		/* Allocate an array. */
		if (IMALLOC(reqs, D->mr_reqs, struct proto_kvlds_request *))
			goto err0;

		/* Fill the array with requests. */
		for (i = 0; i < D->mr_reqs; i++) {
			/* We should have a request. */
			assert(D->mr_head != NULL);

			/* Dequeue. */
			RQ = D->mr_head;
			D->mr_head = RQ->next;
			D->mr_qlen -= 1;

			/* Insert into the array. */
			reqs[i] = RQ->R;

			/* Free linked list node. */
			mpool_requestq_free(RQ);
		}

		/* Modifying requests are now in progress. */
		D->mr_inprogress = 1;

		/* Launch the batch of modifying requests. */
		if (dispatch_mr_launch(D->T, reqs, D->mr_reqs, D->writeq,
		    callback_mr_done, D))
			goto err1;

		/* We beat the clock.  Disable it. */
		if (D->mr_timer != NULL) {
			events_timer_cancel(D->mr_timer);
			D->mr_timer = NULL;
		}

		/* The (unset) timer hasn't expired. */
		D->mr_timer_expired = 0;

		/* Reset the do-a-cleaning-only-batch timer to 5 seconds. */
		if (D->mrc_timer != NULL) {
			events_timer_cancel(D->mrc_timer);
			D->mrc_timer = NULL;
		}
		if ((D->mrc_timer = events_timer_register(callback_mrc_timer,
		    D, &fivesec)) == NULL)
			goto err0;

		/* We don't need to launch another batch any more. */
		D->docleans = 0;
	}

	/*
	 * If we have requests and the clock isn't ticking (and hasn't
	 * already expired), then start the timer.  Note that this is useful
	 * even with a mr_timeout value of zero, since network events take
	 * priority over timers -- if multiple requests arrive simultaneously
	 * this allows them to all be included in the batch.
	 */
	if ((D->mr_timer == NULL) && (D->mr_timer_expired == 0) &&
	    (D->mr_qlen > 0)) {
		if ((D->mr_timer = events_timer_register(callback_mr_timer,
		    D, &D->mr_timeout)) == NULL)
			goto err0;
	}

	/* Success! */
	return (0);

err1:
	/* These requests can never be done, but at least we can free them. */
	for (i = 0; i < D->mr_reqs; i++)
		proto_kvlds_request_free(reqs[i]);
	free(reqs);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x88(%rdi), %r15
cmpq $0x1001, %r15           # imm = 0x1001
jae 0x3f7a
movq %rdi, %rbx
cmpl $0x0, 0x80(%rdi)
je 0x3cb1
xorl %ebp, %ebp
cmpq $0x0, 0x90(%rbx)
jne 0x3ed7
cmpl $0x0, 0x98(%rbx)
jne 0x3ed7
cmpq $0x0, 0x88(%rbx)
je 0x3ed7
leaq 0xa0(%rbx), %rdx
leaq 0x453(%rip), %rdi       # 0x40e7
movq %rbx, %rsi
callq 0xc738
movq %rax, 0x90(%rbx)
testq %rax, %rax
jne 0x3ed7
jmp 0x3ed2
movq 0x28(%rbx), %rcx
movq 0x78(%rbx), %rax
movq 0x28(%rcx), %rcx
movsbq 0x1d(%rcx), %rcx
cmpl $0x0, 0x98(%rbx)
jne 0x3ce1
cmpl $0x0, 0xc0(%rbx)
jne 0x3ce1
cmpq 0xb0(%rbx), %r15
jb 0x3c5b
incq %rcx
movq %rcx, %rdx
imulq %r15, %rdx
cmpq %rax, %rdx
jbe 0x3cf8
xorl %edx, %edx
divq %rcx
movq %rax, %r15
movq %r15, 0x70(%rbx)
testq %r15, %r15
je 0x3d15
movq %r15, %rax
shrq $0x3d, %rax
je 0x3d1a
callq 0x20a0
movl $0xc, (%rax)
xorl %r13d, %r13d
jmp 0x3d2a
leaq (,%r15,8), %rdi
callq 0x22a0
movq %rax, %r13
testq %r15, %r15
setne %al
testq %r13, %r13
sete %cl
testb %cl, %al
jne 0x3ed2
movq 0x70(%rbx), %rdx
testq %rdx, %rdx
je 0x3e85
movq 0x194fe(%rip), %rax     # 0x1d250
movq %rax, 0x10(%rsp)
movq 0x194c2(%rip), %rbp     # 0x1d220
movq 0x194c3(%rip), %rcx     # 0x1d228
movq 0x194c4(%rip), %r15     # 0x1d230
xorl %r14d, %r14d
movq %r13, 0x20(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x60(%rbx), %r12
testq %r12, %r12
je 0x3f5b
movq 0x8(%r12), %rax
movq %rax, 0x60(%rbx)
decq 0x88(%rbx)
movq (%r12), %rax
movq %rax, (%r13,%r14,8)
cmpq %rcx, %rbp
jae 0x3dbb
leaq 0x1(%rbp), %rax
movq %rax, 0x19471(%rip)     # 0x1d220
movq %r12, (%r15,%rbp,8)
movq %rax, %rbp
jmp 0x3e75
movq 0x19476(%rip), %rax     # 0x1d238
shrq $0x8, %rax
cmpq %rax, 0x19473(%rip)     # 0x1d240
jbe 0x3e3d
testq %rcx, %rcx
je 0x3f99
movq %rcx, %rbx
movq %rcx, %rdi
shlq $0x4, %rdi
callq 0x22a0
testq %rax, %rax
je 0x3e50
movq %rax, %r13
movq %rbx, 0x18(%rsp)
leaq (,%rbx,8), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2280
cmpq 0x10(%rsp), %r15
je 0x3e16
movq %r15, %rdi
callq 0x2040
movq %r13, 0x19413(%rip)     # 0x1d230
movq 0x18(%rsp), %rcx
addq %rcx, %rcx
movq %rcx, 0x193fc(%rip)     # 0x1d228
movq %r12, (%r13,%rbp,8)
incq %rbp
movq %rbp, 0x193e5(%rip)     # 0x1d220
jmp 0x3e5e
movq %r15, %r13
movq %rcx, %r15
movq %r12, %rdi
callq 0x2040
movq %r15, %rcx
jmp 0x3e63
movq %r12, %rdi
callq 0x2040
movq %r15, %r13
movq %rbx, %rcx
movq 0x8(%rsp), %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x193cb(%rip)    # 0x1d238
movq %r13, %r15
movq 0x20(%rsp), %r13
incq %r14
movq 0x70(%rbx), %rdx
cmpq %rdx, %r14
jb 0x3d79
movl $0x1, 0x80(%rbx)
movq 0x10(%rbx), %rcx
movq 0x28(%rbx), %rdi
leaq 0x21a(%rip), %r8        # 0x40b8
movq %r13, %rsi
movq %rbx, %r9
callq 0x4938
testl %eax, %eax
je 0x3ee8
cmpq $0x0, 0x70(%rbx)
je 0x3eca
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
callq 0x10bd2
incq %r14
cmpq 0x70(%rbx), %r14
jb 0x3eb7
movq %r13, %rdi
callq 0x2040
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
je 0x3f04
callq 0xc8b1
movq $0x0, 0x90(%rbx)
movl $0x0, 0x98(%rbx)
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x3f2a
callq 0xc8b1
movq $0x0, 0xb8(%rbx)
leaq -0x60f(%rip), %rdi      # 0x3922
leaq 0x10508(%rip), %rdx     # 0x14440
movq %rbx, %rsi
callq 0xc738
movq %rax, 0xb8(%rbx)
testq %rax, %rax
je 0x3ed2
movl $0x0, 0xc0(%rbx)
jmp 0x3c5b
leaq 0x105c0(%rip), %rdi     # 0x14522
leaq 0x10511(%rip), %rsi     # 0x1447a
leaq 0x1058d(%rip), %rcx     # 0x144fd
movl $0x101, %edx            # imm = 0x101
callq 0x21c0
leaq 0x10566(%rip), %rdi     # 0x144e7
leaq 0x104f2(%rip), %rsi     # 0x1447a
leaq 0x1056e(%rip), %rcx     # 0x144fd
movl $0xed, %edx
callq 0x21c0
leaq 0x10595(%rip), %rdi     # 0x14535
leaq 0x1059f(%rip), %rsi     # 0x14546
leaq 0x105ba(%rip), %rcx     # 0x14568
movl $0x5a, %edx
callq 0x21c0