// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: mg_send_file_internal
void mg_send_file_internal(struct mg_connection *c, const char *file_name,
                           file_stat_t *st, int exists,
                           const char *extra_headers) {
  struct connection *conn = MG_CONN_2_CONN(c);
  char path[MAX_PATH_SIZE];
  const int is_directory = S_ISDIR(st->st_mode);
#ifndef MONGOOSE_NO_CGI
  const char *cgi_pat = conn->server->config_options[CGI_PATTERN];
#else
  const char *cgi_pat = DEFAULT_CGI_PATTERN;
#endif
#ifndef MONGOOSE_NO_DIRECTORY_LISTING
  const char *dir_lst = conn->server->config_options[ENABLE_DIRECTORY_LISTING];
#else
  const char *dir_lst = "yes";
#endif

  mg_snprintf(path, sizeof(path), "%s", file_name);

  if (!exists || must_hide_file(conn, path)) {
    send_http_error(conn, 404, NULL);
  } else if (is_directory &&
             conn->mg_conn.uri[strlen(conn->mg_conn.uri) - 1] != '/') {
    conn->mg_conn.status_code = 301;
    mg_printf(&conn->mg_conn, "HTTP/1.1 301 Moved Permanently\r\n"
              "Location: %s/\r\n\r\n", conn->mg_conn.uri);
    close_local_endpoint(conn);
  } else if (is_directory && !find_index_file(conn, path, sizeof(path), st)) {
    if (!mg_strcasecmp(dir_lst, "yes")) {
#ifndef MONGOOSE_NO_DIRECTORY_LISTING
      send_directory_listing(conn, path);
#else
      send_http_error(conn, 501, NULL);
#endif
    } else {
      send_http_error(conn, 403, NULL);
    }
  } else if (mg_match_prefix(cgi_pat, strlen(cgi_pat), path) > 0) {
#if !defined(MONGOOSE_NO_CGI)
    open_cgi_endpoint(conn, path);
#else
    send_http_error(conn, 501, NULL);
#endif // !MONGOOSE_NO_CGI
#ifndef MONGOOSE_NO_SSI
  } else if (mg_match_prefix(conn->server->config_options[SSI_PATTERN],
                             strlen(conn->server->config_options[SSI_PATTERN]),
                             path) > 0) {
    handle_ssi_request(conn, path);
#endif
  } else if (is_not_modified(conn, st)) {
    send_http_error(conn, 304, NULL);
  } else if ((conn->endpoint.fd = open(path, O_RDONLY | O_BINARY, 0)) != -1) {
    // O_BINARY is required for Windows, otherwise in default text mode
    // two bytes \r\n will be read as one.
    open_file_endpoint(conn, path, st, extra_headers);
  } else {
    send_http_error(conn, 404, NULL);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2060, %rsp           # imm = 0x2060
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $-0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2034(%rbp)
movq -0x30(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0x58(%rax), %rax
movq %rax, -0x2040(%rbp)
movq -0x30(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0x78(%rax), %rax
movq %rax, -0x2048(%rbp)
leaq -0x2030(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x2000, %esi           # imm = 0x2000
leaq 0x10e34(%rip), %rdx     # 0xc4830
movb $0x0, %al
callq 0xb3c50
cmpl $0x0, -0x1c(%rbp)
je 0xb3a1e
movq -0x30(%rbp), %rdi
leaq -0x2030(%rbp), %rsi
callq 0xb3d00
cmpl $0x0, %eax
je 0xb3a37
movq -0x30(%rbp), %rdi
movl $0x194, %esi            # imm = 0x194
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xb3db0
jmp 0xb3c41
cmpl $0x0, -0x2034(%rbp)
je 0xb3aad
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x2050(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xd550
movq %rax, %rcx
movq -0x2050(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0xb3aad
movq -0x30(%rbp), %rax
movl $0x12d, 0x284(%rax)     # imm = 0x12D
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x1321e(%rip), %rsi     # 0xc6cb6
movb $0x0, %al
callq 0xb0cb0
movq -0x30(%rbp), %rdi
callq 0xb23e0
jmp 0xb3c3f
cmpl $0x0, -0x2034(%rbp)
je 0xb3b17
movq -0x30(%rbp), %rdi
leaq -0x2030(%rbp), %rsi
movq -0x18(%rbp), %rcx
movl $0x2000, %edx           # imm = 0x2000
callq 0xb40f0
cmpl $0x0, %eax
jne 0xb3b17
movq -0x2048(%rbp), %rdi
leaq 0xef62(%rip), %rsi      # 0xc2a44
callq 0xb1070
cmpl $0x0, %eax
jne 0xb3afe
movq -0x30(%rbp), %rdi
leaq -0x2030(%rbp), %rsi
callq 0xb42b0
jmp 0xb3b12
movq -0x30(%rbp), %rdi
movl $0x193, %esi            # imm = 0x193
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xb3db0
jmp 0xb3c3d
movq -0x2040(%rbp), %rax
movq %rax, -0x2058(%rbp)
movq -0x2040(%rbp), %rdi
callq 0xd550
movq -0x2058(%rbp), %rdi
movq %rax, %rsi
leaq -0x2030(%rbp), %rdx
callq 0xb10f0
cmpl $0x0, %eax
jle 0xb3b61
movq -0x30(%rbp), %rdi
leaq -0x2030(%rbp), %rsi
callq 0xb4410
jmp 0xb3c3b
movq -0x30(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0xc0(%rax), %rax
movq %rax, -0x2060(%rbp)
movq -0x30(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0xc0(%rax), %rdi
callq 0xd550
movq -0x2060(%rbp), %rdi
movq %rax, %rsi
leaq -0x2030(%rbp), %rdx
callq 0xb10f0
cmpl $0x0, %eax
jle 0xb3bbe
movq -0x30(%rbp), %rdi
leaq -0x2030(%rbp), %rsi
callq 0xb4680
jmp 0xb3c39
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xb4780
cmpl $0x0, %eax
je 0xb3be6
movq -0x30(%rbp), %rdi
movl $0x130, %esi            # imm = 0x130
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xb3db0
jmp 0xb3c37
leaq -0x2030(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
movb $0x0, %al
callq 0xdf10
movq -0x30(%rbp), %rcx
movl %eax, 0x2b0(%rcx)
cmpl $-0x1, %eax
je 0xb3c21
movq -0x30(%rbp), %rdi
leaq -0x2030(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xb4840
jmp 0xb3c35
movq -0x30(%rbp), %rdi
movl $0x194, %esi            # imm = 0x194
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xb3db0
jmp 0xb3c37
jmp 0xb3c39
jmp 0xb3c3b
jmp 0xb3c3d
jmp 0xb3c3f
jmp 0xb3c41
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopw (%rax,%rax)