// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/perf/dispatch.c
// Function: callback_gotrequests
static int
callback_gotrequests(void * cookie, int status)
{
	struct dispatch_state * D = cookie;
	struct wire_packet P;
	struct forwardee * F;

	/* We're not waiting for a packet to be available any more. */
	D->read_cookie = NULL;

	/* If the wait failed, the connection is dying. */
	if (status)
		goto fail;

	/* Handle packets until there are no more or we encounter an error. */
	do {
		/* Grab a packet. */
		if (wire_readpacket_peek(D->readq, &P))
			goto fail;

		/* Exit the loop if no packet is available. */
		if (P.buf == NULL)
			break;

		/* Bake a cookie. */
		if ((F = mpool_forwardee_malloc()) == NULL)
			goto err0;
		F->D = D;
		F->ID = P.ID;

		/* Record the request type. */
		if (P.len >= 4)
			F->reqtype = be32dec(&P.buf[0]);
		else
			F->reqtype = (uint32_t)(-1);

		/* Record when we send the request. */
		if (monoclock_get(&F->t_start)) {
			warnp("monoclock_get");
			goto err1;
		}

		/* Send the request to the target. */
		if (wire_requestqueue_add(D->Q, P.buf, P.len,
		    callback_gotresponse, F))
			goto err1;

		/* We have an additional outstanding request. */
		D->nrequests++;

		/* Consume the packet. */
		wire_readpacket_consume(D->readq, &P);
	} while (1);

	/* Wait for more packets to arrive. */
	if ((D->read_cookie = wire_readpacket_wait(D->readq,
	    callback_gotrequests, D)) == NULL) {
		warnp("Error reading request from connection");
		goto err0;
	}

	/* Success! */
	return (0);

fail:
	/*
	 * Something went wrong with the source connection -- either it failed
	 * while we were waiting for a packet, or we read a corrupted packet.
	 * Either way, we're not going to try reading any more packets -- and
	 * once the currently in-flight requests have had responses, we'll
	 * return zero from dispatch_alive.
	 */

	/* Return success; the connection will be reaped later. */
	return (0);

err1:
	free(F);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq $0x0, 0x20(%rdi)
xorl %ebx, %ebx
testl %esi, %esi
jne 0x38e9
movq %rdi, %r14
movq 0x8(%rdi), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9e7c
testl %eax, %eax
jne 0x38e9
leaq 0x195(%rip), %r15       # 0x3909
leaq 0x8(%rsp), %r12
cmpq $0x0, 0x18(%rsp)
je 0x386c
incq 0xeabc(%rip)            # 0x12248
movq 0xea9d(%rip), %rax      # 0x12230
testq %rax, %rax
je 0x37b1
movq 0xeaa1(%rip), %rcx      # 0x12240
leaq -0x1(%rax), %rdx
movq %rdx, 0xea86(%rip)      # 0x12230
movq -0x8(%rcx,%rax,8), %r13
jmp 0x37e4
incq 0xea98(%rip)            # 0x12250
cmpl $0x0, 0xea99(%rip)      # 0x12258
jne 0x37d7
movq 0xeaa0(%rip), %rdi      # 0x12268
callq 0xbfb0
movl $0x1, 0xea81(%rip)      # 0x12258
movl $0x28, %edi
callq 0x22a0
movq %rax, %r13
testq %r13, %r13
je 0x38e4
movq %r14, (%r13)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r13)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x4, 0x10(%rsp)
jb 0x3810
movq 0x18(%rsp), %rax
movl (%rax), %eax
bswapl %eax
movl %eax, 0x20(%r13)
leaq 0x10(%r13), %rdi
callq 0x7b28
testl %eax, %eax
jne 0x38ab
movq 0x28(%r14), %rdi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq %r15, %rcx
movq %r13, %r8
callq 0xaa1d
testl %eax, %eax
jne 0x38dc
incq 0x30(%r14)
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0xa324
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0x9e7c
testl %eax, %eax
je 0x3779
jmp 0x38e9
movq 0x8(%r14), %rdi
leaq -0x142(%rip), %rsi      # 0x3735
movq %r14, %rdx
callq 0x9fad
movq %rax, 0x20(%r14)
testq %rax, %rax
jne 0x38e9
callq 0x20a0
cmpl $0x0, (%rax)
je 0x38f9
movq %rax, %rbx
leaq 0x8b2d(%rip), %rdi      # 0xc3c9
xorl %eax, %eax
callq 0x8ecc
movl $0x0, (%rbx)
jmp 0x38e4
callq 0x20a0
cmpl $0x0, (%rax)
je 0x38ce
movq %rax, %rbx
leaq 0x8b30(%rip), %rdi      # 0xc3ef
xorl %eax, %eax
callq 0x8ecc
movl $0x0, (%rbx)
jmp 0x38dc
leaq 0x8b1a(%rip), %rdi      # 0xc3ef
xorl %eax, %eax
callq 0x8feb
movq %r13, %rdi
callq 0x2040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x8ac9(%rip), %rdi      # 0xc3c9
xorl %eax, %eax
callq 0x8feb
jmp 0x38e4