// File: /workspace/github_c_makefile_star2_O1/neosploit[P]compiler/libfort/lib/fort.c
// Function: utf8rchr
void *utf8rchr(const void *src, int chr)
{
    const char *s = (const char *)src;
    const char *match = utf8_null;
    char c[5] = {'\0', '\0', '\0', '\0', '\0'};

    if (0 == chr) {
        // being asked to return position of null terminating byte, so
        // just run s to the end, and return!
        while ('\0' != *s) {
            s++;
        }
        return (void *)s;
    } else if (0 == ((int)0xffffff80 & chr)) {
        // 1-byte/7-bit ascii
        // (0b0xxxxxxx)
        c[0] = (char)chr;
    } else if (0 == ((int)0xfffff800 & chr)) {
        // 2-byte/11-bit utf8 code point
        // (0b110xxxxx 0b10xxxxxx)
        c[0] = 0xc0 | (char)(chr >> 6);
        c[1] = 0x80 | (char)(chr & 0x3f);
    } else if (0 == ((int)0xffff0000 & chr)) {
        // 3-byte/16-bit utf8 code point
        // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx)
        c[0] = 0xe0 | (char)(chr >> 12);
        c[1] = 0x80 | (char)((chr >> 6) & 0x3f);
        c[2] = 0x80 | (char)(chr & 0x3f);
    } else { // if (0 == ((int)0xffe00000 & chr)) {
        // 4-byte/21-bit utf8 code point
        // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx)
        c[0] = 0xf0 | (char)(chr >> 18);
        c[1] = 0x80 | (char)((chr >> 12) & 0x3f);
        c[2] = 0x80 | (char)((chr >> 6) & 0x3f);
        c[3] = 0x80 | (char)(chr & 0x3f);
    }

    // we've created a 2 utf8 codepoint string in c that is
    // the utf8 character asked for by chr, and a null
    // terminating byte

    while ('\0' != *s) {
        size_t offset = 0;

        while (s[offset] == c[offset]) {
            offset++;
        }

        if ('\0' == c[offset]) {
            // we found a matching utf8 code point
            match = s;
            s += offset;
        } else {
            s += offset;

            // need to march s along to next utf8 codepoint start
            // (the next byte that doesn't match 0b10xxxxxx)
            if ('\0' != *s) {
                do {
                    s++;
                } while (0x80 == (0xc0 & *s));
            }
        }
    }

    // return the last match we found (or 0 if no match was found)
    return (void *)match;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb $0x0, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
testl %esi, %esi
je 0xe298
cmpl $0x7f, %esi
ja 0xe2ad
movb %sil, -0x8(%rbp)
jmp 0xe323
decq %rdi
leaq 0x1(%rdi), %rax
cmpb $0x0, 0x1(%rdi)
movq %rax, %rdi
jne 0xe29b
jmp 0xe373
movl %esi, %eax
cmpl $0x7ff, %esi            # imm = 0x7FF
ja 0xe2cd
shrl $0x6, %eax
orb $-0x40, %al
movb %al, -0x8(%rbp)
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x7(%rbp)
jmp 0xe323
cmpl $0xffff, %esi           # imm = 0xFFFF
ja 0xe2f7
shrl $0xc, %eax
orb $-0x20, %al
movb %al, -0x8(%rbp)
movl %esi, %eax
shrl $0x6, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x7(%rbp)
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x6(%rbp)
jmp 0xe323
shrl $0x12, %eax
orb $-0x10, %al
movb %al, -0x8(%rbp)
movl %esi, %eax
shrl $0xc, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x7(%rbp)
movl %esi, %eax
shrl $0x6, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, -0x6(%rbp)
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x5(%rbp)
cmpb $0x0, (%rdi)
je 0xe371
xorl %eax, %eax
leaq -0x8(%rbp), %rcx
leaq -0x1(%rdi), %rdx
movq %rcx, %rsi
movb 0x1(%rdx), %r8b
incq %rdx
movb (%rsi), %r9b
incq %rsi
cmpb %r9b, %r8b
je 0xe335
testb %r9b, %r9b
je 0xe364
testb %r8b, %r8b
je 0xe361
movb 0x1(%rdx), %sil
incq %rdx
andb $-0x40, %sil
negb %sil
jo 0xe351
movq %rax, %rdi
movq %rdi, %rax
cmpb $0x0, (%rdx)
movq %rdx, %rdi
jne 0xe32e
jmp 0xe373
xorl %eax, %eax
popq %rbp
retq