// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
andq $0x0, 0x20(%rdi)
xorl %ebx, %ebx
testl %esi, %esi
jne 0x3333
movq %rdi, %r14
movq %rsp, %r15
pushq $-0x1
popq %r12
leaq 0x17e(%rip), %r13       # 0x3354
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x8f80
testl %eax, %eax
jne 0x3333
cmpq $0x0, 0x10(%rsp)
je 0x32be
incq 0xf04b(%rip)            # 0x12248
movq 0xf02c(%rip), %rax      # 0x12230
testq %rax, %rax
je 0x3222
movq 0xf030(%rip), %rcx      # 0x12240
leaq -0x1(%rax), %rdx
movq %rdx, 0xf015(%rip)      # 0x12230
movq -0x8(%rcx,%rax,8), %rbp
jmp 0x3253
incq 0xf027(%rip)            # 0x12250
cmpl $0x0, 0xf028(%rip)      # 0x12258
jne 0x3248
movq 0xf02f(%rip), %rdi      # 0x12268
callq 0xac50
movl $0x1, 0xf010(%rip)      # 0x12258
pushq $0x28
popq %rdi
callq 0x22a0
movq %rax, %rbp
testq %rbp, %rbp
je 0x3330
movq %r14, (%rbp)
movq (%rsp), %rax
movq %rax, 0x8(%rbp)
cmpq $0x4, 0x8(%rsp)
movl %r12d, %eax
jb 0x327c
movq 0x10(%rsp), %rax
movl (%rax), %eax
bswapl %eax
movl %eax, 0x20(%rbp)
leaq 0x10(%rbp), %rdi
callq 0x6f28
testl %eax, %eax
jne 0x32fa
movq 0x28(%r14), %rdi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq %r13, %rcx
movq %rbp, %r8
callq 0x9855
testl %eax, %eax
jne 0x3328
incq 0x30(%r14)
movq 0x8(%r14), %rdi
movq %r15, %rsi
callq 0x9340
jmp 0x31d6
movq 0x8(%r14), %rdi
leaq -0x121(%rip), %rsi      # 0x31a8
movq %r14, %rdx
callq 0x90b1
movq %rax, 0x20(%r14)
testq %rax, %rax
jne 0x3333
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3344
movq %rax, %rbx
leaq 0x807b(%rip), %rdi      # 0xb369
xorl %eax, %eax
callq 0x80c9
andl $0x0, (%rbx)
jmp 0x3330
callq 0x20a0
cmpl $0x0, (%rax)
je 0x331a
movq %rax, %rbx
leaq 0x8081(%rip), %rdi      # 0xb38f
xorl %eax, %eax
callq 0x80c9
andl $0x0, (%rbx)
jmp 0x3328
leaq 0x806e(%rip), %rdi      # 0xb38f
xorl %eax, %eax
callq 0x8258
movq %rbp, %rdi
callq 0x2040
movl %r12d, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x801e(%rip), %rdi      # 0xb369
xorl %eax, %eax
callq 0x8258
jmp 0x3330