// File: /workspace/github_c_makefile_star2_O2/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
callq 0xb106
movq %rax, %r14
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rdx
movq %rcx, %rax
subq %rdx, %rax
movl 0x1c(%r14), %esi
cmpl $0x2, %esi
je 0xba86
cmpl $0x1, %esi
jne 0xba93
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 0xba31
movq (%r14), %rcx
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x3100
testq %rax, %rax
je 0xba31
movq %rax, %r15
movq %rsp, %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x7b89
addq %r15, 0x10(%r14)
leaq 0x9a52(%rip), %rsi      # 0x15458
leaq 0x8ba1(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xba31
movl 0x10(%r14), %ecx
leaq 0x9a4f(%rip), %rdi      # 0x15473
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x430a
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rax
jl 0xbaec
leaq 0x9a12(%rip), %rsi      # 0x15458
leaq 0x8b61(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xba6e
movl 0x10(%r14), %edx
leaq 0x9a25(%rip), %rdi      # 0x15489
movq %rbx, %rsi
xorl %eax, %eax
callq 0x430a
cmpl $0x0, 0x18(%r14)
jne 0xba7c
orb $0x4, 0xc9(%rbx)
movq %r14, %rdi
callq 0x11df2
jmp 0xbaec
leaq 0x40(%rbx), %r15
cmpq %rdx, %rcx
jne 0xbab2
xorl %edx, %edx
jmp 0xbabd
movq 0x20(%r14), %rsi
testq %rsi, %rsi
je 0xbaec
movq %rbx, %rdi
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x904b
movq 0x48(%rbx), %rdx
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq (%r15), %rdi
movq (%r14), %rcx
pushq $0x1
popq %rsi
callq 0x35e0
testq %rax, %rax
je 0xbafb
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x6845
addq 0x10(%r14), %r12
movq %r12, 0x10(%r14)
cmpq 0x8(%r14), %r12
jge 0xbafb
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpl $0x0, 0x18(%r14)
jne 0xbb09
orb $0x4, 0xc9(%rbx)
movq %r14, %rdi
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x11df2