// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x2223(%rip), %rsi      # 0xb45e
movl $0x6, %r13d
movl $0x6, %edx
callq 0x3150
testl %eax, %eax
je 0x927c
leaq 0x220f(%rip), %rsi      # 0xb465
movl $0x6, %r14d
movl $0x6, %edx
movq %r15, %rdi
callq 0x3150
xorl %r13d, %r13d
xorl %ebp, %ebp
testl %eax, %eax
sete %bpl
cmoveq %r14, %r13
incl %ebp
jmp 0x9281
movl $0x1, %ebp
addq %r13, %r15
testq %r12, %r12
je 0x928d
movl %ebp, (%r12)
cmpb $0x40, (%r15)
jne 0x92c2
incq %r15
movq 0x10(%rsp), %rax
movl $0x6e, (%rax)
movw $0x1, (%rbx)
leaq 0x2(%rbx), %rdi
movl $0x6c, %edx
movq %r15, %rsi
callq 0x3180
movb $0x0, 0x6d(%rbx)
movl $0x1, %eax
jmp 0x9337
movq %r15, %rdi
movl $0x3a, %esi
callq 0x33a0
testq %rax, %rax
je 0x9327
movq %rax, %r14
movq %rax, %r13
subq %r15, %r13
cmpq $0x401, %r13            # imm = 0x401
jge 0x931a
leaq 0x70(%rsp), %r12
movl $0x401, %edx            # imm = 0x401
movq %r12, %rdi
movq %r15, %rsi
callq 0x3180
movb $0x0, 0x70(%rsp,%r13)
movq %r15, %rdi
callq 0x3140
addq %r15, %rax
movq %r14, %rcx
notq %rcx
addq %rax, %rcx
cmpl $0x20, %ecx
jl 0x9349
callq 0x3060
movl $0x7, (%rax)
jmp 0x9332
callq 0x3060
movl $0x16, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq %r14
movslq %ecx, %r15
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x32a0
movb $0x0, 0x20(%rsp,%r15)
leaq 0x18(%rsp), %rcx
movq $0x0, (%rcx)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, 0x20(%rdx)
movl %ebp, 0x8(%rdx)
movl $0x1, (%rdx)
movb 0x70(%rsp), %al
xorb $0x2a, %al
xorl %r13d, %r13d
orb 0x71(%rsp), %al
cmoveq %r13, %r12
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3440
movl %eax, %r15d
callq 0x3060
movl %r15d, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r15d, %r15d
jne 0x9337
movq 0x18(%rsp), %rdi
movl 0x8(%rsp), %edx
testl %edx, %edx
setg %al
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x9436
movl %edx, %r12d
xorl %r13d, %r13d
movq %rdi, 0x8(%rsp)
movq %rdi, %r15
movq 0x10(%rsp), %r14
cmpl %ebp, 0x8(%r15)
jne 0x9420
movl 0x4(%r15), %eax
orl $0x8, %eax
cmpl $0xa, %eax
jne 0x941c
movq 0x18(%r15), %rsi
movl 0x10(%r15), %edx
movq %rbx, %rdi
callq 0x32a0
movl 0x10(%r15), %eax
movl %eax, (%r14,%r13,4)
movq 0x28(%r15), %r15
incq %r13
cmpq %r12, %r13
jae 0x9431
addq $0x10, %rbx
testq %r15, %r15
jne 0x93f2
movq 0x8(%rsp), %rdi
callq 0x3460
movl %r13d, %eax
jmp 0x9337