// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movsd %xmm0, -0x18(%rbp)
movb $0x1, %al
cmpl $0x0, -0xc(%rbp)
movb %al, -0x29(%rbp)
jne 0xdaaa
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0xc0, %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xdb1b
jmp 0xdabd
movl $0x4, %edi
leaq 0x11d42(%rip), %rsi     # 0x1f80b
leaq 0x11a7a(%rip), %rdx     # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0xdb17
movq -0x8(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x20(%rax), %edx
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %r8
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, %r9d
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
leaq 0x11d11(%rip), %rdi     # 0x1f81e
movl %eax, (%rsp)
movb $0x0, %al
callq 0x47a0
jmp 0xdb19
jmp 0xdb1b
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x8, %rax
cmpq $0x0, %rax
je 0xdbd0
cmpl $0x0, -0xc(%rbp)
je 0xdbb2
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x2, %rax
cmpq $0x0, %rax
jne 0xdba4
movl $0x4, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x20(%rax), %edi
movl $0x1, %esi
movl $0x4, %edx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x3320
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0xdb8d
movl $0x1, -0x20(%rbp)
jmp 0xdba2
cmpl $0xb, -0x20(%rbp)
je 0xdb99
cmpl $0xb, -0x20(%rbp)
jne 0xdba0
movl $0x0, -0x20(%rbp)
jmp 0xdba2
jmp 0xdba4
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0xc000
jmp 0xdbce
movq -0x8(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0xdbcc
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x24(%rax), %esi
callq 0xc000
jmp 0xdbce
jmp 0xdbd0
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xdc28
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0xdbfb
movq -0x8(%rbp), %rdi
callq 0xdcf0
jmp 0xdc26
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xdc1b
movq -0x8(%rbp), %rdi
callq 0xddb0
jmp 0xdc24
movq -0x8(%rbp), %rdi
callq 0xdef0
jmp 0xdc26
jmp 0xdc28
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x800, %rax            # imm = 0x800
cmpq $0x0, %rax
jne 0xdc7b
movl -0xc(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xdc5e
movq -0x8(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jbe 0xdc5e
movq -0x8(%rbp), %rdi
callq 0xe040
movq -0x8(%rbp), %rdi
cvttsd2si -0x18(%rbp), %rsi
callq 0xab90
movq -0x8(%rbp), %rdi
movsd -0x18(%rbp), %xmm0
callq 0xa860
cmpl $0x0, -0x1c(%rbp)
je 0xdcde
jmp 0xdc83
movl $0x4, %edi
leaq 0x11b7c(%rip), %rsi     # 0x1f80b
leaq 0x118b4(%rip), %rdx     # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0xdcda
movq -0x8(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x20(%rax), %edx
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, %r8d
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movl %eax, %r9d
leaq 0x11b7d(%rip), %rdi     # 0x1f850
movb $0x0, %al
callq 0x47a0
jmp 0xdcdc
jmp 0xdcde
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)