// File: /workspace/github_c_makefile_star2_O1/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 0x51cf
testq %rax, %rax
je 0x29f3
movq %rax, %rbx
movq %rax, %rdi
callq 0x538b
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x2a11
movl $0x50, %edi
callq 0x21f0
testq %rax, %rax
je 0x2a2f
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 0x2bd9
testl %eax, %eax
je 0x2a53
leaq 0x47a2(%rip), %rdi      # 0x7176
xorl %eax, %eax
callq 0x5df7
callq 0x2090
movl $0x0, (%rax)
movq %r14, %rdi
callq 0x2040
jmp 0x2aa0
leaq 0x474f(%rip), %rdi      # 0x7149
xorl %eax, %eax
callq 0x5df7
callq 0x2090
movl $0x0, (%rax)
jmp 0x2ae7
leaq 0x4742(%rip), %rdi      # 0x715a
xorl %eax, %eax
callq 0x5df7
callq 0x2090
movl $0x0, (%rax)
jmp 0x2adf
callq 0x2090
cmpl $0x0, (%rax)
je 0x2a92
movq %rax, %r14
leaq 0x4725(%rip), %rdi      # 0x7168
xorl %eax, %eax
callq 0x5cd8
movl $0x0, (%r14)
jmp 0x2aa0
movq %r14, %rdi
addq $0x4, %rdi
callq 0x32a1
testl %eax, %eax
je 0x2afb
callq 0x2090
cmpl $0x0, (%rax)
je 0x2b97
movq %rax, %r15
leaq 0x4700(%rip), %rdi      # 0x717f
xorl %eax, %eax
callq 0x5cd8
movl $0x0, (%r15)
jmp 0x2ba5
leaq 0x46cf(%rip), %rdi      # 0x7168
xorl %eax, %eax
callq 0x5df7
movl 0x4(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x2adf
callq 0x2090
cmpl $0x0, (%rax)
je 0x2ad1
movq %rax, %r14
leaq 0x45ec(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5cd8
movl $0x0, (%r14)
jmp 0x2adf
leaq 0x45d5(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5df7
movq %rbx, %rdi
callq 0x532b
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 0x532b
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x2b11
callq 0x44ce
leaq 0x469c(%rip), %rbx      # 0x71b4
movq 0x38(%r14), %r15
testq %r15, %r15
je 0x2b67
movq %r15, %rdi
callq 0x2ee7
testl %eax, %eax
je 0x2b42
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5df7
callq 0x2090
movl $0x0, (%rax)
cmpq 0x38(%r14), %r15
jne 0x2b18
leaq 0x46da(%rip), %rdi      # 0x7229
leaq 0x469d(%rip), %rsi      # 0x71f3
leaq 0x46f5(%rip), %rcx      # 0x7252
movl $0x100, %edx            # imm = 0x100
callq 0x2160
movl (%r14), %edi
callq 0x2180
cmpl $-0x1, %eax
jne 0x2bca
callq 0x2090
cmpl $0x0, (%rax)
je 0x2bbc
movq %rax, %rbx
leaq 0x4525(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5cd8
movl $0x0, (%rbx)
jmp 0x2bca
leaq 0x45e1(%rip), %rdi      # 0x717f
xorl %eax, %eax
callq 0x5df7
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x29e6
callq 0x44ce
jmp 0x29e6
leaq 0x44ea(%rip), %rdi      # 0x70ad
xorl %eax, %eax
callq 0x5df7
movq %r14, %rdi
callq 0x2040
xorl %eax, %eax
jmp 0x2aec