// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x7c, %esi
callq 0xd5c0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0xb1189
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movq -0x20(%rbp), %rdx
callq 0xb10f0
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0xb1157
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xb117e
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
movq -0x10(%rbp), %rsi
addq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
addq $0x1, %rax
subq %rax, %rsi
movq -0x20(%rbp), %rdx
callq 0xb10f0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb1354
jmp 0xb118b
movslq -0x34(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0xb134e
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jne 0xb11c0
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xb11c0
jmp 0xb1337
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x24, %eax
jne 0xb11ff
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xb11ea
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xb11f4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x40(%rbp)
jmp 0xb11f4
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb1354
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
jne 0xb12fa
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2a, %eax
jne 0xb124c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
callq 0xd550
movl %eax, -0x2c(%rbp)
jmp 0xb1266
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
leaq 0x16c4e(%rip), %rsi     # 0xc7eac
callq 0xd9c0
movl %eax, -0x2c(%rbp)
movslq -0x34(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0xb127e
movl -0x38(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb1354
jmp 0xb1280
movq -0x10(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x34(%rbp), %rax
subq %rax, %rsi
movq -0x20(%rbp), %rdx
movslq -0x38(%rbp), %rax
addq %rax, %rdx
movslq -0x2c(%rbp), %rax
addq %rax, %rdx
callq 0xb10f0
movl %eax, -0x30(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x30(%rbp)
movb %al, -0x41(%rbp)
jne 0xb12cf
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x2c(%rbp)
cmpl $0x0, %eax
setg %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0xb1280
cmpl $-0x1, -0x30(%rbp)
jne 0xb12e6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x48(%rbp)
jmp 0xb12f2
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb1354
movq -0x10(%rbp), %rdi
movslq -0x34(%rbp), %rax
addq %rax, %rdi
callq 0xb1360
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
callq 0xb1360
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
je 0xb132f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb1354
jmp 0xb1331
jmp 0xb1333
jmp 0xb1335
jmp 0xb1337
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb118b
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)