// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
cmpl $-0x1, -0x14(%rbp)
jne 0x3970
jmp 0x3936
callq 0x20a0
cmpl $0x0, (%rax)
je 0x395b
leaq 0xcb73(%rip), %rdi      # 0x104ba
movb $0x0, %al
callq 0xbc80
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3969
leaq 0xcb58(%rip), %rdi      # 0x104ba
movb $0x0, %al
callq 0xbed0
jmp 0x396b
jmp 0x3bae
movq -0x28(%rbp), %rdi
callq 0x3bc0
movl $0x40, %edi
callq 0x2290
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x3992
jmp 0x3b66
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x10(%rax)
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x30(%rbp), %rax
movl 0x18(%rax), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x2110
cmpl $-0x1, %eax
jne 0x3a30
jmp 0x39f6
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3a1b
leaq 0xcace(%rip), %rdi      # 0x104d5
movb $0x0, %al
callq 0xbc80
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3a29
leaq 0xcab3(%rip), %rdi      # 0x104d5
movb $0x0, %al
callq 0xbed0
jmp 0x3a2b
jmp 0x3b5d
movq -0x30(%rbp), %rax
movl 0x18(%rax), %edi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x7090
movq -0x30(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x3a8d
jmp 0x3a53
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3a78
leaq 0xca95(%rip), %rdi      # 0x104f9
movb $0x0, %al
callq 0xbc80
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3a86
leaq 0xca7a(%rip), %rdi      # 0x104f9
movb $0x0, %al
callq 0xbed0
jmp 0x3a88
jmp 0x3b5d
movq -0x30(%rbp), %rax
movl 0x18(%rax), %edi
callq 0x69b0
movq -0x30(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x3ac7
jmp 0x3aa9
leaq 0xca6a(%rip), %rdi      # 0x1051a
movb $0x0, %al
callq 0xbed0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3b50
movq -0x30(%rbp), %rdi
callq 0x3c30
cmpl $0x0, %eax
je 0x3ad7
jmp 0x3b43
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3b02
movq -0x30(%rbp), %rcx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq 0x18(%rcx), %rax
addq $0x1, %rax
movq %rax, 0x18(%rcx)
movq -0x28(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x3b3a
movq -0x28(%rbp), %rdi
callq 0x3720
cmpl $0x0, %eax
je 0x3b38
jmp 0x3bae
jmp 0x3b3a
movl $0x0, -0x4(%rbp)
jmp 0x3bb5
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x7000
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x76d0
movq -0x30(%rbp), %rdi
callq 0x2040
movl -0x14(%rbp), %edi
callq 0x21e0
cmpl $0x0, %eax
je 0x3bac
jmp 0x3b75
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3b9a
leaq 0xd266(%rip), %rdi      # 0x10dec
movb $0x0, %al
callq 0xbc80
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3ba8
leaq 0xd24b(%rip), %rdi      # 0x10dec
movb $0x0, %al
callq 0xbed0
jmp 0x3baa
jmp 0x3bac
jmp 0x3bae
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop