// File: /workspace/github_c_makefile_star2_O2/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)
andl $0x0, -0x8(%rbp)
testl %esi, %esi
je 0xdbf2
cmpl $0x7f, %esi
ja 0xdc04
movb %sil, -0x8(%rbp)
jmp 0xdc7a
decq %rdi
leaq 0x1(%rdi), %rax
cmpb $0x0, 0x1(%rdi)
movq %rax, %rdi
jne 0xdbf5
popq %rbp
retq
movl %esi, %eax
cmpl $0x7ff, %esi            # imm = 0x7FF
ja 0xdc24
shrl $0x6, %eax
orb $-0x40, %al
movb %al, -0x8(%rbp)
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x7(%rbp)
jmp 0xdc7a
cmpl $0xffff, %esi           # imm = 0xFFFF
ja 0xdc4e
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 0xdc7a
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)
movb (%rdi), %dl
xorl %esi, %esi
leaq -0x8(%rbp), %rcx
movq %rsi, %rax
testb %dl, %dl
je 0xdc02
movq %rdi, %rsi
decq %rdi
movq %rcx, %r8
movb 0x1(%rdi), %dl
incq %rdi
movb (%r8), %r9b
incq %r8
cmpb %r9b, %dl
je 0xdc96
testb %r9b, %r9b
je 0xdc82
movq %rax, %rsi
testb %dl, %dl
movl $0x0, %edx
je 0xdc82
movb 0x1(%rdi), %dl
incq %rdi
movl %edx, %esi
andb $-0x40, %sil
negb %sil
jo 0xdcb8
movq %rax, %rsi
jmp 0xdc82