// File: /workspace/github_c_makefile_star2_O2/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_strmatch_fuzzy_text
NK_API int
nk_strmatch_fuzzy_text(const char *str, int str_len,
    const char *pattern, int *out_score)
{
    /* Returns true if each character in pattern is found sequentially within str
     * if found then out_score is also set. Score value has no intrinsic meaning.
     * Range varies with pattern. Can only compare scores with same search pattern. */

    /* bonus for adjacent matches */
    #define NK_ADJACENCY_BONUS 5
    /* bonus if match occurs after a separator */
    #define NK_SEPARATOR_BONUS 10
    /* bonus if match is uppercase and prev is lower */
    #define NK_CAMEL_BONUS 10
    /* penalty applied for every letter in str before the first match */
    #define NK_LEADING_LETTER_PENALTY (-3)
    /* maximum penalty for leading letters */
    #define NK_MAX_LEADING_LETTER_PENALTY (-9)
    /* penalty for every letter that doesn't matter */
    #define NK_UNMATCHED_LETTER_PENALTY (-1)

    /* loop variables */
    int score = 0;
    char const * pattern_iter = pattern;
    int str_iter = 0;
    int prev_matched = nk_false;
    int prev_lower = nk_false;
    /* true so if first letter match gets separator bonus*/
    int prev_separator = nk_true;

    /* use "best" matched letter if multiple string letters match the pattern */
    char const * best_letter = 0;
    int best_letter_score = 0;

    /* loop over strings */
    NK_ASSERT(str);
    NK_ASSERT(pattern);
    if (!str || !str_len || !pattern) return 0;
    while (str_iter < str_len)
    {
        const char pattern_letter = *pattern_iter;
        const char str_letter = str[str_iter];

        int next_match = *pattern_iter != '\0' &&
            nk_to_lower(pattern_letter) == nk_to_lower(str_letter);
        int rematch = best_letter && nk_to_upper(*best_letter) == nk_to_upper(str_letter);

        int advanced = next_match && best_letter;
        int pattern_repeat = best_letter && *pattern_iter != '\0';
        pattern_repeat = pattern_repeat &&
            nk_to_lower(*best_letter) == nk_to_lower(pattern_letter);

        if (advanced || pattern_repeat) {
            score += best_letter_score;
            best_letter = 0;
            best_letter_score = 0;
        }

        if (next_match || rematch)
        {
            int new_score = 0;
            /* Apply penalty for each letter before the first pattern match */
            if (pattern_iter == pattern) {
                int count = (int)(&str[str_iter] - str);
                int penalty = NK_LEADING_LETTER_PENALTY * count;
                if (penalty < NK_MAX_LEADING_LETTER_PENALTY)
                    penalty = NK_MAX_LEADING_LETTER_PENALTY;

                score += penalty;
            }

            /* apply bonus for consecutive bonuses */
            if (prev_matched)
                new_score += NK_ADJACENCY_BONUS;

            /* apply bonus for matches after a separator */
            if (prev_separator)
                new_score += NK_SEPARATOR_BONUS;

            /* apply bonus across camel case boundaries */
            if (prev_lower && nk_is_upper(str_letter))
                new_score += NK_CAMEL_BONUS;

            /* update pattern iter IFF the next pattern letter was matched */
            if (next_match)
                ++pattern_iter;

            /* update best letter in str which may be for a "next" letter or a rematch */
            if (new_score >= best_letter_score) {
                /* apply penalty for now skipped letter */
                if (best_letter != 0)
                    score += NK_UNMATCHED_LETTER_PENALTY;

                best_letter = &str[str_iter];
                best_letter_score = new_score;
            }
            prev_matched = nk_true;
        } else {
            score += NK_UNMATCHED_LETTER_PENALTY;
            prev_matched = nk_false;
        }

        /* separators should be more easily defined */
        prev_lower = nk_is_lower(str_letter) != 0;
        prev_separator = str_letter == '_' || str_letter == ' ';

        ++str_iter;
    }

    /* apply score for last match */
    if (best_letter)
        score += best_letter_score;

    /* did not match full pattern */
    if (*pattern_iter != '\0')
        return nk_false;

    if (out_score)
        *out_score = score;
    return nk_true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r13
movl %esi, %r12d
movq %rdi, %r15
testq %rdi, %rdi
jne 0x229fa
movq 0x6261b(%rip), %rbx     # 0x84ff0
movq (%rbx), %rdi
leaq 0x4732d(%rip), %rsi     # 0x69d0c
leaq 0x47344(%rip), %rdx     # 0x69d2a
movl $0x1ace, %ecx           # imm = 0x1ACE
xorl %eax, %eax
callq 0x12ea0
movq (%rbx), %rdi
callq 0x13960
testq %r13, %r13
je 0x22c01
movq %r14, 0x10(%rsp)
testq %r15, %r15
sete %al
testl %r12d, %r12d
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x22c53
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
leaq (%r12,%r12,2), %rcx
movq %rcx, 0x20(%rsp)
pushq $0x1
popq %rdx
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %r13, 0x18(%rsp)
movq %r13, %r8
xorl %r13d, %r13d
movq 0x20(%rsp), %rsi
addq %rax, %rsi
je 0x22c31
movsbl (%r8), %ebx
xorl %r14d, %r14d
movsbl (%r15), %r11d
testl %ebx, %ebx
je 0x22a8d
leal -0x41(%rbx), %esi
movl $0xffffff5e, %ecx       # imm = 0xFFFFFF5E
leal (%rbx,%rcx), %edi
cmpl $0x1a, %esi
cmovael %ebx, %edi
leal -0x41(%r11), %esi
addl %r11d, %ecx
cmpl $0x1a, %esi
cmovael %r11d, %ecx
cmpl %ecx, %edi
sete %sil
jmp 0x22a8f
xorl %esi, %esi
testq %r9, %r9
je 0x22b23
movq %rax, 0x8(%rsp)
movq %r15, %rax
movl %r13d, 0x4(%rsp)
movq %r8, %r13
movl %ebp, %r8d
movsbl (%r9), %edi
leal -0x61(%rdi), %ecx
leal -0x20(%rdi), %r14d
cmpl $0x1a, %ecx
cmovael %edi, %r14d
leal -0x61(%r11), %ecx
leal -0x20(%r11), %ebp
cmpl $0x1a, %ecx
cmovael %r11d, %ebp
cmpl %ebp, %r14d
sete %r14b
testb %bl, %bl
je 0x22bf1
leal -0x41(%rdi), %ecx
movl $0xffffff5e, %r15d      # imm = 0xFFFFFF5E
leal (%rdi,%r15), %ebp
cmpl $0x1a, %ecx
cmovael %edi, %ebp
leal -0x41(%rbx), %ecx
leal (%rbx,%r15), %edi
cmpl $0x1a, %ecx
cmovael %ebx, %edi
cmpl %edi, %ebp
sete %dil
orb %sil, %dil
je 0x22b0c
movl $0x0, %r9d
testb %dil, %dil
movl %r8d, %ebp
je 0x22b2e
xorl %ebx, %ebx
testb %dil, %dil
movq %r13, %r8
movq %rax, %r15
je 0x22b3f
jmp 0x22b42
movl %r10d, %ebx
xorl %r9d, %r9d
xorl %r10d, %r10d
jmp 0x22b4c
movl %r10d, %ebx
testb %dil, %dil
movq %r13, %r8
movq %rax, %r15
jne 0x22b42
movl %r10d, %ebx
xorl %r10d, %r10d
movl 0x4(%rsp), %r13d
movq 0x8(%rsp), %rax
addl %r13d, %r10d
orb %sil, %r14b
testb $0x1, %r14b
je 0x22bb7
cmpq 0x18(%rsp), %r8
jne 0x22b6b
cmpl $-0x8, %eax
pushq $-0x9
popq %rcx
cmovgel %eax, %ecx
addl %ecx, %r10d
xorl %ecx, %ecx
testl %ebp, %ebp
setne %cl
leal (%rcx,%rcx,4), %edi
testl %edx, %edx
leal 0xa(%rcx,%rcx,4), %ecx
cmovel %edi, %ecx
leal -0x5b(%r11), %edx
leal 0xa(%rcx), %edi
cmpl $-0x1a, %edx
cmovbl %ecx, %edi
testl %r12d, %r12d
cmovel %ecx, %edi
movzbl %sil, %ecx
addq %rcx, %r8
testq %r9, %r9
setne %cl
cmpl %ebx, %edi
setge %dl
cmovgeq %r15, %r9
cmovgl %edi, %ebx
andb %cl, %dl
movzbl %dl, %ecx
subl %ecx, %r10d
pushq $0x1
popq %rbp
jmp 0x22bbc
decl %r10d
xorl %ebp, %ebp
movl %r10d, %r13d
movl %r11d, %ecx
addl $-0x61, %ecx
xorl %r12d, %r12d
cmpl $0x1a, %ecx
setb %r12b
cmpb $0x5f, %r11b
sete %cl
cmpb $0x20, %r11b
sete %dl
orb %cl, %dl
movzbl %dl, %edx
addq $-0x3, %rax
incq %r15
movl %ebx, %r10d
jmp 0x22a49
movl %esi, %edi
testb %sil, %sil
jne 0x22b06
jmp 0x22b0c
movq 0x623e8(%rip), %rbx     # 0x84ff0
movq (%rbx), %rdi
leaq 0x470fa(%rip), %rsi     # 0x69d0c
leaq 0x47111(%rip), %rdx     # 0x69d2a
xorl %ebp, %ebp
movl $0x1acf, %ecx           # imm = 0x1ACF
xorl %eax, %eax
callq 0x12ea0
movq (%rbx), %rdi
callq 0x13960
jmp 0x22c53
xorl %ebp, %ebp
testq %r9, %r9
cmovel %ebp, %r10d
cmpb $0x0, (%r8)
jne 0x22c53
pushq $0x1
popq %rbp
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x22c53
addl %r10d, %r13d
movl %r13d, (%rax)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq