// File: /workspace/github_c_makefile_star2_O2/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, (%rsp)
movq %rsi, %r14
movq %rdi, %r15
pushq $0x7c
popq %r13
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x32c0
testq %rax, %rax
jne 0x744e
movq %r15, %rdi
pushq $0x2c
popq %rsi
movq %r14, %rdx
callq 0x32c0
testq %rax, %rax
je 0x748b
movq %rax, %r12
movq %rax, %rsi
subq %r15, %rsi
movq %r15, %rdi
movq (%rsp), %rdx
movq %rbx, %rcx
callq 0x740c
testl %eax, %eax
jg 0x7478
incq %r12
addq %r15, %r14
subq %r12, %r14
movq %r12, %r15
jmp 0x7428
movl %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
pushq $-0x1
popq %rbp
cmpq %r13, %r14
je 0x74de
movzbl (%r15,%r13), %eax
cmpl $0x3f, %eax
setne %cl
movq %rbx, %r12
subq %r13, %r12
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x74d9
cmpl $0x2a, %eax
je 0x74e3
cmpl $0x24, %eax
je 0x74fa
leaq (%r15,%r13), %rdi
callq 0x718f
movl %eax, %r12d
movq (%rsp), %rax
leaq (%rax,%r13), %rdi
callq 0x718f
cmpl %eax, %r12d
jne 0x747a
incq %r13
jmp 0x7491
movl %r14d, %ebp
jmp 0x747a
leaq 0x1(%r13), %rax
cmpq %r14, %rax
jae 0x7509
cmpb $0x2a, 0x1(%r15,%r13)
jne 0x7509
leaq 0x2(%r13), %rax
jmp 0x7530
cmpq %r13, %rbx
pushq $-0x1
popq %rbp
cmovel %r13d, %ebp
jmp 0x747a
movq %r13, %rdx
subq %rbx, %rdx
xorl %ecx, %ecx
movq %rdx, %rsi
addq %rcx, %rsi
je 0x7530
movq (%rsp), %rsi
addq %rcx, %rsi
cmpb $0x2f, (%r13,%rsi)
je 0x752d
incq %rcx
jmp 0x7511
movq %rcx, %r12
subq %rax, %r14
jne 0x7540
addl %r13d, %r12d
movl %r12d, %ebp
jmp 0x747a
addq %rax, %r15
subq %r12, %rbx
subq %r13, %rbx
addq %r13, (%rsp)
pushq $-0x1
popq %rbp
movq (%rsp), %rax
leaq (%rax,%r12), %rdx
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x740c
cmpl $-0x1, %eax
jne 0x7577
incq %rbx
addq $-0x1, %r12
jb 0x7550
movq %rbp, %r12
addl %r12d, %r13d
addl %eax, %r13d
cmpl $-0x1, %eax
cmovel %eax, %r13d
movl %r13d, %ebp
jmp 0x747a