// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x1060, %rsp           # imm = 0x1060
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x109b0
movq %rax, -0x10(%rbp)
movq $0x0, -0x1018(%rbp)
movq $0x0, -0x1020(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x10(%rcx), %rax
movq %rax, -0x1028(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x113ed
movq -0x8(%rbp), %rax
addq $0x58, %rax
movq %rax, -0x1030(%rbp)
movq -0x1030(%rbp), %rax
cmpq $0x1000, 0x8(%rax)      # imm = 0x1000
jb 0x11284
movq $0x0, -0x1020(%rbp)
jmp 0x1129b
movq -0x1030(%rbp), %rcx
movl $0x1000, %eax           # imm = 0x1000
subq 0x8(%rcx), %rax
movq %rax, -0x1020(%rbp)
movq -0x1020(%rbp), %rax
cmpq -0x1028(%rbp), %rax
jbe 0x112b9
movq -0x1028(%rbp), %rax
movq %rax, -0x1020(%rbp)
cmpq $0x0, -0x1020(%rbp)
jbe 0x1136b
leaq -0x1010(%rbp), %rdi
movq -0x1020(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x169d0
movq %rax, -0x1018(%rbp)
cmpq $0x0, -0x1018(%rbp)
jbe 0x11369
movq -0x8(%rbp), %rdi
leaq -0x1010(%rbp), %rsi
movq -0x1018(%rbp), %rax
movl %eax, %edx
callq 0xb260
movq -0x1018(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movl $0x4, %edi
leaq 0xf104(%rip), %rsi      # 0x20433
leaq 0xe214(%rip), %rdx      # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0x11365
movq -0x8(%rbp), %rsi
movq -0x1018(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
leaq 0xf0f0(%rip), %rdi      # 0x2044e
movb $0x0, %al
callq 0x47a0
jmp 0x11367
jmp 0x11369
jmp 0x1136d
jmp 0x1136d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jl 0x113e8
jmp 0x11381
movl $0x3, %edi
leaq 0xf0a6(%rip), %rsi      # 0x20433
leaq 0xe1b6(%rip), %rdx      # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0x113ba
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0xf0b1(%rip), %rdi      # 0x20464
movb $0x0, %al
callq 0x47a0
jmp 0x113bc
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x113df
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x400, %rcx            # imm = 0x400
movq %rcx, 0xc8(%rax)
movq -0x10(%rbp), %rdi
callq 0x19ad0
jmp 0x1155c
movq -0x10(%rbp), %rax
cmpl $0x2, 0x1c(%rax)
jne 0x11514
movq -0x8(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x1038(%rbp)
cmpq $0x0, -0x1028(%rbp)
ja 0x1141f
xorl %eax, %eax
movq %rax, -0x1050(%rbp)
jmp 0x11463
movq -0x1028(%rbp), %rax
movq -0x1038(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x11443
movq -0x1028(%rbp), %rax
movq %rax, -0x1058(%rbp)
jmp 0x11455
movq -0x1038(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1058(%rbp)
movq -0x1058(%rbp), %rax
movq %rax, -0x1050(%rbp)
movq -0x1050(%rbp), %rax
movq %rax, -0x1040(%rbp)
movq -0x1038(%rbp), %rax
movq (%rax), %rdi
movq -0x1040(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x16a10
movq %rax, -0x1048(%rbp)
cmpq $0x0, -0x1048(%rbp)
jbe 0x114ca
movq -0x1038(%rbp), %rdi
movq -0x1048(%rbp), %rsi
callq 0x89f0
movq -0x1048(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x1048(%rbp)
je 0x114e6
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jl 0x11512
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x11509
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x400, %rcx            # imm = 0x400
movq %rcx, 0xc8(%rax)
movq -0x10(%rbp), %rdi
callq 0x19ad0
jmp 0x1155a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x11558
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1153d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xd1e0
jmp 0x11556
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x400, %rcx            # imm = 0x400
movq %rcx, 0xc8(%rax)
jmp 0x11558
jmp 0x1155a
jmp 0x1155c
addq $0x1060, %rsp           # imm = 0x1060
popq %rbp
retq
nopw %cs:(%rax,%rax)