// File: /workspace/github_c_makefile_star2_O1/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 0x4b23
movsd %xmm0, 0x8(%rsp)
movq 0xa0(%rbx), %r14
testl %ebp, %ebp
je 0x1275c
leaq 0x4ff9(%rip), %rsi      # 0x1772d
leaq 0x2e6f(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x1275c
leaq 0x4ff1(%rip), %rdi      # 0x17741
movl %ebp, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x45a0
testq %r14, %r14
je 0x128d9
cmpl $0x6, %ebp
ja 0x128d9
movl %ebp, %eax
leaq 0x2c6d(%rip), %rcx      # 0x153e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, %al
jmp 0x127ca
movl $0xc20, %edi            # imm = 0xC20
callq 0x33e0
movq %rax, %r12
movq 0x40(%rbx), %rdi
movl (%r15), %esi
movq %rax, %rdx
callq 0x12296
testl %eax, %eax
je 0x12898
movl $0x1, 0x424(%r14)
jmp 0x128ca
movl $0x3, 0x424(%r14)
jmp 0x128d2
xorl %eax, %eax
movl 0x430(%r14), %ecx
cmpl 0x420(%r14), %ecx
jle 0x127ea
movl $0x2, 0x424(%r14)
jmp 0x128d2
cvttsd2si 0x8(%rsp), %r15
testb %al, %al
je 0x1280c
movq %r15, %rax
subq 0x428(%r14), %rax
cmpq 0x418(%r14), %rax
jl 0x128d9
movl 0x400(%r14), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x12138
movq %r15, 0x428(%r14)
incl 0x430(%r14)
jmp 0x128d9
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 0x6bb8
leaq 0x28(%rbx), %rdi
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movl $0x1, %ecx
callq 0xaa56
movq 0x410(%r14), %rsi
movl 0x424(%r14), %edx
xorl %edi, %edi
callq *0x408(%r14)
movq $0x0, 0xa0(%rbx)
movq %r14, %rdi
callq 0x3060
jmp 0x128d9
cmpl $0x0, 0x18(%r12)
jle 0x127a8
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