// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x6990
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x2d51
jmp 0x2d33
leaq 0x748d(%rip), %rdi      # 0xa1c7
movb $0x0, %al
callq 0x7df0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2f59
movq -0x40(%rbp), %rdi
callq 0x6bc0
movl %eax, -0x44(%rbp)
cmpl $-0x1, %eax
jne 0x2d82
jmp 0x2d64
leaq 0x746d(%rip), %rdi      # 0xa1d8
movb $0x0, %al
callq 0x7df0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2f50
movl $0x50, %edi
callq 0x2220
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x2dd2
jmp 0x2d98
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2dbd
leaq 0x743d(%rip), %rdi      # 0xa1e6
movb $0x0, %al
callq 0x7ba0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2dcb
leaq 0x7422(%rip), %rdi      # 0xa1e6
movb $0x0, %al
callq 0x7df0
jmp 0x2dcd
jmp 0x2f08
movl -0x44(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x38(%rbp), %rdi
callq 0x2f70
cmpl $0x0, %eax
je 0x2e7f
jmp 0x2e61
leaq 0x738c(%rip), %rdi      # 0xa1f4
movb $0x0, %al
callq 0x7df0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2eff
movq -0x38(%rbp), %rdi
addq $0x4, %rdi
callq 0x38f0
cmpl $0x0, %eax
je 0x2eca
jmp 0x2e93
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2eb8
leaq 0x7359(%rip), %rdi      # 0xa1fd
movb $0x0, %al
callq 0x7ba0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2ec6
leaq 0x733e(%rip), %rdi      # 0xa1fd
movb $0x0, %al
callq 0x7df0
jmp 0x2ec8
jmp 0x2ee5
movq -0x40(%rbp), %rdi
callq 0x6b30
movq -0x38(%rbp), %rdi
callq 0x3020
movl $0x0, -0x4(%rbp)
jmp 0x2f60
movq -0x38(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x2efd
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x5600
jmp 0x2eff
movq -0x38(%rbp), %rdi
callq 0x2040
movl -0x44(%rbp), %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x2f4e
jmp 0x2f17
callq 0x20a0
cmpl $0x0, (%rax)
je 0x2f3c
leaq 0x7185(%rip), %rdi      # 0xa0ad
movb $0x0, %al
callq 0x7ba0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x2f4a
leaq 0x716a(%rip), %rdi      # 0xa0ad
movb $0x0, %al
callq 0x7df0
jmp 0x2f4c
jmp 0x2f4e
jmp 0x2f50
movq -0x40(%rbp), %rdi
callq 0x6b30
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)