// File: /workspace/github_c_makefile_star2_O1/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 %rbx
movq (%rdi), %r15
movq $0x0, 0x10(%rdi)
cmpl $-0x1, %esi
je 0x35a4
movl %esi, %ebx
movq %r15, %rdi
callq 0x36cf
movl $0x40, %edi
callq 0x2270
testq %rax, %rax
je 0x3686
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 0x35bd
movl 0x18(%r14), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5934
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x35df
movl 0x18(%r14), %edi
callq 0x55a0
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x3607
movq %r14, %rdi
callq 0x371c
testl %eax, %eax
je 0x3634
movq 0x20(%r14), %rdi
callq 0x58c8
jmp 0x3620
callq 0x20a0
cmpl $0x0, (%rax)
je 0x35d3
movq %rax, %rbx
leaq 0x7da0(%rip), %rdi      # 0xb358
jmp 0x36a5
callq 0x20a0
cmpl $0x0, (%rax)
je 0x362b
movq %rax, %r15
leaq 0x7da2(%rip), %rdi      # 0xb373
jmp 0x35f7
leaq 0x7d7e(%rip), %rdi      # 0xb358
jmp 0x36bb
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3670
movq %rax, %r15
leaq 0x7da0(%rip), %rdi      # 0xb397
xorl %eax, %eax
callq 0x8940
movl $0x0, (%r15)
jmp 0x367e
leaq 0x7daa(%rip), %rdi      # 0xb3b8
xorl %eax, %eax
callq 0x8a5f
callq 0x20a0
movl $0x0, (%rax)
movq 0x28(%r14), %rdi
callq 0x5cb3
jmp 0x367e
leaq 0x7d41(%rip), %rdi      # 0xb373
jmp 0x3677
movq %r14, %rcx
addq $0x8, %rcx
movq 0x10(%r15), %rax
movq %rax, (%rcx)
testq %rax, %rax
je 0x364b
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 0x36c7
movq %r15, %rdi
callq 0x33c2
testl %eax, %eax
jne 0x36c2
jmp 0x36c7
leaq 0x7d20(%rip), %rdi      # 0xb397
xorl %eax, %eax
callq 0x8a5f
movq %r14, %rdi
callq 0x2040
movl %ebx, %edi
callq 0x21c0
testl %eax, %eax
je 0x36c2
callq 0x20a0
cmpl $0x0, (%rax)
je 0x36b4
movq %rax, %rbx
leaq 0x85ef(%rip), %rdi      # 0xbc94
xorl %eax, %eax
callq 0x8940
movl $0x0, (%rbx)
jmp 0x36c2
leaq 0x85d9(%rip), %rdi      # 0xbc94
xorl %eax, %eax
callq 0x8a5f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
popq %rbx
popq %r14
popq %r15
retq