// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/mux/dispatch.c
// Function: callback_gotconn
static int
callback_gotconn(void * cookie, int s)
{
	struct sock_listen * L = cookie;
	struct dispatch_state * dstate = L->dstate;
	struct sock_active * S;

	/* This listener is no longer accepting. */
	L->accept_cookie = NULL;

	/* Check if the accept failed. */
	if (s == -1) {
		warnp("Error accepting connection");
		goto err0;
	}

	/* Stop trying to accept connections. */
	accept_stop(dstate);

	/* Allocate an active connection structure. */
	if ((S = malloc(sizeof(struct sock_active))) == NULL)
		goto err1;
	S->dstate = dstate;
	S->next = NULL;
	S->prev = NULL;
	S->s = s;
	S->read_cookie = NULL;
	S->nrequests = 0;

	/* Make the accepted connection non-blocking. */
	if (fcntl(S->s, F_SETFL, O_NONBLOCK) == -1) {
		warnp("Cannot make connection non-blocking");
		goto err2;
	}

	/*
	 * Create a buffered writer for the connection.  We don't care to find
	 * out if we failed to write responses back to the incoming connection;
	 * we can't drop the connection until all our responses have come back
	 * from the target server, and once that happens the connection will
	 * be dropped automatically (since if we can't write, we won't be able
	 * to read either).
	 */
	if ((S->writeq = netbuf_write_init(S->s, NULL, NULL)) == NULL) {
		warnp("Cannot create packet write queue");
		goto err2;
	}

	/* Create a buffered reader for the connection. */
	if ((S->readq = netbuf_read_init(S->s)) == NULL) {
		warn0("Cannot create packet read queue");
		goto err3;
	}

	/* Wait for request packets to arrive. */
	if (readreq(S))
		goto err4;

	/* Add this connection to the list. */
	S->next = dstate->sock_active;
	if (S->next != NULL)
		S->next->prev = S;
	dstate->sock_active = S;

	/* We have a connection.  Do we want more? */
	if (++dstate->nsock_active < dstate->nsock_active_max) {
		if (accept_start(dstate))
			goto err0;
	}

	/* Success! */
	return (0);

err4:
	netbuf_read_free(S->readq);
err3:
	netbuf_write_free(S->writeq);
err2:
	free(S);
err1:
	if (close(s))
		warnp("close");
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq (%rdi), %r15
andq $0x0, 0x10(%rdi)
cmpl $-0x1, %esi
je 0x302f
movl %esi, %ebx
movq %r15, %rdi
callq 0x3150
pushq $0x40
popq %rdi
callq 0x2270
testq %rax, %rax
je 0x3106
movq %rax, %r14
movq %r15, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movl %ebx, 0x18(%rax)
movups %xmm0, 0x30(%rax)
pushq $0x4
popq %rsi
movl %ebx, %edi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2100
cmpl $-0x1, %eax
je 0x3048
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4f08
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x306a
movq %rax, %r12
movl %ebx, %edi
callq 0x4b8c
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x308b
movq %r14, %rdi
callq 0x3193
testl %eax, %eax
je 0x30b4
movq 0x20(%r14), %rdi
callq 0x4e9f
movq 0x28(%r14), %r12
jmp 0x30a1
callq 0x20a0
cmpl $0x0, (%rax)
je 0x305e
movq %rax, %rbx
leaq 0x72a1(%rip), %rdi      # 0xa2e4
jmp 0x3125
callq 0x20a0
cmpl $0x0, (%rax)
je 0x30ab
movq %rax, %r15
leaq 0x72a3(%rip), %rdi      # 0xa2ff
jmp 0x307e
leaq 0x727f(%rip), %rdi      # 0xa2e4
jmp 0x3138
callq 0x20a0
cmpl $0x0, (%rax)
je 0x30f0
movq %rax, %r15
leaq 0x72a5(%rip), %rdi      # 0xa323
xorl %eax, %eax
callq 0x7afd
andl $0x0, (%r15)
jmp 0x30fe
leaq 0x72b2(%rip), %rdi      # 0xa344
xorl %eax, %eax
callq 0x7c8c
callq 0x20a0
andl $0x0, (%rax)
movq %r12, %rdi
callq 0x5254
jmp 0x30fe
leaq 0x724d(%rip), %rdi      # 0xa2ff
jmp 0x30f7
movq %r14, %rcx
addq $0x8, %rcx
movq 0x10(%r15), %rax
movq %rax, (%rcx)
testq %rax, %rax
je 0x30cb
movq %r14, 0x10(%rax)
movq %r14, 0x10(%r15)
movq 0x18(%r15), %rax
incq %rax
movq %rax, 0x18(%r15)
xorl %ebx, %ebx
cmpq 0x20(%r15), %rax
jae 0x3142
movq %r15, %rdi
callq 0x2e53
testl %eax, %eax
jne 0x313f
jmp 0x3142
leaq 0x722c(%rip), %rdi      # 0xa323
xorl %eax, %eax
callq 0x7c8c
movq %r14, %rdi
callq 0x2040
movl %ebx, %edi
callq 0x21c0
testl %eax, %eax
je 0x313f
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3131
movq %rax, %rbx
leaq 0x7b17(%rip), %rdi      # 0xac3c
xorl %eax, %eax
callq 0x7afd
andl $0x0, (%rbx)
jmp 0x313f
leaq 0x7b04(%rip), %rdi      # 0xac3c
xorl %eax, %eax
callq 0x7c8c
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq