// File: /workspace/github_c_makefile_star2_O3/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 0x7804
movq %r12, %rdi
movl $0x2c, %esi
movq %r14, %rdx
callq 0x32c0
testq %rax, %rax
je 0x7831
movq %rax, %rbp
movq %rax, %rsi
subq %r12, %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x77c3
testl %eax, %eax
jg 0x78a5
incq %rbp
addq %r12, %r14
subq %rbp, %r14
movq %rbp, %r12
jmp 0x77da
xorl %r13d, %r13d
testq %r14, %r14
je 0x78a8
movzbl (%r12,%r13), %ebp
cmpl $0x3f, %ebp
setne %al
movq %rbx, %rsi
subq %r13, %rsi
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x7875
cmpl $0x2a, %ebp
je 0x7882
cmpl $0x24, %ebp
je 0x7899
callq 0x3650
movq (%rax), %rax
movl %ebp, %ecx
movl (%rax,%rcx,4), %ecx
movzbl (%r15,%r13), %edx
cmpl (%rax,%rdx,4), %ecx
jne 0x78ba
incq %r13
cmpq %r13, %r14
jne 0x7839
movl %r14d, %r13d
jmp 0x78a8
leaq 0x1(%r13), %rax
cmpq %r14, %rax
jae 0x78c2
cmpb $0x2a, 0x1(%r12,%r13)
jne 0x78c2
leaq 0x2(%r13), %rax
jmp 0x78eb
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 0x78a8
cmpq %r13, %rbx
jne 0x78cb
xorl %esi, %esi
jmp 0x78eb
movq %r13, %rcx
subq %rbx, %rcx
xorl %esi, %esi
leaq (%r15,%rsi), %rdx
cmpb $0x2f, (%r13,%rdx)
je 0x78eb
leaq (%rcx,%rsi), %rdx
incq %rsi
incq %rdx
jne 0x78d3
subq %rax, %r14
jne 0x78f8
addl %r13d, %esi
movl %esi, %r13d
jmp 0x78a8
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 0x77c3
cmpl $-0x1, %eax
jne 0x7931
incq %rbx
addq $-0x1, %rbp
movq %rbp, %rsi
jb 0x7904
movq $-0x1, %rbp
addl %ebp, %r13d
addl %eax, %r13d
cmpl $-0x1, %eax
cmovel %eax, %r13d
jmp 0x78a8