// File: /workspace/github_c_makefile_star2_O1/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), %dl
testb %dl, %dl
je 0xe64f
pushq %rbp
movq %rsp, %rbp
movq %rdi, %rax
movzbl %dl, %ecx
movl %ecx, %esi
andl $-0x8, %esi
cmpl $0xf0, %esi
jne 0xe5c8
movzbl 0x1(%rax), %edx
movl %edx, %esi
andl $-0x40, %esi
cmpl $0x80, %esi
jne 0xe64d
movb 0x2(%rax), %sil
andb $-0x40, %sil
negb %sil
jno 0xe64d
movb 0x3(%rax), %sil
andb $-0x40, %sil
negb %sil
jno 0xe64d
movb 0x4(%rax), %sil
andb $-0x40, %sil
negb %sil
jo 0xe64d
andl $0x7, %ecx
andl $0x30, %edx
orl %ecx, %edx
je 0xe64d
addq $0x4, %rax
jmp 0xe641
movl %ecx, %esi
andl $-0x10, %esi
cmpl $0xe0, %esi
jne 0xe610
movzbl 0x1(%rax), %edx
movl %edx, %esi
andl $-0x40, %esi
cmpl $0x80, %esi
jne 0xe64d
movb 0x2(%rax), %sil
andb $-0x40, %sil
negb %sil
jno 0xe64d
movb 0x3(%rax), %sil
andb $-0x40, %sil
negb %sil
jo 0xe64d
andl $0xf, %ecx
andl $0x20, %edx
orl %ecx, %edx
je 0xe64d
addq $0x3, %rax
jmp 0xe641
andl $-0x20, %ecx
cmpl $0xc0, %ecx
jne 0xe63a
movb 0x1(%rax), %cl
andb $-0x40, %cl
negb %cl
jno 0xe64d
testb $0x1e, %dl
je 0xe64d
movb 0x2(%rax), %cl
andb $-0x40, %cl
negb %cl
jo 0xe64d
addq $0x2, %rax
jmp 0xe641
testb %dl, %dl
js 0xe64d
incq %rax
movb (%rax), %dl
testb %dl, %dl
jne 0xe55c
xorl %eax, %eax
popq %rbp
retq
xorl %eax, %eax
retq