// File: /workspace/github_c_makefile_star2_O3/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 0x4aab
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rbx), %r14
testl %ebp, %ebp
je 0x12c3b
leaq 0x4b38(%rip), %rsi      # 0x1774b
leaq 0x29b4(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x12c3b
leaq 0x4b30(%rip), %rdi      # 0x1775f
movl %ebp, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4539
testq %r14, %r14
je 0x12dc0
cmpl $0x6, %ebp
ja 0x12dc0
cvttsd2si 0x8(%rsp), %r12
movl %ebp, %eax
leaq 0x2793(%rip), %rcx      # 0x153f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x430(%r14), %eax
cmpl 0x420(%r14), %eax
jg 0x12ce6
movq %r12, %rax
subq 0x428(%r14), %rax
cmpq 0x418(%r14), %rax
jl 0x12dc0
jmp 0x12d5d
movl $0xc20, %edi            # imm = 0xC20
callq 0x33e0
movq %rax, %r12
movq 0x40(%rbx), %rdi
movl (%r15), %esi
movq %rax, %rdx
callq 0x1276f
testl %eax, %eax
je 0x12d7f
movl $0x1, 0x424(%r14)
jmp 0x12db1
movl $0x3, 0x424(%r14)
jmp 0x12db9
movl 0x430(%r14), %eax
cmpl 0x420(%r14), %eax
jle 0x12d5d
movl $0x2, 0x424(%r14)
jmp 0x12db9
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 0x6af6
leaq 0x28(%rbx), %rdi
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movl $0x1, %ecx
callq 0xa911
movq 0x410(%r14), %rsi
movl 0x424(%r14), %edx
xorl %edi, %edi
callq *0x408(%r14)
movq $0x0, 0xa0(%rbx)
movq %r14, %rdi
callq 0x3060
jmp 0x12dc0
movl 0x400(%r14), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x125f6
movq %r12, 0x428(%r14)
incl 0x430(%r14)
jmp 0x12dc0
cmpl $0x0, 0x18(%r12)
jle 0x12cb6
movq 0x410(%r14), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq *0x408(%r14)
movq $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