// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_transfer_file_data
static void mg_http_transfer_file_data(struct mg_connection *nc) {
  struct mg_http_proto_data *pd = mg_http_get_proto_data(nc);
  char buf[MG_MAX_HTTP_SEND_MBUF];
  size_t n = 0, to_read = 0, left = (size_t)(pd->file.cl - pd->file.sent);

  if (pd->file.type == DATA_FILE) {
    struct mbuf *io = &nc->send_mbuf;
    if (io->len >= MG_MAX_HTTP_SEND_MBUF) {
      to_read = 0;
    } else {
      to_read = MG_MAX_HTTP_SEND_MBUF - io->len;
    }
    if (to_read > left) {
      to_read = left;
    }
    if (to_read > 0) {
      n = mg_fread(buf, 1, to_read, pd->file.fp);
      if (n > 0) {
        mg_send(nc, buf, n);
        pd->file.sent += n;
        DBG(("%p sent %d (total %d)", nc, (int) n, (int) pd->file.sent));
      }
    } else {
      /* Rate-limited */
    }
    if (pd->file.sent >= pd->file.cl) {
      LOG(LL_DEBUG, ("%p done, %d bytes", nc, (int) pd->file.sent));
      if (!pd->file.keepalive) nc->flags |= MG_F_SEND_AND_CLOSE;
      mg_http_free_proto_data_file(&pd->file);
    }
  } else if (pd->file.type == DATA_PUT) {
    struct mbuf *io = &nc->recv_mbuf;
    size_t to_write = left <= 0 ? 0 : left < io->len ? (size_t) left : io->len;
    size_t n = mg_fwrite(io->buf, 1, to_write, pd->file.fp);
    if (n > 0) {
      mbuf_remove(io, n);
      pd->file.sent += n;
    }
    if (n == 0 || pd->file.sent >= pd->file.cl) {
      if (!pd->file.keepalive) nc->flags |= MG_F_SEND_AND_CLOSE;
      mg_http_free_proto_data_file(&pd->file);
    }
  }
#if MG_ENABLE_HTTP_CGI
  else if (pd->cgi.cgi_nc != NULL) {
    /* This is POST data that needs to be forwarded to the CGI process */
    if (pd->cgi.cgi_nc != NULL) {
      mg_forward(nc, pd->cgi.cgi_nc);
    } else {
      nc->flags |= MG_F_SEND_AND_CLOSE;
    }
  }
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq %rdi, %r14
movq 0x88(%rdi), %rbx
testq %rbx, %rbx
jne 0xc264
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, %rbx
movq %rax, 0x88(%r14)
leaq 0x6ea1(%rip), %rax      # 0x130fe
movq %rax, 0x90(%r14)
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rdx
movq %rcx, %rax
subq %rdx, %rax
movl 0x1c(%rbx), %esi
cmpl $0x2, %esi
je 0xc36d
cmpl $0x1, %esi
jne 0xc37a
movq 0x60(%r14), %rcx
leaq -0x1000(%rcx), %rsi
negq %rsi
xorl %edx, %edx
cmpq $0x1000, %rcx           # imm = 0x1000
cmovbq %rsi, %rdx
cmpq %rax, %rdx
cmovaeq %rax, %rdx
testq %rdx, %rdx
je 0xc32d
movq (%rbx), %rcx
movq %rsp, %rdi
movl $0x1, %esi
callq 0x3100
testq %rax, %rax
je 0xc32d
movq %rax, %r15
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movslq %r15d, %rdx
movq %rsp, %rsi
movq %r14, %rdi
callq *0x48(%rcx,%rax,4)
addq %r15, 0x10(%rbx)
leaq 0xa174(%rip), %rsi      # 0x16475
leaq 0x92c6(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0xc32d
movl 0x10(%rbx), %ecx
leaq 0xa170(%rip), %rdi      # 0x16490
movq %r14, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4539
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rax
jl 0xc3fd
leaq 0xa133(%rip), %rsi      # 0x16475
leaq 0x9285(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
testl %eax, %eax
je 0xc3d5
movl 0x10(%rbx), %edx
leaq 0xa145(%rip), %rdi      # 0x164a6
movq %r14, %rsi
xorl %eax, %eax
callq 0x4539
jmp 0xc3d5
leaq 0x40(%r14), %r15
cmpq %rdx, %rcx
jne 0xc399
xorl %edx, %edx
jmp 0xc3a4
movq 0x20(%rbx), %rsi
testq %rsi, %rsi
je 0xc3fd
movq %r14, %rdi
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x955a
movq 0x48(%r14), %rdx
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq (%r15), %rdi
movq (%rbx), %rcx
movl $0x1, %esi
callq 0x35e0
testq %rax, %rax
je 0xc3d5
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x6af6
addq 0x10(%rbx), %r12
movq %r12, 0x10(%rbx)
cmpq 0x8(%rbx), %r12
jl 0xc3fd
cmpl $0x0, 0x18(%rbx)
jne 0xc3e3
orb $0x4, 0xc9(%r14)
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xc3f0
callq 0x3160
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rbx)
movupd %xmm0, (%rbx)
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
retq