// File: /workspace/github_c_makefile_star2_O3/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 0xe11a
cmpl $0x7f, %esi
ja 0xe12f
movb %sil, -0x8(%rbp)
jmp 0xe1a5
decq %rdi
leaq 0x1(%rdi), %rax
cmpb $0x0, 0x1(%rdi)
movq %rax, %rdi
jne 0xe11d
jmp 0xe1f6
movl %esi, %eax
cmpl $0x7ff, %esi            # imm = 0x7FF
ja 0xe14f
shrl $0x6, %eax
orb $-0x40, %al
movb %al, -0x8(%rbp)
andb $0x3f, %sil
orb $-0x80, %sil
movb %sil, -0x7(%rbp)
jmp 0xe1a5
cmpl $0xffff, %esi           # imm = 0xFFFF
ja 0xe179
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 0xe1a5
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 0xe1f4
xorl %eax, %eax
leaq -0x8(%rbp), %rcx
leaq -0x1(%rdi), %rdx
movq %rcx, %r8
movb 0x1(%rdx), %sil
incq %rdx
movb (%r8), %r9b
incq %r8
cmpb %r9b, %sil
je 0xe1b7
testb %r9b, %r9b
je 0xe1e7
testb %sil, %sil
je 0xe1f6
movb 0x1(%rdx), %sil
incq %rdx
movl %esi, %edi
andb $-0x40, %dil
negb %dil
jo 0xe1d3
jmp 0xe1ea
movq %rdi, %rax
movq %rdx, %rdi
testb %sil, %sil
jne 0xe1b0
jmp 0xe1f6
xorl %eax, %eax
popq %rbp
retq