// File: /workspace/github_c_makefile_star2_O3/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 0x3f23
movq %rdi, %rbx
cmpl $0x0, 0x80(%rdi)
je 0x3c5c
xorl %ebp, %ebp
cmpq $0x0, 0x90(%rbx)
jne 0x3e80
cmpl $0x0, 0x98(%rbx)
jne 0x3e80
cmpq $0x0, 0x88(%rbx)
je 0x3e80
leaq 0xa0(%rbx), %rdx
leaq 0x45d(%rip), %rdi       # 0x409c
movq %rbx, %rsi
callq 0xc618
movq %rax, 0x90(%rbx)
testq %rax, %rax
jne 0x3e80
jmp 0x3e7b
movq 0x28(%rbx), %rdi
movq 0x78(%rbx), %rax
movq 0x28(%rdi), %rcx
movsbq 0x1d(%rcx), %rcx
cmpl $0x0, 0x98(%rbx)
jne 0x3c8c
cmpl $0x0, 0xc0(%rbx)
jne 0x3c8c
cmpq 0xb0(%rbx), %r15
jb 0x3c06
incq %rcx
movq %rcx, %rdx
imulq %r15, %rdx
cmpq %rax, %rdx
jbe 0x3ca3
xorl %edx, %edx
divq %rcx
movq %rax, %r15
movq %r15, 0x70(%rbx)
testq %r15, %r15
je 0x3cc5
movq %r15, %rax
shrq $0x3d, %rax
je 0x3ccf
callq 0x20a0
movl $0xc, (%rax)
jmp 0x3e7b
xorl %ebp, %ebp
xorl %r15d, %r15d
jmp 0x3e2f
leaq (,%r15,8), %rdi
callq 0x22a0
testq %rax, %rax
je 0x3e7b
movq %rax, %rbp
movq 0x19561(%rip), %rax     # 0x1d250
movq %rax, 0x10(%rsp)
movq 0x19525(%rip), %r12     # 0x1d220
movq 0x19526(%rip), %rcx     # 0x1d228
movq 0x19527(%rip), %rdx     # 0x1d230
xorl %r14d, %r14d
movq %rbp, 0x20(%rsp)
movq 0x60(%rbx), %r13
testq %r13, %r13
je 0x3f04
movq 0x8(%r13), %rax
movq %rax, 0x60(%rbx)
decq 0x88(%rbx)
movq (%r13), %rax
movq %rax, (%rbp,%r14,8)
cmpq %rcx, %r12
jae 0x3d53
leaq 0x1(%r12), %rax
movq %rax, 0x194d9(%rip)     # 0x1d220
movq %r13, (%rdx,%r12,8)
movq %rax, %r12
jmp 0x3e1f
movq 0x194de(%rip), %rax     # 0x1d238
shrq $0x8, %rax
cmpq %rax, 0x194db(%rip)     # 0x1d240
jbe 0x3de3
movq %r12, 0x8(%rsp)
testq %rcx, %rcx
je 0x3f42
movq %rdx, %r15
movq %rcx, %r12
movq %rcx, %rdi
shlq $0x4, %rdi
callq 0x22a0
testq %rax, %rax
je 0x3df6
movq %rax, %rbp
movq %r12, 0x18(%rsp)
leaq (,%r12,8), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2280
cmpq 0x10(%rsp), %r15
je 0x3db6
movq %r15, %rdi
callq 0x2040
movq %rbp, 0x19473(%rip)     # 0x1d230
movq 0x18(%rsp), %rcx
addq %rcx, %rcx
movq %rcx, 0x1945c(%rip)     # 0x1d228
movq 0x8(%rsp), %rax
movq %r13, (%rbp,%rax,8)
leaq 0x1(%rax), %r12
movq %r12, 0x1943f(%rip)     # 0x1d220
jmp 0x3e09
movq %rcx, %r15
movq %rdx, %rbp
movq %r13, %rdi
callq 0x2040
movq %r15, %rcx
jmp 0x3e09
movq %r13, %rdi
callq 0x2040
movq %r15, %rbp
movq %r12, %rcx
movq 0x8(%rsp), %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x19425(%rip)    # 0x1d238
movq 0x70(%rbx), %r15
movq %rbp, %rdx
movq 0x20(%rsp), %rbp
incq %r14
cmpq %r15, %r14
jb 0x3d11
movq 0x28(%rbx), %rdi
movl $0x1, 0x80(%rbx)
movq 0x10(%rbx), %rcx
leaq 0x229(%rip), %r8        # 0x406d
movq %rbp, %rsi
movq %r15, %rdx
movq %rbx, %r9
callq 0x4910
testl %eax, %eax
je 0x3e91
cmpq $0x0, 0x70(%rbx)
je 0x3e73
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rdi
callq 0x10b73
incq %r14
cmpq 0x70(%rbx), %r14
jb 0x3e60
movq %rbp, %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 0x3ead
callq 0xc792
movq $0x0, 0x90(%rbx)
movl $0x0, 0x98(%rbx)
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x3ed3
callq 0xc792
movq $0x0, 0xb8(%rbx)
leaq -0x60d(%rip), %rdi      # 0x38cd
leaq 0x104ff(%rip), %rdx     # 0x143e0
movq %rbx, %rsi
callq 0xc618
movq %rax, 0xb8(%rbx)
testq %rax, %rax
je 0x3e7b
movl $0x0, 0xc0(%rbx)
jmp 0x3c06
leaq 0x105b7(%rip), %rdi     # 0x144c2
leaq 0x10508(%rip), %rsi     # 0x1441a
leaq 0x10584(%rip), %rcx     # 0x1449d
movl $0x101, %edx            # imm = 0x101
callq 0x21c0
leaq 0x1055d(%rip), %rdi     # 0x14487
leaq 0x104e9(%rip), %rsi     # 0x1441a
leaq 0x10565(%rip), %rcx     # 0x1449d
movl $0xed, %edx
callq 0x21c0
leaq 0x1058c(%rip), %rdi     # 0x144d5
leaq 0x10596(%rip), %rsi     # 0x144e6
leaq 0x105b1(%rip), %rcx     # 0x14508
movl $0x5a, %edx
callq 0x21c0