// File: /workspace/github_c_makefile_star2_O0/neosploit[P]compiler/libfort/lib/fort.c
// Function: utf8chr
void *utf8chr(const void *src, utf8_int32_t chr)
{
    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!
        const char *s = (const char *)src;
        while ('\0' != *s) {
            s++;
        }
        return (void *)s;
    } else if (0 == ((utf8_int32_t)0xffffff80 & chr)) {
        // 1-byte/7-bit ascii
        // (0b0xxxxxxx)
        c[0] = (char)chr;
    } else if (0 == ((utf8_int32_t)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 == ((utf8_int32_t)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 made c into a 2 utf8 codepoint string, one for the chr we are
    // seeking, another for the null terminating byte. Now use utf8str to
    // search
    return utf8str(src, c);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
leaq -0x19(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x7130
xorl %eax, %eax
cmpl -0x14(%rbp), %eax
jne 0x10cb6
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x10ca9
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x10c8e
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x10dae
movl -0x14(%rbp), %ecx
andl $0xffffff80, %ecx       # imm = 0xFFFFFF80
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x10cd0
movl -0x14(%rbp), %eax
movb %al, -0x19(%rbp)
jmp 0x10d9b
movl -0x14(%rbp), %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x10d06
movl -0x14(%rbp), %eax
sarl $0x6, %eax
movsbl %al, %eax
orl $0xc0, %eax
movb %al, -0x19(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x18(%rbp)
jmp 0x10d99
movl -0x14(%rbp), %ecx
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x10d4d
movl -0x14(%rbp), %eax
sarl $0xc, %eax
movsbl %al, %eax
orl $0xe0, %eax
movb %al, -0x19(%rbp)
movl -0x14(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x18(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x17(%rbp)
jmp 0x10d97
movl -0x14(%rbp), %eax
sarl $0x12, %eax
movsbl %al, %eax
orl $0xf0, %eax
movb %al, -0x19(%rbp)
movl -0x14(%rbp), %eax
sarl $0xc, %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x18(%rbp)
movl -0x14(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x17(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movsbl %al, %eax
orl $0x80, %eax
movb %al, -0x16(%rbp)
jmp 0x10d99
jmp 0x10d9b
jmp 0x10d9d
movq -0x10(%rbp), %rdi
leaq -0x19(%rbp), %rsi
callq 0x10dc0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)