// File: /workspace/github_c_makefile_star2_O1/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 0x23108
movl $0x16, %ebp
cmpl $0xa, %eax
jne 0x2327c
leaq 0x251ba(%rip), %rax     # 0x482c0
jmp 0x2310f
leaq 0x251a9(%rip), %rax     # 0x482b8
movq %rax, 0x2551a(%rip)     # 0x48630
cmpl $-0x1, 0x4(%rax)
je 0x23137
movzwl (%r12), %eax
cmpl $0x1, %eax
je 0x2319a
cmpl $0x2, %eax
je 0x23193
cmpl $0xa, %eax
jne 0x231a1
movl $0x1c, %edx
jmp 0x231a3
movzwl (%rax), %edi
movl $0x80002, %esi          # imm = 0x80002
xorl %edx, %edx
callq 0xf300
movq 0x254e3(%rip), %rcx     # 0x48630
movl %eax, 0x4(%rcx)
cmpl $-0x1, %eax
je 0x23275
movl %eax, %edi
movl $0x1, %esi
callq 0xf430
testl %eax, %eax
je 0x2311c
movl %eax, %ebp
movq 0x254be(%rip), %r12     # 0x48630
movl 0x4(%r12), %edi
cmpl $-0x1, %edi
je 0x2327c
callq 0x10a10
movl $0xffffffff, 0x4(%r12)  # imm = 0xFFFFFFFF
jmp 0x2327c
movl $0x10, %edx
jmp 0x231a3
movl $0x6e, %edx
jmp 0x231a3
xorl %edx, %edx
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xfa60
movzwl (%r13), %eax
cmpl $0xa, %eax
je 0x231c2
cmpl $0x2, %eax
jne 0x231c9
movzwl 0x12(%rsp), %ecx
jmp 0x231cb
xorl %ecx, %ecx
testw %cx, %cx
jne 0x231f2
movw $0x0, 0xa(%rsp)
cmpl $0xa, %eax
je 0x231e1
cmpl $0x2, %eax
jne 0x231e8
leaq 0x12(%rsp), %rcx
jmp 0x231ed
leaq 0xa(%rsp), %rcx
movw $0x3a1b, (%rcx)         # imm = 0x3A1B
movq 0x25437(%rip), %rcx     # 0x48630
movl 0x4(%rcx), %edi
cmpl $0x1, %eax
je 0x23219
cmpl $0x2, %eax
je 0x23212
cmpl $0xa, %eax
jne 0x23220
movl $0x1c, %edx
jmp 0x23222
movl $0x10, %edx
jmp 0x23222
movl $0x6e, %edx
jmp 0x23222
xorl %edx, %edx
leaq 0x10(%rsp), %rsi
callq 0xfaa0
testl %eax, %eax
jne 0x23275
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 0x253d2(%rip), %rax     # 0x48630
movl 0x4(%rax), %edi
leaq 0xc(%rsp), %rdx
movl $0x80, (%rdx)
callq 0xfc30
testl %eax, %eax
je 0x232a6
callq 0xf0a0
movl (%rax), %ebp
testq %r15, %r15
je 0x23284
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 0x232c8
cmpl $0x2, %eax
je 0x232c1
cmpl $0xa, %eax
jne 0x232cf
movl $0x1c, %ecx
jmp 0x232d1
movl $0x10, %ecx
jmp 0x232d1
movl $0x6e, %ecx
jmp 0x232d1
xorl %ecx, %ecx
movl $0x1c, %ebp
cmpq %r14, %rcx
ja 0x2327c
cmpl $0x1, %eax
je 0x232f8
cmpl $0x2, %eax
je 0x232f1
cmpl $0xa, %eax
jne 0x232ff
movl $0x1c, %edx
jmp 0x23301
movl $0x10, %edx
jmp 0x23301
movl $0x6e, %edx
jmp 0x23301
xorl %edx, %edx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa60
jmp 0x23291