// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_resolve_async_opt
int mg_resolve_async_opt(struct mg_mgr *mgr, const char *name, int query,
                         mg_resolve_callback_t cb, void *data,
                         struct mg_resolve_async_opts opts) {
  struct mg_resolve_async_request *req;
  struct mg_connection *dns_nc;
  const char *nameserver = opts.nameserver;
  char dns_server_buff[17], nameserver_url[26];

  if (nameserver == NULL) {
    nameserver = mgr->nameserver;
  }

  DBG(("%s %d %p", name, query, opts.dns_conn));

  /* resolve with DNS */
  req = (struct mg_resolve_async_request *) MG_CALLOC(1, sizeof(*req));
  if (req == NULL) {
    return -1;
  }

  strncpy(req->name, name, sizeof(req->name));
  req->query = query;
  req->callback = cb;
  req->data = data;
  /* TODO(mkm): parse defaults out of resolve.conf */
  req->max_retries = opts.max_retries ? opts.max_retries : 2;
  req->timeout = opts.timeout ? opts.timeout : 5;

  /* Lazily initialize dns server */
  if (nameserver == NULL) {
    if (mg_get_ip_address_of_nameserver(dns_server_buff,
                                        sizeof(dns_server_buff)) != -1) {
      nameserver = dns_server_buff;
    } else {
      nameserver = MG_DEFAULT_NAMESERVER;
    }
  }

  snprintf(nameserver_url, sizeof(nameserver_url), "udp://%s:53", nameserver);

  dns_nc = mg_connect(mgr, nameserver_url, MG_CB(mg_resolve_async_eh, NULL));
  if (dns_nc == NULL) {
    MG_FREE(req);
    return -1;
  }
  dns_nc->user_data = req;
  if (opts.dns_conn != NULL) {
    *opts.dns_conn = dns_nc;
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %r8, %rbx
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %r13
movq 0x2c0(%rsp), %r15
testq %r15, %r15
jne 0x8dd5
movq 0x30(%rdi), %r15
movq %rdi, 0x38(%rsp)
leaq 0x2c0(%rsp), %r14
leaq 0xd349(%rip), %rsi      # 0x16132
leaq 0xc7ba(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x8e15
movq 0x18(%r14), %rcx
leaq 0xd33e(%rip), %rdi      # 0x16147
movq %r13, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x45a0
movl $0x1, %edi
movl $0x438, %esi            # imm = 0x438
callq 0x3300
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x9001
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r13, %rsi
callq 0x30b0
movl %ebp, 0x400(%r14)
movq %r12, 0x408(%r14)
movq %rbx, 0x410(%r14)
leaq 0x2c0(%rsp), %rdx
movl 0x8(%rdx), %eax
testl %eax, %eax
movl $0x2, %ecx
cmovnel %eax, %ecx
movl 0xc(%rdx), %eax
testl %eax, %eax
movl $0x5, %edx
cmovnel %eax, %edx
movl %ecx, 0x420(%r14)
movslq %edx, %rax
movq %rax, 0x418(%r14)
testq %r15, %r15
jne 0x8f59
leaq 0xe868(%rip), %rdi      # 0x17705
leaq 0xe27b(%rip), %rsi      # 0x1711f
callq 0x3370
testq %rax, %rax
je 0x8f52
movq %rax, %r12
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x80(%rsp), %r13
leaq 0x60(%rsp), %r15
movq %r13, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdx
callq 0x32e0
testq %rax, %rax
je 0x8f3a
movq %r13, %rdi
leaq 0xe830(%rip), %rsi      # 0x17716
leaq 0x40(%rsp), %rdx
leaq 0x34(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x2c(%rsp), %r9
xorl %eax, %eax
callq 0x3420
movl %eax, %ebp
cmpl $0x4, %eax
jne 0x8f35
movl 0x40(%rsp), %ecx
movl 0x34(%rsp), %r8d
movl 0x30(%rsp), %r9d
movl 0x2c(%rsp), %eax
movl %eax, (%rsp)
xorl %ebx, %ebx
movl $0x11, %esi
movq %r15, %rdi
leaq 0xe7f3(%rip), %rdx      # 0x17721
xorl %eax, %eax
callq 0x31e0
cmpl $0x4, %ebp
jne 0x8ec7
movq %r12, %rdi
callq 0x3160
cmpl $-0x1, %ebx
leaq 0xd204(%rip), %rax      # 0x16150
cmoveq %rax, %r15
jmp 0x8f59
leaq 0xd1f7(%rip), %r15      # 0x16150
leaq 0xd1f8(%rip), %rdx      # 0x16158
leaq 0x40(%rsp), %rbx
movl $0x1a, %esi
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x31e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x9740(%rip), %rdx      # 0x12703
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x8a58
testq %rax, %rax
je 0x8ff4
movq %r14, 0xa0(%rax)
leaq 0x2c0(%rsp), %rcx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x8ff0
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x9001
movq %r14, %rdi
callq 0x3060
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq