// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movl %esi, 0x84(%rsp)
movq %rdx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x1, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
cmpq $0x0, 0x88(%rsp)
jne 0x2bef1
movq 0x9912b(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
leaq 0x854d1(%rip), %rsi     # 0xb13a0
leaq 0x854e8(%rip), %rdx     # 0xb13be
movl $0x1ace, %ecx           # imm = 0x1ACE
movb $0x0, %al
callq 0x13ec0
movq 0x99107(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
callq 0x149a0
jmp 0x2bef3
jmp 0x2bef5
cmpq $0x0, 0x78(%rsp)
jne 0x2bf30
movq 0x990ec(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
leaq 0x85492(%rip), %rsi     # 0xb13a0
leaq 0x854a9(%rip), %rdx     # 0xb13be
movl $0x1acf, %ecx           # imm = 0x1ACF
movb $0x0, %al
callq 0x13ec0
movq 0x990c8(%rip), %rax     # 0xc4ff0
movq (%rax), %rdi
callq 0x149a0
jmp 0x2bf32
cmpq $0x0, 0x88(%rsp)
je 0x2bf4f
cmpl $0x0, 0x84(%rsp)
je 0x2bf4f
cmpq $0x0, 0x78(%rsp)
jne 0x2bf5f
movl $0x0, 0x94(%rsp)
jmp 0x2c29e
jmp 0x2bf61
movl 0x5c(%rsp), %eax
cmpl 0x84(%rsp), %eax
jge 0x2c252
movq 0x60(%rsp), %rax
movb (%rax), %al
movb %al, 0x43(%rsp)
movq 0x88(%rsp), %rax
movslq 0x5c(%rsp), %rcx
movb (%rax,%rcx), %al
movb %al, 0x42(%rsp)
movq 0x60(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x23(%rsp)
je 0x2bfcb
movsbl 0x43(%rsp), %edi
callq 0x2c2b0
movl %eax, 0x1c(%rsp)
movsbl 0x42(%rsp), %edi
callq 0x2c2b0
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
sete %al
movb %al, 0x23(%rsp)
movb 0x23(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x3c(%rsp)
xorl %eax, %eax
cmpq $0x0, 0x48(%rsp)
movb %al, 0x1b(%rsp)
je 0x2c010
movq 0x48(%rsp), %rax
movsbl (%rax), %edi
callq 0x2c2e0
movl %eax, 0x14(%rsp)
movsbl 0x42(%rsp), %edi
callq 0x2c2e0
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
sete %al
movb %al, 0x1b(%rsp)
movb 0x1b(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x38(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x3c(%rsp)
movb %al, 0x13(%rsp)
je 0x2c037
cmpq $0x0, 0x48(%rsp)
setne %al
movb %al, 0x13(%rsp)
movb 0x13(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x34(%rsp)
xorl %eax, %eax
cmpq $0x0, 0x48(%rsp)
movb %al, 0x12(%rsp)
je 0x2c064
movq 0x60(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x12(%rsp)
movb 0x12(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x30(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x30(%rsp)
movb %al, 0x11(%rsp)
je 0x2c0a8
movq 0x48(%rsp), %rax
movsbl (%rax), %edi
callq 0x2c2b0
movl %eax, 0xc(%rsp)
movsbl 0x43(%rsp), %edi
callq 0x2c2b0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
sete %al
movb %al, 0x11(%rsp)
movb 0x11(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x34(%rsp)
jne 0x2c0c3
cmpl $0x0, 0x30(%rsp)
je 0x2c0e0
movl 0x44(%rsp), %eax
addl 0x6c(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq $0x0, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0x0, 0x3c(%rsp)
jne 0x2c0f2
cmpl $0x0, 0x38(%rsp)
je 0x2c1ea
movl $0x0, 0x2c(%rsp)
movq 0x60(%rsp), %rax
cmpq 0x78(%rsp), %rax
jne 0x2c14c
movq 0x88(%rsp), %rax
movslq 0x5c(%rsp), %rcx
addq %rcx, %rax
movq 0x88(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x28(%rsp)
imull $0xfffffffd, 0x28(%rsp), %eax # imm = 0xFFFFFFFD
movl %eax, 0x24(%rsp)
cmpl $-0x9, 0x24(%rsp)
jge 0x2c140
movl $0xfffffff7, 0x24(%rsp) # imm = 0xFFFFFFF7
movl 0x24(%rsp), %eax
addl 0x6c(%rsp), %eax
movl %eax, 0x6c(%rsp)
cmpl $0x0, 0x58(%rsp)
je 0x2c15e
movl 0x2c(%rsp), %eax
addl $0x5, %eax
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x50(%rsp)
je 0x2c170
movl 0x2c(%rsp), %eax
addl $0xa, %eax
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x2c191
movsbl 0x42(%rsp), %edi
callq 0x2c310
cmpl $0x0, %eax
je 0x2c191
movl 0x2c(%rsp), %eax
addl $0xa, %eax
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x3c(%rsp)
je 0x2c1a6
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jl 0x2c1e0
cmpq $0x0, 0x48(%rsp)
je 0x2c1c3
movl 0x6c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x6c(%rsp)
movq 0x88(%rsp), %rax
movslq 0x5c(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x44(%rsp)
movl $0x1, 0x58(%rsp)
jmp 0x2c1fd
movl 0x6c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x6c(%rsp)
movl $0x0, 0x58(%rsp)
movsbl 0x42(%rsp), %edi
callq 0x2c360
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x54(%rsp)
movsbl 0x42(%rsp), %ecx
movb $0x1, %al
cmpl $0x5f, %ecx
movb %al, 0xb(%rsp)
je 0x2c235
movsbl 0x42(%rsp), %eax
cmpl $0x20, %eax
sete %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x50(%rsp)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x2bf61
cmpq $0x0, 0x48(%rsp)
je 0x2c266
movl 0x44(%rsp), %eax
addl 0x6c(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x60(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x2c280
movl $0x0, 0x94(%rsp)
jmp 0x2c29e
cmpq $0x0, 0x70(%rsp)
je 0x2c293
movl 0x6c(%rsp), %ecx
movq 0x70(%rsp), %rax
movl %ecx, (%rax)
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopl (%rax)