// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: do_ssi_include
static void do_ssi_include(struct mg_connection *conn, const char *ssi,
                           char *tag, int include_level) {
  char file_name[BUFSIZ], path[PATH_MAX], *p;
  struct vec root;
  int is_ssi;
  FILE *fp;

  get_document_root(conn, &root);

  // sscanf() is safe here, since send_ssi_file() also uses buffer
  // of size BUFSIZ to get the tag. So strlen(tag) is always < BUFSIZ.
  if (sscanf(tag, " virtual=\"%[^\"]\"", file_name) == 1) {
    // File name is relative to the webserver root
    (void) mg_snprintf(conn, path, sizeof(path), "%.*s%c%s",
        root.len, root.ptr, DIRSEP, file_name);
  } else if (sscanf(tag, " file=\"%[^\"]\"", file_name) == 1) {
    // File name is relative to the webserver working directory
    // or it is absolute system path
    (void) mg_snprintf(conn, path, sizeof(path), "%s", file_name);
  } else if (sscanf(tag, " \"%[^\"]\"", file_name) == 1) {
    // File name is relative to the currect document
    (void) mg_snprintf(conn, path, sizeof(path), "%s", ssi);
    if ((p = strrchr(path, DIRSEP)) != NULL) {
      p[1] = '\0';
    }
    (void) mg_snprintf(conn, path + strlen(path),
        sizeof(path) - strlen(path), "%s", file_name);
  } else {
    cry(conn, "Bad SSI #include: [%s]", tag);
    return;
  }

  if ((fp = mg_fopen(path, "rb")) == NULL) {
    cry(conn, "Cannot open SSI #include: [%s]: fopen(%s): %s",
        tag, path, strerror(ERRNO));
  } else {
    set_close_on_exec(fileno(fp));
    is_ssi = match_extension(path, conn->ctx->config[SSI_EXTENSIONS]);
    if (is_ssi) {
      send_ssi_file(conn, path, fp, include_level + 1);
    } else {
      send_file_data(conn, fp, INT64_MAX);
    }
    (void) fclose(fp);
  }
}

// Assembly:
subq $0x3098, %rsp           # imm = 0x3098
movq %rdi, 0x3090(%rsp)
movq %rsi, 0x3088(%rsp)
movq %rdx, 0x3080(%rsp)
movl %ecx, 0x307c(%rsp)
movq 0x3090(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1efc0
movq 0x3080(%rsp), %rdi
leaq 0x1070(%rsp), %rdx
leaq 0x2ad8(%rip), %rsi      # 0x23897
movb $0x0, %al
callq 0x5540
cmpl $0x1, %eax
jne 0x20e0e
movq 0x3090(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %r9
leaq 0x1070(%rsp), %rax
movl $0x1000, %edx           # imm = 0x1000
leaq 0x23a9(%rip), %rcx      # 0x2319f
movl $0x2f, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x1cc90
jmp 0x20f5c
movq 0x3080(%rsp), %rdi
leaq 0x1070(%rsp), %rdx
leaq 0x2a83(%rip), %rsi      # 0x238a8
movb $0x0, %al
callq 0x5540
cmpl $0x1, %eax
jne 0x20e5e
movq 0x3090(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x1070(%rsp), %r8
movl $0x1000, %edx           # imm = 0x1000
leaq 0x2926(%rip), %rcx      # 0x23778
movb $0x0, %al
callq 0x1cc90
jmp 0x20f5a
movq 0x3080(%rsp), %rdi
leaq 0x1070(%rsp), %rdx
leaq 0x2a41(%rip), %rsi      # 0x238b6
movb $0x0, %al
callq 0x5540
cmpl $0x1, %eax
jne 0x20f35
movq 0x3090(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq 0x3088(%rsp), %r8
movl $0x1000, %edx           # imm = 0x1000
leaq 0x28d2(%rip), %rcx      # 0x23778
movb $0x0, %al
callq 0x1cc90
leaq 0x70(%rsp), %rdi
movl $0x2f, %esi
callq 0x5630
movq %rax, 0x68(%rsp)
cmpq $0x0, %rax
je 0x20ed0
movq 0x68(%rsp), %rax
movb $0x0, 0x1(%rax)
movq 0x3090(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x5230
movq %rax, %rcx
movq 0x30(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x40(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x5230
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
subq %rax, %rdx
leaq 0x1070(%rsp), %r8
leaq 0x284c(%rip), %rcx      # 0x23778
movb $0x0, %al
callq 0x1cc90
jmp 0x20f58
movq 0x3090(%rsp), %rdi
movq 0x3080(%rsp), %rdx
leaq 0x2973(%rip), %rsi      # 0x238bf
movb $0x0, %al
callq 0x184e0
jmp 0x2104f
jmp 0x20f5a
jmp 0x20f5c
leaq 0x70(%rsp), %rdi
leaq 0x2605(%rip), %rsi      # 0x2356d
callq 0x56b0
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
jne 0x20fcd
movq 0x3090(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x3080(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq %rax, %r8
leaq 0x2915(%rip), %rsi      # 0x238d6
movb $0x0, %al
callq 0x184e0
jmp 0x2104f
movq 0x48(%rsp), %rdi
callq 0x55c0
movl %eax, %edi
callq 0x1ae20
leaq 0x70(%rsp), %rdi
movq 0x3090(%rsp), %rax
movq 0x458(%rax), %rax
movq 0x40(%rax), %rsi
callq 0x1e3c0
movl %eax, 0x54(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x21029
movq 0x3090(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq 0x48(%rsp), %rdx
movl 0x307c(%rsp), %ecx
addl $0x1, %ecx
callq 0x20a60
jmp 0x21045
movq 0x3090(%rsp), %rdi
movq 0x48(%rsp), %rsi
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
callq 0x207c0
movq 0x48(%rsp), %rdi
callq 0x5560
addq $0x3098, %rsp           # imm = 0x3098
retq
nopw (%rax,%rax)