// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_write_to_socket
static void mg_write_to_socket(struct mg_connection *nc) {
  struct mbuf *io = &nc->send_mbuf;
  int n = 0;

#if MG_LWIP
  /* With LWIP we don't know if the socket is ready */
  if (io->len == 0) return;
#endif

  assert(io->len > 0);

  if (nc->flags & MG_F_UDP) {
    int n =
        sendto(nc->sock, io->buf, io->len, 0, &nc->sa.sa, sizeof(nc->sa.sin));
    DBG(("%p %d %d %d %s:%hu", nc, nc->sock, n, mg_get_errno(),
         inet_ntoa(nc->sa.sin.sin_addr), ntohs(nc->sa.sin.sin_port)));
    mg_if_sent_cb(nc, n);
    return;
  }

#if MG_ENABLE_SSL
  if (nc->flags & MG_F_SSL) {
    if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) {
      n = mg_ssl_if_write(nc, io->buf, io->len);
      DBG(("%p %d bytes -> %d (SSL)", nc, n, nc->sock));
      if (n < 0) {
        if (n != MG_SSL_WANT_READ && n != MG_SSL_WANT_WRITE) {
          nc->flags |= MG_F_CLOSE_IMMEDIATELY;
        }
        return;
      } else {
        /* Successful SSL operation, clear off SSL wait flags */
        nc->flags &= ~(MG_F_WANT_READ | MG_F_WANT_WRITE);
      }
    } else {
      mg_ssl_begin(nc);
      return;
    }
  } else
#endif
  {
    n = (int) MG_SEND_FUNC(nc->sock, io->buf, io->len, 0);
    DBG(("%p %d bytes -> %d", nc, n, nc->sock));
  }

  mg_if_sent_cb(nc, n);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0xe06c
jmp 0xe08b
leaq 0x1230b(%rip), %rdi     # 0x2037e
leaq 0x114d0(%rip), %rsi     # 0x1f54a
movl $0xdc3, %edx            # imm = 0xDC3
leaq 0x12304(%rip), %rcx     # 0x2038a
callq 0x3230
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0xe162
movq -0x8(%rbp), %rax
movl 0x20(%rax), %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %r8
addq $0x28, %r8
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x3280
movl %eax, -0x18(%rbp)
movl $0x4, %edi
leaq 0x122dc(%rip), %rsi     # 0x203ba
leaq 0x11465(%rip), %rdx     # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0xe152
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
callq 0xd6a0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %edi
callq 0x3140
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x2a(%rax), %edi
callq 0x34e0
movq -0x38(%rbp), %rsi
movl -0x2c(%rbp), %edx
movl -0x28(%rbp), %ecx
movl -0x24(%rbp), %r8d
movq -0x20(%rbp), %r9
movzwl %ax, %eax
leaq 0x12285(%rip), %rdi     # 0x203cd
movl %eax, (%rsp)
movb $0x0, %al
callq 0x47a0
jmp 0xe154
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0xb6f0
jmp 0xe1c9
movq -0x8(%rbp), %rax
movl 0x20(%rax), %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %ecx, %ecx
callq 0x31d0
movl %eax, -0x14(%rbp)
movl $0x4, %edi
leaq 0x1222c(%rip), %rsi     # 0x203ba
leaq 0x113b5(%rip), %rdx     # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0xe1bb
movq -0x8(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0x20(%rax), %ecx
leaq 0x1222c(%rip), %rdi     # 0x203e0
movb $0x0, %al
callq 0x47a0
jmp 0xe1bd
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xb6f0
addq $0x40, %rsp
popq %rbp
retq
nop