// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rcx, %r13
movl %edx, %ebx
movq %rsi, %rbp
movq 0x2c0(%rsp), %r15
testq %r15, %r15
jne 0x8c82
movq 0x30(%rdi), %r15
movq %rdi, 0x38(%rsp)
leaq 0x2c0(%rsp), %r14
leaq 0xd4ba(%rip), %rsi      # 0x16150
leaq 0xc931(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x8cc2
movq 0x18(%r14), %rcx
leaq 0xd4af(%rip), %rdi      # 0x16165
movq %rbp, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x4539
movl $0x1, %edi
movl $0x438, %esi            # imm = 0x438
callq 0x3300
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x8e83
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %rbp, %rsi
callq 0x30b0
movl %ebx, 0x400(%r14)
movq %r13, 0x408(%r14)
movq %r12, 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 0x8ddb
leaq 0xe9d9(%rip), %rdi      # 0x17723
leaq 0xe3ec(%rip), %rsi      # 0x1713d
callq 0x3370
testq %rax, %rax
je 0x8dd4
movq %rax, %r12
leaq 0x80(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rax, %rdx
callq 0x32e0
testq %rax, %rax
je 0x8dcc
leaq 0x80(%rsp), %r15
leaq 0x34(%rsp), %rbp
leaq 0x30(%rsp), %rbx
leaq 0x2c(%rsp), %r13
movq %r15, %rdi
leaq 0xe99b(%rip), %rsi      # 0x17734
leaq 0x40(%rsp), %rdx
movq %rbp, %rcx
movq %rbx, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x3420
cmpl $0x4, %eax
je 0x8e95
movq %r15, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdx
callq 0x32e0
testq %rax, %rax
jne 0x8d8f
movq %r12, %rdi
callq 0x3160
leaq 0xd393(%rip), %r15      # 0x1616e
leaq 0xd394(%rip), %rdx      # 0x16176
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 0x9d9d(%rip), %rdx      # 0x12be2
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x8909
testq %rax, %rax
je 0x8e76
movq %r14, 0xa0(%rax)
leaq 0x2c0(%rsp), %rcx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x8e72
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x8e83
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
movl 0x40(%rsp), %ecx
movl 0x34(%rsp), %r8d
movl 0x30(%rsp), %r9d
movl 0x2c(%rsp), %eax
movl %eax, (%rsp)
leaq 0xe88e(%rip), %rdx      # 0x1773f
leaq 0x60(%rsp), %r15
movl $0x11, %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x31e0
movq %r12, %rdi
callq 0x3160
jmp 0x8ddb