// File: /workspace/github_c_makefile_star2_O1/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, %rbx
cmpq $0x0, 0x88(%rdi)
jne 0xc4d0
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, 0x88(%rbx)
leaq 0x6758(%rip), %rax      # 0x12c21
movq %rax, 0x90(%rbx)
movq 0x88(%rbx), %r12
movq 0x8(%r12), %rcx
movq 0x10(%r12), %rdx
movq %rcx, %rax
subq %rdx, %rax
movl 0x1c(%r12), %esi
cmpl $0x2, %esi
je 0xc5e5
cmpl $0x1, %esi
jne 0xc5f2
movq 0x60(%rbx), %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 0xc586
movq (%r12), %rcx
movq %rsp, %rdi
movl $0x1, %esi
callq 0x3100
testq %rax, %rax
je 0xc586
movq %rax, %r14
movq %rsp, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x808e
addq %r14, 0x10(%r12)
leaq 0x9eff(%rip), %rsi      # 0x16457
leaq 0x904b(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0xc586
movl 0x10(%r12), %ecx
leaq 0x9ef9(%rip), %rdi      # 0x16472
movq %rbx, %rsi
movl %r14d, %edx
xorl %eax, %eax
callq 0x45a0
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rax
jl 0xc695
leaq 0x9eba(%rip), %rsi      # 0x16457
leaq 0x9006(%rip), %rdx      # 0x155aa
movl $0x3, %edi
callq 0x44b4
testl %eax, %eax
je 0xc5c8
movl 0x10(%r12), %edx
leaq 0x9eca(%rip), %rdi      # 0x16488
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
cmpl $0x0, 0x18(%r12)
jne 0xc5d7
orb $0x4, 0xc9(%rbx)
testq %r12, %r12
jne 0xc679
jmp 0xc695
leaq 0x40(%rbx), %r14
cmpq %rdx, %rcx
jne 0xc62a
xorl %edx, %edx
jmp 0xc635
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0xc695
leaq 0x40(%rbx), %r14
movq 0x40(%rbx), %rsi
movl 0x48(%rbx), %edx
callq 0x808e
movq 0x48(%rbx), %rsi
movq %r14, %rdi
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x6bb8
movq 0x48(%rbx), %rdx
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq (%r14), %rdi
movq (%r12), %rcx
movl $0x1, %esi
callq 0x35e0
testq %rax, %rax
je 0xc66a
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x6bb8
addq 0x10(%r12), %r15
movq %r15, 0x10(%r12)
cmpq 0x8(%r12), %r15
jl 0xc695
cmpl $0x0, 0x18(%r12)
jne 0xc679
orb $0x4, 0xc9(%rbx)
movq (%r12), %rdi
testq %rdi, %rdi
je 0xc687
callq 0x3160
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movups %xmm0, (%r12)
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
retq