// File: /workspace/github_c_makefile_star2_O3/michaelnmmeyer[P]gourgandine/src/lib/utf8proc.c
// Function: utf8proc_iterate
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_iterate(
  const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_int32_t *dst
) {
  utf8proc_uint32_t uc;
  const utf8proc_uint8_t *end;

  *dst = -1;
  if (!strlen) return 0;
  end = str + ((strlen < 0) ? 4 : strlen);
  uc = *str++;
  if (uc < 0x80) {
    *dst = uc;
    return 1;
  }
  // Must be between 0xc2 and 0xf4 inclusive to be valid
  if ((uc - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
  if (uc < 0xe0) {         // 2-byte sequence
     // Must have valid continuation character
     if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
     *dst = ((uc & 0x1f)<<6) | (*str & 0x3f);
     return 2;
  }
  if (uc < 0xf0) {        // 3-byte sequence
     if ((str + 1 >= end) || !utf_cont(*str) || !utf_cont(str[1]))
        return UTF8PROC_ERROR_INVALIDUTF8;
     // Check for surrogate chars
     if (uc == 0xed && *str > 0x9f)
         return UTF8PROC_ERROR_INVALIDUTF8;
     uc = ((uc & 0xf)<<12) | ((*str & 0x3f)<<6) | (str[1] & 0x3f);
     if (uc < 0x800)
         return UTF8PROC_ERROR_INVALIDUTF8;
     *dst = uc;
     return 3;
  }
  // 4-byte sequence
  // Must have 3 valid continuation characters
  if ((str + 2 >= end) || !utf_cont(*str) || !utf_cont(str[1]) || !utf_cont(str[2]))
     return UTF8PROC_ERROR_INVALIDUTF8;
  // Make sure in correct range (0x10000 - 0x10ffff)
  if (uc == 0xf0) {
    if (*str < 0x90) return UTF8PROC_ERROR_INVALIDUTF8;
  } else if (uc == 0xf4) {
    if (*str > 0x8f) return UTF8PROC_ERROR_INVALIDUTF8;
  }
  *dst = ((uc & 7)<<18) | ((*str & 0x3f)<<12) | ((str[1] & 0x3f)<<6) | (str[2] & 0x3f);
  return 4;
}

// Assembly:
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
testq %rsi, %rsi
je 0x7c09
movl $0x4, %eax
cmovsq %rax, %rsi
movzbl (%rdi), %ecx
movl $0x1, %eax
testb %cl, %cl
js 0x7c0c
movl %ecx, (%rdx)
retq
xorl %eax, %eax
retq
leal -0xf5(%rcx), %r8d
movq $-0x3, %rax
cmpl $-0x33, %r8d
jae 0x7c21
retq
cmpb $-0x21, %cl
ja 0x7c4b
movzbl 0x1(%rdi), %esi
movl %esi, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x7c20
andl $0x1f, %ecx
shll $0x6, %ecx
andl $0x3f, %esi
orl %ecx, %esi
movl $0x2, %eax
movl %esi, %ecx
jmp 0x7c06
cmpb $-0x11, %cl
ja 0x7cb3
cmpq $0x3, %rsi
jb 0x7c20
movzbl 0x1(%rdi), %esi
movl %esi, %r8d
andb $-0x40, %r8b
negb %r8b
jno 0x7c20
movzbl 0x2(%rdi), %edi
movl %edi, %r8d
andb $-0x40, %r8b
negb %r8b
jno 0x7c20
cmpl $0xed, %ecx
sete %r8b
cmpb $-0x60, %sil
setae %r9b
testb %r9b, %r8b
jne 0x7c20
shll $0xc, %ecx
movzwl %cx, %ecx
andl $0x3f, %esi
shll $0x6, %esi
orl %ecx, %esi
cmpl $0x800, %esi            # imm = 0x800
jb 0x7c20
andl $0x3f, %edi
orl %edi, %esi
movl $0x3, %eax
jmp 0x7c47
cmpq $0x4, %rsi
jb 0x7c20
movzbl 0x1(%rdi), %esi
movl %esi, %r8d
andb $-0x40, %r8b
negb %r8b
jno 0x7c20
movzbl 0x2(%rdi), %r8d
movl %r8d, %r9d
andb $-0x40, %r9b
negb %r9b
jno 0x7c20
movzbl 0x3(%rdi), %edi
movl %edi, %r9d
andb $-0x40, %r9b
negb %r9b
jno 0x7c20
cmpl $0xf4, %ecx
je 0x7d15
cmpl $0xf0, %ecx
jne 0x7d1f
cmpb $-0x70, %sil
jae 0x7d1f
jmp 0x7c20
cmpb $-0x71, %sil
ja 0x7c20
andl $0x7, %ecx
shll $0x12, %ecx
andl $0x3f, %esi
shll $0xc, %esi
orl %ecx, %esi
andl $0x3f, %r8d
shll $0x6, %r8d
orl %esi, %r8d
andl $0x3f, %edi
orl %r8d, %edi
movl $0x4, %eax
movl %edi, %ecx
jmp 0x7c06