// File: /workspace/github_cpp_makefile_star2_O2/roberty65[P]bServer/common/src/xbs_naddr.cpp
// Function: beyondy::str2sockaddr(char const*, int*, sockaddr*, unsigned int*, int)
int str2sockaddr(const char *str, int *ptype, struct sockaddr *naddr, socklen_t *nlen, int count)
{
	int type = SOCK_STREAM;
	if (strncmp(str, "tcp://", 6) == 0) { type = SOCK_STREAM; str += 6; }
	else if (strncmp(str, "udp://", 6) == 0) { type = SOCK_DGRAM; str += 6; }


	if (ptype != NULL) *ptype = type;
	if (*str == '@') {
		return __unix_str2sockaddr(str + 1, naddr, nlen, count);
	}

	const char *iptr;
	char host[NI_MAXHOST], serv[NI_MAXSERV];
	if ((iptr = strrchr(str, ':')) == NULL)
		return errno = EINVAL, -1;

	if (iptr - str > (int)sizeof(host) - 1)
		return errno = E2BIG, -1;
	strncpy(host, str, sizeof host);
	host[iptr - str] = 0;

	int slen = str + strlen(str) - iptr - 1;
	if (slen > (int)sizeof(serv) - 1) return errno = E2BIG, -1;
	memcpy(serv, iptr + 1, slen); serv[slen] = 0;

	return __inet_str2sockaddr(type, host, serv, naddr, nlen, count);	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %r8d, 0xc(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x2a77(%rip), %rsi      # 0xb45e
pushq $0x6
popq %r13
movq %r13, %rdx
callq 0x3160
testl %eax, %eax
je 0x8a21
leaq 0x2a67(%rip), %rsi      # 0xb465
pushq $0x6
popq %rbp
movq %r15, %rdi
movq %rbp, %rdx
callq 0x3160
xorl %r13d, %r13d
xorl %r14d, %r14d
testl %eax, %eax
sete %r14b
cmoveq %rbp, %r13
incl %r14d
jmp 0x8a25
pushq $0x1
popq %r14
addq %r13, %r15
testq %r12, %r12
je 0x8a31
movl %r14d, (%r12)
cmpb $0x40, (%r15)
jne 0x8a64
incq %r15
movq 0x10(%rsp), %rax
movl $0x6e, (%rax)
movw $0x1, (%rbx)
leaq 0x2(%rbx), %rdi
pushq $0x6c
popq %rdx
movq %r15, %rsi
callq 0x3190
movb $0x0, 0x6d(%rbx)
pushq $0x1
jmp 0x8b42
pushq $0x3a
popq %rsi
movq %r15, %rdi
callq 0x33b0
testq %rax, %rax
je 0x8ac6
movq %rax, %r13
movq %rax, %rbp
subq %r15, %rbp
cmpq $0x401, %rbp            # imm = 0x401
jge 0x8ab9
leaq 0x70(%rsp), %r12
movl $0x401, %edx            # imm = 0x401
movq %r12, %rdi
movq %r15, %rsi
callq 0x3190
movb $0x0, 0x70(%rsp,%rbp)
movq %r15, %rdi
callq 0x3140
addq %r15, %rax
movq %r13, %rcx
notq %rcx
addq %rax, %rcx
cmpl $0x20, %ecx
jl 0x8ad3
callq 0x3060
movl $0x7, (%rax)
jmp 0x8b40
callq 0x3060
movl $0x16, (%rax)
jmp 0x8b40
incq %r13
movslq %ecx, %r15
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x32b0
leaq 0x18(%rsp), %rcx
andq $0x0, (%rcx)
movb $0x0, 0x20(%rsp,%r15)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movl %r14d, 0x8(%rdx)
movl $0x1, (%rdx)
movb 0x70(%rsp), %al
xorb $0x2a, %al
xorl %esi, %esi
orb 0x71(%rsp), %al
cmoveq %rsi, %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3450
movl %eax, %ebp
callq 0x3060
movl %ebp, (%rax)
testl %ebp, %ebp
je 0x8b59
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %r12
movslq 0xc(%rsp), %r13
xorl %r15d, %r15d
movq %r12, %rbp
cmpq %r13, %r15
jge 0x8bac
testq %rbp, %rbp
je 0x8bac
cmpl %r14d, 0x8(%rbp)
jne 0x8ba3
movl 0x4(%rbp), %eax
orl $0x8, %eax
cmpl $0xa, %eax
jne 0x8b9f
movq 0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movq %rbx, %rdi
callq 0x32b0
movl 0x10(%rbp), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
movq 0x28(%rbp), %rbp
incq %r15
addq $0x10, %rbx
jmp 0x8b69
movq %r12, %rdi
callq 0x3480
jmp 0x8b44