// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: send_ssi_file
static void send_ssi_file(struct mg_connection *conn, const char *path,
                          FILE *fp, int include_level) {
  char buf[BUFSIZ];
  int ch, len, in_ssi_tag;

  if (include_level > 10) {
    cry(conn, "SSI #include level is too deep (%s)", path);
    return;
  }

  in_ssi_tag = 0;
  len = 0;

  while ((ch = fgetc(fp)) != EOF) {
    if (in_ssi_tag && ch == '>') {
      in_ssi_tag = 0;
      buf[len++] = (char) ch;
      buf[len] = '\0';
      assert(len <= (int) sizeof(buf));
      if (len < 6 || memcmp(buf, "<!--#", 5) != 0) {
        // Not an SSI tag, pass it
        (void) mg_write(conn, buf, (size_t)len);
      } else {
        if (!memcmp(buf + 5, "include", 7)) {
          do_ssi_include(conn, path, buf + 12, include_level);
#if !defined(NO_POPEN)
        } else if (!memcmp(buf + 5, "exec", 4)) {
          do_ssi_exec(conn, buf + 9);
#endif // !NO_POPEN
        } else {
          cry(conn, "%s: unknown SSI " "command: \"%s\"", path, buf);
        }
      }
      len = 0;
    } else if (in_ssi_tag) {
      if (len == 5 && memcmp(buf, "<!--#", 5) != 0) {
        // Not an SSI tag
        in_ssi_tag = 0;
      } else if (len == (int) sizeof(buf) - 2) {
        cry(conn, "%s: SSI tag is too large", path);
        len = 0;
      }
      buf[len++] = ch & 0xff;
    } else if (ch == '<') {
      in_ssi_tag = 1;
      if (len > 0) {
        (void) mg_write(conn, buf, (size_t)len);
      }
      len = 0;
      buf[len++] = ch & 0xff;
    } else {
      buf[len++] = ch & 0xff;
      if (len == (int) sizeof(buf)) {
        (void) mg_write(conn, buf, (size_t)len);
        len = 0;
      }
    }
  }

  // Send the rest of buffered data
  if (len > 0) {
    (void) mg_write(conn, buf, (size_t)len);
  }
}

// Assembly:
subq $0x2038, %rsp           # imm = 0x2038
movq %rdi, 0x2030(%rsp)
movq %rsi, 0x2028(%rsp)
movq %rdx, 0x2020(%rsp)
movl %ecx, 0x201c(%rsp)
cmpl $0xa, 0x201c(%rsp)
jle 0x20ab3
movq 0x2030(%rsp), %rdi
movq 0x2028(%rsp), %rdx
leaq 0x2d82(%rip), %rsi      # 0x23829
movb $0x0, %al
callq 0x184e0
jmp 0x20d5a
movl $0x0, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x2020(%rsp), %rdi
callq 0x5960
movl %eax, 0xc(%rsp)
cmpl $-0x1, %eax
je 0x20d3c
cmpl $0x0, 0x4(%rsp)
je 0x20c09
cmpl $0x3e, 0xc(%rsp)
jne 0x20c09
movl $0x0, 0x4(%rsp)
movl 0xc(%rsp), %eax
movb %al, %cl
movl 0x8(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x8(%rsp)
cltq
movb %cl, 0x10(%rsp,%rax)
movslq 0x8(%rsp), %rax
movb $0x0, 0x10(%rsp,%rax)
cmpl $0x6, 0x8(%rsp)
jl 0x20b40
leaq 0x10(%rsp), %rdi
leaq 0x2d1c(%rip), %rsi      # 0x2384d
movl $0x5, %edx
callq 0x5250
cmpl $0x0, %eax
je 0x20b5c
movq 0x2030(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movslq 0x8(%rsp), %rdx
callq 0x16ed0
jmp 0x20bfc
leaq 0x10(%rsp), %rdi
addq $0x5, %rdi
leaq 0x2ce7(%rip), %rsi      # 0x23853
movl $0x7, %edx
callq 0x5250
cmpl $0x0, %eax
jne 0x20ba2
movq 0x2030(%rsp), %rdi
movq 0x2028(%rsp), %rsi
leaq 0x10(%rsp), %rdx
addq $0xc, %rdx
movl 0x201c(%rsp), %ecx
callq 0x20d70
jmp 0x20bfa
leaq 0x10(%rsp), %rax
addq $0x5, %rax
movl (%rax), %eax
subl $0x63657865, %eax       # imm = 0x63657865
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x20bd5
movq 0x2030(%rsp), %rdi
leaq 0x10(%rsp), %rsi
addq $0x9, %rsi
callq 0x21060
jmp 0x20bf8
movq 0x2030(%rsp), %rdi
movq 0x2028(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x2c6f(%rip), %rsi      # 0x23860
movb $0x0, %al
callq 0x184e0
jmp 0x20bfa
jmp 0x20bfc
movl $0x0, 0x8(%rsp)
jmp 0x20d37
cmpl $0x0, 0x4(%rsp)
je 0x20c95
cmpl $0x5, 0x8(%rsp)
jne 0x20c40
leaq 0x10(%rsp), %rdi
leaq 0x2c26(%rip), %rsi      # 0x2384d
movl $0x5, %edx
callq 0x5250
cmpl $0x0, %eax
je 0x20c40
movl $0x0, 0x4(%rsp)
jmp 0x20c72
cmpl $0x1ffe, 0x8(%rsp)      # imm = 0x1FFE
jne 0x20c70
movq 0x2030(%rsp), %rdi
movq 0x2028(%rsp), %rdx
leaq 0x2c1d(%rip), %rsi      # 0x2387e
movb $0x0, %al
callq 0x184e0
movl $0x0, 0x8(%rsp)
jmp 0x20c72
movl 0xc(%rsp), %eax
andl $0xff, %eax
movb %al, %cl
movl 0x8(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x8(%rsp)
cltq
movb %cl, 0x10(%rsp,%rax)
jmp 0x20d35
cmpl $0x3c, 0xc(%rsp)
jne 0x20cea
movl $0x1, 0x4(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x20cc2
movq 0x2030(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movslq 0x8(%rsp), %rdx
callq 0x16ed0
movl $0x0, 0x8(%rsp)
movl 0xc(%rsp), %eax
andl $0xff, %eax
movb %al, %cl
movl 0x8(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x8(%rsp)
cltq
movb %cl, 0x10(%rsp,%rax)
jmp 0x20d33
movl 0xc(%rsp), %eax
andl $0xff, %eax
movb %al, %cl
movl 0x8(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x8(%rsp)
cltq
movb %cl, 0x10(%rsp,%rax)
cmpl $0x2000, 0x8(%rsp)      # imm = 0x2000
jne 0x20d31
movq 0x2030(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movslq 0x8(%rsp), %rdx
callq 0x16ed0
movl $0x0, 0x8(%rsp)
jmp 0x20d33
jmp 0x20d35
jmp 0x20d37
jmp 0x20ac3
cmpl $0x0, 0x8(%rsp)
jle 0x20d5a
movq 0x2030(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movslq 0x8(%rsp), %rdx
callq 0x16ed0
addq $0x2038, %rsp           # imm = 0x2038
retq
nopw %cs:(%rax,%rax)