// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: on_cgi_data
static void on_cgi_data(struct ns_connection *nc) {
  struct connection *conn = (struct connection *) nc->user_data;
  const char *status = "500";
  struct mg_connection c;

  if (!conn) return;

  // Copy CGI data from CGI socket to the client send buffer
  ns_forward(nc, conn->ns_conn);

  // If reply has not been parsed yet, parse it
  if (conn->ns_conn->flags & NSF_BUFFER_BUT_DONT_SEND) {
    struct iobuf *io = &conn->ns_conn->send_iobuf;
    size_t s_len = sizeof(cgi_status) - 1;
    int len = get_request_len(io->buf + s_len, io->len - s_len);
    char buf[MAX_REQUEST_SIZE], *s = buf;

    if (len == 0) return;

    if (len < 0 || len > (int) sizeof(buf)) {
      len = io->len;
      iobuf_remove(io, io->len);
      send_http_error(conn, 500, "CGI program sent malformed headers: [%.*s]",
        len, io->buf);
    } else {
      memset(&c, 0, sizeof(c));
      memcpy(buf, io->buf + s_len, len);
      buf[len - 1] = '\0';
      parse_http_headers(&s, &c);
      if (mg_get_header(&c, "Location") != NULL) {
        status = "302";
      } else if ((status = (char *) mg_get_header(&c, "Status")) == NULL) {
        status = "200";
      }
      memcpy(io->buf + 9, status, 3);
      conn->mg_conn.status_code = atoi(status);
    }
    conn->ns_conn->flags &= ~NSF_BUFFER_BUT_DONT_SEND;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x42e0, %rsp           # imm = 0x42E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x10(%rbp)
leaq 0xa3a8(%rip), %rax      # 0xc830d
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xbdf75
jmp 0xbe161
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0xb9ca0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0xa0(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xbe161
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x58, %rax
movq %rax, -0x2c0(%rbp)
movq $0x11, -0x2c8(%rbp)
movq -0x2c0(%rbp), %rax
movq (%rax), %rdi
addq -0x2c8(%rbp), %rdi
movq -0x2c0(%rbp), %rax
movq 0x8(%rax), %rsi
subq -0x2c8(%rbp), %rsi
callq 0xb53e0
movl %eax, -0x2cc(%rbp)
leaq -0x42d0(%rbp), %rax
movq %rax, -0x42d8(%rbp)
cmpl $0x0, -0x2cc(%rbp)
jne 0xbe005
jmp 0xbe161
cmpl $0x0, -0x2cc(%rbp)
jl 0xbe01a
cmpl $0x4000, -0x2cc(%rbp)   # imm = 0x4000
jle 0xbe06e
movq -0x2c0(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, -0x2cc(%rbp)
movq -0x2c0(%rbp), %rdi
movq -0x2c0(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xaedd0
movq -0x10(%rbp), %rdi
movl -0x2cc(%rbp), %ecx
movq -0x2c0(%rbp), %rax
movq (%rax), %r8
movl $0x1f4, %esi            # imm = 0x1F4
leaq 0xa2af(%rip), %rdx      # 0xc8311
movb $0x0, %al
callq 0xb3db0
jmp 0xbe14b
leaq -0x2b8(%rbp), %rdi
xorl %esi, %esi
movl $0x2a0, %edx            # imm = 0x2A0
callq 0xd430
leaq -0x42d0(%rbp), %rdi
movq -0x2c0(%rbp), %rax
movq (%rax), %rsi
addq -0x2c8(%rbp), %rsi
movslq -0x2cc(%rbp), %rdx
callq 0xd100
movl -0x2cc(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x42d0(%rbp,%rax)
leaq -0x42d8(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0xba2b0
leaq -0x2b8(%rbp), %rdi
leaq 0xa263(%rip), %rsi      # 0xc833c
callq 0xb0fe0
cmpq $0x0, %rax
je 0xbe0f1
leaq 0xa25a(%rip), %rax      # 0xc8345
movq %rax, -0x18(%rbp)
jmp 0xbe11b
leaq -0x2b8(%rbp), %rdi
leaq 0x8d42(%rip), %rsi      # 0xc6e41
callq 0xb0fe0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xbe119
leaq 0x9702(%rip), %rax      # 0xc7817
movq %rax, -0x18(%rbp)
jmp 0xbe11b
movq -0x2c0(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movw (%rcx), %dx
movw %dx, 0x9(%rax)
movb 0x2(%rcx), %cl
movb %cl, 0xb(%rax)
movq -0x18(%rbp), %rdi
callq 0xd440
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x284(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0xa0(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0xa0(%rax)
addq $0x42e0, %rsp           # imm = 0x42E0
popq %rbp
retq
nopw (%rax,%rax)