// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, (%rsp)
movq %rdi, %r14
movl $0x48, %edi
callq 0x22a0
testq %rax, %rax
je 0x4afb
movq %rax, %rbx
movq %rbp, (%rax)
movq %r13, 0x8(%rax)
movq %r15, 0x10(%rax)
movq %r14, 0x18(%rax)
movq %r12, 0x20(%rax)
testq %r15, %r15
je 0x4998
movq %r15, %rax
shrq $0x3d, %rax
je 0x499c
callq 0x20a0
movl $0xc, (%rax)
xorl %eax, %eax
jmp 0x49a9
leaq (,%r15,8), %rdi
callq 0x22a0
testq %r15, %r15
setne %cl
movq %rax, 0x28(%rbx)
testq %rax, %rax
sete %al
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %al, %cl
jne 0x4b32
testq %r15, %r15
je 0x49e1
xorl %eax, %eax
movq 0x28(%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
incq %rax
cmpq %rax, %r15
jne 0x49cd
movq 0x10(%rbx), %rax
testq %rax, %rax
movq (%rsp), %r15
je 0x4a94
xorl %r14d, %r14d
incq 0x1887c(%rip)           # 0x1d278
movq 0x1885d(%rip), %rax     # 0x1d260
testq %rax, %rax
je 0x4a21
movq 0x18861(%rip), %rcx     # 0x1d270
leaq -0x1(%rax), %rdx
movq %rdx, 0x18846(%rip)     # 0x1d260
movq -0x8(%rcx,%rax,8), %rax
jmp 0x4a51
incq 0x18858(%rip)           # 0x1d280
cmpl $0x0, 0x18859(%rip)     # 0x1d288
jne 0x4a47
movq 0x18860(%rip), %rdi     # 0x1d298
callq 0x130a0
movl $0x1, 0x18841(%rip)     # 0x1d288
movl $0x20, %edi
callq 0x22a0
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
je 0x4b02
movq (%r15,%r14,8), %rax
movq 0x28(%rbx), %rcx
movq (%rcx,%r14,8), %rdx
movq %rax, (%rdx)
movq (%rcx,%r14,8), %rax
movq %rbx, 0x10(%rax)
movq (%rcx,%r14,8), %rax
movl $0x0, 0x18(%rax)
incq %r14
movq 0x10(%rbx), %rax
cmpq %rax, %r14
jb 0x49f5
movq %rax, 0x30(%rbx)
testq %rax, %rax
jne 0x4ab6
leaq 0xa7(%rip), %rdi        # 0x4b4b
movq %rbx, %rsi
movl $0x1, %edx
callq 0xba4c
testq %rax, %rax
je 0x4b02
cmpq $0x0, 0x10(%rbx)
je 0x4b2d
xorl %r14d, %r14d
leaq 0x519(%rip), %r15       # 0x4fe0
movq 0x18(%rbx), %rdi
movq 0x28(%rbx), %rax
movq 0x28(%rdi), %rsi
movq (%rax,%r14,8), %r8
movq (%r8), %rax
movq 0x10(%rax), %rdx
movq %r15, %rcx
callq 0x8064
testl %eax, %eax
jne 0x4afb
incq %r14
cmpq 0x10(%rbx), %r14
jb 0x4ac7
xorl %ebp, %ebp
movq (%rsp), %rbx
jmp 0x4b32
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x4b3a
cmpq $0x0, 0x10(%rbx)
je 0x4b22
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x5016
incq %r14
cmpq 0x10(%rbx), %r14
jb 0x4b0c
movq 0x28(%rbx), %rdi
callq 0x2040
jmp 0x4b32
xorl %ebp, %ebp
movq %r15, %rbx
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq