// File: /workspace/github_c_makefile_star2_O3/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 0x38dd
movq %rdi, %r14
movq 0x8(%rdi), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9ed8
testl %eax, %eax
jne 0x38dd
leaq 0x195(%rip), %r15       # 0x38fd
leaq 0x8(%rsp), %r12
cmpq $0x0, 0x18(%rsp)
je 0x3860
incq 0xfac8(%rip)            # 0x13248
movq 0xfaa9(%rip), %rax      # 0x13230
testq %rax, %rax
je 0x37a5
movq 0xfaad(%rip), %rcx      # 0x13240
leaq -0x1(%rax), %rdx
movq %rdx, 0xfa92(%rip)      # 0x13230
movq -0x8(%rcx,%rax,8), %r13
jmp 0x37d8
incq 0xfaa4(%rip)            # 0x13250
cmpl $0x0, 0xfaa5(%rip)      # 0x13258
jne 0x37cb
movq 0xfaac(%rip), %rdi      # 0x13268
callq 0xc060
movl $0x1, 0xfa8d(%rip)      # 0x13258
movl $0x28, %edi
callq 0x22a0
movq %rax, %r13
testq %r13, %r13
je 0x38d8
movq %r14, (%r13)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r13)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x4, 0x10(%rsp)
jb 0x3804
movq 0x18(%rsp), %rax
movl (%rax), %eax
bswapl %eax
movl %eax, 0x20(%r13)
leaq 0x10(%r13), %rdi
callq 0x7bec
testl %eax, %eax
jne 0x389f
movq 0x28(%r14), %rdi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq %r15, %rcx
movq %r13, %r8
callq 0xaabd
testl %eax, %eax
jne 0x38d0
incq 0x30(%r14)
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0xa395
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0x9ed8
testl %eax, %eax
je 0x376d
jmp 0x38dd
movq 0x8(%r14), %rdi
leaq -0x142(%rip), %rsi      # 0x3729
movq %r14, %rdx
callq 0xa006
movq %rax, 0x20(%r14)
testq %rax, %rax
jne 0x38dd
callq 0x20a0
cmpl $0x0, (%rax)
je 0x38ed
movq %rax, %rbx
leaq 0x9ad9(%rip), %rdi      # 0xd369
xorl %eax, %eax
callq 0x8f6c
movl $0x0, (%rbx)
jmp 0x38d8
callq 0x20a0
cmpl $0x0, (%rax)
je 0x38c2
movq %rax, %rbx
leaq 0x9adc(%rip), %rdi      # 0xd38f
xorl %eax, %eax
callq 0x8f6c
movl $0x0, (%rbx)
jmp 0x38d0
leaq 0x9ac6(%rip), %rdi      # 0xd38f
xorl %eax, %eax
callq 0x908b
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 0x9a75(%rip), %rdi      # 0xd369
xorl %eax, %eax
callq 0x908b
jmp 0x38d8