// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_ssi_file
static void mg_send_ssi_file(struct mg_connection *nc, struct http_message *hm,
                             const char *path, FILE *fp, int include_level,
                             const struct mg_serve_http_opts *opts) {
  static const struct mg_str btag = MG_MK_STR("<!--#");
  static const struct mg_str d_include = MG_MK_STR("include");
  static const struct mg_str d_call = MG_MK_STR("call");
#if MG_ENABLE_HTTP_SSI_EXEC
  static const struct mg_str d_exec = MG_MK_STR("exec");
#endif
  char buf[BUFSIZ], *p = buf + btag.len; /* p points to SSI directive */
  int ch, len, in_ssi_tag;

  if (include_level > 10) {
    mg_printf(nc, "SSI #include level is too deep (%s)", path);
    return;
  }

  in_ssi_tag = len = 0;
  while ((ch = fgetc(fp)) != EOF) {
    if (in_ssi_tag && ch == '>' && buf[len - 1] == '-' && buf[len - 2] == '-') {
      size_t i = len - 2;
      in_ssi_tag = 0;

      /* Trim closing --> */
      buf[i--] = '\0';
      while (i > 0 && buf[i] == ' ') {
        buf[i--] = '\0';
      }

      /* Handle known SSI directives */
      if (strncmp(p, d_include.p, d_include.len) == 0) {
        mg_do_ssi_include(nc, hm, path, p + d_include.len + 1, include_level,
                          opts);
      } else if (strncmp(p, d_call.p, d_call.len) == 0) {
        struct mg_ssi_call_ctx cctx;
        memset(&cctx, 0, sizeof(cctx));
        cctx.req = hm;
        cctx.file = mg_mk_str(path);
        cctx.arg = mg_mk_str(p + d_call.len + 1);
        mg_call(nc, NULL, nc->user_data, MG_EV_SSI_CALL,
                (void *) cctx.arg.p); /* NUL added above */
        mg_call(nc, NULL, nc->user_data, MG_EV_SSI_CALL_CTX, &cctx);
#if MG_ENABLE_HTTP_SSI_EXEC
      } else if (strncmp(p, d_exec.p, d_exec.len) == 0) {
        do_ssi_exec(nc, p + d_exec.len + 1);
#endif
      } else {
        /* Silently ignore unknown SSI directive. */
      }
      len = 0;
    } else if (ch == '<') {
      in_ssi_tag = 1;
      if (len > 0) {
        mg_send(nc, buf, (size_t) len);
      }
      len = 0;
      buf[len++] = ch & 0xff;
    } else if (in_ssi_tag) {
      if (len == (int) btag.len && strncmp(buf, btag.p, btag.len) != 0) {
        /* Not an SSI tag */
        in_ssi_tag = 0;
      } else if (len == (int) sizeof(buf) - 2) {
        mg_printf(nc, "%s: SSI tag is too large", path);
        len = 0;
      }
      buf[len++] = ch & 0xff;
    } else {
      buf[len++] = ch & 0xff;
      if (len == (int) sizeof(buf)) {
        mg_send(nc, buf, (size_t) len);
        len = 0;
      }
    }
  }

  /* Send the rest of buffered data */
  if (len > 0) {
    mg_send(nc, buf, (size_t) len);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4028, %rsp           # imm = 0x4028
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
cmpl $0xa, %r8d
jle 0x1246a
leaq 0x3d56(%rip), %rsi      # 0x161a5
movq %rbx, %rdi
xorl %eax, %eax
addq $0x4028, %rsp           # imm = 0x4028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7bce
movq %rcx, %r12
movq %r9, 0x10(%rsp)
movq %rdx, (%rsp)
incl %r8d
movl %r8d, 0xc(%rsp)
pushq $0x1
popq %r14
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x3270
cmpl $-0x1, %eax
je 0x12856
movl %eax, %ebp
testl %r13d, %r13d
sete %al
cmpl $0x3e, %ebp
setne %cl
orb %al, %cl
movslq %r15d, %rax
jne 0x1259e
leaq 0x1020(%rsp), %rcx
cmpb $0x2d, -0x1(%rax,%rcx)
jne 0x125d3
cmpb $0x2d, 0x101e(%rsp,%rax)
jne 0x125d3
addq $-0x2, %rax
movb $0x0, 0x1020(%rsp,%rax)
cmpq $0x1, %rax
je 0x124f3
cmpb $0x20, 0x101f(%rsp,%rax)
leaq -0x1(%rax), %rax
je 0x124d7
leaq 0x1025(%rsp), %r15
movq %r15, %rdi
leaq 0x3c98(%rip), %rsi      # 0x1619d
pushq $0x7
popq %rdx
callq 0x3470
testl %eax, %eax
je 0x12672
cmpl $0x6c6c6163, (%r15)     # imm = 0x6C6C6163
movl $0x0, %r13d
movl $0x0, %r15d
jne 0x12488
leaq 0x28(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
movq (%rsp), %rdi
callq 0x6875
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
leaq 0x102a(%rsp), %rdi
callq 0x6875
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
pushq $0x69
popq %rdx
movq %rax, %rcx
callq 0x75bd
movq %rbx, %rdi
xorl %esi, %esi
pushq $0x6a
popq %rdx
leaq 0x20(%rsp), %rcx
callq 0x75bd
xorl %r15d, %r15d
jmp 0x12488
cmpl $0x3c, %ebp
jne 0x125ce
testl %r15d, %r15d
jle 0x125bb
movq %rbx, %rdi
leaq 0x1020(%rsp), %rsi
movl %r15d, %edx
callq 0x7b89
movb $0x3c, 0x1020(%rsp)
movl %r14d, %r13d
movl %r14d, %r15d
jmp 0x12488
testl %r13d, %r13d
je 0x12639
cmpl $0x1ffe, %r15d          # imm = 0x1FFE
je 0x1260b
movl %r14d, %r13d
cmpl $0x5, %r15d
jne 0x12626
leaq 0x1020(%rsp), %rdi
leaq 0x3ba3(%rip), %rsi      # 0x16197
pushq $0x5
popq %rdx
callq 0x3470
xorl %r13d, %r13d
testl %eax, %eax
sete %r13b
pushq $0x5
popq %r15
jmp 0x12626
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x3bb1(%rip), %rsi      # 0x161c9
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x7bce
movl %r14d, %r13d
movslq %r15d, %rax
incl %r15d
movb %bpl, 0x1020(%rsp,%rax)
jmp 0x12488
leal 0x1(%rax), %r15d
movb %bpl, 0x1020(%rsp,%rax)
movl $0x0, %r13d
cmpl $0x2000, %r15d          # imm = 0x2000
jne 0x12488
movq %rbx, %rdi
leaq 0x1020(%rsp), %rsi
movl $0x2000, %edx           # imm = 0x2000
callq 0x7b89
jmp 0x12482
leaq 0x102d(%rsp), %r15
movq %r15, %rdi
leaq 0x3b5e(%rip), %rsi      # 0x161e2
leaq 0x20(%rsp), %rbp
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
jne 0x126c9
movq 0x10(%rsp), %rax
movq %rax, %r14
movq (%rax), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x3020(%rsp), %r13
movq %r13, %rdi
leaq 0x3178(%rip), %rdx      # 0x15832
movq %rbp, %r8
xorl %eax, %eax
callq 0x31e0
jmp 0x12794
movq %r15, %rdi
leaq 0x3b20(%rip), %rsi      # 0x161f3
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
movq 0x10(%rsp), %r14
jne 0x126fc
movl $0x1000, %esi           # imm = 0x1000
leaq 0x3020(%rsp), %r13
movq %r13, %rdi
jmp 0x12783
movq %r15, %rdi
leaq 0x3afe(%rip), %rsi      # 0x16204
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
je 0x12732
movq %r15, %rdi
leaq 0x3af3(%rip), %rsi      # 0x16212
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
jne 0x12839
movl $0x1000, %esi           # imm = 0x1000
leaq 0x3020(%rsp), %r13
movq %r13, %rdi
leaq 0x28ad(%rip), %rdx      # 0x14ff6
movq (%rsp), %rcx
xorl %eax, %eax
callq 0x31e0
movq %r13, %rdi
pushq $0x2f
popq %rsi
callq 0x31f0
testq %rax, %rax
je 0x12768
movb $0x0, 0x1(%rax)
movq %r13, %rdi
callq 0x3180
leaq (%rsp,%rax), %rdi
addq $0x3020, %rdi           # imm = 0x3020
movl $0x1000, %esi           # imm = 0x1000
subq %rax, %rsi
leaq 0x286c(%rip), %rdx      # 0x14ff6
movq %rbp, %rcx
xorl %eax, %eax
callq 0x31e0
movq %r13, %rdi
leaq 0x24b3(%rip), %rsi      # 0x14c51
callq 0x3370
testq %rax, %rax
je 0x127f4
movq %rax, %r15
movq %rax, %rdi
callq 0x33c0
movl %eax, %edi
callq 0x9abd
movq 0x30(%r14), %rbp
movq %rbp, %rdi
callq 0x3180
movq %rbp, %rdi
movl %eax, %esi
movq %r13, %rdx
callq 0x42d8
movq %rbx, %rdi
testl %eax, %eax
jle 0x12820
movq 0x18(%rsp), %rsi
movq %r13, %rdx
movq %r15, %rcx
movl 0xc(%rsp), %r8d
movq %r14, %r9
callq 0x12429
jmp 0x12828
callq 0x9306
movl %eax, %edi
callq 0x3600
movq %rbx, %rdi
leaq 0x3a28(%rip), %rsi      # 0x16232
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x7bce
pushq $0x1
popq %r14
jmp 0x12482
movq %r15, %rsi
callq 0x12880
pushq $0x1
popq %r14
movq %r15, %rdi
callq 0x3160
jmp 0x12482
movq %rbx, %rdi
leaq 0x39d8(%rip), %rsi      # 0x1621b
movq %r15, %rdx
xorl %eax, %eax
callq 0x7bce
pushq $0x1
popq %r14
jmp 0x12482
testl %r15d, %r15d
jle 0x1286e
leaq 0x1020(%rsp), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x7b89
addq $0x4028, %rsp           # imm = 0x4028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq