// File: /workspace/github_c_makefile_star2_O0/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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd430
movq -0x10(%rbp), %rax
movw $0x2, (%rax)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
leaq 0x17703(%rip), %rsi     # 0xc6d1a
movl $0x6, %edx
callq 0xddb0
cmpl $0x0, %eax
jne 0xaf63e
movq -0x8(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x8(%rbp)
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
jmp 0xaf69a
movq -0x8(%rbp), %rdi
leaq 0x17709(%rip), %rsi     # 0xc6d52
movl $0x6, %edx
callq 0xddb0
cmpl $0x0, %eax
jne 0xaf670
movq -0x8(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
movl $0x2, (%rax)
jmp 0xaf698
movq -0x8(%rbp), %rdi
leaq 0x176de(%rip), %rsi     # 0xc6d59
movl $0x6, %edx
callq 0xddb0
cmpl $0x0, %eax
jne 0xaf696
movq -0x8(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x8(%rbp)
jmp 0xaf698
jmp 0xaf69a
movq -0x8(%rbp), %rdi
leaq 0x176bb(%rip), %rsi     # 0xc6d60
leaq -0x34(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x3c(%rbp), %r8
leaq -0x40(%rbp), %r9
leaq -0x44(%rbp), %r10
leaq -0x4c(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0xd130
cmpl $0x5, %eax
jne 0xaf714
movl -0x34(%rbp), %edi
shll $0x18, %edi
movl -0x38(%rbp), %eax
shll $0x10, %eax
orl %eax, %edi
movl -0x3c(%rbp), %eax
shll $0x8, %eax
orl %eax, %edi
orl -0x40(%rbp), %edi
callq 0xd930
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x44(%rbp), %eax
movzwl %ax, %edi
callq 0xd920
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2(%rax)
jmp 0xaf79f
movq -0x8(%rbp), %rdi
leaq -0x120(%rbp), %rdx
leaq 0x1764b(%rip), %rsi     # 0xc6d71
leaq -0x44(%rbp), %rcx
leaq -0x4c(%rbp), %r8
movb $0x0, %al
callq 0xd130
cmpl $0x2, %eax
jne 0xaf766
movl -0x44(%rbp), %eax
movzwl %ax, %edi
callq 0xd920
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2(%rax)
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x4, %rsi
callq 0xaf410
jmp 0xaf79d
movq -0x8(%rbp), %rdi
leaq 0x1760a(%rip), %rsi     # 0xc6d7b
leaq -0x44(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
movb $0x0, %al
callq 0xd130
cmpl $0x1, %eax
jne 0xaf79b
movl -0x44(%rbp), %eax
movzwl %ax, %edi
callq 0xd920
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2(%rax)
jmp 0xaf79d
jmp 0xaf79f
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xaf801
movq -0x8(%rbp), %rdi
movslq -0x4c(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq 0x175be(%rip), %rsi     # 0xc6d80
leaq -0x48(%rbp), %r8
movb $0x0, %al
callq 0xd130
cmpl $0x2, %eax
je 0xaf7f8
movq -0x8(%rbp), %rdi
movslq -0x4c(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rdx
leaq 0x175a1(%rip), %rsi     # 0xc6d89
leaq -0x48(%rbp), %rcx
movb $0x0, %al
callq 0xd130
cmpl $0x1, %eax
jne 0xaf801
movl -0x48(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0xffff, -0x44(%rbp)    # imm = 0xFFFF
jae 0xaf826
movq -0x8(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xaf826
movl -0x4c(%rbp), %eax
movl %eax, -0x124(%rbp)
jmp 0xaf830
xorl %eax, %eax
movl %eax, -0x124(%rbp)
jmp 0xaf830
movl -0x124(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nop