// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %rbx
xorl %edi, %edi
callq 0x5430
movq %rax, 0x38(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x458(%rbx), %rax
movq 0x90(%rax), %r12
movq %r14, %rdi
callq 0x5210
movq %rax, %r13
movq %r14, (%rsp)
leaq (%r14,%rax), %rbx
leaq 0x40(%rsp), %rbp
leaq 0x80(%rsp), %r14
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x11d0e
testq %rax, %rax
je 0x13dab
movq %rax, %r12
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %rbx, %rdi
subq %rdx, %rdi
callq 0xea9f
testl %eax, %eax
jne 0x13d62
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x88(%rsp), %r14
jmp 0x13e2d
leaq 0x7afe(%rip), %r14      # 0x1b8b0
leaq 0x2cdc(%rip), %rbx      # 0x16a95
xorl %r12d, %r12d
leaq 0x2cc7(%rip), %rax      # 0x16a8a
movq %rax, 0x10(%rsp)
movq %r14, %rbp
movq %r13, %r15
subq 0x8(%rbp), %r15
jbe 0x13e00
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 0x13dfc
incq %rcx
cmpl %esi, %edx
je 0x13de2
cmpl %esi, %edx
je 0x13e20
incq %r12
movq %r12, %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rbp
movq (%rax,%r14), %rbx
cmpq $0x26, %r12
jne 0x13dcb
movl $0xa, %r14d
jmp 0x13e2d
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 0x2711(%rip), %rsi      # 0x16562
movq (%rsp), %rbp
movq %rbp, %rdi
callq 0x55c0
testq %rax, %rax
je 0x13f06
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 0x23cf(%rip), %rsi      # 0x1626f
callq 0xe5cf
testq %rax, %rax
movq %r14, 0x28(%rsp)
je 0x13efd
leaq 0x23bf(%rip), %rsi      # 0x16275
leaq 0x8(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %rax, %rdi
xorl %eax, %eax
callq 0x5490
testl %eax, %eax
jle 0x13efd
movl %eax, %ebp
movl $0xce, 0x4c(%rbx)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x52a0
cmpl $0x2, %ebp
jne 0x13f3a
movq 0x20(%rsp), %r15
movq 0x8(%rsp), %r8
subq %r8, %r15
incq %r15
jmp 0x13f42
leaq 0x15c0(%rip), %rax      # 0x154c4
jmp 0x13f7a
callq 0x5060
movl (%rax), %edi
callq 0x51a0
leaq 0x2176(%rip), %rdx      # 0x1608f
leaq 0x29cb(%rip), %rcx      # 0x168eb
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %rbp, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x12224
jmp 0x14077
movq 0x8(%rsp), %r8
subq %r8, %r15
leaq (%r15,%r8), %r9
decq %r9
subq $0x8, %rsp
leaq 0x2a6e(%rip), %rcx      # 0x169c2
leaq 0xc8(%rsp), %rsi
movl $0x40, %edx
movq %rbx, %rdi
xorl %eax, %eax
pushq 0x8(%r13)
callq 0x12579
addq $0x10, %rsp
leaq 0x2a6b(%rip), %rax      # 0x169e5
movq %rax, (%rsp)
leaq 0x38(%rsp), %rdi
callq 0x5340
leaq 0x2a1a(%rip), %r14      # 0x169a9
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 0x2a1e(%rip), %rcx      # 0x169f5
leaq 0x100(%rsp), %r14
movl $0x40, %edx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x12579
movl 0x4c(%rbx), %r13d
movq %rbx, %rdi
callq 0x124f2
testl %eax, %eax
leaq 0x1efd(%rip), %rax      # 0x15f03
leaq 0x1eeb(%rip), %r10      # 0x15ef8
cmoveq %rax, %r10
leaq 0xc0(%rsp), %r11
leaq 0x29dd(%rip), %rsi      # 0x169fd
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 0xe860
addq $0x30, %rsp
movq 0x10(%rbx), %rdi
leaq 0x1ec0(%rip), %rsi      # 0x15f18
callq 0x56b0
testl %eax, %eax
je 0x1406f
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x145dd
movq %r12, %rdi
callq 0x54a0
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq