// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, (%rsp)
movq %rdi, %r15
movl $0x48, %edi
callq 0x22a0
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x4bc9
movq %rbx, (%r14)
movq %rbp, 0x8(%r14)
movq %r13, 0x10(%r14)
movq %r15, 0x18(%r14)
movq %r12, 0x20(%r14)
testq %r13, %r13
je 0x497a
movq %r13, %rax
shrq $0x3d, %rax
je 0x49ba
callq 0x20a0
movl $0xc, (%rax)
jmp 0x4bbc
movq %r14, %rbx
addq $0x28, %rbx
pxor %xmm0, %xmm0
movdqu %xmm0, 0x28(%r14)
leaq 0x246(%rip), %rdi       # 0x4bd8
movq %r14, %rsi
movl $0x1, %edx
callq 0xb910
movq 0x10(%r14), %rcx
testq %rax, %rax
je 0x4b96
testq %rcx, %rcx
jne 0x4b50
jmp 0x4b85
leaq (,%r13,8), %rdi
callq 0x22a0
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x4bbc
movq %rax, %r12
movq %r14, %rbx
addq $0x28, %rbx
leaq 0x1(%r13), %rcx
movabsq $0x3ffffffffffffffe, %rax # imm = 0x3FFFFFFFFFFFFFFE
andq %rcx, %rax
decq %r13
movq %r13, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0xfbfc(%rip), %xmm1     # 0x14600
xorl %ecx, %ecx
movdqa 0xfc02(%rip), %xmm2     # 0x14610
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0xfc02(%rip), %xmm4     # 0x14620
movq (%rsp), %rsi
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x4a5b
movq $0x0, (%r12,%rcx,8)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x4a72
movq $0x0, 0x8(%r12,%rcx,8)
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %rax
jne 0x4a22
movq 0x187f2(%rip), %r13     # 0x1d278
movq 0x187d3(%rip), %rbp     # 0x1d260
xorl %r15d, %r15d
incq %r13
movq %r13, 0x187de(%rip)     # 0x1d278
testq %rbp, %rbp
je 0x4abb
movq 0x187ca(%rip), %rax     # 0x1d270
leaq -0x1(%rbp), %rcx
movq %rcx, 0x187af(%rip)     # 0x1d260
movq -0x8(%rax,%rbp,8), %rax
movq %rcx, %rbp
jmp 0x4b04
incq 0x187be(%rip)           # 0x1d280
cmpl $0x0, 0x187bf(%rip)     # 0x1d288
je 0x4acf
xorl %ebp, %ebp
jmp 0x4af6
movq 0x187c2(%rip), %rdi     # 0x1d298
callq 0x13090
movl $0x1, 0x187a3(%rip)     # 0x1d288
movq 0x1878c(%rip), %r13     # 0x1d278
movq 0x1876d(%rip), %rbp     # 0x1d260
movq (%rbx), %r12
movl $0x20, %edi
callq 0x22a0
movq (%rsp), %rsi
movq %rax, (%r12,%r15,8)
testq %rax, %rax
je 0x4b92
movq (%rsi,%r15,8), %rax
movq 0x28(%r14), %r12
movq (%r12,%r15,8), %rcx
movq %rax, (%rcx)
movq (%r12,%r15,8), %rax
movq %r14, 0x10(%rax)
movq (%r12,%r15,8), %rax
movl $0x0, 0x18(%rax)
incq %r15
movq 0x10(%r14), %rax
cmpq %rax, %r15
jb 0x4a90
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x498b
xorl %ebx, %ebx
leaq 0x4c6(%rip), %r12       # 0x501f
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 0x800f
testl %eax, %eax
jne 0x4bc4
incq %rbx
cmpq 0x10(%r14), %rbx
jb 0x4b59
movq (%rsp), %rdi
callq 0x2040
xorl %eax, %eax
jmp 0x4bc9
movq 0x10(%r14), %rcx
testq %rcx, %rcx
je 0x4bb4
xorl %r15d, %r15d
movq 0x28(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0x5055
incq %r15
cmpq 0x10(%r14), %r15
jb 0x4b9e
movq (%rbx), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq