// File: 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:
subq $0x2048, %rsp           # imm = 0x2048
movq %rdi, 0x2040(%rsp)
movq %rsi, 0x2038(%rsp)
movl %edx, 0x2034(%rsp)
movq %rcx, 0x2028(%rsp)
movl $0x0, (%rsp)
movq 0x2040(%rsp), %rdi
leaq 0x5b4a(%rip), %rsi      # 0x23046
callq 0x16b70
movq %rax, 0x2020(%rsp)
movq 0x2040(%rsp), %rax
cmpq $-0x1, 0x4b8(%rax)
jne 0x1d542
movq 0x2040(%rsp), %rdi
movl $0x19b, %esi            # imm = 0x19B
leaq 0x5b1e(%rip), %rdx      # 0x2304d
leaq 0x4dba(%rip), %rcx      # 0x222f0
movb $0x0, %al
callq 0x1bc40
jmp 0x1d7ca
cmpq $0x0, 0x2020(%rsp)
je 0x1d58d
movq 0x2020(%rsp), %rdi
leaq 0x5b01(%rip), %rsi      # 0x2305d
callq 0x19510
cmpl $0x0, %eax
je 0x1d58d
movq 0x2040(%rsp), %rdi
movl $0x1a1, %esi            # imm = 0x1A1
leaq 0x5af0(%rip), %rdx      # 0x2306a
leaq 0x4d6f(%rip), %rcx      # 0x222f0
movb $0x0, %al
callq 0x1bc40
jmp 0x1d7c8
cmpq $0x0, 0x2020(%rsp)
je 0x1d5b5
movq 0x2040(%rsp), %rdi
leaq 0x61d1(%rip), %rsi      # 0x23778
leaq 0x5acf(%rip), %rdx      # 0x2307d
movb $0x0, %al
callq 0x17030
movq 0x2040(%rsp), %rax
movq 0x4c8(%rax), %rax
movq 0x2040(%rsp), %rcx
movslq 0x4d4(%rcx), %rcx
addq %rcx, %rax
movq %rax, 0x2018(%rsp)
movq 0x2040(%rsp), %rax
movl 0x4d8(%rax), %eax
movq 0x2040(%rsp), %rcx
subl 0x4d4(%rcx), %eax
movl %eax, 0x4(%rsp)
cmpl $0x0, 0x4(%rsp)
jle 0x1d672
movslq 0x4(%rsp), %rax
movq 0x2040(%rsp), %rcx
cmpq 0x4b8(%rcx), %rax
jle 0x1d62e
movq 0x2040(%rsp), %rax
movq 0x4b8(%rax), %rax
movl %eax, 0x4(%rsp)
movq 0x2038(%rsp), %rdi
movl 0x2034(%rsp), %esi
movq 0x2028(%rsp), %rdx
movq 0x2018(%rsp), %rcx
movslq 0x4(%rsp), %r8
callq 0x16f10
movslq 0x4(%rsp), %rcx
movq 0x2040(%rsp), %rax
addq 0x4c0(%rax), %rcx
movq %rcx, 0x4c0(%rax)
jmp 0x1d674
movq 0x2040(%rsp), %rax
movq 0x4c0(%rax), %rax
movq 0x2040(%rsp), %rcx
cmpq 0x4b8(%rcx), %rax
jge 0x1d777
movl $0x2000, 0xc(%rsp)      # imm = 0x2000
movslq 0xc(%rsp), %rax
movq 0x2040(%rsp), %rcx
movq 0x4b8(%rcx), %rcx
movq 0x2040(%rsp), %rdx
subq 0x4c0(%rdx), %rcx
cmpq %rcx, %rax
jle 0x1d6ea
movq 0x2040(%rsp), %rax
movq 0x4b8(%rax), %rax
movq 0x2040(%rsp), %rcx
subq 0x4c0(%rcx), %rax
movl %eax, 0xc(%rsp)
movq 0x2040(%rsp), %rax
movl 0x470(%rax), %esi
movq 0x2040(%rsp), %rax
movq 0x460(%rax), %rdx
leaq 0x10(%rsp), %rcx
movl 0xc(%rsp), %r8d
xorl %eax, %eax
movl %eax, %edi
callq 0x16e30
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x1d755
movq 0x2038(%rsp), %rdi
movl 0x2034(%rsp), %esi
movq 0x2028(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movslq 0x8(%rsp), %r8
callq 0x16f10
movslq 0x8(%rsp), %rcx
cmpq %rcx, %rax
je 0x1d757
jmp 0x1d777
movslq 0x8(%rsp), %rcx
movq 0x2040(%rsp), %rax
addq 0x4c0(%rax), %rcx
movq %rcx, 0x4c0(%rax)
jmp 0x1d674
movq 0x2040(%rsp), %rax
movq 0x4c0(%rax), %rax
movq 0x2040(%rsp), %rcx
cmpq 0x4b8(%rcx), %rax
jne 0x1d79e
movl $0x1, (%rsp)
cmpl $0x0, (%rsp)
jne 0x1d7c6
movq 0x2040(%rsp), %rdi
movq 0xe2ad(%rip), %rdx      # 0x2ba60
movl $0x241, %esi            # imm = 0x241
leaq 0x4b31(%rip), %rcx      # 0x222f0
movb $0x0, %al
callq 0x1bc40
jmp 0x1d7c8
jmp 0x1d7ca
movl (%rsp), %eax
addq $0x2048, %rsp           # imm = 0x2048
retq
nopw %cs:(%rax,%rax)