// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_handle_cgi
MG_INTERNAL void mg_handle_cgi(struct mg_connection *nc, const char *prog,
                               const struct mg_str *path_info,
                               const struct http_message *hm,
                               const struct mg_serve_http_opts *opts) {
  struct mg_cgi_env_block blk;
  char dir[MG_MAX_PATH];
  const char *p;
  sock_t fds[2];

  DBG(("%p [%s]", nc, prog));
  mg_prepare_cgi_environment(nc, prog, path_info, hm, opts, &blk);
  /*
   * CGI must be executed in its own directory. 'dir' must point to the
   * directory containing executable program, 'p' must point to the
   * executable program name relative to 'dir'.
   */
  if ((p = strrchr(prog, DIRSEP)) == NULL) {
    snprintf(dir, sizeof(dir), "%s", ".");
  } else {
    snprintf(dir, sizeof(dir), "%.*s", (int) (p - prog), prog);
    prog = p + 1;
  }

  if (!mg_socketpair(fds, SOCK_STREAM)) {
    nc->flags |= MG_F_CLOSE_IMMEDIATELY;
    return;
  }

#ifndef _WIN32
  struct sigaction sa;

  sigemptyset(&sa.sa_mask);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  sigaction(SIGCHLD, &sa, NULL);
#endif

  if (mg_start_process(opts->cgi_interpreter, prog, blk.buf, blk.vars, dir,
                       fds[1]) != 0) {
    size_t n = nc->recv_mbuf.len - (hm->message.len - hm->body.len);
    struct mg_connection *cgi_nc =
        mg_add_sock(nc->mgr, fds[0], mg_cgi_ev_handler MG_UD_ARG(nc));
    struct mg_http_proto_data *cgi_pd = mg_http_get_proto_data(nc);
    cgi_pd->cgi.cgi_nc = cgi_nc;
#if !MG_ENABLE_CALLBACK_USERDATA
    cgi_pd->cgi.cgi_nc->user_data = nc;
#endif
    nc->flags |= MG_F_HTTP_CGI_PARSE_HEADERS;
    /* Push POST data to the CGI */
    if (n > 0 && n < nc->recv_mbuf.len) {
      mg_send(cgi_pd->cgi.cgi_nc, hm->body.p, n);
    }
    mbuf_remove(&nc->recv_mbuf, nc->recv_mbuf.len);
  } else {
    closesocket(fds[0]);
    mg_http_send_error(nc, 500, "CGI failure");
  }

#ifndef _WIN32
  closesocket(fds[1]); /* On Windows, CGI stdio thread closes that socket */
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3300, %rsp           # imm = 0x3300
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x4, %edi
leaq 0x6511(%rip), %rsi      # 0x207ac
leaq 0x52a8(%rip), %rdx      # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0x1a2c2
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq 0x64ff(%rip), %rdi      # 0x207ba
movb $0x0, %al
callq 0x47a0
jmp 0x1a2c4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
leaq -0x2238(%rbp), %r9
callq 0x1a9b0
movq -0x10(%rbp), %rdi
movl $0x2f, %esi
callq 0x3200
movq %rax, -0x3248(%rbp)
cmpq $0x0, %rax
jne 0x1a322
leaq -0x3240(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5c80(%rip), %rdx      # 0x1ff92
leaq 0x5672(%rip), %rcx      # 0x1f98b
movb $0x0, %al
callq 0x31f0
jmp 0x1a35f
leaq -0x3240(%rbp), %rdi
movq -0x3248(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x589f(%rip), %rdx      # 0x1fbe8
movb $0x0, %al
callq 0x31f0
movq -0x3248(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
leaq -0x3250(%rbp), %rdi
movl $0x1, %esi
callq 0xe2d0
cmpl $0x0, %eax
jne 0x1a393
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x800, %rcx            # imm = 0x800
movq %rcx, 0xc8(%rax)
jmp 0x1a521
leaq -0x32e8(%rbp), %rdi
addq $0x8, %rdi
callq 0x3380
movl $0x1, %eax
movq %rax, -0x32e8(%rbp)
movl $0x0, -0x3260(%rbp)
movl $0x11, %edi
leaq -0x32e8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x30f0
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x10(%rbp), %rsi
leaq -0x2238(%rbp), %rdx
addq $0x8, %rdx
leaq -0x2238(%rbp), %rcx
addq $0x2008, %rcx           # imm = 0x2008
leaq -0x3240(%rbp), %r8
movl -0x324c(%rbp), %r9d
callq 0x1afe0
cmpl $0x0, %eax
je 0x1a4f6
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x20(%rbp), %rdx
subq 0x18(%rdx), %rcx
subq %rcx, %rax
movq %rax, -0x32f0(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x3250(%rbp), %esi
leaq 0xd4a(%rip), %rdx       # 0x1b190
callq 0xd420
movq %rax, -0x32f8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x109b0
movq %rax, -0x3300(%rbp)
movq -0x32f8(%rbp), %rcx
movq -0x3300(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rcx
movq -0x3300(%rbp), %rax
movq 0x20(%rax), %rax
movq %rcx, 0xa0(%rax)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x100000, %rcx         # imm = 0x100000
movq %rcx, 0xc8(%rax)
cmpq $0x0, -0x32f0(%rbp)
jbe 0x1a4df
movq -0x32f0(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x1a4df
movq -0x3300(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x32f0(%rbp), %rax
movl %eax, %edx
callq 0xb260
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rsi
callq 0x89f0
jmp 0x1a516
movl -0x3250(%rbp), %edi
callq 0x32a0
movq -0x8(%rbp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
leaq 0x62b1(%rip), %rdx      # 0x207c2
callq 0x11e30
movl -0x324c(%rbp), %edi
callq 0x32a0
addq $0x3300, %rsp           # imm = 0x3300
popq %rbp
retq
nopw (%rax,%rax)