// File: /workspace/github_c_makefile_star2_O3/neosploit[P]compiler/libfort/lib/fort.c
// Function: utf8valid
void *utf8valid(const void *str)
{
    const char *s = (const char *)str;

    while ('\0' != *s) {
        if (0xf0 == (0xf8 & *s)) {
            // ensure each of the 3 following bytes in this 4-byte
            // utf8 codepoint began with 0b10xxxxxx
            if ((0x80 != (0xc0 & s[1])) || (0x80 != (0xc0 & s[2])) ||
                (0x80 != (0xc0 & s[3]))) {
                return (void *)s;
            }

            // ensure that our utf8 codepoint ended after 4 bytes
            if (0x80 == (0xc0 & s[4])) {
                return (void *)s;
            }

            // ensure that the top 5 bits of this 4-byte utf8
            // codepoint were not 0, as then we could have used
            // one of the smaller encodings
            if ((0 == (0x07 & s[0])) && (0 == (0x30 & s[1]))) {
                return (void *)s;
            }

            // 4-byte utf8 code point (began with 0b11110xxx)
            s += 4;
        } else if (0xe0 == (0xf0 & *s)) {
            // ensure each of the 2 following bytes in this 3-byte
            // utf8 codepoint began with 0b10xxxxxx
            if ((0x80 != (0xc0 & s[1])) || (0x80 != (0xc0 & s[2]))) {
                return (void *)s;
            }

            // ensure that our utf8 codepoint ended after 3 bytes
            if (0x80 == (0xc0 & s[3])) {
                return (void *)s;
            }

            // ensure that the top 5 bits of this 3-byte utf8
            // codepoint were not 0, as then we could have used
            // one of the smaller encodings
            if ((0 == (0x0f & s[0])) && (0 == (0x20 & s[1]))) {
                return (void *)s;
            }

            // 3-byte utf8 code point (began with 0b1110xxxx)
            s += 3;
        } else if (0xc0 == (0xe0 & *s)) {
            // ensure the 1 following byte in this 2-byte
            // utf8 codepoint began with 0b10xxxxxx
            if (0x80 != (0xc0 & s[1])) {
                return (void *)s;
            }

            // ensure that our utf8 codepoint ended after 2 bytes
            if (0x80 == (0xc0 & s[2])) {
                return (void *)s;
            }

            // ensure that the top 4 bits of this 2-byte utf8
            // codepoint were not 0, as then we could have used
            // one of the smaller encodings
            if (0 == (0x1e & s[0])) {
                return (void *)s;
            }

            // 2-byte utf8 code point (began with 0b110xxxxx)
            s += 2;
        } else if (0x00 == (0x80 & *s)) {
            // 1-byte ascii (began with 0b0xxxxxxx)
            s += 1;
        } else {
            // we have an invalid 0b1xxxxxxx utf8 code point entry
            return (void *)s;
        }
    }

    return utf8_null;
}

// Assembly:
movb (%rdi), %cl
testb %cl, %cl
je 0xe4c8
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rax
movzbl %cl, %edx
movl %edx, %esi
andl $-0x8, %esi
cmpl $0xf0, %esi
jne 0xe440
movzbl 0x1(%rax), %esi
movl %esi, %ecx
andl $-0x40, %ecx
cmpl $0x80, %ecx
jne 0xe4c6
movb 0x2(%rax), %cl
andb $-0x40, %cl
negb %cl
jno 0xe4c6
movb 0x3(%rax), %cl
andb $-0x40, %cl
negb %cl
jno 0xe4c6
movb 0x4(%rax), %cl
movl %ecx, %edi
andb $-0x40, %dil
negb %dil
jo 0xe4c6
andl $0x7, %edx
andl $0x30, %esi
orl %edx, %esi
je 0xe4c6
addq $0x4, %rax
jmp 0xe4bc
movl %edx, %esi
andl $-0x10, %esi
cmpl $0xe0, %esi
jne 0xe486
movzbl 0x1(%rax), %esi
movl %esi, %ecx
andl $-0x40, %ecx
cmpl $0x80, %ecx
jne 0xe4c6
movb 0x2(%rax), %cl
andb $-0x40, %cl
negb %cl
jno 0xe4c6
movb 0x3(%rax), %cl
movl %ecx, %edi
andb $-0x40, %dil
negb %dil
jo 0xe4c6
andl $0xf, %edx
andl $0x20, %esi
orl %edx, %esi
je 0xe4c6
addq $0x3, %rax
jmp 0xe4bc
andl $-0x20, %edx
cmpl $0xc0, %edx
jne 0xe4b2
movb 0x1(%rax), %dl
andb $-0x40, %dl
negb %dl
jno 0xe4c6
testb $0x1e, %cl
je 0xe4c6
movb 0x2(%rax), %cl
movl %ecx, %edx
andb $-0x40, %dl
negb %dl
jo 0xe4c6
addq $0x2, %rax
jmp 0xe4bc
testb %cl, %cl
js 0xe4c6
movb 0x1(%rax), %cl
incq %rax
testb %cl, %cl
jne 0xe3d9
xorl %eax, %eax
popq %rbp
retq
xorl %eax, %eax
retq