// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x3a0e
jmp 0x3b95
jmp 0x3a10
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0xd9f0
cmpl $0x0, %eax
je 0x3a2b
jmp 0x3b95
cmpq $0x0, -0x28(%rbp)
jne 0x3a37
jmp 0x3b2d
callq 0x3bc0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x3a4b
jmp 0x3ba7
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x4, -0x30(%rbp)
jb 0x3a7d
movq -0x28(%rbp), %rdi
callq 0x3be0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0x3a88
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rdi
addq $0x10, %rdi
callq 0xa3b0
cmpl $0x0, %eax
je 0x3ad6
jmp 0x3a9c
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3ac1
leaq 0xea9a(%rip), %rdi      # 0x12547
movb $0x0, %al
callq 0xc460
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3acf
leaq 0xea7f(%rip), %rdi      # 0x12547
movb $0x0, %al
callq 0xc6b0
jmp 0x3ad1
jmp 0x3b9e
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %r8
leaq 0x12f(%rip), %rcx       # 0x3c20
callq 0xe730
cmpl $0x0, %eax
je 0x3b00
jmp 0x3b9e
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0xdec0
movb $0x1, %al
testb $0x1, %al
jne 0x3a10
jmp 0x3b2d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq -0x160(%rip), %rsi      # 0x39e0
callq 0xdc90
movq -0x20(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x3b8c
jmp 0x3b55
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3b7a
leaq 0xe9bb(%rip), %rdi      # 0x12521
movb $0x0, %al
callq 0xc460
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3b88
leaq 0xe9a0(%rip), %rdi      # 0x12521
movb $0x0, %al
callq 0xc6b0
jmp 0x3b8a
jmp 0x3ba7
movl $0x0, -0x4(%rbp)
jmp 0x3bae
movl $0x0, -0x4(%rbp)
jmp 0x3bae
movq -0x40(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)