// File: /workspace/github_c_makefile_star2_O2/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 $0x248, %rsp            # imm = 0x248
movq %r8, %r12
movq %rcx, %r13
movl %edx, %ebx
movq %rsi, %rbp
movq 0x280(%rsp), %r15
testq %r15, %r15
jne 0x87cb
movq 0x30(%rdi), %r15
movq %rdi, 0x18(%rsp)
leaq 0x280(%rsp), %r14
leaq 0xc954(%rip), %rsi      # 0x15133
leaq 0xbdc8(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x8809
movq 0x18(%r14), %rcx
leaq 0xc94b(%rip), %rdi      # 0x15148
movq %rbp, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x430a
pushq $0x1
popq %rdi
movl $0x438, %esi            # imm = 0x438
callq 0x3300
movq %rax, %r14
pushq $-0x1
popq %rax
testq %r14, %r14
je 0x8994
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 0x280(%rsp), %rdx
movl 0x8(%rdx), %eax
testl %eax, %eax
pushq $0x2
popq %rcx
cmovnel %eax, %ecx
movl 0xc(%rdx), %eax
testl %eax, %eax
pushq $0x5
popq %rdx
cmovnel %eax, %edx
movl %ecx, 0x420(%r14)
movslq %edx, %rax
movq %rax, 0x418(%r14)
testq %r15, %r15
jne 0x8935
leaq 0xde7d(%rip), %rdi      # 0x16706
leaq 0xd890(%rip), %rsi      # 0x16120
callq 0x3370
testq %rax, %rax
je 0x892e
movq %rax, %r12
leaq 0x40(%rsp), %rbx
leaq 0x10(%rsp), %rbp
leaq 0xc(%rsp), %r15
leaq 0x8(%rsp), %r13
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdx
callq 0x32e0
testq %rax, %rax
je 0x8926
movq %rbx, %rdi
leaq 0xde43(%rip), %rsi      # 0x16717
leaq 0x14(%rsp), %rdx
movq %rbp, %rcx
movq %r15, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x3420
cmpl $0x4, %eax
jne 0x88b5
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
movl 0xc(%rsp), %r9d
movl 0x8(%rsp), %eax
movl %eax, (%rsp)
leaq 0xde18(%rip), %rdx      # 0x16722
leaq 0x20(%rsp), %r15
pushq $0x11
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x31e0
movq %r12, %rdi
callq 0x3160
jmp 0x8935
movq %r12, %rdi
callq 0x3160
leaq 0xc81c(%rip), %r15      # 0x15151
leaq 0xc81d(%rip), %rdx      # 0x15159
leaq 0x40(%rsp), %rbx
pushq $0x1a
popq %rsi
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x31e0
leaq 0x9000(%rip), %rdx      # 0x11958
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x842d
testq %rax, %rax
je 0x8989
movq %r14, 0xa0(%rax)
leaq 0x280(%rsp), %rcx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x8985
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x8994
movq %r14, %rdi
callq 0x3060
pushq $-0x1
popq %rax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq