// File: /workspace/github_c_makefile_star2_O1/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 $0xe8, %rsp
movq %r9, %r15
movq %r8, %rbx
movq %rcx, %r12
movq %rsi, %r13
movq %rdi, %r14
xorl %eax, %eax
movl %eax, -0x34(%rbp)
movl %eax, -0x2c(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x1, (%rdx)
movl %eax, (%rcx)
movb %al, (%r9)
movb %al, (%r8)
movl $0x3a6c7373, %eax       # imm = 0x3A6C7373
xorl (%rdi), %eax
movzwl 0x4(%rdi), %ecx
xorl $0x2f2f, %ecx           # imm = 0x2F2F
orl %eax, %ecx
je 0x6869b
movl $0x3a706475, %eax       # imm = 0x3A706475
xorl (%r14), %eax
movzwl 0x4(%r14), %ecx
xorl $0x2f2f, %ecx           # imm = 0x2F2F
orl %eax, %ecx
je 0x686a9
movl $0x3a706374, %eax       # imm = 0x3A706374
xorl (%r14), %eax
movzwl 0x4(%r14), %ecx
xorl $0x2f2f, %ecx           # imm = 0x2F2F
leaq 0x6(%r14), %rdx
orl %eax, %ecx
cmoveq %rdx, %r14
jmp 0x686b3
addq $0x6, %r14
movl $0x1, (%r12)
jmp 0x686b3
addq $0x6, %r14
movl $0x2, (%rdx)
leaq -0x2c(%rbp), %r10
leaq -0x30(%rbp), %r11
leaq 0x11db7(%rip), %rsi     # 0x7a479
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 0xc100
addq $0x10, %rsp
cmpl $0x5, %eax
jne 0x68780
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)
cmpl $0x0, (%r12)
je 0x6876e
movslq -0x2c(%rbp), %rdi
addq %r14, %rdi
leaq 0x11d6b(%rip), %rsi     # 0x7a499
leaq -0x34(%rbp), %r8
movq %rbx, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xc100
cmpl $0x2, %eax
je 0x68768
movslq -0x2c(%rbp), %rax
addq %rax, %r14
leaq 0x11d50(%rip), %rsi     # 0x7a4a2
leaq -0x34(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xc100
cmpl $0x1, %eax
jne 0x6876e
movl -0x34(%rbp), %eax
addl %eax, -0x2c(%rbp)
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11d03(%rip), %rsi     # 0x7a48a
leaq -0x110(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x2c(%rbp), %r8
movq %r14, %rdi
xorl %eax, %eax
callq 0xc100
cmpl $0x2, %eax
jne 0x687d9
movzwl -0x30(%rbp), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r13)
leaq -0x110(%rbp), %rdi
callq 0xc4f0
testq %rax, %rax
je 0x68719
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%r13)
jmp 0x68719
leaq 0x11cb4(%rip), %rsi     # 0x7a494
leaq -0x30(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0xc100
cmpl $0x1, %eax
je 0x6870c
jmp 0x68719