// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdx, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2bd10
movzwl (%rax), %eax
movl %eax, -0x10c(%rbp)
subl $0x2, %eax
je 0x2c071
jmp 0x2c064
movl -0x10c(%rbp), %eax
subl $0xa, %eax
je 0x2c081
jmp 0x2c091
leaq 0x31380(%rip), %rax     # 0x5d3f8
movq %rax, 0x31929(%rip)     # 0x5d9a8
jmp 0x2c0a0
leaq 0x31378(%rip), %rax     # 0x5d400
movq %rax, 0x31919(%rip)     # 0x5d9a8
jmp 0x2c0a0
movl $0x16, -0xac(%rbp)
jmp 0x2c34c
movq 0x31901(%rip), %rax     # 0x5d9a8
cmpl $-0x1, 0x4(%rax)
jne 0x2c117
movq 0x318f4(%rip), %rax     # 0x5d9a8
movzwl (%rax), %edi
movl $0x80002, %esi          # imm = 0x80002
xorl %edx, %edx
callq 0xf340
movl %eax, %ecx
movq 0x318dc(%rip), %rax     # 0x5d9a8
movl %ecx, 0x4(%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x2c0dd
jmp 0x2c33f
movq 0x318c4(%rip), %rax     # 0x5d9a8
movl 0x4(%rax), %edi
movl $0x1, %esi
callq 0xf480
movl %eax, -0xac(%rbp)
cmpl $0x0, %eax
je 0x2c115
movq 0x318a5(%rip), %rdi     # 0x5d9a8
addq $0x4, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xf2f0
jmp 0x2c34c
jmp 0x2c117
movq -0x10(%rbp), %rdi
callq 0x2c000
movl %eax, %eax
movl %eax, %ecx
movl $0x80, %eax
cmpq %rcx, %rax
jb 0x2c130
jmp 0x2c14f
leaq 0x1db1b(%rip), %rdi     # 0x49c52
leaq 0x1db2d(%rip), %rsi     # 0x49c6b
movl $0x2c2, %edx            # imm = 0x2C2
leaq 0x1db69(%rip), %rcx     # 0x49cb3
callq 0xf920
movq -0x10(%rbp), %rdi
callq 0x2c450
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2c000
movq -0x118(%rbp), %rsi
movl %eax, %eax
movl %eax, %edx
leaq -0xa8(%rbp), %rdi
callq 0xfb40
leaq -0xa8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movw $0x0, -0xc2(%rbp)
movq -0xc0(%rbp), %rdi
leaq -0xc2(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2c470
cmpw $0x0, (%rax)
jne 0x2c20a
movl $0x1b3a, %edi           # imm = 0x1B3A
callq 0xf0e0
movw %ax, -0x11a(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movw $0x0, -0xd2(%rbp)
movq -0xd0(%rbp), %rdi
leaq -0xd2(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2c470
movw -0x11a(%rbp), %cx
movw %cx, (%rax)
movq 0x31797(%rip), %rax     # 0x5d9a8
movl 0x4(%rax), %eax
movl %eax, -0x120(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x2c000
movl -0x120(%rbp), %edi
movl %eax, %edx
movq -0xe0(%rbp), %rsi
callq 0xfb80
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2c263
jmp 0x2c33f
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0xf7d0
movq 0x3172b(%rip), %rax     # 0x5d9a8
movl 0x4(%rax), %edi
leaq -0xa8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x80, -0xf4(%rbp)
movq -0xf0(%rbp), %rsi
leaq -0xf4(%rbp), %rdx
callq 0xfd30
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2c2b8
jmp 0x2c33f
movq -0x20(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
callq 0x2c000
movl %eax, %ecx
movq -0x128(%rbp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x2c2f9
movl $0x1c, -0xac(%rbp)
jmp 0x2c34c
movq -0x18(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rdi
callq 0x2c000
movq -0x130(%rbp), %rdi
movl %eax, %eax
movl %eax, %edx
leaq -0xa8(%rbp), %rsi
callq 0xfb40
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2c380
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0xac(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2c35f
movl -0xac(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movq %rdi, -0x138(%rbp)
movq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0xf7d0
movq -0x138(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax)