// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
movq 0x88(%rdi), %r14
cmpq $0x1001, %r14           # imm = 0x1001
jae 0x3858
movq %rdi, %rbx
cmpl $0x0, 0x80(%rdi)
je 0x36ba
xorl %ebp, %ebp
cmpq $0x0, 0x90(%rbx)
jne 0x37c7
cmpl $0x0, 0x98(%rbx)
jne 0x37c7
cmpq $0x0, 0x88(%rbx)
je 0x37c7
leaq 0xa0(%rbx), %rdx
leaq 0x30e(%rip), %rdi       # 0x39ab
movq %rbx, %rsi
callq 0xaa98
movq %rax, 0x90(%rbx)
testq %rax, %rax
jne 0x37c7
jmp 0x37c4
movq 0x28(%rbx), %rcx
movq 0x78(%rbx), %rax
movq 0x28(%rcx), %rcx
movsbq 0x1d(%rcx), %rcx
cmpl $0x0, 0x98(%rbx)
jne 0x36ea
cmpl $0x0, 0xc0(%rbx)
jne 0x36ea
cmpq 0xb0(%rbx), %r14
jb 0x3664
incq %rcx
movq %rcx, %rdx
imulq %r14, %rdx
cmpq %rax, %rdx
jbe 0x3701
xorl %edx, %edx
divq %rcx
movq %rax, %r14
movq %r14, 0x70(%rbx)
testq %r14, %r14
je 0x3723
movq %r14, %rax
shrq $0x3d, %rax
je 0x3728
callq 0x20a0
movl $0xc, (%rax)
jmp 0x37c4
xorl %r15d, %r15d
jmp 0x3741
leaq (,%r14,8), %rdi
callq 0x22a0
movq %rax, %r15
testq %rax, %rax
je 0x37c4
xorl %r12d, %r12d
cmpq %r14, %r12
jae 0x377a
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x3839
movq 0x8(%rdi), %rax
movq %rax, 0x60(%rbx)
decq 0x88(%rbx)
movq (%rdi), %rax
movq %rax, (%r15,%r12,8)
callq 0x3877
incq %r12
movq 0x70(%rbx), %r14
jmp 0x3744
movl $0x1, 0x80(%rbx)
movq 0x10(%rbx), %rcx
movq 0x28(%rbx), %rdi
leaq 0x1ee(%rip), %r8        # 0x3981
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %r9
callq 0x3e44
testl %eax, %eax
je 0x37d2
xorl %r14d, %r14d
cmpq 0x70(%rbx), %r14
jae 0x37bc
movq (%r15,%r14,8), %rdi
callq 0xeb7a
incq %r14
jmp 0x37a8
movq %r15, %rdi
callq 0x2040
pushq $-0x1
popq %rbp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x90(%rbx), %rdi
testq %rdi, %rdi
je 0x37eb
callq 0xac0b
andq $0x0, 0x90(%rbx)
andl $0x0, 0x98(%rbx)
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x380b
callq 0xac0b
andq $0x0, 0xb8(%rbx)
leaq -0x4c4(%rip), %rdi      # 0x334e
leaq 0xdc0f(%rip), %rdx      # 0x11428
movq %rbx, %rsi
callq 0xaa98
movq %rax, 0xb8(%rbx)
testq %rax, %rax
je 0x37c4
andl $0x0, 0xc0(%rbx)
jmp 0x3664
leaq 0xdcca(%rip), %rdi      # 0x1150a
leaq 0xdc1b(%rip), %rsi      # 0x11462
leaq 0xdc97(%rip), %rcx      # 0x114e5
movl $0x101, %edx            # imm = 0x101
callq 0x21c0
leaq 0xdc70(%rip), %rdi      # 0x114cf
leaq 0xdbfc(%rip), %rsi      # 0x11462
leaq 0xdc78(%rip), %rcx      # 0x114e5
movl $0xed, %edx
callq 0x21c0