// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_resolve_async_eh
static void mg_resolve_async_eh(struct mg_connection *nc, int ev,
                                void *data MG_UD_ARG(void *user_data)) {
  time_t now = (time_t) mg_time();
  struct mg_resolve_async_request *req;
  struct mg_dns_message *msg;
  int first = 0;
#if !MG_ENABLE_CALLBACK_USERDATA
  void *user_data = nc->user_data;
#endif

  if (ev != MG_EV_POLL) DBG(("ev=%d user_data=%p", ev, user_data));

  req = (struct mg_resolve_async_request *) user_data;

  if (req == NULL) {
    return;
  }

  switch (ev) {
    case MG_EV_CONNECT:
      /* don't depend on timer not being at epoch for sending out first req */
      first = 1;
    /* fallthrough */
    case MG_EV_POLL:
      if (req->retries > req->max_retries) {
        req->err = MG_RESOLVE_EXCEEDED_RETRY_COUNT;
        nc->flags |= MG_F_CLOSE_IMMEDIATELY;
        break;
      }
      if (first || now - req->last_time >= req->timeout) {
        mg_send_dns_query(nc, req->name, req->query);
        req->last_time = now;
        req->retries++;
      }
      break;
    case MG_EV_RECV:
      msg = (struct mg_dns_message *) MG_MALLOC(sizeof(*msg));
      if (mg_parse_dns(nc->recv_mbuf.buf, *(int *) data, msg) == 0 &&
          msg->num_answers > 0) {
        req->callback(msg, req->data, MG_RESOLVE_OK);
        nc->user_data = NULL;
        MG_FREE(req);
      } else {
        req->err = MG_RESOLVE_NO_ANSWERS;
      }
      MG_FREE(msg);
      nc->flags |= MG_F_CLOSE_IMMEDIATELY;
      break;
    case MG_EV_SEND:
      /*
       * If a send error occurs, prevent closing of the connection by the core.
       * We will retry after timeout.
       */
      nc->flags &= ~MG_F_CLOSE_IMMEDIATELY;
      mbuf_remove(&nc->send_mbuf, nc->send_mbuf.len);
      break;
    case MG_EV_TIMER:
      req->err = MG_RESOLVE_TIMEOUT;
      nc->flags |= MG_F_CLOSE_IMMEDIATELY;
      break;
    case MG_EV_CLOSE:
      /* If we got here with request still not done, fire an error callback. */
      if (req != NULL) {
        char addr[32];
        mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr), MG_SOCK_STRINGIFY_IP);
#ifdef MG_LOG_DNS_FAILURES
        LOG(LL_ERROR, ("Failed to resolve '%s', server %s", req->name, addr));
#endif
        req->callback(NULL, req->data, req->err);
        nc->user_data = NULL;
        MG_FREE(req);
      }
      break;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
callq 0x483c
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rbx), %r14
testl %ebp, %ebp
je 0x119af
leaq 0x4da5(%rip), %rsi      # 0x1672e
leaq 0x2c1e(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x119af
leaq 0x4d9f(%rip), %rdi      # 0x16742
movl %ebp, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x430a
testq %r14, %r14
je 0x11b2a
cmpl $0x6, %ebp
ja 0x11b2a
cvttsd2si 0x8(%rsp), %r12
movl %ebp, %eax
leaq 0x29ff(%rip), %rcx      # 0x143d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x430(%r14), %eax
cmpl 0x420(%r14), %eax
jg 0x11a5a
movq %r12, %rax
subq 0x428(%r14), %rax
cmpq 0x418(%r14), %rax
jl 0x11b2a
jmp 0x11aca
movl $0xc20, %edi            # imm = 0xC20
callq 0x33e0
movq %rax, %r12
movq 0x40(%rbx), %rdi
movl (%r15), %esi
movq %rax, %rdx
callq 0x11565
testl %eax, %eax
je 0x11aec
movl $0x1, 0x424(%r14)
jmp 0x11b1b
movl $0x3, 0x424(%r14)
jmp 0x11b23
movl 0x430(%r14), %eax
cmpl 0x420(%r14), %eax
jle 0x11aca
movl $0x2, 0x424(%r14)
jmp 0x11b23
andb $-0x9, 0xc9(%rbx)
movq 0x60(%rbx), %rsi
addq $0x58, %rbx
movq %rbx, %rdi
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x6845
leaq 0x28(%rbx), %rdi
leaq 0x10(%rsp), %rsi
pushq $0x20
popq %rdx
pushq $0x1
popq %rcx
callq 0xa13d
movq 0x410(%r14), %rsi
movl 0x424(%r14), %edx
xorl %edi, %edi
callq *0x408(%r14)
andq $0x0, 0xa0(%rbx)
movq %r14, %rdi
callq 0x3060
jmp 0x11b2a
movl 0x400(%r14), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1143c
movq %r12, 0x428(%r14)
incl 0x430(%r14)
jmp 0x11b2a
cmpl $0x0, 0x18(%r12)
jle 0x11a2a
movq 0x410(%r14), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq *0x408(%r14)
andq $0x0, 0xa0(%rbx)
movq %r14, %rdi
callq 0x3060
movq %r12, %rdi
callq 0x3060
orb $0x8, 0xc9(%rbx)
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq