// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_call
MG_INTERNAL void mg_call(struct mg_connection *nc,
                         mg_event_handler_t ev_handler, void *user_data, int ev,
                         void *ev_data) {
  static int nesting_level = 0;
  nesting_level++;
  if (ev_handler == NULL) {
    /*
     * If protocol handler is specified, call it. Otherwise, call user-specified
     * event handler.
     */
    ev_handler = nc->proto_handler ? nc->proto_handler : nc->handler;
  }
  if (ev != MG_EV_POLL) {
    DBG(("%p %s ev=%d ev_data=%p flags=%lu rmbl=%d smbl=%d", nc,
         ev_handler == nc->handler ? "user" : "proto", ev, ev_data, nc->flags,
         (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
  }

#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
  if (nc->mgr->hexdump_file != NULL && ev != MG_EV_POLL && ev != MG_EV_RECV &&
      ev != MG_EV_SEND /* handled separately */) {
    mg_hexdump_connection(nc, nc->mgr->hexdump_file, NULL, 0, ev);
  }
#endif
  if (ev_handler != NULL) {
    unsigned long flags_before = nc->flags;
    size_t recv_mbuf_before = nc->recv_mbuf.len, recved;
    ev_handler(nc, ev, ev_data MG_UD_ARG(user_data));
    recved = (recv_mbuf_before - nc->recv_mbuf.len);
    /* Prevent user handler from fiddling with system flags. */
    if (ev_handler == nc->handler && nc->flags != flags_before) {
      nc->flags = (flags_before & ~_MG_CALLBACK_MODIFIABLE_FLAGS_MASK) |
                  (nc->flags & _MG_CALLBACK_MODIFIABLE_FLAGS_MASK);
    }
    /* It's important to not double-count recved bytes, and since mg_call can be
     * called recursively (e.g. proto_handler invokes user handler), we keep
     * track of recursion and only report received bytes at the top level. */
    if (nesting_level == 1 && recved > 0 && !(nc->flags & MG_F_UDP)) {
      nc->iface->vtable->recved(nc, recved);
    }
  }
  if (ev != MG_EV_POLL) {
    DBG(("%p after %s flags=%lu rmbl=%d smbl=%d", nc,
         ev_handler == nc->handler ? "user" : "proto", nc->flags,
         (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
  }
  nesting_level--;
#if !MG_ENABLE_CALLBACK_USERDATA
  (void) user_data;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
incl 0x17047(%rip)           # 0x1e620
testq %rsi, %rsi
jne 0x75f1
movq 0x80(%rbx), %r14
testq %r14, %r14
jne 0x75f1
movq 0x98(%rbx), %r14
testl %ebp, %ebp
je 0x7653
leaq 0xdbbf(%rip), %rsi      # 0x151bb
leaq 0xcfab(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x7653
cmpq 0x98(%rbx), %r14
leaq 0xf43c(%rip), %rax      # 0x16a59
leaq 0xdbd0(%rip), %rdx      # 0x151f4
cmoveq %rax, %rdx
movq 0xc8(%rbx), %r9
movl 0x48(%rbx), %r10d
movl 0x60(%rbx), %r11d
leaq 0xdb85(%rip), %rdi      # 0x151c3
movq %rbx, %rsi
movl %ebp, %ecx
movq %r15, %r8
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x430a
popq %rax
popq %rcx
movq 0x18(%rbx), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x767c
cmpl $0x4, %ebp
ja 0x766d
pushq $0x19
popq %rax
btl %ebp, %eax
jb 0x767c
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x7ed8
testq %r14, %r14
je 0x76fe
movq 0x48(%rbx), %r12
movq 0xc8(%rbx), %r13
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq *%r14
movq 0x48(%rbx), %rax
cmpq 0x98(%rbx), %r14
jne 0x76c7
movq 0xc8(%rbx), %rcx
cmpq %r13, %rcx
je 0x76c7
andq $-0x3f03d01, %r13       # imm = 0xFC0FC2FF
andl $0x3f03d00, %ecx        # imm = 0x3F03D00
orq %r13, %rcx
movq %rcx, 0xc8(%rbx)
cmpl $0x1, 0x16f52(%rip)     # 0x1e620
sete %cl
cmpq %rax, %r12
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x76fe
testb $0x2, 0xc8(%rbx)
jne 0x76fe
subq %rax, %r12
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x58(%rax)
testl %ebp, %ebp
je 0x7755
leaq 0xdab2(%rip), %rsi      # 0x151bb
leaq 0xce9e(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x7755
cmpq 0x98(%rbx), %r14
leaq 0xf32f(%rip), %rax      # 0x16a59
leaq 0xdac3(%rip), %rdx      # 0x151f4
cmoveq %rax, %rdx
movq 0xc8(%rbx), %rcx
movl 0x48(%rbx), %r8d
movl 0x60(%rbx), %r9d
leaq 0xdaaf(%rip), %rdi      # 0x151fa
movq %rbx, %rsi
xorl %eax, %eax
callq 0x430a
decl 0x16ec5(%rip)           # 0x1e620
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq