// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: set_ports_option
static int set_ports_option(struct mg_context *ctx) {
  const char *list = ctx->config[LISTENING_PORTS];
  int reuseaddr = 1, success = 1;
  SOCKET sock;
  struct vec vec;
  struct socket so, *listener;

  while (success && (list = next_option(list, &vec, NULL)) != NULL) {
    if (!parse_port_string(&vec, &so)) {
      cry(fc(ctx), "%s: %.*s: invalid port spec. Expecting list of: %s",
          __func__, vec.len, vec.ptr, "[IP_ADDRESS:]PORT[s|p]");
      success = 0;
    } else if (so.is_ssl && ctx->ssl_ctx == NULL) {
      cry(fc(ctx), "Cannot add SSL socket, is -ssl_cert option set?");
      success = 0;
    } else if ((sock = socket(PF_INET, SOCK_STREAM, 6)) == INVALID_SOCKET ||
#if !defined(_WIN32)
               // On Windows, SO_REUSEADDR is recommended only for
               // broadcast UDP sockets
               setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr,
                          sizeof(reuseaddr)) != 0 ||
#endif // !_WIN32
               bind(sock, &so.lsa.u.sa, so.lsa.len) != 0 ||
               listen(sock, 20) != 0) {
      closesocket(sock);
      cry(fc(ctx), "%s: cannot bind to %.*s: %s", __func__,
          vec.len, vec.ptr, strerror(ERRNO));
      success = 0;
    } else if ((listener = (struct socket *)
                calloc(1, sizeof(*listener))) == NULL) {
      closesocket(sock);
      cry(fc(ctx), "%s: %s", __func__, strerror(ERRNO));
      success = 0;
    } else {
      *listener = so;
      listener->sock = sock;
      set_close_on_exec(listener->sock);
      listener->next = ctx->listening_sockets;
      ctx->listening_sockets = listener;
    }
  }

  if (!success) {
    close_all_listening_sockets(ctx);
  }

  return success;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq 0x98(%rax), %rax
movq %rax, 0x98(%rsp)
movl $0x1, 0x94(%rsp)
movl $0x1, 0x90(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x90(%rsp)
movb %al, 0x2f(%rsp)
je 0x18c25
movq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1ab00
movq %rax, 0x98(%rsp)
cmpq $0x0, %rax
setne %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x18c32
jmp 0x18ea0
leaq 0x78(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x1ac80
cmpl $0x0, %eax
jne 0x18c8f
movq 0xa0(%rsp), %rdi
callq 0x18750
movq %rax, %rdi
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %r8
leaq 0x9fe9(%rip), %rsi      # 0x22c53
leaq 0xa015(%rip), %rdx      # 0x22c86
leaq 0xa01f(%rip), %r9       # 0x22c97
movb $0x0, %al
callq 0x184e0
movl $0x0, 0x90(%rsp)
jmp 0x18e9b
cmpl $0x0, 0x6c(%rsp)
je 0x18cd3
movq 0xa0(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x18cd3
movq 0xa0(%rsp), %rdi
callq 0x18750
movq %rax, %rdi
leaq 0x9ff2(%rip), %rsi      # 0x22cae
movb $0x0, %al
callq 0x184e0
movl $0x0, 0x90(%rsp)
jmp 0x18e99
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x5120
movl %eax, 0x8c(%rsp)
cmpl $-0x1, %eax
je 0x18d54
movl 0x8c(%rsp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq 0x94(%rsp), %rcx
movl $0x4, %r8d
callq 0x5a80
cmpl $0x0, %eax
jne 0x18d54
movl 0x8c(%rsp), %edi
leaq 0x38(%rsp), %rsi
addq $0xc, %rsi
addq $0x4, %rsi
movl 0x44(%rsp), %edx
callq 0x50d0
cmpl $0x0, %eax
jne 0x18d54
movl 0x8c(%rsp), %edi
movl $0x14, %esi
callq 0x5660
cmpl $0x0, %eax
je 0x18dcc
movl 0x8c(%rsp), %edi
callq 0x5b70
movq 0xa0(%rsp), %rdi
callq 0x18750
movq %rax, 0x10(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %rax, %r9
leaq 0x9f30(%rip), %rsi      # 0x22cde
leaq 0x9ed1(%rip), %rdx      # 0x22c86
movb $0x0, %al
callq 0x184e0
movl $0x0, 0x90(%rsp)
jmp 0x18e97
movl $0x1, %edi
movl $0x40, %esi
callq 0x5350
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
jne 0x18e3a
movl 0x8c(%rsp), %edi
callq 0x5b70
movq 0xa0(%rsp), %rdi
callq 0x18750
movq %rax, 0x8(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x8(%rsp), %rdi
movq %rax, %rcx
leaq 0x9d68(%rip), %rsi      # 0x22b87
leaq 0x9e60(%rip), %rdx      # 0x22c86
movb $0x0, %al
callq 0x184e0
movl $0x0, 0x90(%rsp)
jmp 0x18e95
movq 0x30(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl $0x40, %edx
callq 0x5450
movl 0x8c(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x30(%rsp), %rax
movl 0x8(%rax), %edi
callq 0x1ae20
movq 0xa0(%rsp), %rax
movq 0xd0(%rax), %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax)
movq 0x30(%rsp), %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0xd0(%rax)
jmp 0x18e97
jmp 0x18e99
jmp 0x18e9b
jmp 0x18bec
cmpl $0x0, 0x90(%rsp)
jne 0x18eb7
movq 0xa0(%rsp), %rdi
callq 0x1ae40
movl 0x90(%rsp), %eax
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)