// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x30, %rsp
movsd %xmm0, 0x28(%rsp)
movl %esi, %ebp
movq %rdi, %rbx
movb $0x1, %r12b
testl %esi, %esi
jne 0x9ba3
testb $-0x40, 0xc8(%rbx)
setne %r12b
testb %r12b, %r12b
je 0x9beb
leaq 0xbcbc(%rip), %rsi      # 0x1586b
leaq 0xb9f4(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9beb
movq 0xc8(%rbx), %r8
movl 0x20(%rbx), %edx
movl 0x48(%rbx), %r9d
movl 0x60(%rbx), %eax
movl %eax, (%rsp)
leaq 0xbc9f(%rip), %rdi      # 0x1587e
movq %rbx, %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x45a0
movq 0xc8(%rbx), %rax
testb $0x8, %al
je 0x9c5b
testl %ebp, %ebp
je 0x9c37
movl $0x0, 0x18(%rsp)
testb $0x2, %al
jne 0x9c4f
leaq 0x14(%rsp), %r8
movl $0x4, (%r8)
movl 0x20(%rbx), %edi
leaq 0x18(%rsp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x32f0
testl %eax, %eax
je 0x9c40
movl $0x1, 0x18(%rsp)
jmp 0x9c4f
movl 0x24(%rbx), %esi
testl %esi, %esi
jne 0x9c53
jmp 0x9c5b
cmpl $0xb, 0x18(%rsp)
jne 0x9c4f
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %esi
movq %rbx, %rdi
callq 0x899a
testb $0x1, %bpl
je 0x9eee
movq 0xc8(%rbx), %rax
testb $0x2, %al
jne 0x9d1a
testb $0x1, %al
jne 0x9da9
movl $0x400, %r15d           # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x33e0
testq %rax, %rax
je 0xa04a
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 0xc6e4(%rip), %rsi      # 0x163b1
leaq 0xb8d6(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9cf9
movl 0x20(%rbx), %ecx
leaq 0xc6d8(%rip), %rdi      # 0x163c4
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x45a0
testl %r15d, %r15d
jle 0xa0db
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x85c4
jmp 0xa0e3
movl $0x10, 0x14(%rsp)
movl $0x5dc, %edi            # imm = 0x5DC
callq 0x33e0
movq %rax, %r14
testq %rax, %rax
je 0x9e5f
movl 0x20(%rbx), %edi
leaq 0x18(%rsp), %r8
leaq 0x14(%rsp), %r9
movl $0x5dc, %edx            # imm = 0x5DC
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x3450
movq %rax, %r15
testl %r15d, %r15d
jg 0x9e8f
leaq 0xc5e5(%rip), %rsi      # 0x1634c
leaq 0xb83c(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9d9c
callq 0x30a0
movl (%rax), %edi
callq 0x3600
leaq 0xc5d7(%rip), %rdi      # 0x16366
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x45a0
movq %r14, %rdi
callq 0x3060
jmp 0x9e8f
leaq 0x14(%rsp), %rdx
movl $0x10, (%rdx)
movl 0x20(%rbx), %edi
leaq 0x18(%rsp), %rsi
callq 0x3550
cmpl $-0x1, %eax
je 0xa07d
movl %eax, %r14d
movq %rbx, %rdi
callq 0x8157
testq %rax, %rax
je 0xa11c
movq %rax, %r15
leaq 0xc58e(%rip), %rsi      # 0x16376
leaq 0xb7bb(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9e26
movl 0x1c(%rsp), %edi
callq 0x3140
movzwl 0x1a(%rsp), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
leaq 0xc585(%rip), %rdi      # 0x1639e
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x45a0
movq 0xc0(%r15), %rax
movq 0x10(%rax), %rax
movq %r15, %rdi
movl %r14d, %esi
callq *0x70(%rax)
movq %r15, %rcx
addq $0x28, %rcx
movups 0x18(%rsp), %xmm0
movups %xmm0, 0x28(%r15)
movq %r15, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x7a51
jmp 0x9eee
leaq 0xc4e6(%rip), %rsi      # 0x1634c
leaq 0xb73d(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
movl $0xfffffff4, %r15d      # imm = 0xFFFFFFF4
testl %eax, %eax
je 0x9e8f
leaq 0xc4d0(%rip), %rdi      # 0x16358
xorl %eax, %eax
callq 0x45a0
leaq 0xc48c(%rip), %rsi      # 0x16322
leaq 0xb70d(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9ed6
movl 0x2c(%rbx), %edi
callq 0x3140
movzwl 0x2a(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
leaq 0xc46f(%rip), %rdi      # 0x16335
movq %rbx, %rsi
movl %r15d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x45a0
movl 0x14(%rsp), %r8d
leaq 0x18(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x86f7
movq 0xc8(%rbx), %rax
btl $0xb, %eax
jb 0x9ff9
testb $0x2, %bpl
je 0x9fdc
movq 0x60(%rbx), %rdx
testq %rdx, %rdx
je 0x9fdc
movl 0x20(%rbx), %edi
movq 0x58(%rbx), %rsi
testb $0x2, %al
jne 0x9f64
xorl %ecx, %ecx
callq 0x31c0
movq %rax, %r14
leaq 0xc4ac(%rip), %rsi      # 0x163de
leaq 0xb671(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9fd1
movl 0x20(%rbx), %ecx
leaq 0xc4af(%rip), %rdi      # 0x16404
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x45a0
jmp 0x9fd1
leaq 0x28(%rbx), %r8
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x3260
movq %rax, %r14
leaq 0xc45f(%rip), %rsi      # 0x163de
leaq 0xb624(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9fd1
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 0xc435(%rip), %rdi      # 0x163f1
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
movl %r15d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x45a0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x8349
cvttsd2si 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x7c06
movq %rbx, %rdi
movsd 0x28(%rsp), %xmm0
callq 0x7a1b
testb %r12b, %r12b
je 0xa03d
leaq 0xb866(%rip), %rsi      # 0x1586b
leaq 0xb59e(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0xa03d
movq 0xc8(%rbx), %rcx
movl 0x20(%rbx), %edx
movl 0x48(%rbx), %r8d
movl 0x60(%rbx), %r9d
leaq 0xb87d(%rip), %rdi      # 0x158b0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc360(%rip), %rsi      # 0x163b1
leaq 0xb552(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9eee
leaq 0xb6e6(%rip), %rdi      # 0x15757
xorl %eax, %eax
callq 0x45a0
jmp 0x9eee
callq 0x30a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x9eee
cmpl $0xb, %eax
je 0x9eee
cmpl $0x73, %eax
je 0x9eee
leaq 0xc2cd(%rip), %rsi      # 0x16376
leaq 0xb4fa(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9eee
movl (%r14), %edx
leaq 0xc2b9(%rip), %rdi      # 0x16385
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
jmp 0x9eee
movq %r14, %rdi
callq 0x3060
testl %r15d, %r15d
je 0xa129
jns 0x9eee
callq 0x30a0
movl (%rax), %eax
cmpl $0x4, %eax
je 0x9eee
cmpl $0xb, %eax
je 0x9eee
cmpl $0x73, %eax
je 0x9eee
orb $0x8, 0xc9(%rbx)
jmp 0x9eee
movl %r14d, %edi
callq 0x3280
jmp 0x9eee
orb $0x4, 0xc9(%rbx)
jmp 0x9eee