// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/parse.c
// Function: janet_valid_utf8
int janet_valid_utf8(const uint8_t *str, int32_t len) {
    int32_t i = 0;
    int32_t j;
    while (i < len) {
        int32_t nexti;
        uint8_t c = str[i];

        /* Check the number of bytes in code point */
        if (c < 0x80) nexti = i + 1;
        else if ((c >> 5) == 0x06) nexti = i + 2;
        else if ((c >> 4) == 0x0E) nexti = i + 3;
        else if ((c >> 3) == 0x1E) nexti = i + 4;
        /* Don't allow 5 or 6 byte code points */
        else return 0;

        /* No overflow */
        if (nexti > len) return 0;

        /* Ensure trailing bytes are well formed (10XX XXXX) */
        for (j = i + 1; j < nexti; j++) {
            if ((str[j] >> 6) != 2) return 0;
        }

        /* Check for overlong encoding */
        if ((nexti == i + 2) && str[i] < 0xC2) return 0;
        if ((str[i] == 0xE0) && str[i + 1] < 0xA0) return 0;
        if ((str[i] == 0xF0) && str[i + 1] < 0x90) return 0;

        i = nexti;
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4f977
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x80, %eax
jge 0x4f832
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4f889
movzbl -0x21(%rbp), %eax
sarl $0x5, %eax
cmpl $0x6, %eax
jne 0x4f849
movl -0x18(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x20(%rbp)
jmp 0x4f887
movzbl -0x21(%rbp), %eax
sarl $0x4, %eax
cmpl $0xe, %eax
jne 0x4f860
movl -0x18(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x20(%rbp)
jmp 0x4f885
movzbl -0x21(%rbp), %eax
sarl $0x3, %eax
cmpl $0x1e, %eax
jne 0x4f877
movl -0x18(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x20(%rbp)
jmp 0x4f883
movl $0x0, -0x4(%rbp)
jmp 0x4f97e
jmp 0x4f885
jmp 0x4f887
jmp 0x4f889
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x4f89d
movl $0x0, -0x4(%rbp)
jmp 0x4f97e
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x4f8db
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
sarl $0x6, %eax
cmpl $0x2, %eax
je 0x4f8ce
movl $0x0, -0x4(%rbp)
jmp 0x4f97e
jmp 0x4f8d0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4f8a6
movl -0x20(%rbp), %eax
movl -0x18(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jne 0x4f904
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xc2, %eax
jge 0x4f904
movl $0x0, -0x4(%rbp)
jmp 0x4f97e
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xe0, %eax
jne 0x4f938
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xa0, %eax
jge 0x4f938
movl $0x0, -0x4(%rbp)
jmp 0x4f97e
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xf0, %eax
jne 0x4f96c
movq -0x10(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x90, %eax
jge 0x4f96c
movl $0x0, -0x4(%rbp)
jmp 0x4f97e
movl -0x20(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x4f802
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)