// File: /workspace/github_cpp_makefile_star2_O2/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, 0x4(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
addq $0x8, %rdi
leaq 0x2556(%rip), %rsi      # 0x1303e
callq 0xb940
cmpq $-0x1, 0x4b8(%rbx)
je 0x10b2c
testq %rax, %rax
je 0x10b61
leaq 0x2552(%rip), %rsi      # 0x13055
movq %rax, %rdi
callq 0xd3cf
testl %eax, %eax
je 0x10b49
leaq 0x254c(%rip), %rdx      # 0x13062
leaq 0x2722(%rip), %rcx      # 0x1323f
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x1a1, %esi            # imm = 0x1A1
jmp 0x10c4d
leaq 0x2512(%rip), %rdx      # 0x13045
leaq 0x2705(%rip), %rcx      # 0x1323f
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x19b, %esi            # imm = 0x19B
jmp 0x10c4d
leaq 0x2c1d(%rip), %rsi      # 0x1376d
leaq 0x251e(%rip), %rdx      # 0x13075
movq %rbx, %rdi
xorl %eax, %eax
callq 0xbb9c
movslq 0x4d4(%rbx), %rcx
movl 0x4d8(%rbx), %eax
subl %ecx, %eax
jle 0x10baf
addq 0x4c8(%rbx), %rcx
movl %eax, %edx
movq 0x4b8(%rbx), %rsi
cmpq %rdx, %rsi
cmovgel %eax, %esi
movslq %esi, %r13
movq %r15, %rdi
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
movq %r13, %r8
callq 0xbada
addq 0x4c0(%rbx), %r13
movq %r13, 0x4c0(%rbx)
jmp 0x10bb6
movq 0x4c0(%rbx), %r13
movl $0x2000, %ebp           # imm = 0x2000
leaq 0x10(%rsp), %r12
movq 0x4b8(%rbx), %r8
subq %r13, %r8
jle 0x10c27
cmpq %rbp, %r8
cmovgeq %rbp, %r8
movl 0x470(%rbx), %esi
movq 0x460(%rbx), %rdx
xorl %edi, %edi
movq %r12, %rcx
callq 0xba57
testl %eax, %eax
jle 0x10c20
movl %eax, %r14d
movq %r15, %rdi
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0xbada
movq 0x4c0(%rbx), %r13
cmpq %r14, %rax
jne 0x10c27
addq %r14, %r13
movq %r13, 0x4c0(%rbx)
jmp 0x10bc0
movq 0x4c0(%rbx), %r13
cmpq 0x4b8(%rbx), %r13
jne 0x10c35
pushq $0x1
popq %rbp
jmp 0x10c54
leaq 0x2453(%rip), %rdx      # 0x1308f
leaq 0x25fc(%rip), %rcx      # 0x1323f
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x241, %esi            # imm = 0x241
xorl %eax, %eax
callq 0x105c0
movl %ebp, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq