// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]spiped/tests/nc-server/simple_server.c
// Function: simple_server
int
simple_server(const char * addr, size_t nconn_max, size_t shutdown_after,
    int (* callback_nc_message)(void *, uint8_t *, size_t, int),
    void * caller_cookie)
{
	struct accept_state * A;
	struct sock_addr * sa;
	int sock;

	/* Resolve the address. */
	if ((sa = sock_resolve_one(addr, 0)) == NULL) {
		warn0("sock_resolve_one");
		goto err0;
	}

	/* Create a socket, bind it, mark it as listening. */
	if ((sock = sock_listener(sa)) == -1) {
		warn0("sock_listener");
		goto err1;
	}

	/* Bake a cookie for the server. */
	if ((A = malloc(sizeof(struct accept_state))) == NULL) {
		warnp("Out of memory");
		goto err2;
	}
	A->s = sock;
	A->conndone = 0;
	A->shutdown_requested = 0;
	A->shutdown_after = shutdown_after;
	A->shutdown_current = 0;
	A->nconn = 0;
	A->nconn_max = nconn_max;
	A->accept_cookie = NULL;
	A->callback_nc_message = callback_nc_message;
	A->caller_cookie = caller_cookie;
	LIST_INIT(&A->conn_cookies);

	/* Accept a connection. */
	if (doaccept(A)) {
		warn0("doaccept");
		goto err3;
	}

	/* Loop until we die. */
	if (events_spin(&A->conndone)) {
		warnp("Error running event loop");
		goto err4;
	}

	/* Clean up. */
	sock_addr_free(sa);
	simple_server_shutdown(A);

	/* Success! */
	return (0);

err4:
	if (A->accept_cookie != NULL)
		network_accept_cancel(A->accept_cookie);
err3:
	free(A);
err2:
	if (close(sock))
		warnp("close");
err1:
	sock_addr_free(sa);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %r13
xorl %esi, %esi
callq 0x4a4f
testq %rax, %rax
je 0x2863
movq %rax, %rbx
movq %rax, %rdi
callq 0x4bd9
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x287e
pushq $0x50
popq %rdi
callq 0x21f0
testq %rax, %rax
je 0x2899
movq %rax, %r14
movl 0x4(%rsp), %eax
movl %eax, (%r14)
andq $0x0, 0x4(%r14)
movq %rbp, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r14)
movq %r13, 0x28(%r14)
movups %xmm0, 0x30(%r14)
movq %r12, 0x48(%r14)
movq %r15, 0x40(%r14)
movq %r14, %rdi
callq 0x2a38
testl %eax, %eax
je 0x28ba
leaq 0x492f(%rip), %rdi      # 0x7176
xorl %eax, %eax
callq 0x562c
callq 0x2090
andl $0x0, (%rax)
movq %r14, %rdi
callq 0x2040
jmp 0x2904
leaq 0x48df(%rip), %rdi      # 0x7149
xorl %eax, %eax
callq 0x562c
callq 0x2090
andl $0x0, (%rax)
jmp 0x2948
leaq 0x48d5(%rip), %rdi      # 0x715a
xorl %eax, %eax
callq 0x562c
callq 0x2090
andl $0x0, (%rax)
jmp 0x2940
callq 0x2090
cmpl $0x0, (%rax)
je 0x28f6
movq %rax, %r14
leaq 0x48bb(%rip), %rdi      # 0x7168
xorl %eax, %eax
callq 0x549d
andl $0x0, (%r14)
jmp 0x2904
movq %r14, %rdi
addq $0x4, %rdi
callq 0x30a3
testl %eax, %eax
je 0x295a
callq 0x2090
cmpl $0x0, (%rax)
je 0x29f6
movq %rax, %r15
leaq 0x4899(%rip), %rdi      # 0x717f
xorl %eax, %eax
callq 0x549d
andl $0x0, (%r15)
jmp 0x2a04
leaq 0x486b(%rip), %rdi      # 0x7168
xorl %eax, %eax
callq 0x562c
movl 0x4(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x2940
callq 0x2090
cmpl $0x0, (%rax)
je 0x2932
movq %rax, %r14
leaq 0x4788(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x549d
andl $0x0, (%r14)
jmp 0x2940
leaq 0x4774(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x562c
movq %rbx, %rdi
callq 0x4b8b
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x4b8b
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x2970
callq 0x403c
movq 0x38(%r14), %r15
leaq 0x4839(%rip), %rbx      # 0x71b4
testq %r15, %r15
je 0x29c9
movq %r15, %rdi
callq 0x2d13
testl %eax, %eax
je 0x299e
movq %rbx, %rdi
xorl %eax, %eax
callq 0x562c
callq 0x2090
andl $0x0, (%rax)
movq 0x38(%r14), %rax
cmpq %rax, %r15
movq %rax, %r15
jne 0x297b
leaq 0x4878(%rip), %rdi      # 0x7229
leaq 0x483b(%rip), %rsi      # 0x71f3
leaq 0x4893(%rip), %rcx      # 0x7252
movl $0x100, %edx            # imm = 0x100
callq 0x2160
movl (%r14), %edi
callq 0x2180
cmpl $-0x1, %eax
jne 0x2a29
callq 0x2090
cmpl $0x0, (%rax)
je 0x2a1b
movq %rax, %rbx
leaq 0x46c3(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x549d
andl $0x0, (%rbx)
jmp 0x2a29
leaq 0x4782(%rip), %rdi      # 0x717f
xorl %eax, %eax
callq 0x562c
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x2856
callq 0x403c
jmp 0x2856
leaq 0x468b(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x562c
movq %r14, %rdi
callq 0x2040
xorl %eax, %eax
jmp 0x294b