// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x28(%rax), %rax
movsbl 0x1d(%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x1000, 0x88(%rax) # imm = 0x1000
ja 0x4484
jmp 0x44a3
leaq 0x1a35c(%rip), %rdi     # 0x1e7e7
leaq 0x1a2e8(%rip), %rsi     # 0x1e77a
movl $0xed, %edx
leaq 0x1a35f(%rip), %rcx     # 0x1e7fd
callq 0x21d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x80(%rax)
jne 0x46e4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jne 0x44ea
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc0(%rax)
jne 0x44ea
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0xb0(%rcx), %rax
jb 0x46e4
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
imulq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jbe 0x4519
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x20(%rbp)
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x452c
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rdi
movl $0x8, %esi
callq 0x47a0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x4558
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jbe 0x4558
jmp 0x4784
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x70(%rcx), %rax
jae 0x45fd
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x457f
jmp 0x459e
leaq 0x1a29c(%rip), %rdi     # 0x1e822
leaq 0x1a1ed(%rip), %rsi     # 0x1e77a
movl $0x101, %edx            # imm = 0x101
leaq 0x1a264(%rip), %rcx     # 0x1e7fd
callq 0x21d0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rcx
subq $0x1, %rcx
movq %rcx, 0x88(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdi
callq 0x4840
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x4560
movq -0x10(%rbp), %rax
movl $0x1, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %r9
leaq 0x23e(%rip), %r8        # 0x4870
callq 0x5280
cmpl $0x0, %eax
je 0x4641
jmp 0x4746
movq -0x10(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x466e
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x127a0
movq -0x10(%rbp), %rax
movq $0x0, 0x90(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x98(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb8(%rax)
je 0x46a9
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x127a0
movq -0x10(%rbp), %rax
movq $0x0, 0xb8(%rax)
movq -0x10(%rbp), %rsi
leaq -0x694(%rip), %rdi      # 0x4020
leaq 0x1a085(%rip), %rdx     # 0x1e740
callq 0x12560
movq -0x10(%rbp), %rcx
movq %rax, 0xb8(%rcx)
cmpq $0x0, %rax
jne 0x46d6
jmp 0x4784
movq -0x10(%rbp), %rax
movl $0x0, 0xc0(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x473d
movq -0x10(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jne 0x473d
movq -0x10(%rbp), %rax
cmpq $0x0, 0x88(%rax)
jbe 0x473d
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rdx
addq $0xa0, %rdx
leaq 0x1bd(%rip), %rdi       # 0x48e0
callq 0x12560
movq -0x10(%rbp), %rcx
movq %rax, 0x90(%rcx)
cmpq $0x0, %rax
jne 0x473b
jmp 0x4784
jmp 0x473d
movl $0x0, -0x4(%rbp)
jmp 0x478b
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x70(%rcx), %rax
jae 0x477b
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x19810
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x474e
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)