// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
leaq -0x2d(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x7130
xorl %eax, %eax
cmpl -0x14(%rbp), %eax
jne 0x11d70
jmp 0x11d48
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x11d63
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x11d48
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x11f0c
movl -0x14(%rbp), %ecx
andl $0xffffff80, %ecx       # imm = 0xFFFFFF80
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11d8a
movl -0x14(%rbp), %eax
movb %al, -0x2d(%rbp)
jmp 0x11e55
movl -0x14(%rbp), %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11dc0
movl -0x14(%rbp), %eax
sarl $0x6, %eax
movsbl %al, %eax
orl $0xc0, %eax
movb %al, -0x2d(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x2c(%rbp)
jmp 0x11e53
movl -0x14(%rbp), %ecx
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11e07
movl -0x14(%rbp), %eax
sarl $0xc, %eax
movsbl %al, %eax
orl $0xe0, %eax
movb %al, -0x2d(%rbp)
movl -0x14(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x2c(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x2b(%rbp)
jmp 0x11e51
movl -0x14(%rbp), %eax
sarl $0x12, %eax
movsbl %al, %eax
orl $0xf0, %eax
movb %al, -0x2d(%rbp)
movl -0x14(%rbp), %eax
sarl $0xc, %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x2c(%rbp)
movl -0x14(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x2b(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x2a(%rbp)
jmp 0x11e53
jmp 0x11e55
jmp 0x11e57
jmp 0x11e59
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x11f04
movq $0x0, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rcx
movsbl -0x2d(%rbp,%rcx), %ecx
cmpl %ecx, %eax
jne 0x11e99
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x11e72
movq -0x38(%rbp), %rax
movsbl -0x2d(%rbp,%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x11ebe
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x11eff
movq -0x38(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x11efd
jmp 0x11ed9
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
andl $0xc0, %ecx
movl $0x80, %eax
cmpl %ecx, %eax
je 0x11ed9
jmp 0x11efd
jmp 0x11eff
jmp 0x11e59
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)