// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mgr_handle_conn
void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now) {
  int worth_logging =
      fd_flags != 0 || (nc->flags & (MG_F_WANT_READ | MG_F_WANT_WRITE));
  if (worth_logging) {
    DBG(("%p fd=%d fd_flags=%d nc_flags=%lu rmbl=%d smbl=%d", nc, nc->sock,
         fd_flags, nc->flags, (int) nc->recv_mbuf.len,
         (int) nc->send_mbuf.len));
  }

  if (nc->flags & MG_F_CONNECTING) {
    if (fd_flags != 0) {
      int err = 0;
#if !defined(MG_ESP8266)
      if (!(nc->flags & MG_F_UDP)) {
        socklen_t len = sizeof(err);
        int ret =
            getsockopt(nc->sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len);
        if (ret != 0) {
          err = 1;
        } else if (err == EAGAIN || err == EWOULDBLOCK) {
          err = 0;
        }
      }
#else
      /*
       * On ESP8266 we use blocking connect.
       */
      err = nc->err;
#endif
#if MG_ENABLE_SSL
      if ((nc->flags & MG_F_SSL) && err == 0) {
        mg_ssl_begin(nc);
      } else {
        mg_if_connect_cb(nc, err);
      }
#else
      mg_if_connect_cb(nc, err);
#endif
    } else if (nc->err != 0) {
      mg_if_connect_cb(nc, nc->err);
    }
  }

  if (fd_flags & _MG_F_FD_CAN_READ) {
    if (nc->flags & MG_F_UDP) {
      mg_handle_udp_read(nc);
    } else {
      if (nc->flags & MG_F_LISTENING) {
        /*
         * We're not looping here, and accepting just one connection at
         * a time. The reason is that eCos does not respect non-blocking
         * flag on a listening socket and hangs in a loop.
         */
        mg_accept_conn(nc);
      } else {
        mg_handle_tcp_read(nc);
      }
    }
  }

  if (!(nc->flags & MG_F_CLOSE_IMMEDIATELY)) {
    if ((fd_flags & _MG_F_FD_CAN_WRITE) && nc->send_mbuf.len > 0) {
      mg_write_to_socket(nc);
    }
    mg_if_poll(nc, (time_t) now);
    mg_if_timer(nc, now);
  }

  if (worth_logging) {
    DBG(("%p after fd=%d nc_flags=%lu rmbl=%d smbl=%d", nc, nc->sock, nc->flags,
         (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x20(%rsp)
movl %esi, %ebp
movq %rdi, %rbx
testl %esi, %esi
jne 0x9508
movq 0xc8(%rbx), %rax
testb $-0x40, %al
je 0x95a5
leaq 0xb360(%rip), %rsi      # 0x1486f
leaq 0xb098(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9549
movq 0xc8(%rbx), %r8
movl 0x20(%rbx), %edx
movl 0x48(%rbx), %r9d
movl 0x60(%rbx), %eax
movl %eax, (%rsp)
leaq 0xb345(%rip), %rdi      # 0x14882
movq %rbx, %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x430a
leaq 0xc8(%rbx), %r13
movq 0xc8(%rbx), %rax
testb $0x8, %al
je 0x95ed
testl %ebp, %ebp
je 0x95a0
andl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
testb $0x2, %al
jne 0x95e2
leaq 0xc(%rsp), %r8
movl $0x4, (%r8)
movl 0x20(%rbx), %edi
pushq $0x1
popq %r14
pushq $0x4
popq %rdx
leaq 0x10(%rsp), %rcx
movl %r14d, %esi
callq 0x32f0
testl %eax, %eax
je 0x95cf
movl $0x1, 0x10(%rsp)
jmp 0x95e2
movb $0x1, %r12b
jmp 0x95b7
leaq 0xc8(%rbx), %r13
xorl %r12d, %r12d
testb $0x8, %al
je 0x985f
movl 0x24(%rbx), %esi
testl %esi, %esi
je 0x985f
movq %rbx, %rdi
callq 0x83b9
jmp 0x985f
movl 0x10(%rsp), %r14d
cmpl $0xb, %r14d
jne 0x95e2
andl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x83b9
movb $0x1, %r12b
testb $0x1, %bpl
je 0x985f
movq (%r13), %rax
testb $0x2, %al
jne 0x96a8
testb $0x1, %al
jne 0x9735
movl $0x400, %r15d           # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x33e0
testq %rax, %rax
je 0x99b2
movq %rax, %r14
movq 0x38(%rbx), %rax
movq 0x48(%rbx), %rcx
movq %rax, %rsi
subq %rcx, %rsi
cmpq %r15, %rsi
cmovaeq %r15, %rsi
xorl %edx, %edx
cmpq %rcx, %rax
movl 0x20(%rbx), %edi
cmovaeq %rsi, %rdx
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x3070
movq %rax, %r15
leaq 0xbd53(%rip), %rsi      # 0x153b2
leaq 0xaf48(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9689
movl 0x20(%rbx), %ecx
leaq 0xbd49(%rip), %rdi      # 0x153c5
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x430a
testl %r15d, %r15d
jle 0x9a2b
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x8010
jmp 0x985f
movl $0x10, 0xc(%rsp)
movl $0x5dc, %edi            # imm = 0x5DC
callq 0x33e0
movq %rax, %r14
testq %rax, %rax
je 0x97d6
movl 0x20(%rbx), %edi
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
movl $0x5dc, %edx            # imm = 0x5DC
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x3450
movq %rax, %r15
testl %r15d, %r15d
jg 0x9802
leaq 0xbc58(%rip), %rsi      # 0x1534d
leaq 0xaeb2(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9728
callq 0x9306
movl %eax, %edi
callq 0x3600
leaq 0xbc4c(%rip), %rdi      # 0x15367
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x430a
movq %r14, %rdi
callq 0x3060
jmp 0x9802
leaq 0xc(%rsp), %rdx
movl $0x10, (%rdx)
movl 0x20(%rbx), %edi
leaq 0x10(%rsp), %rsi
callq 0x3550
cmpl $-0x1, %eax
je 0x99e3
movl %eax, %r14d
movq %rbx, %rdi
callq 0x7c52
testq %rax, %rax
je 0x9a4f
movq %rax, %r15
leaq 0xbc03(%rip), %rsi      # 0x15377
leaq 0xae33(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x97b0
movl 0x14(%rsp), %edi
callq 0x3140
movzwl 0x12(%rsp), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
leaq 0xbbfc(%rip), %rdi      # 0x1539f
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x430a
movq 0xc0(%r15), %rax
movq 0x10(%rax), %rax
movq %r15, %rdi
movl %r14d, %esi
callq *0x70(%rax)
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x7e1e
jmp 0x985f
leaq 0xbb70(%rip), %rsi      # 0x1534d
leaq 0xadca(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
pushq $-0xc
popq %r15
testl %eax, %eax
je 0x9802
leaq 0xbb5e(%rip), %rdi      # 0x15359
xorl %eax, %eax
callq 0x430a
leaq 0xbb1a(%rip), %rsi      # 0x15323
leaq 0xad9e(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9847
movl 0x2c(%rbx), %edi
callq 0x3140
movzwl 0x2a(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
leaq 0xbaff(%rip), %rdi      # 0x15336
movq %rbx, %rsi
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x430a
movl 0xc(%rsp), %r8d
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x8137
movq (%r13), %rax
btl $0xb, %eax
jb 0x9961
testb $0x2, %bpl
je 0x9944
movq 0x60(%rbx), %rdx
testq %rdx, %rdx
je 0x9944
movl 0x20(%rbx), %edi
movq 0x58(%rbx), %rsi
testb $0x2, %al
jne 0x98d0
xorl %ecx, %ecx
callq 0x31c0
movq %rax, %r14
leaq 0xbb3f(%rip), %rsi      # 0x153df
leaq 0xad07(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9939
movl 0x20(%rbx), %ecx
leaq 0xbb44(%rip), %rdi      # 0x15405
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x430a
jmp 0x9939
leaq 0x28(%rbx), %r8
pushq $0x10
popq %r9
xorl %ecx, %ecx
callq 0x3260
movq %rax, %r14
leaq 0xbaf6(%rip), %rsi      # 0x153df
leaq 0xacbe(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9939
movl 0x20(%rbx), %ebp
callq 0x9306
movl %eax, %r15d
movl 0x2c(%rbx), %edi
callq 0x3140
movzwl 0x2a(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, (%rsp)
leaq 0xbace(%rip), %rdi      # 0x153f2
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
movl %r15d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x430a
movq %rbx, %rdi
movl %r14d, %esi
callq 0x7e38
cvttsd2si 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x776a
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x758c
testb %r12b, %r12b
je 0x99a3
leaq 0xaf02(%rip), %rsi      # 0x1486f
leaq 0xac3a(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x99a3
movq 0xc8(%rbx), %rcx
movl 0x20(%rbx), %edx
movl 0x48(%rbx), %r8d
movl 0x60(%rbx), %r9d
leaq 0xaf1b(%rip), %rdi      # 0x148b4
movq %rbx, %rsi
xorl %eax, %eax
callq 0x430a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb9f9(%rip), %rsi      # 0x153b2
leaq 0xabee(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x985f
leaq 0xad84(%rip), %rdi      # 0x1475b
xorl %eax, %eax
callq 0x430a
jmp 0x985f
callq 0x9310
testl %eax, %eax
je 0x985f
leaq 0xb980(%rip), %rsi      # 0x15377
leaq 0xabb0(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x985f
callq 0x9306
leaq 0xb96c(%rip), %rdi      # 0x15386
movq %rbx, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x430a
jmp 0x985f
movq %r14, %rdi
callq 0x3060
testl %r15d, %r15d
je 0x9a5c
callq 0x9310
testl %eax, %eax
je 0x985f
orb $0x8, 0x1(%r13)
jmp 0x985f
movl %r14d, %edi
callq 0x3280
jmp 0x985f
orb $0x4, 0x1(%r13)
jmp 0x985f