// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: ns_parse_address
static int ns_parse_address(const char *str, union socket_address *sa,
                            int *proto, int *use_ssl, char *cert, char *ca) {
  unsigned int a, b, c, d, port;
  int n = 0, len = 0;
  char host[200];
#ifdef NS_ENABLE_IPV6
  char buf[100];
#endif

  // MacOS needs that. If we do not zero it, subsequent bind() will fail.
  // Also, all-zeroes in the socket address means binding to all addresses
  // for both IPv4 and IPv6 (INADDR_ANY and IN6ADDR_ANY_INIT).
  memset(sa, 0, sizeof(*sa));
  sa->sin.sin_family = AF_INET;

  *proto = SOCK_STREAM;
  *use_ssl = 0;
  cert[0] = ca[0] = '\0';

  if (memcmp(str, "ssl://", 6) == 0) {
    str += 6;
    *use_ssl = 1;
  } else if (memcmp(str, "udp://", 6) == 0) {
    str += 6;
    *proto = SOCK_DGRAM;
  } else if (memcmp(str, "tcp://", 6) == 0) {
    str += 6;
  }

  if (sscanf(str, "%u.%u.%u.%u:%u%n", &a, &b, &c, &d, &port, &len) == 5) {
    // Bind to a specific IPv4 address, e.g. 192.168.1.5:8080
    sa->sin.sin_addr.s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);
    sa->sin.sin_port = htons((uint16_t) port);
#ifdef NS_ENABLE_IPV6
  } else if (sscanf(str, "[%99[^]]]:%u%n", buf, &port, &len) == 2 &&
             inet_pton(AF_INET6, buf, &sa->sin6.sin6_addr)) {
    // IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080
    sa->sin6.sin6_family = AF_INET6;
    sa->sin6.sin6_port = htons((uint16_t) port);
#endif
  } else if (sscanf(str, "%199[^ :]:%u%n", host, &port, &len) == 2) {
    sa->sin.sin_port = htons((uint16_t) port);
    ns_resolve2(host, &sa->sin.sin_addr);
  } else if (sscanf(str, "%u%n", &port, &len) == 1) {
    // If only port is specified, bind to IPv4, INADDR_ANY
    sa->sin.sin_port = htons((uint16_t) port);
  }

  if (*use_ssl && (sscanf(str + len, ":%99[^:,]:%99[^:,]%n", cert, ca, &n) == 2 ||
                   sscanf(str + len, ":%99[^:,]%n", cert, &n) == 1)) {
    len += n;
  }

  return port < 0xffff && str[len] == '\0' ? len : 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, %rbx
movq %rcx, %r12
andl $0x0, -0x34(%rbp)
movq %rdx, %r15
andl $0x0, -0x2c(%rbp)
movq %rsi, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x1, (%rdx)
andl $0x0, (%rcx)
movq %rdi, %r14
xorl %eax, %eax
movq %r9, -0x50(%rbp)
movb %al, (%r9)
movb %al, (%r8)
leaq 0x106be(%rip), %rsi     # 0x68413
pushq $0x6
popq %rdx
callq 0xc800
testl %eax, %eax
je 0x57d95
leaq 0x106e3(%rip), %rsi     # 0x6844b
pushq $0x6
popq %rdx
movq %r14, %rdi
callq 0xc800
testl %eax, %eax
je 0x57da3
leaq 0x106d4(%rip), %rsi     # 0x68452
pushq $0x6
popq %rdx
movq %r14, %rdi
callq 0xc800
leaq 0x6(%r14), %rcx
testl %eax, %eax
cmoveq %rcx, %r14
jmp 0x57dae
addq $0x6, %r14
movl $0x1, (%r12)
jmp 0x57dae
addq $0x6, %r14
movl $0x2, (%r15)
leaq -0x2c(%rbp), %r10
leaq -0x30(%rbp), %r11
leaq 0x1069c(%rip), %rsi     # 0x68459
leaq -0x44(%rbp), %rdx
leaq -0x40(%rbp), %rcx
leaq -0x3c(%rbp), %r8
leaq -0x38(%rbp), %r9
movq %r14, %rdi
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0xc110
popq %rcx
popq %rdx
cmpl $0x5, %eax
jne 0x57e10
movl -0x44(%rbp), %eax
shll $0x18, %eax
movl -0x40(%rbp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movl -0x3c(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
orl -0x38(%rbp), %eax
bswapl %eax
movl %eax, 0x4(%r13)
movzwl -0x30(%rbp), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r13)
jmp 0x57e75
leaq 0x10653(%rip), %rsi     # 0x6846a
leaq -0x120(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x2c(%rbp), %r8
movq %r14, %rdi
xorl %eax, %eax
callq 0xc110
cmpl $0x2, %eax
jne 0x57e57
movzwl -0x30(%rbp), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r13)
addq $0x4, %r13
leaq -0x120(%rbp), %rdi
movq %r13, %rsi
callq 0x57b89
jmp 0x57e75
leaq 0x10616(%rip), %rsi     # 0x68474
leaq -0x30(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0xc110
cmpl $0x1, %eax
je 0x57e01
cmpl $0x0, (%r12)
je 0x57ecb
movslq -0x2c(%rbp), %rdi
addq %r14, %rdi
leaq 0x105ef(%rip), %rsi     # 0x68479
leaq -0x34(%rbp), %r8
movq %rbx, %rdx
movq -0x50(%rbp), %rcx
xorl %eax, %eax
callq 0xc110
cmpl $0x2, %eax
je 0x57ec5
movslq -0x2c(%rbp), %rax
addq %rax, %r14
leaq 0x105d3(%rip), %rsi     # 0x68482
leaq -0x34(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xc110
cmpl $0x1, %eax
jne 0x57ecb
movl -0x34(%rbp), %eax
addl %eax, -0x2c(%rbp)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq