// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x7c, %esi
callq 0x32e0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xa577
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x2c, %esi
callq 0x32e0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xa5f7
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0xa510
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jle 0xa5b7
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xa84d
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
addq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0xa510
movl %eax, -0x4(%rbp)
jmp 0xa84d
jmp 0xa5f9
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0xa846
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jne 0xa627
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0xa627
jmp 0xa829
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x24, %eax
jne 0xa669
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0xa64e
movq -0x48(%rbp), %rax
movl %eax, -0x84(%rbp)
jmp 0xa65b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x84(%rbp)
jmp 0xa65b
movl -0x84(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xa84d
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
jne 0xa7ec
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0xa6bf
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
jne 0xa6bf
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xa715
movq $0x0, -0x38(%rbp)
movq -0x48(%rbp), %rcx
addq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x85(%rbp)
je 0xa6f9
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
addq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
setne %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
testb $0x1, %al
jne 0xa705
jmp 0xa713
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa6c7
jmp 0xa715
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jne 0xa72f
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0xa84d
jmp 0xa731
movq -0x18(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
addq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rax
subq -0x48(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
callq 0xa510
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x4c(%rbp)
movb %al, -0x86(%rbp)
jne 0xa7ab
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x38(%rbp)
cmpq $0x0, %rax
seta %al
movb %al, -0x86(%rbp)
movb -0x86(%rbp), %al
testb $0x1, %al
jne 0xa731
cmpl $-0x1, -0x4c(%rbp)
jne 0xa7cc
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x8c(%rbp)
jmp 0xa7e1
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
addq %rcx, %rax
addq -0x38(%rbp), %rax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xa84d
movq -0x18(%rbp), %rdi
addq -0x40(%rbp), %rdi
callq 0xa0a0
movl %eax, -0x90(%rbp)
movq -0x28(%rbp), %rdi
addq -0x48(%rbp), %rdi
callq 0xa0a0
movl %eax, %ecx
movl -0x90(%rbp), %eax
cmpl %ecx, %eax
je 0xa821
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa84d
jmp 0xa823
jmp 0xa825
jmp 0xa827
jmp 0xa829
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xa5f9
movq -0x48(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)