// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/kvlds/dispatch_mr.c
// Function: dispatch_mr_launch
int
dispatch_mr_launch(struct btree * T, struct proto_kvlds_request ** reqs,
    size_t nreqs, struct netbuf_write * WQ,
    int (* callback_done)(void *), void * cookie)
{
	struct batch * B;
	size_t i;

#ifdef SANITY_CHECKS
	/* Sanity check the B+Tree. */
	btree_sanity(T);
#endif

	/* Bake a cookie. */
	if ((B = malloc(sizeof(struct batch))) == NULL)
		goto err0;
	B->callback_done = callback_done;
	B->cookie = cookie;
	B->nreqs = nreqs;
	B->T = T;
	B->WQ = WQ;

	/* Allocate an array of request cookie pointers. */
	if (IMALLOC(B->reqs, B->nreqs, struct req_cookie *))
		goto err1;

	/* Bake request cookies. */
	for (i = 0; i < B->nreqs; i++)
		B->reqs[i] = NULL;
	for (i = 0; i < B->nreqs; i++) {
		if ((B->reqs[i] = mpool_reqcookie_malloc()) == NULL)
			goto err2;
		B->reqs[i]->R = reqs[i];
		B->reqs[i]->batch = B;
		B->reqs[i]->opdone = 0;
	}

	/* If we don't need to find any leaves, schedule the next step. */
	if ((B->leavestofind = B->nreqs) == 0) {
		if (!events_immediate_register(callback_gotleaves, B, 1))
			goto err2;
	}

	/* Look for the leaves. */
	for (i = 0; i < B->nreqs; i++) {
		if (btree_find_leaf(B->T, B->T->root_dirty,
		    B->reqs[i]->R->key, callback_gotleaf, B->reqs[i])) {
			/*
			 * We can't clean up properly since we can't cancel
			 * any already-in-progress leaf-finding; just error
			 * out without cleaning up.
			 */
			goto err0;
		}
	}

	/* Free input request vector. */
	free(reqs);

	/* Success! */
	return (0);

err2:
	for (i = 0; i < B->nreqs; i++)
		mpool_reqcookie_free(B->reqs[i]);
	free(B->reqs);
err1:
	free(B);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %r13
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, (%rsp)
movq %rdi, %r15
pushq $0x48
popq %rdi
callq 0x22a0
movq %rax, %r14
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x3fed
movq %rbx, (%r14)
movq %r13, 0x8(%r14)
movq %rbp, 0x10(%r14)
movq %r15, 0x18(%r14)
movq %r12, 0x20(%r14)
pushq $0x8
popq %rsi
movq %rbp, %rdi
callq 0x4008
movq %rax, %r12
movq %rax, 0x28(%r14)
testq %rax, %rax
sete %al
testq %rbp, %rbp
setne %cl
testb %cl, %al
jne 0x3fe2
xorl %eax, %eax
movq (%rsp), %r15
cmpq %rax, %rbp
je 0x3ec7
andq $0x0, (%r12,%rax,8)
incq %rax
jmp 0x3eb8
xorl %ebx, %ebx
pushq $0x20
popq %r13
cmpq %rbp, %rbx
jae 0x3f6c
incq 0x1739b(%rip)           # 0x1b278
movq 0x1737c(%rip), %rax     # 0x1b260
testq %rax, %rax
je 0x3f02
movq 0x17380(%rip), %rcx     # 0x1b270
leaq -0x1(%rax), %rdx
movq %rdx, 0x17365(%rip)     # 0x1b260
movq -0x8(%rcx,%rax,8), %rax
jmp 0x3f34
incq 0x17377(%rip)           # 0x1b280
cmpl $0x0, 0x17378(%rip)     # 0x1b288
jne 0x3f2c
movq 0x1737f(%rip), %rdi     # 0x1b298
callq 0x10c20
movl $0x1, 0x17360(%rip)     # 0x1b288
movq 0x28(%r14), %r12
movq %r13, %rdi
callq 0x22a0
movq %rax, (%r12,%rbx,8)
testq %rax, %rax
je 0x3fc3
movq (%r15,%rbx,8), %rax
movq 0x28(%r14), %r12
movq (%r12,%rbx,8), %rcx
movq %rax, (%rcx)
movq (%r12,%rbx,8), %rax
movq %r14, 0x10(%rax)
movq (%r12,%rbx,8), %rax
andl $0x0, 0x18(%rax)
incq %rbx
movq 0x10(%r14), %rbp
jmp 0x3ecd
movq %rbp, 0x30(%r14)
testq %rbp, %rbp
jne 0x3f8c
leaq 0xb8(%rip), %rdi        # 0x4034
pushq $0x1
popq %rdx
movq %r14, %rsi
callq 0x9f40
testq %rax, %rax
je 0x3fc3
xorl %ebx, %ebx
leaq 0x469(%rip), %r12       # 0x43fe
cmpq 0x10(%r14), %rbx
jae 0x3ffc
movq 0x18(%r14), %rdi
movq 0x28(%r14), %rax
movq 0x28(%rdi), %rsi
movq (%rax,%rbx,8), %r8
movq (%r8), %rax
movq 0x10(%rax), %rdx
movq %r12, %rcx
callq 0x6e81
incq %rbx
testl %eax, %eax
je 0x3f95
jmp 0x3fea
xorl %ebx, %ebx
movq 0x28(%r14), %rdi
cmpq 0x10(%r14), %rbx
jae 0x3fdd
movq (%rdi,%rbx,8), %rdi
callq 0x4432
incq %rbx
jmp 0x3fc5
callq 0x2040
movq %r14, %rdi
callq 0x2040
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2040
xorl %eax, %eax
jmp 0x3fed