// File: /workspace/github_c_makefile_star2_O3/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 0x23b16
movq 0x634ff(%rip), %rbx     # 0x86ff0
movq (%rbx), %rdi
leaq 0x4d2a1(%rip), %rsi     # 0x70d9c
leaq 0x4d2b8(%rip), %rdx     # 0x70dba
movl $0x1ace, %ecx           # imm = 0x1ACE
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
testq %r13, %r13
je 0x23d20
testq %r15, %r15
sete %al
testl %r12d, %r12d
sete %cl
xorl %ebp, %ebp
orb %al, %cl
jne 0x23d7d
xorl %ebp, %ebp
testl %r12d, %r12d
jle 0x23d65
movq %r14, 0x10(%rsp)
movl %r12d, %eax
leaq (%rax,%rax,2), %rax
movq %rax, 0x20(%rsp)
movq %r13, %rax
movl $0x1, %r13d
xorl %edx, %edx
xorl %r9d, %r9d
movq %rax, 0x18(%rsp)
xorl %r11d, %r11d
xorl %r12d, %r12d
xorl %r8d, %r8d
xorl %edi, %edi
movsbl (%rax), %r14d
xorl %ebp, %ebp
movsbl (%r15), %r10d
testl %r14d, %r14d
je 0x23ba7
leal -0x41(%r14), %ecx
movl $0xffffff5e, %esi       # imm = 0xFFFFFF5E
leal (%r14,%rsi), %ebx
cmpl $0x1a, %ecx
cmovael %r14d, %ebx
leal -0x41(%r10), %ecx
addl %r10d, %esi
cmpl $0x1a, %ecx
cmovael %r10d, %esi
cmpl %esi, %ebx
sete %bl
jmp 0x23ba9
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x23c33
movl %r13d, 0x8(%rsp)
movl %r11d, 0xc(%rsp)
movsbl (%rdi), %ecx
leal -0x61(%rcx), %esi
leal -0x20(%rcx), %ebp
cmpl $0x1a, %esi
cmovael %ecx, %ebp
leal -0x61(%r10), %esi
leal -0x20(%r10), %r11d
cmpl $0x1a, %esi
cmovael %r10d, %r11d
cmpl %r11d, %ebp
sete %bpl
testb %r14b, %r14b
je 0x23d11
leal -0x41(%rcx), %esi
movl $0xffffff5e, %r13d      # imm = 0xFFFFFF5E
leal (%rcx,%r13), %r11d
cmpl $0x1a, %esi
cmovael %ecx, %r11d
leal -0x41(%r14), %ecx
leal (%r14,%r13), %esi
cmpl $0x1a, %ecx
cmovael %r14d, %esi
cmpl %esi, %r11d
sete %cl
orb %bl, %cl
je 0x23c1c
movl $0x0, %edi
testb %cl, %cl
movl 0xc(%rsp), %r11d
je 0x23c3a
xorl %r14d, %r14d
testb %cl, %cl
movl 0x8(%rsp), %r13d
je 0x23c49
jmp 0x23c4c
movl %r8d, %r14d
xorl %edi, %edi
jmp 0x23c49
movl %r8d, %r14d
testb %cl, %cl
movl 0x8(%rsp), %r13d
jne 0x23c4c
movl %r8d, %r14d
xorl %r8d, %r8d
addl %r9d, %r8d
orb %bl, %bpl
testb $0x1, %bpl
je 0x23cc8
cmpq 0x18(%rsp), %rax
jne 0x23c6d
cmpl $-0x8, %edx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
cmovgel %edx, %ecx
addl %ecx, %r8d
xorl %ecx, %ecx
testl %r11d, %r11d
setne %cl
leal (%rcx,%rcx,4), %esi
testl %r13d, %r13d
leal 0xa(%rcx,%rcx,4), %ecx
cmovel %esi, %ecx
leal -0x5b(%r10), %esi
leal 0xa(%rcx), %ebp
cmpl $-0x1a, %esi
cmovbl %ecx, %ebp
testl %r12d, %r12d
cmovel %ecx, %ebp
movl %r8d, %r9d
movzbl %bl, %ecx
addq %rcx, %rax
testq %rdi, %rdi
setne %cl
cmpl %r14d, %ebp
cmovgeq %r15, %rdi
setge %sil
cmovlel %r14d, %ebp
andb %cl, %sil
movzbl %sil, %ecx
subl %ecx, %r9d
movl $0x1, %r11d
movl %ebp, %r8d
jmp 0x23cd4
movl %r8d, %r9d
decl %r9d
xorl %r11d, %r11d
movl %r14d, %r8d
movl %r10d, %ecx
addl $-0x61, %ecx
xorl %r12d, %r12d
cmpl $0x1a, %ecx
setb %r12b
cmpb $0x5f, %r10b
sete %cl
cmpb $0x20, %r10b
sete %sil
orb %cl, %sil
movzbl %sil, %r13d
addq $-0x3, %rdx
incq %r15
movq 0x20(%rsp), %rcx
addq %rdx, %rcx
jne 0x23b6f
jmp 0x23d50
movl %ebx, %ecx
testb %bl, %bl
jne 0x23c17
jmp 0x23c1c
movq 0x632c9(%rip), %rbx     # 0x86ff0
movq (%rbx), %rdi
leaq 0x4d06b(%rip), %rsi     # 0x70d9c
leaq 0x4d082(%rip), %rdx     # 0x70dba
xorl %ebp, %ebp
movl $0x1acf, %ecx           # imm = 0x1ACF
xorl %eax, %eax
callq 0x12d80
movq (%rbx), %rdi
callq 0x13780
jmp 0x23d7d
xorl %ecx, %ecx
testq %rdi, %rdi
cmovel %ecx, %r8d
addl %r8d, %r9d
movq 0x10(%rsp), %r14
xorl %ebp, %ebp
jmp 0x23d6b
movq %r13, %rax
xorl %r9d, %r9d
cmpb $0x0, (%rax)
jne 0x23d7d
movl $0x1, %ebp
testq %r14, %r14
je 0x23d7d
movl %r9d, (%r14)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq