// File: /workspace/github_cpp_makefile_star2_O1/nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: handle_file_request
static void handle_file_request(struct mg_connection *conn, const char *path,
                                struct mgstat *stp) {
  char date[64], lm[64], etag[64], range[64];
  const char *fmt = "%a, %d %b %Y %H:%M:%S %Z", *msg = "OK", *hdr;
  time_t curtime = time(NULL);
  int64_t cl, r1, r2;
  struct vec mime_vec;
  FILE *fp;
  int n;

  get_mime_type(conn->ctx, path, &mime_vec);
  cl = stp->size;
  conn->request_info.status_code = 200;
  range[0] = '\0';

  if ((fp = mg_fopen(path, "rb")) == NULL) {
    send_http_error(conn, 500, http_500_error,
        "fopen(%s): %s", path, strerror(ERRNO));
    return;
  }
  set_close_on_exec(fileno(fp));

  // If Range: header specified, act accordingly
  r1 = r2 = 0;
  hdr = mg_get_header(conn, "Range");
  if (hdr != NULL && (n = parse_range_header(hdr, &r1, &r2)) > 0) {
    conn->request_info.status_code = 206;
    (void) fseeko(fp, (off_t) r1, SEEK_SET);
    cl = n == 2 ? r2 - r1 + 1: cl - r1;
    (void) mg_snprintf(conn, range, sizeof(range),
        "Content-Range: bytes "
        "%" INT64_FMT "-%"
        INT64_FMT "/%" INT64_FMT "\r\n",
        r1, r1 + cl - 1, stp->size);
    msg = "Partial Content";
  }

  // Prepare Etag, Date, Last-Modified headers
  (void) strftime(date, sizeof(date), fmt, localtime(&curtime));
  (void) strftime(lm, sizeof(lm), fmt, localtime(&stp->mtime));
  (void) mg_snprintf(conn, etag, sizeof(etag), "%lx.%lx",
      (unsigned long) stp->mtime, (unsigned long) stp->size);

  (void) mg_printf(conn,
      "HTTP/1.1 %d %s\r\n"
      "Date: %s\r\n"
      "Last-Modified: %s\r\n"
      "Etag: \"%s\"\r\n"
      "Content-Type: %.*s\r\n"
      "Content-Length: %" INT64_FMT "\r\n"
      "Connection: %s\r\n"
      "Accept-Ranges: bytes\r\n"
      "%s\r\n",
      conn->request_info.status_code, msg, date, lm, etag,
      mime_vec.len, mime_vec.ptr, cl, suggest_connection_header(conn), range);

  if (strcmp(conn->request_info.request_method, "HEAD") != 0) {
    send_file_data(conn, fp, cl);
  }
  (void) fclose(fp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdx, 0x30(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
xorl %edi, %edi
callq 0x5430
movq %rax, 0x38(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x458(%rbx), %rbx
movq %r15, %rdi
callq 0x5210
movq %rax, %r13
movq 0x90(%rbx), %r14
movq %r15, (%rsp)
leaq (%r15,%rax), %rbx
leaq 0x40(%rsp), %r12
leaq 0x80(%rsp), %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x12976
testq %rax, %rax
je 0x13f5b
movq %rax, %r14
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %rbx, %rdi
subq %rdx, %rdi
callq 0xeb3c
testl %eax, %eax
jne 0x13f12
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %r14
jmp 0x13fdd
leaq 0x794e(%rip), %r14      # 0x1b8b0
leaq 0x2b2f(%rip), %rbx      # 0x16a98
xorl %r12d, %r12d
leaq 0x2b1a(%rip), %rax      # 0x16a8d
movq %rax, 0x10(%rsp)
movq %r14, %rbp
movq %r13, %r15
subq 0x8(%rbp), %r15
jbe 0x13fb0
addq (%rsp), %r15
callq 0x50e0
movq (%rax), %rax
xorl %ecx, %ecx
movzbl (%r15,%rcx), %edi
movl (%rax,%rdi,4), %edx
movzbl (%rbx,%rcx), %esi
movl (%rax,%rsi,4), %esi
testl %edi, %edi
je 0x13fac
incq %rcx
cmpl %esi, %edx
je 0x13f92
cmpl %esi, %edx
je 0x13fd0
incq %r12
movq %r12, %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rbp
movq (%rax,%r14), %rbx
cmpq $0x26, %r12
jne 0x13f7b
movl $0xa, %r14d
jmp 0x13fdd
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rbp), %r14
movq 0x30(%rsp), %r13
movq 0x8(%r13), %r15
movq 0x18(%rsp), %rbx
movl $0xc8, 0x4c(%rbx)
movb $0x0, 0xc0(%rsp)
leaq 0x2564(%rip), %rsi      # 0x16565
movq (%rsp), %rbp
movq %rbp, %rdi
callq 0x55c0
testq %rax, %rax
je 0x140b3
movq %rax, %r12
movq %rax, %rdi
callq 0x54f0
xorl %ebx, %ebx
movl %eax, %edi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x5290
movq %rbx, 0x20(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x18(%rsp), %rbx
leaq 0x8(%rbx), %rdi
leaq 0x2222(%rip), %rsi      # 0x16272
callq 0xe677
testq %rax, %rax
movq %r14, 0x28(%rsp)
je 0x140aa
leaq 0x2212(%rip), %rsi      # 0x16278
leaq 0x8(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %rax, %rdi
xorl %eax, %eax
callq 0x5490
testl %eax, %eax
jle 0x140aa
movl %eax, %ebp
movl $0xce, 0x4c(%rbx)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x52a0
cmpl $0x2, %ebp
jne 0x140e7
movq 0x20(%rsp), %r15
subq 0x8(%rsp), %r15
incq %r15
jmp 0x140ec
leaq 0x1413(%rip), %rax      # 0x154c4
jmp 0x14129
callq 0x5060
movl (%rax), %edi
callq 0x51a0
leaq 0x1fc9(%rip), %rdx      # 0x1608f
leaq 0x2821(%rip), %rcx      # 0x168ee
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %rbp, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x12ea8
jmp 0x14226
subq 0x8(%rsp), %r15
movq 0x8(%rsp), %r8
leaq (%r15,%r8), %r9
decq %r9
subq $0x8, %rsp
leaq 0x28c2(%rip), %rcx      # 0x169c5
leaq 0xc8(%rsp), %rsi
movl $0x40, %edx
movq %rbx, %rdi
xorl %eax, %eax
pushq 0x8(%r13)
callq 0x131fd
addq $0x10, %rsp
leaq 0x28bf(%rip), %rax      # 0x169e8
movq %rax, (%rsp)
leaq 0x38(%rsp), %rdi
callq 0x5340
leaq 0x286e(%rip), %r14      # 0x169ac
leaq 0x40(%rsp), %rdi
movl $0x40, %esi
movq %r14, %rdx
movq %rax, %rcx
callq 0x53a0
leaq 0x10(%r13), %rdi
callq 0x5340
leaq 0x80(%rsp), %rbp
movl $0x40, %esi
movq %rbp, %rdi
movq %r14, %rdx
movq %rax, %rcx
callq 0x53a0
movq 0x8(%r13), %r9
movq 0x10(%r13), %r8
leaq 0x2872(%rip), %rcx      # 0x169f8
leaq 0x100(%rsp), %r14
movl $0x40, %edx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x131fd
movl 0x4c(%rbx), %r13d
movq %rbx, %rdi
callq 0x13176
testl %eax, %eax
leaq 0x1d4e(%rip), %rax      # 0x15f03
leaq 0x1d3c(%rip), %r10      # 0x15ef8
cmoveq %rax, %r10
leaq 0xc0(%rsp), %r11
leaq 0x2831(%rip), %rsi      # 0x16a00
movq %rbx, %rdi
movl %r13d, %edx
movq (%rsp), %rcx
leaq 0x40(%rsp), %r8
movq %rbp, %r9
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %r15
pushq 0x28(%rsp)
pushq 0x48(%rsp)
pushq %r14
callq 0xe8fd
addq $0x30, %rsp
movq 0x10(%rbx), %rdi
leaq 0x1d11(%rip), %rsi      # 0x15f18
callq 0x56b0
testl %eax, %eax
je 0x1421e
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x147b9
movq %r12, %rdi
callq 0x54a0
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq