// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x10(%rdi)
cmpl $-0x1, %esi
je 0x35aa
movl %esi, %ebx
movq %r15, %rdi
callq 0x36da
movl $0x40, %edi
callq 0x2270
testq %rax, %rax
je 0x368b
movq %rax, %r14
movq %r15, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movl %ebx, 0x18(%rax)
movups %xmm0, 0x30(%rax)
movl %ebx, %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2100
cmpl $-0x1, %eax
je 0x35c3
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5988
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x35e5
movq %rax, %r12
movl %ebx, %edi
callq 0x55f0
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x360d
movq %r14, %rdi
callq 0x372c
testl %eax, %eax
je 0x3639
movq 0x20(%r14), %rdi
callq 0x591e
movq 0x28(%r14), %r12
jmp 0x3626
callq 0x20a0
cmpl $0x0, (%rax)
je 0x35d9
movq %rax, %rbx
leaq 0x7d26(%rip), %rdi      # 0xb2e4
jmp 0x36aa
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3630
movq %rax, %r15
leaq 0x7d28(%rip), %rdi      # 0xb2ff
jmp 0x35fd
leaq 0x7d04(%rip), %rdi      # 0xb2e4
jmp 0x36c0
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3675
movq %rax, %r15
leaq 0x7d26(%rip), %rdi      # 0xb323
xorl %eax, %eax
callq 0x8a00
movl $0x0, (%r15)
jmp 0x3683
leaq 0x7d30(%rip), %rdi      # 0xb344
xorl %eax, %eax
callq 0x8b1f
callq 0x20a0
movl $0x0, (%rax)
movq %r12, %rdi
callq 0x5ce7
jmp 0x3683
leaq 0x7cc8(%rip), %rdi      # 0xb2ff
jmp 0x367c
movq %r14, %rcx
addq $0x8, %rcx
movq 0x10(%r15), %rax
movq %rax, (%rcx)
testq %rax, %rax
je 0x3650
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 0x36cc
movq %r15, %rdi
callq 0x33c2
testl %eax, %eax
jne 0x36c7
jmp 0x36cc
leaq 0x7ca7(%rip), %rdi      # 0xb323
xorl %eax, %eax
callq 0x8b1f
movq %r14, %rdi
callq 0x2040
movl %ebx, %edi
callq 0x21c0
testl %eax, %eax
je 0x36c7
callq 0x20a0
cmpl $0x0, (%rax)
je 0x36b9
movq %rax, %rbx
leaq 0x8592(%rip), %rdi      # 0xbc3c
xorl %eax, %eax
callq 0x8a00
movl $0x0, (%rbx)
jmp 0x36c7
leaq 0x857c(%rip), %rdi      # 0xbc3c
xorl %eax, %eax
callq 0x8b1f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq