// File: /workspace/github_c_makefile_star2_O3/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 0x5217
testq %rax, %rax
je 0x29eb
movq %rax, %rbx
movq %rax, %rdi
callq 0x53ca
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x2a09
movl $0x50, %edi
callq 0x21f0
testq %rax, %rax
je 0x2a27
movq %rax, %r14
movl 0x4(%rsp), %eax
movl %eax, (%r14)
movq $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 0x2bd7
testl %eax, %eax
je 0x2a4b
leaq 0x47aa(%rip), %rdi      # 0x7176
xorl %eax, %eax
callq 0x5e17
callq 0x2090
movl $0x0, (%rax)
movq %r14, %rdi
callq 0x2040
jmp 0x2a98
leaq 0x4757(%rip), %rdi      # 0x7149
xorl %eax, %eax
callq 0x5e17
callq 0x2090
movl $0x0, (%rax)
jmp 0x2adf
leaq 0x474a(%rip), %rdi      # 0x715a
xorl %eax, %eax
callq 0x5e17
callq 0x2090
movl $0x0, (%rax)
jmp 0x2ad7
callq 0x2090
cmpl $0x0, (%rax)
je 0x2a8a
movq %rax, %r14
leaq 0x472d(%rip), %rdi      # 0x7168
xorl %eax, %eax
callq 0x5cf8
movl $0x0, (%r14)
jmp 0x2a98
movq %r14, %rdi
addq $0x4, %rdi
callq 0x3289
testl %eax, %eax
je 0x2af3
callq 0x2090
cmpl $0x0, (%rax)
je 0x2b95
movq %rax, %r15
leaq 0x4708(%rip), %rdi      # 0x717f
xorl %eax, %eax
callq 0x5cf8
movl $0x0, (%r15)
jmp 0x2ba3
leaq 0x46d7(%rip), %rdi      # 0x7168
xorl %eax, %eax
callq 0x5e17
movl 0x4(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x2ad7
callq 0x2090
cmpl $0x0, (%rax)
je 0x2ac9
movq %rax, %r14
leaq 0x45f4(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5cf8
movl $0x0, (%r14)
jmp 0x2ad7
leaq 0x45dd(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5e17
movq %rbx, %rdi
callq 0x536a
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x536a
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x2b09
callq 0x44f2
movq 0x38(%r14), %r15
leaq 0x46a0(%rip), %rbx      # 0x71b4
testq %r15, %r15
je 0x2b65
movq %r15, %rdi
callq 0x2ee5
testl %eax, %eax
je 0x2b3a
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5e17
callq 0x2090
movl $0x0, (%rax)
movq 0x38(%r14), %rax
cmpq %rax, %r15
movq %rax, %r15
jne 0x2b14
leaq 0x46dc(%rip), %rdi      # 0x7229
leaq 0x469f(%rip), %rsi      # 0x71f3
leaq 0x46f7(%rip), %rcx      # 0x7252
movl $0x100, %edx            # imm = 0x100
callq 0x2160
movl (%r14), %edi
callq 0x2180
cmpl $-0x1, %eax
jne 0x2bc8
callq 0x2090
cmpl $0x0, (%rax)
je 0x2bba
movq %rax, %rbx
leaq 0x4527(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5cf8
movl $0x0, (%rbx)
jmp 0x2bc8
leaq 0x45e3(%rip), %rdi      # 0x717f
xorl %eax, %eax
callq 0x5e17
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x29de
callq 0x44f2
jmp 0x29de
leaq 0x44ec(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5e17
movq %r14, %rdi
callq 0x2040
xorl %eax, %eax
jmp 0x2ae4