// File: /workspace/github_cpp_makefile_star2_O1/nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: forward_body_data
static int forward_body_data(struct mg_connection *conn, FILE *fp,
                             SOCKET sock, SSL *ssl) {
  const char *expect, *buffered;
  char buf[BUFSIZ];
  int to_read, nread, buffered_len, success = 0;

  expect = mg_get_header(conn, "Expect");
  assert(fp != NULL);

  if (conn->content_len == -1) {
    send_http_error(conn, 411, "Length Required", "");
  } else if (expect != NULL && mg_strcasecmp(expect, "100-continue")) {
    send_http_error(conn, 417, "Expectation Failed", "");
  } else {
    if (expect != NULL) {
      (void) mg_printf(conn, "%s", "HTTP/1.1 100 Continue\r\n\r\n");
    }

    buffered = conn->buf + conn->request_len;
    buffered_len = conn->data_len - conn->request_len;
    assert(buffered_len >= 0);
    assert(conn->consumed_content == 0);

    if (buffered_len > 0) {
      if ((int64_t) buffered_len > conn->content_len) {
        buffered_len = (int) conn->content_len;
      }
      push(fp, sock, ssl, buffered, (int64_t) buffered_len);
      conn->consumed_content += buffered_len;
    }

    while (conn->consumed_content < conn->content_len) {
      to_read = sizeof(buf);
      if ((int64_t) to_read > conn->content_len - conn->consumed_content) {
        to_read = (int) (conn->content_len - conn->consumed_content);
      }
      nread = pull(NULL, conn->client.sock, conn->ssl, buf, to_read);
      if (nread <= 0 || push(fp, sock, ssl, buf, nread) != nread) {
        break;
      }
      conn->consumed_content += nread;
    }

    if (conn->consumed_content == conn->content_len) {
      success = 1;
    }

    // Each error code path in this function must send an error
    if (!success) {
      send_http_error(conn, 577, http_500_error, "");
    }
  }

  return success;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movq %rcx, 0x8(%rsp)
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
addq $0x8, %rdi
leaq 0x2bfa(%rip), %rsi      # 0x1603e
callq 0xe677
cmpq $-0x1, 0x4b8(%rbx)
je 0x135ab
movq %rax, %r12
testq %rax, %rax
je 0x134ac
callq 0x50e0
movq (%rax), %rax
xorl %ecx, %ecx
leaq 0x2be5(%rip), %rdx      # 0x16055
movzbl (%r12,%rcx), %r8d
movl (%rax,%r8,4), %esi
movzbl (%rcx,%rdx), %edi
movl (%rax,%rdi,4), %edi
testl %r8d, %r8d
je 0x1348c
incq %rcx
cmpl %edi, %esi
je 0x13470
cmpl %edi, %esi
jne 0x135c5
leaq 0x32d5(%rip), %rsi      # 0x16770
leaq 0x2bd3(%rip), %rdx      # 0x16075
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8fd
movslq 0x4d4(%rbx), %rcx
movl 0x4d8(%rbx), %eax
subl %ecx, %eax
jle 0x134ef
addq 0x4c8(%rbx), %rcx
movl %eax, %edx
movq 0x4b8(%rbx), %rsi
cmpq %rdx, %rsi
cmovgel %eax, %esi
movslq %esi, %r12
movq %r15, %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
movq %r12, %r8
callq 0xe841
addq %r12, 0x4c0(%rbx)
movq 0x4b8(%rbx), %rdx
movq 0x4c0(%rbx), %r13
cmpq %rdx, %r13
jge 0x1357c
movl $0x2000, %r14d          # imm = 0x2000
leaq 0x10(%rsp), %r12
subq %r13, %rdx
cmpq %r14, %rdx
cmovgeq %r14, %rdx
movq 0x460(%rbx), %rdi
testq %rdi, %rdi
je 0x1352e
movq %r12, %rsi
callq *0x92ec(%rip)           # 0x1c818
jmp 0x13541
movl 0x470(%rbx), %edi
movslq %edx, %rdx
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x5180
testl %eax, %eax
jle 0x1357c
movl %eax, %r13d
movq %r15, %rdi
movl %ebp, %esi
movq 0x8(%rsp), %rdx
movq %r12, %rcx
movq %r13, %r8
callq 0xe841
cmpq %r13, %rax
jne 0x1357c
addq 0x4c0(%rbx), %r13
movq %r13, 0x4c0(%rbx)
movq 0x4b8(%rbx), %rdx
cmpq %rdx, %r13
jl 0x1350d
movq 0x4c0(%rbx), %rax
movl $0x1, %ebp
cmpq 0x4b8(%rbx), %rax
je 0x135e4
leaq 0x2af7(%rip), %rdx      # 0x1608f
leaq 0x2ca3(%rip), %rcx      # 0x16242
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x241, %esi            # imm = 0x241
jmp 0x135dd
leaq 0x2a93(%rip), %rdx      # 0x16045
leaq 0x2c89(%rip), %rcx      # 0x16242
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x19b, %esi            # imm = 0x19B
jmp 0x135dd
leaq 0x2a96(%rip), %rdx      # 0x16062
leaq 0x2c6f(%rip), %rcx      # 0x16242
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x1a1, %esi            # imm = 0x1A1
xorl %eax, %eax
callq 0x12ea8
movl %ebp, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq