// File: /workspace/github_c_makefile_star2_O1/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 0x16bb3(%rip)           # 0x1e620
testq %rsi, %rsi
jne 0x7a85
movq 0x80(%rbx), %r14
testq %r14, %r14
jne 0x7a85
movq 0x98(%rbx), %r14
testl %ebp, %ebp
je 0x7aeb
leaq 0xe72a(%rip), %rsi      # 0x161ba
leaq 0xdb13(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x7aeb
cmpq 0x98(%rbx), %r14
leaq 0xffa5(%rip), %rax      # 0x17a58
leaq 0xe739(%rip), %rdx      # 0x161f3
cmoveq %rax, %rdx
movq 0xc8(%rbx), %r9
movl 0x48(%rbx), %r10d
movl 0x60(%rbx), %r11d
leaq 0xe6ee(%rip), %rdi      # 0x161c2
movq %rbx, %rsi
movl %ebp, %ecx
movq %r15, %r8
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x45a0
addq $0x10, %rsp
movq 0x18(%rbx), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x7b16
cmpl $0x4, %ebp
ja 0x7b07
movl $0x19, %eax
btl %ebp, %eax
jb 0x7b16
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x83f0
testq %r14, %r14
je 0x7b98
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 0x7b61
movq 0xc8(%rbx), %rcx
cmpq %r13, %rcx
je 0x7b61
andq $-0x3f03d01, %r13       # imm = 0xFC0FC2FF
andl $0x3f03d00, %ecx        # imm = 0x3F03D00
orq %r13, %rcx
movq %rcx, 0xc8(%rbx)
cmpl $0x1, 0x16ab8(%rip)     # 0x1e620
sete %cl
cmpq %rax, %r12
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x7b98
testb $0x2, 0xc8(%rbx)
jne 0x7b98
subq %rax, %r12
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x58(%rax)
testl %ebp, %ebp
je 0x7bf1
leaq 0xe617(%rip), %rsi      # 0x161ba
leaq 0xda00(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x7bf1
cmpq 0x98(%rbx), %r14
leaq 0xfe92(%rip), %rax      # 0x17a58
leaq 0xe626(%rip), %rdx      # 0x161f3
cmoveq %rax, %rdx
movq 0xc8(%rbx), %rcx
movl 0x48(%rbx), %r8d
movl 0x60(%rbx), %r9d
leaq 0xe612(%rip), %rdi      # 0x161f9
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
decl 0x16a29(%rip)           # 0x1e620
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq