// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x48, %edi
callq 0x22a0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x52b9
jmp 0x54fe
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x8, %esi
callq 0x5510
movq -0x40(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x5324
movq -0x40(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jbe 0x5324
jmp 0x54f5
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x535c
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x532c
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x53f1
callq 0x55b0
movq -0x40(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x48(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x5392
jmp 0x54af
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x18(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x5364
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x5429
movq -0x40(%rbp), %rsi
leaq 0x1be(%rip), %rdi       # 0x55d0
movl $0x1, %edx
callq 0x111b0
cmpq $0x0, %rax
jne 0x5427
jmp 0x54af
jmp 0x5429
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x549d
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rsi
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq 0x10(%rax), %rdx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %r8
leaq 0x1ff(%rip), %rcx       # 0x5680
callq 0xaeb0
cmpl $0x0, %eax
je 0x548d
jmp 0x54fe
jmp 0x548f
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x5431
movq -0x18(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0x5505
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x54e8
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x5710
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x54b7
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2040
movq -0x40(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop