// File: /workspace/github_c_makefile_star2_O2/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:
orl $-0x1, (%rdx)
testq %rsi, %rsi
je 0x745f
pushq $0x4
popq %r8
cmovsq %r8, %rsi
movzbl (%rdi), %ecx
testb %cl, %cl
js 0x7462
pushq $0x1
popq %r8
movl %ecx, (%rdx)
movq %r8, %rax
retq
xorl %eax, %eax
retq
leal -0xf5(%rcx), %r9d
pushq $-0x3
popq %rax
cmpl $-0x33, %r9d
jae 0x7473
retq
cmpb $-0x21, %cl
ja 0x749c
movzbl 0x1(%rdi), %esi
movl %esi, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x7472
andl $0x1f, %ecx
shll $0x6, %ecx
andl $0x3f, %esi
orl %ecx, %esi
pushq $0x2
popq %r8
movl %esi, %ecx
jmp 0x7459
cmpb $-0x11, %cl
ja 0x7501
cmpq $0x3, %rsi
jb 0x7472
movzbl 0x1(%rdi), %esi
movl %esi, %r8d
andb $-0x40, %r8b
negb %r8b
jno 0x7472
movzbl 0x2(%rdi), %edi
movl %edi, %r8d
andb $-0x40, %r8b
negb %r8b
jno 0x7472
cmpl $0xed, %ecx
sete %r8b
cmpb $-0x60, %sil
setae %r9b
testb %r9b, %r8b
jne 0x7472
shll $0xc, %ecx
movzwl %cx, %ecx
andl $0x3f, %esi
shll $0x6, %esi
orl %ecx, %esi
cmpl $0x800, %esi            # imm = 0x800
jb 0x7472
andl $0x3f, %edi
orl %edi, %esi
pushq $0x3
jmp 0x7496
cmpq $0x4, %rsi
jb 0x7472
movzbl 0x1(%rdi), %esi
movl %esi, %r9d
andb $-0x40, %r9b
negb %r9b
jno 0x7472
movzbl 0x2(%rdi), %r9d
movl %r9d, %r10d
andb $-0x40, %r10b
negb %r10b
jno 0x7472
movzbl 0x3(%rdi), %edi
movl %edi, %r10d
andb $-0x40, %r10b
negb %r10b
jno 0x7472
cmpl $0xf4, %ecx
je 0x7563
cmpl $0xf0, %ecx
jne 0x756d
cmpb $-0x70, %sil
jae 0x756d
jmp 0x7472
cmpb $-0x71, %sil
ja 0x7472
andl $0x7, %ecx
shll $0x12, %ecx
andl $0x3f, %esi
shll $0xc, %esi
orl %ecx, %esi
andl $0x3f, %r9d
shll $0x6, %r9d
orl %esi, %r9d
andl $0x3f, %edi
orl %r9d, %edi
movl %edi, %ecx
jmp 0x7459