// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/lib/socket.c
// Function: sa_egress
void *sa_egress(void *lcl, size_t lim, sockaddr_arg_t rmt, int *_error) {
	static struct { sa_family_t pf; int fd;} udp4 = { PF_INET, -1 }, udp6 = { PF_INET6, -1 }, *udp;
	struct sockaddr_storage ss;
	int error;

	switch (*sa_family(rmt)) {
	case AF_INET:
		udp = &udp4;

		break;
	case AF_INET6:
		udp = &udp6;

		break;
	default:
		error = EINVAL;

		goto error;
	}

	if (udp->fd == -1) {
#if defined SOCK_CLOEXEC
		if (-1 == (udp->fd = socket(udp->pf, SOCK_DGRAM|SOCK_CLOEXEC, 0)))
			goto syerr;
#else
		if (-1 == (udp->fd = socket(udp->pf, SOCK_DGRAM, 0)))
			goto syerr;
#endif

		if ((error = so_cloexec(udp->fd, 1))) {
			so_closesocket(&udp->fd, NULL);

			goto error;
		}
	}

	assert(sizeof ss >= sa_len(rmt));
	memcpy(&ss, sockaddr_ref(rmt).sa, sa_len(rmt));

	if (!*sa_port(&ss, SA_PORT_NONE, NULL))
		*sa_port(&ss, SA_PORT_NONE, NULL) = htons(6970);

	if (0 != connect(udp->fd, (struct sockaddr *)&ss, sa_len(&ss)))
		goto syerr;

	memset(&ss, 0, sizeof ss);

	if (0 != getsockname(udp->fd, (struct sockaddr *)&ss, &(socklen_t){ sizeof ss }))
		goto syerr;

	if (lim < sa_len(&ss)) {
		error = ENOSPC;

		goto error;
	}

	memcpy(lcl, &ss, sa_len(&ss));

	return lcl;
syerr:
	error = so_syerr();
error:
	if (_error)
		*_error = error;

	return memset(lcl, 0, lim);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movzwl (%rdx), %eax
cmpl $0x2, %eax
je 0x22fa0
movl $0x16, %ebp
cmpl $0xa, %eax
jne 0x23108
leaq 0x25322(%rip), %rcx     # 0x482c0
jmp 0x22fa7
leaq 0x25311(%rip), %rcx     # 0x482b8
movq %rcx, 0x25682(%rip)     # 0x48630
cmpl $-0x1, 0x4(%rcx)
je 0x22fce
cmpw $0x1, %ax
je 0x23035
movzwl %ax, %eax
cmpl $0x2, %eax
je 0x2302e
cmpl $0xa, %eax
jne 0x2303c
movl $0x1c, %edx
jmp 0x2303e
movzwl (%rcx), %edi
movl $0x80002, %esi          # imm = 0x80002
xorl %edx, %edx
callq 0xf300
movq 0x2564c(%rip), %rcx     # 0x48630
movl %eax, 0x4(%rcx)
cmpl $-0x1, %eax
je 0x23101
movl %eax, %edi
movl $0x1, %esi
callq 0xf430
testl %eax, %eax
je 0x2314d
movl %eax, %ebp
movq 0x25623(%rip), %r12     # 0x48630
movl 0x4(%r12), %edi
cmpl $-0x1, %edi
je 0x23108
callq 0x10a10
movl $0xffffffff, 0x4(%r12)  # imm = 0xFFFFFFFF
jmp 0x23108
movl $0x10, %edx
jmp 0x2303e
movl $0x6e, %edx
jmp 0x2303e
xorl %edx, %edx
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xfa60
movzwl (%r13), %eax
leaq 0xa(%rsp), %rcx
movl %eax, %edx
orl $0x8, %edx
cmpl $0xa, %edx
jne 0x23079
cmpw $0x0, 0x12(%rsp)
jne 0x2307e
cmpl $0xa, %eax
je 0x23074
cmpl $0x2, %eax
jne 0x23079
leaq 0x12(%rsp), %rcx
movw $0x3a1b, (%rcx)         # imm = 0x3A1B
movq 0x255ab(%rip), %rcx     # 0x48630
movl 0x4(%rcx), %edi
cmpl $0x1, %eax
je 0x230a5
cmpl $0x2, %eax
je 0x2309e
cmpl $0xa, %eax
jne 0x230ac
movl $0x1c, %edx
jmp 0x230ae
movl $0x10, %edx
jmp 0x230ae
movl $0x6e, %edx
jmp 0x230ae
xorl %edx, %edx
leaq 0x10(%rsp), %rsi
callq 0xfaa0
testl %eax, %eax
jne 0x23101
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movaps %xmm0, 0x70(%rsi)
movaps %xmm0, 0x60(%rsi)
movaps %xmm0, 0x50(%rsi)
movaps %xmm0, 0x40(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movq 0x25546(%rip), %rax     # 0x48630
movl 0x4(%rax), %edi
leaq 0xc(%rsp), %rdx
movl $0x80, (%rdx)
callq 0xfc30
testl %eax, %eax
je 0x23132
callq 0xf0a0
movl (%rax), %ebp
testq %r15, %r15
je 0x23110
movl %ebp, (%r15)
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0xf750
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzwl 0x10(%rsp), %eax
cmpl $0x1, %eax
je 0x2315e
cmpl $0x2, %eax
je 0x23157
cmpl $0xa, %eax
jne 0x23183
movl $0x1c, %ecx
jmp 0x23163
movzwl (%r12), %eax
jmp 0x22fb4
movl $0x10, %ecx
jmp 0x23163
movl $0x6e, %ecx
movl $0x1c, %ebp
cmpq %r14, %rcx
ja 0x23108
cmpl $0x1, %eax
je 0x2318e
cmpl $0x2, %eax
je 0x23187
cmpl $0xa, %eax
jne 0x23183
movl $0x1c, %edx
jmp 0x23193
xorl %edx, %edx
jmp 0x23193
movl $0x10, %edx
jmp 0x23193
movl $0x6e, %edx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa60
jmp 0x2311d