// File: /workspace/github_cpp_makefile_star2_O3/donfreiday[P]gb/./imgui/imgui.cpp
// Function: ImTextCharFromUtf8(unsigned int*, char const*, char const*)
int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char* in_text_end)
{
    unsigned int c = (unsigned int)-1;
    const unsigned char* str = (const unsigned char*)in_text;
    if (!(*str & 0x80))
    {
        c = (unsigned int)(*str++);
        *out_char = c;
        return 1;
    }
    if ((*str & 0xe0) == 0xc0)
    {
        *out_char = 0xFFFD; // will be invalid but not end of string
        if (in_text_end && in_text_end - (const char*)str < 2) return 0;
        if (*str < 0xc2) return 2;
        c = (unsigned int)((*str++ & 0x1f) << 6);
        if ((*str & 0xc0) != 0x80) return 2;
        c += (*str++ & 0x3f);
        *out_char = c;
        return 2;
    }
    if ((*str & 0xf0) == 0xe0)
    {
        *out_char = 0xFFFD; // will be invalid but not end of string
        if (in_text_end && in_text_end - (const char*)str < 3) return 0; 
        if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 3;
        if (*str == 0xed && str[1] > 0x9f) return 3; // str[1] < 0x80 is checked below
        c = (unsigned int)((*str++ & 0x0f) << 12);
        if ((*str & 0xc0) != 0x80) return 3;
        c += (unsigned int)((*str++ & 0x3f) << 6);
        if ((*str & 0xc0) != 0x80) return 3;
        c += (*str++ & 0x3f);
        *out_char = c;
        return 3;
    }
    if ((*str & 0xf8) == 0xf0)
    {
        *out_char = 0xFFFD; // will be invalid but not end of string
        if (in_text_end && in_text_end - (const char*)str < 4) return 0;
        if (*str > 0xf4) return 4;
        if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 4;
        if (*str == 0xf4 && str[1] > 0x8f) return 4; // str[1] < 0x80 is checked below
        c = (unsigned int)((*str++ & 0x07) << 18);
        if ((*str & 0xc0) != 0x80) return 4;
        c += (unsigned int)((*str++ & 0x3f) << 12);
        if ((*str & 0xc0) != 0x80) return 4;
        c += (unsigned int)((*str++ & 0x3f) << 6);
        if ((*str & 0xc0) != 0x80) return 4;
        c += (*str++ & 0x3f);
        // utf-8 encodings of values used in surrogate pairs are invalid
        if ((c & 0xFFFFF800) == 0xD800) return 4;
        *out_char = c;
        return 4;
    }
    *out_char = 0;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzbl (%rsi), %ecx
movl $0x1, %eax
testb %cl, %cl
js 0x881e
movl %ecx, (%rdi)
popq %rbp
retq
movl %ecx, %eax
andl $-0x20, %eax
cmpl $0xc0, %eax
jne 0x8876
movl $0xfffd, (%rdi)         # imm = 0xFFFD
testq %rdx, %rdx
setne %al
subq %rsi, %rdx
cmpq $0x2, %rdx
setl %cl
testb %cl, %al
jne 0x8901
movzbl (%rsi), %edx
movl $0x2, %eax
cmpl $0xc2, %edx
jb 0x881c
movzbl 0x1(%rsi), %ecx
movl %ecx, %esi
andl $-0x40, %esi
cmpl $0x80, %esi
jne 0x881c
andl $0x1f, %edx
shll $0x6, %edx
andl $0x3f, %ecx
orl %edx, %ecx
jmp 0x881a
movl %ecx, %eax
andl $-0x10, %eax
cmpl $0xe0, %eax
jne 0x88d1
movl $0xfffd, (%rdi)         # imm = 0xFFFD
testq %rdx, %rdx
setne %al
subq %rsi, %rdx
cmpq $0x3, %rdx
setl %cl
testb %cl, %al
jne 0x8901
movzbl (%rsi), %r8d
movzbl 0x1(%rsi), %edx
cmpl $0xed, %r8d
je 0x893a
cmpl $0xe0, %r8d
jne 0x8948
leal 0x40(%rdx), %ecx
movl $0x3, %eax
cmpb $-0x20, %cl
jb 0x881c
jmp 0x8948
andl $-0x8, %ecx
xorl %eax, %eax
cmpl $0xf0, %ecx
movl $0x0, %ecx
jne 0x881a
movl $0xfffd, (%rdi)         # imm = 0xFFFD
testq %rdx, %rdx
setne %al
subq %rsi, %rdx
cmpq $0x4, %rdx
setl %cl
testb %cl, %al
je 0x8908
xorl %eax, %eax
jmp 0x881c
movzbl (%rsi), %edx
movl $0x4, %eax
cmpl $0xf4, %edx
ja 0x881c
movzbl 0x1(%rsi), %r8d
je 0x898e
cmpl $0xf0, %edx
jne 0x8998
leal 0x40(%r8), %ecx
cmpb $-0x30, %cl
jb 0x881c
jmp 0x8998
movl $0x3, %eax
cmpb $-0x61, %dl
ja 0x881c
movl %edx, %ecx
andl $-0x40, %ecx
movl $0x3, %eax
cmpl $0x80, %ecx
jne 0x881c
movzbl 0x2(%rsi), %ecx
movl %ecx, %esi
andl $-0x40, %esi
cmpl $0x80, %esi
jne 0x881c
andl $0xf, %r8d
shll $0xc, %r8d
andl $0x3f, %edx
shll $0x6, %edx
orl %r8d, %edx
andl $0x3f, %ecx
orl %edx, %ecx
jmp 0x881a
cmpb $-0x71, %r8b
ja 0x881c
movl %r8d, %ecx
andl $-0x40, %ecx
cmpl $0x80, %ecx
jne 0x881c
movzbl 0x2(%rsi), %r9d
movl %r9d, %ecx
andl $-0x40, %ecx
cmpl $0x80, %ecx
jne 0x881c
movzbl 0x3(%rsi), %ecx
movl %ecx, %esi
andl $-0x40, %esi
cmpl $0x80, %esi
jne 0x881c
andl $0x7, %edx
shll $0x12, %edx
andl $0x3f, %r8d
shll $0xc, %r8d
orl %edx, %r8d
andl $0x3f, %r9d
shll $0x6, %r9d
orl %r8d, %r9d
movl %r9d, %edx
andl $0x1ff800, %edx         # imm = 0x1FF800
cmpl $0xd800, %edx           # imm = 0xD800
je 0x881c
andl $0x3f, %ecx
orl %r9d, %ecx
jmp 0x881a