// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
callq 0xb6e0
cvttsd2si %xmm0, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x19065
jmp 0x1902f
movl $0x4, %edi
leaq 0x86da(%rip), %rsi      # 0x21715
leaq 0x6508(%rip), %rdx      # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0x19061
movl -0xc(%rbp), %esi
movq -0x40(%rbp), %rdx
leaq 0x86cf(%rip), %rdi      # 0x21729
movb $0x0, %al
callq 0x47a0
jmp 0x19063
jmp 0x19065
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x19079
jmp 0x192a6
movl -0xc(%rbp), %eax
movq %rax, -0x68(%rbp)
subq $0x6, %rax
ja 0x192a6
movq -0x68(%rbp), %rax
leaq 0x62f7(%rip), %rcx      # 0x1f38c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x34(%rbp)
movq -0x28(%rbp), %rax
movl 0x430(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x420(%rcx), %eax
jle 0x190e7
movq -0x28(%rbp), %rax
movl $0x2, 0x424(%rax)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x800, %rcx            # imm = 0x800
movq %rcx, 0xc8(%rax)
jmp 0x192a6
cmpl $0x0, -0x34(%rbp)
jne 0x19109
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
subq 0x428(%rcx), %rax
movq -0x28(%rbp), %rcx
cmpq 0x418(%rcx), %rax
jl 0x19142
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x400(%rax), %edx
callq 0x18630
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x428(%rax)
movq -0x28(%rbp), %rax
movl 0x430(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x430(%rax)
jmp 0x192a6
movl $0xc20, %edi            # imm = 0xC20
callq 0x3420
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movq -0x30(%rbp), %rdx
callq 0x187b0
cmpl $0x0, %eax
jne 0x191b3
movq -0x30(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x191b3
movq -0x28(%rbp), %rax
movq 0x408(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq 0x410(%rcx), %rsi
xorl %edx, %edx
callq *%rax
movq -0x8(%rbp), %rax
movq $0x0, 0xa0(%rax)
movq -0x28(%rbp), %rdi
callq 0x3050
jmp 0x191c1
movq -0x28(%rbp), %rax
movl $0x1, 0x424(%rax)
movq -0x30(%rbp), %rdi
callq 0x3050
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x800, %rcx            # imm = 0x800
movq %rcx, 0xc8(%rax)
jmp 0x192a6
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
andq $-0x801, %rcx           # imm = 0xF7FF
movq %rcx, 0xc8(%rax)
movq -0x8(%rbp), %rdi
addq $0x58, %rdi
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x89f0
jmp 0x192a6
movq -0x28(%rbp), %rax
movl $0x3, 0x424(%rax)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x800, %rcx            # imm = 0x800
movq %rcx, 0xc8(%rax)
jmp 0x192a6
cmpq $0x0, -0x28(%rbp)
je 0x192a4
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
leaq -0x60(%rbp), %rsi
movl $0x20, %edx
movl $0x1, %ecx
callq 0xeec0
movq -0x28(%rbp), %rax
movq 0x408(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x410(%rcx), %rsi
movq -0x28(%rbp), %rcx
movl 0x424(%rcx), %edx
xorl %ecx, %ecx
movl %ecx, %edi
callq *%rax
movq -0x8(%rbp), %rax
movq $0x0, 0xa0(%rax)
movq -0x28(%rbp), %rdi
callq 0x3050
jmp 0x192a6
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)