// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_match_prefix_n
int mg_match_prefix_n(const struct mg_str pattern, const struct mg_str str) {
  const char *or_str;
  size_t len, i = 0, j = 0;
  int res;

  if ((or_str = (const char *) memchr(pattern.p, '|', pattern.len)) != NULL ||
      (or_str = (const char *) memchr(pattern.p, ',', pattern.len)) != NULL) {
    struct mg_str pstr = {pattern.p, (size_t)(or_str - pattern.p)};
    res = mg_match_prefix_n(pstr, str);
    if (res > 0) return res;
    pstr.p = or_str + 1;
    pstr.len = (pattern.p + pattern.len) - (or_str + 1);
    return mg_match_prefix_n(pstr, str);
  }

  for (; i < pattern.len; i++, j++) {
    if (pattern.p[i] == '?' && j != str.len) {
      continue;
    } else if (pattern.p[i] == '$') {
      return j == str.len ? (int) j : -1;
    } else if (pattern.p[i] == '*') {
      i++;
      if (i < pattern.len && pattern.p[i] == '*') {
        i++;
        len = str.len - j;
      } else {
        len = 0;
        while (j + len != str.len && str.p[j + len] != '/') {
          len++;
        }
      }
      if (i == pattern.len) {
        return j + len;
      }
      do {
        const struct mg_str pstr = {pattern.p + i, pattern.len - i};
        const struct mg_str sstr = {str.p + j + len, str.len - j - len};
        res = mg_match_prefix_n(pstr, sstr);
      } while (res == -1 && len-- > 0);
      return res == -1 ? -1 : (int) (j + res + len);
    } else if (str_util_lowercase(&pattern.p[i]) !=
               str_util_lowercase(&str.p[j])) {
      return -1;
    }
  }
  return j;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq %r12, %rdi
movl $0x7c, %esi
movq %r14, %rdx
callq 0x32c0
testq %rax, %rax
jne 0x78dc
movq %r12, %rdi
movl $0x2c, %esi
movq %r14, %rdx
callq 0x32c0
testq %rax, %rax
je 0x7909
movq %rax, %rbp
movq %rax, %rsi
subq %r12, %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x789b
testl %eax, %eax
jg 0x797d
incq %rbp
addq %r12, %r14
subq %rbp, %r14
movq %rbp, %r12
jmp 0x78b2
xorl %r13d, %r13d
testq %r14, %r14
je 0x7980
movzbl (%r12,%r13), %ebp
cmpl $0x3f, %ebp
setne %al
movq %rbx, %rsi
subq %r13, %rsi
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x794d
cmpl $0x2a, %ebp
je 0x795a
cmpl $0x24, %ebp
je 0x7971
callq 0x3650
movq (%rax), %rax
movl %ebp, %ecx
movl (%rax,%rcx,4), %ecx
movzbl (%r15,%r13), %edx
cmpl (%rax,%rdx,4), %ecx
jne 0x7992
incq %r13
cmpq %r13, %r14
jne 0x7911
movl %r14d, %r13d
jmp 0x7980
leaq 0x1(%r13), %rax
cmpq %r14, %rax
jae 0x799a
cmpb $0x2a, 0x1(%r12,%r13)
jne 0x799a
leaq 0x2(%r13), %rax
jmp 0x79c3
cmpq %r13, %rbx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %r13d, %eax
movl %eax, %r13d
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x7980
cmpq %r13, %rbx
jne 0x79a3
xorl %esi, %esi
jmp 0x79c3
movq %r13, %rcx
subq %rbx, %rcx
xorl %esi, %esi
leaq (%r15,%rsi), %rdx
cmpb $0x2f, (%r13,%rdx)
je 0x79c3
leaq (%rcx,%rsi), %rdx
incq %rsi
incq %rdx
jne 0x79ab
subq %rax, %r14
jne 0x79d0
addl %r13d, %esi
movl %esi, %r13d
jmp 0x7980
addq %rax, %r12
subq %rsi, %rbx
subq %r13, %rbx
addq %r13, %r15
leaq (%r15,%rsi), %rdx
movq %r12, %rdi
movq %rsi, %rbp
movq %r14, %rsi
movq %rbx, %rcx
callq 0x789b
cmpl $-0x1, %eax
jne 0x7a09
incq %rbx
addq $-0x1, %rbp
movq %rbp, %rsi
jb 0x79dc
movq $-0x1, %rbp
addl %ebp, %r13d
addl %eax, %r13d
cmpl $-0x1, %eax
cmovel %eax, %r13d
jmp 0x7980