// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: mg_match_prefix
int mg_match_prefix(const char *pattern, ssize_t pattern_len, const char *str) {
  const char *or_str;
  int len, res, i = 0, j = 0;

  if ((or_str = (const char *) memchr(pattern, '|', pattern_len)) != NULL) {
    res = mg_match_prefix(pattern, or_str - pattern, str);
    return res > 0 ? res : mg_match_prefix(or_str + 1,
      (pattern + pattern_len) - (or_str + 1), str);
  }

  for (; i < pattern_len; i++, j++) {
    if (pattern[i] == '?' && str[j] != '\0') {
      continue;
    } else if (pattern[i] == '$') {
      return str[j] == '\0' ? j : -1;
    } else if (pattern[i] == '*') {
      i++;
      if (pattern[i] == '*') {
        i++;
        len = (int) strlen(str + j);
      } else {
        len = (int) strcspn(str + j, "/");
      }
      if (i == pattern_len) {
        return j + len;
      }
      do {
        res = mg_match_prefix(pattern + i, pattern_len - i, str + j + len);
      } while (res == -1 && len-- > 0);
      return res == -1 ? -1 : j + res + len;
    } else if (lowercase(&pattern[i]) != lowercase(&str[j])) {
      return -1;
    }
  }
  return j;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
movl $0x7c, %esi
movq %rbx, %rdx
callq 0xc4d0
testq %rax, %rax
je 0x67d5a
movq %rax, %r13
movq %r13, %rsi
subq %r12, %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x67cec
testl %eax, %eax
jg 0x67db4
movq %r13, %r15
incq %r15
addq %r12, %rbx
subq %r15, %rbx
movq %r15, %rdi
movl $0x7c, %esi
movq %rbx, %rdx
callq 0xc4d0
movq %rax, %r13
movq %r15, %r12
testq %rax, %rax
jne 0x67d18
jmp 0x67d5d
movq %r12, %r15
testq %rbx, %rbx
jle 0x67dbb
xorl %r12d, %r12d
movq %r14, -0x30(%rbp)
movzbl (%r15,%r12), %r13d
cmpl $0x3f, %r13d
je 0x67d87
cmpl $0x24, %r13d
je 0x67ded
cmpl $0x2a, %r13d
je 0x67dcc
movzbl (%r14,%r12), %r14d
jmp 0x67d91
cmpb $0x0, (%r14,%r12)
jne 0x67da7
xorl %r14d, %r14d
callq 0xc4a0
movq (%rax), %rax
movl (%rax,%r13,4), %ecx
cmpl (%rax,%r14,4), %ecx
movq -0x30(%rbp), %r14
jne 0x67dc2
incq %r12
cmpq %r12, %rbx
jne 0x67d69
jmp 0x67e70
movl %eax, %ebx
jmp 0x67e70
xorl %ebx, %ebx
jmp 0x67e70
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x67e70
leaq 0x1(%r12), %r13
movl %r13d, %eax
cmpb $0x2a, (%r15,%rax)
jne 0x67dfd
movl %r12d, %edi
leal 0x2(%r12), %r13d
addq %r14, %rdi
callq 0xc460
jmp 0x67e0f
movl %r12d, %eax
xorl %ebx, %ebx
cmpb (%r14,%rax), %bl
sbbl %ebx, %ebx
orl %r12d, %ebx
jmp 0x67e70
movl %r12d, %edi
addq %r14, %rdi
leaq 0x117a2(%rip), %rsi     # 0x795ac
callq 0xc870
movslq %r13d, %rcx
subq %rcx, %rbx
jne 0x67e1e
addl %r12d, %eax
movl %eax, %ebx
jmp 0x67e70
addq %rcx, %r15
movslq %eax, %r13
movl %r13d, %eax
sarl $0x1f, %eax
andl %r13d, %eax
decl %eax
movl %eax, -0x30(%rbp)
movl %r12d, %eax
addq %rax, %r14
leaq (%r14,%r13), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x67cec
cmpl $-0x1, %eax
jne 0x67e5d
leaq -0x1(%r13), %rcx
testq %r13, %r13
movq %rcx, %r13
jg 0x67e38
movl -0x30(%rbp), %ecx
jmp 0x67e60
movl %r13d, %ecx
addl %ecx, %r12d
addl %eax, %r12d
cmpl $-0x1, %eax
cmovel %eax, %r12d
movl %r12d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq