// File: /workspace/github_c_makefile_star2_O3/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 0x9aa7
movq 0xc8(%rbx), %rax
testb $-0x40, %al
je 0x9b4f
leaq 0xbde1(%rip), %rsi      # 0x1588f
leaq 0xbb19(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9aea
movq 0xc8(%rbx), %r8
movl 0x20(%rbx), %edx
movl 0x48(%rbx), %r9d
movl 0x60(%rbx), %eax
movl %eax, (%rsp)
leaq 0xbdc4(%rip), %rdi      # 0x158a2
movq %rbx, %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x4539
leaq 0xc8(%rbx), %r12
movq 0xc8(%rbx), %rax
testb $0x8, %al
je 0x9b9a
testl %ebp, %ebp
je 0x9b4a
movl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
testb $0x2, %al
jne 0x9b8f
leaq 0xc(%rsp), %r8
movl $0x4, (%r8)
movl 0x20(%rbx), %edi
movl $0x1, %r14d
leaq 0x10(%rsp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x32f0
testl %eax, %eax
je 0x9b79
movl $0x1, 0x10(%rsp)
jmp 0x9b8f
movb $0x1, %r13b
jmp 0x9b61
leaq 0xc8(%rbx), %r12
xorl %r13d, %r13d
testb $0x8, %al
je 0x9e2d
movl 0x24(%rbx), %esi
testl %esi, %esi
je 0x9e2d
movq %rbx, %rdi
callq 0x8850
jmp 0x9e2d
movl 0x10(%rsp), %r14d
cmpl $0xb, %r14d
jne 0x9b8f
movl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x8850
movb $0x1, %r13b
testb $0x1, %bpl
je 0x9e2d
movq (%r12), %rax
testb $0x2, %al
jne 0x9c59
testb $0x1, %al
jne 0x9ce8
movl $0x400, %r15d           # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x33e0
testq %rax, %rax
je 0x9fa2
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 0xc7c3(%rip), %rsi      # 0x163cf
leaq 0xb9bb(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9c38
movl 0x20(%rbx), %ecx
leaq 0xc7b7(%rip), %rdi      # 0x163e2
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4539
testl %r15d, %r15d
jle 0xa033
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x8488
jmp 0x9e2d
movl $0x10, 0xc(%rsp)
movl $0x5dc, %edi            # imm = 0x5DC
callq 0x33e0
movq %rax, %r14
testq %rax, %rax
je 0x9d9e
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 0x9dce
leaq 0xc6c4(%rip), %rsi      # 0x1636a
leaq 0xb921(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9cdb
callq 0x30a0
movl (%rax), %edi
callq 0x3600
leaq 0xc6b6(%rip), %rdi      # 0x16384
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4539
movq %r14, %rdi
callq 0x3060
jmp 0x9dce
leaq 0xc(%rsp), %rdx
movl $0x10, (%rdx)
movl 0x20(%rbx), %edi
leaq 0x10(%rsp), %rsi
callq 0x3550
cmpl $-0x1, %eax
je 0x9fd5
movl %eax, %r14d
movq %rbx, %rdi
callq 0x8079
testq %rax, %rax
je 0xa06d
movq %rax, %r15
leaq 0xc66d(%rip), %rsi      # 0x16394
leaq 0xb8a0(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9d65
movl 0x14(%rsp), %edi
callq 0x3140
movzwl 0x12(%rsp), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
leaq 0xc664(%rip), %rdi      # 0x163bc
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4539
movq 0xc0(%r15), %rax
movq 0x10(%rax), %rax
movq %r15, %rdi
movl %r14d, %esi
callq *0x70(%rax)
movq %r15, %rcx
addq $0x28, %rcx
movups 0x10(%rsp), %xmm0
movups %xmm0, 0x28(%r15)
movq %r15, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x7979
jmp 0x9e2d
leaq 0xc5c5(%rip), %rsi      # 0x1636a
leaq 0xb822(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
movl $0xfffffff4, %r15d      # imm = 0xFFFFFFF4
testl %eax, %eax
je 0x9dce
leaq 0xc5af(%rip), %rdi      # 0x16376
xorl %eax, %eax
callq 0x4539
leaq 0xc56b(%rip), %rsi      # 0x16340
leaq 0xb7f2(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9e15
movl 0x2c(%rbx), %edi
callq 0x3140
movzwl 0x2a(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
leaq 0xc54e(%rip), %rdi      # 0x16353
movq %rbx, %rsi
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4539
movl 0xc(%rsp), %r8d
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x85b7
movq (%r12), %rax
btl $0xb, %eax
jb 0x9f4f
testb $0x2, %bpl
je 0x9f18
movq 0x60(%rbx), %rdx
testq %rdx, %rdx
je 0x9f18
movl 0x20(%rbx), %edi
movq 0x58(%rbx), %rsi
testb $0x2, %al
jne 0x9ea0
xorl %ecx, %ecx
callq 0x31c0
movq %rax, %r14
leaq 0xc58e(%rip), %rsi      # 0x163fc
leaq 0xb759(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9f0d
movl 0x20(%rbx), %ecx
leaq 0xc591(%rip), %rdi      # 0x16422
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x4539
jmp 0x9f0d
leaq 0x28(%rbx), %r8
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x3260
movq %rax, %r14
leaq 0xc541(%rip), %rsi      # 0x163fc
leaq 0xb70c(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9f0d
movl 0x20(%rbx), %ebp
callq 0x30a0
movl (%rax), %r15d
movl 0x2c(%rbx), %edi
callq 0x3140
movzwl 0x2a(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
movl %ecx, (%rsp)
leaq 0xc517(%rip), %rdi      # 0x1640f
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
movl %r15d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x4539
movq %rbx, %rdi
movl %r14d, %esi
callq 0x8257
cvttsd2si 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movl (%r12), %eax
andl $0x30, %eax
cmpl $0x10, %eax
je 0x9f41
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x7979
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x7943
testb %r13b, %r13b
je 0x9f93
leaq 0xb934(%rip), %rsi      # 0x1588f
leaq 0xb66c(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9f93
movq 0xc8(%rbx), %rcx
movl 0x20(%rbx), %edx
movl 0x48(%rbx), %r8d
movl 0x60(%rbx), %r9d
leaq 0xb94b(%rip), %rdi      # 0x158d4
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4539
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc426(%rip), %rsi      # 0x163cf
leaq 0xb61e(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9e2d
leaq 0xb7b2(%rip), %rdi      # 0x1577b
xorl %eax, %eax
callq 0x4539
jmp 0x9e2d
callq 0x30a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x9e2d
cmpl $0xb, %eax
je 0x9e2d
cmpl $0x73, %eax
je 0x9e2d
leaq 0xc393(%rip), %rsi      # 0x16394
leaq 0xb5c6(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9e2d
movl (%r14), %edx
leaq 0xc37f(%rip), %rdi      # 0x163a3
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4539
jmp 0x9e2d
movq %r14, %rdi
callq 0x3060
testl %r15d, %r15d
je 0xa07a
callq 0x30a0
movl (%rax), %eax
cmpl $0x4, %eax
je 0x9e2d
cmpl $0xb, %eax
je 0x9e2d
cmpl $0x73, %eax
je 0x9e2d
orb $0x8, 0x1(%r12)
jmp 0x9e2d
movl %r14d, %edi
callq 0x3280
jmp 0x9e2d
orb $0x4, 0x1(%r12)
jmp 0x9e2d