// File: /workspace/github_c_makefile_star2_O1/michaelnmmeyer[P]gourgandine/src/lib/utf8proc.c
// Function: utf8proc_reencode
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_reencode(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options) {
  /* UTF8PROC_NULLTERM option will be ignored, 'length' is never ignored
     ASSERT: 'buffer' has one spare byte of free space at the end! */
  if (options & (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS | UTF8PROC_STRIPCC)) {
    utf8proc_ssize_t rpos;
    utf8proc_ssize_t wpos = 0;
    utf8proc_int32_t uc;
    for (rpos = 0; rpos < length; rpos++) {
      uc = buffer[rpos];
      if (uc == 0x000D && rpos < length-1 && buffer[rpos+1] == 0x000A) rpos++;
      if (uc == 0x000A || uc == 0x000D || uc == 0x0085 ||
          ((options & UTF8PROC_STRIPCC) && (uc == 0x000B || uc == 0x000C))) {
        if (options & UTF8PROC_NLF2LS) {
          if (options & UTF8PROC_NLF2PS) {
            buffer[wpos++] = 0x000A;
          } else {
            buffer[wpos++] = 0x2028;
          }
        } else {
          if (options & UTF8PROC_NLF2PS) {
            buffer[wpos++] = 0x2029;
          } else {
            buffer[wpos++] = 0x0020;
          }
        }
      } else if ((options & UTF8PROC_STRIPCC) &&
          (uc < 0x0020 || (uc >= 0x007F && uc < 0x00A0))) {
        if (uc == 0x0009) buffer[wpos++] = 0x0020;
      } else {
        buffer[wpos++] = uc;
      }
    }
    length = wpos;
  }
  if (options & UTF8PROC_COMPOSE) {
    utf8proc_int32_t *starter = NULL;
    utf8proc_int32_t current_char;
    const utf8proc_property_t *starter_property = NULL, *current_property;
    utf8proc_propval_t max_combining_class = -1;
    utf8proc_ssize_t rpos;
    utf8proc_ssize_t wpos = 0;
    utf8proc_int32_t composition;
    for (rpos = 0; rpos < length; rpos++) {
      current_char = buffer[rpos];
      current_property = unsafe_get_property(current_char);
      if (starter && current_property->combining_class > max_combining_class) {
        /* combination perhaps possible */
        utf8proc_int32_t hangul_lindex;
        utf8proc_int32_t hangul_sindex;
        hangul_lindex = *starter - UTF8PROC_HANGUL_LBASE;
        if (hangul_lindex >= 0 && hangul_lindex < UTF8PROC_HANGUL_LCOUNT) {
          utf8proc_int32_t hangul_vindex;
          hangul_vindex = current_char - UTF8PROC_HANGUL_VBASE;
          if (hangul_vindex >= 0 && hangul_vindex < UTF8PROC_HANGUL_VCOUNT) {
            *starter = UTF8PROC_HANGUL_SBASE +
              (hangul_lindex * UTF8PROC_HANGUL_VCOUNT + hangul_vindex) *
              UTF8PROC_HANGUL_TCOUNT;
            starter_property = NULL;
            continue;
          }
        }
        hangul_sindex = *starter - UTF8PROC_HANGUL_SBASE;
        if (hangul_sindex >= 0 && hangul_sindex < UTF8PROC_HANGUL_SCOUNT &&
            (hangul_sindex % UTF8PROC_HANGUL_TCOUNT) == 0) {
          utf8proc_int32_t hangul_tindex;
          hangul_tindex = current_char - UTF8PROC_HANGUL_TBASE;
          if (hangul_tindex >= 0 && hangul_tindex < UTF8PROC_HANGUL_TCOUNT) {
            *starter += hangul_tindex;
            starter_property = NULL;
            continue;
          }
        }
        if (!starter_property) {
          starter_property = unsafe_get_property(*starter);
        }
        if (starter_property->comb1st_index >= 0 &&
            current_property->comb2nd_index >= 0) {
          composition = utf8proc_combinations[
            starter_property->comb1st_index +
            current_property->comb2nd_index
          ];
          if (composition >= 0 && (!(options & UTF8PROC_STABLE) ||
              !(unsafe_get_property(composition)->comp_exclusion))) {
            *starter = composition;
            starter_property = NULL;
            continue;
          }
        }
      }
      buffer[wpos] = current_char;
      if (current_property->combining_class) {
        if (current_property->combining_class > max_combining_class) {
          max_combining_class = current_property->combining_class;
        }
      } else {
        starter = buffer + wpos;
        starter_property = NULL;
        max_combining_class = -1;
      }
      wpos++;
    }
    length = wpos;
  }
  {
    utf8proc_ssize_t rpos, wpos = 0;
    utf8proc_int32_t uc;
    if (options & UTF8PROC_CHARBOUND) {
        for (rpos = 0; rpos < length; rpos++) {
            uc = buffer[rpos];
            wpos += unsafe_encode_char(uc, ((utf8proc_uint8_t *)buffer) + wpos);
        }
    } else {
        for (rpos = 0; rpos < length; rpos++) {
            uc = buffer[rpos];
            wpos += utf8proc_encode_char(uc, ((utf8proc_uint8_t *)buffer) + wpos);
        }
    }
    ((utf8proc_uint8_t *)buffer)[wpos] = 0;
    return wpos;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testl $0x380, %edx            # imm = 0x380
je 0x8be3
testq %rsi, %rsi
jle 0x8be8
leaq -0x1(%rsi), %rcx
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rbx,%rdi,4), %eax
cmpl $0xd, %eax
sete %r9b
cmpq %rcx, %rdi
setl %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x8b3a
cmpl $0xa, 0x4(%rbx,%rdi,4)
jne 0x8b3a
incq %rdi
cmpl $0xa, %eax
je 0x8b5b
cmpl $0xd, %eax
je 0x8b5b
cmpl $0x85, %eax
je 0x8b5b
btl $0x9, %edx
jae 0x8b97
leal -0xb(%rax), %r9d
cmpl $0x1, %r9d
ja 0x8b97
leaq 0x1(%r8), %rax
testb %dl, %dl
js 0x8b73
btl $0x8, %edx
jb 0x8b83
movl $0x20, (%rbx,%r8,4)
jmp 0x8bd2
btl $0x8, %edx
jb 0x8b8d
movl $0x2028, (%rbx,%r8,4)   # imm = 0x2028
jmp 0x8bd2
movl $0x2029, (%rbx,%r8,4)   # imm = 0x2029
jmp 0x8bd2
movl $0xa, (%rbx,%r8,4)
jmp 0x8bd2
btl $0x9, %edx
jae 0x8bc8
cmpl $0x20, %eax
setl %r9b
leal -0x7f(%rax), %r10d
cmpl $0x21, %r10d
setb %r10b
orb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x8bc8
cmpl $0x9, %eax
jne 0x8bcf
movl $0x20, (%rbx,%r8,4)
jmp 0x8bcc
movl %eax, (%rbx,%r8,4)
incq %r8
movq %r8, %rax
incq %rdi
movq %rax, %r8
cmpq %rsi, %rdi
jl 0x8b16
jmp 0x8bea
movq %rsi, %rax
jmp 0x8bea
xorl %eax, %eax
testb $0x8, %dl
jne 0x8bf7
movq %rax, %r15
jmp 0x8df6
xorl %r15d, %r15d
testq %rax, %rax
jle 0x8df6
movw $0xffff, %cx            # imm = 0xFFFF
leaq 0xb0dd2(%rip), %r8      # 0xb99e0
xorl %r10d, %r10d
xorl %r14d, %r14d
xorl %r11d, %r11d
movl (%rbx,%r11,4), %r12d
movl %r12d, %esi
sarl $0x8, %esi
movslq %esi, %rsi
leaq 0x9c5b5(%rip), %rdi     # 0xa51e0
movzwl (%rdi,%rsi,2), %esi
movzbl %r12b, %r9d
addl %esi, %r9d
leaq 0x9e7a3(%rip), %rsi     # 0xa73e0
movzwl (%rsi,%r9,2), %esi
leaq (%rsi,%rsi,8), %rsi
leaq (%r8,%rsi,4), %r13
testq %r10, %r10
je 0x8db1
cmpw %cx, 0x2(%r13)
jle 0x8db1
movl (%r10), %esi
leal -0x1100(%rsi), %r9d
cmpl $0x12, %r9d
ja 0x8caf
leal -0x1176(%r12), %r9d
xorl %ebp, %ebp
cmpl $-0x15, %r9d
jb 0x8ca5
leal (%rsi,%rsi,4), %r14d
leal (%rsi,%r14,4), %esi
addl %r12d, %esi
leal (%rsi,%rsi,8), %r14d
leal (%r14,%r14,2), %r14d
addl %r14d, %esi
addl $0xffd7b964, %esi       # imm = 0xFFD7B964
movl %esi, (%r10)
movl $0x7, %ebp
xorl %r14d, %r14d
cmpl $-0x16, %r9d
ja 0x8dad
movl (%r10), %r9d
leal -0xac00(%r9), %esi
cmpl $0x2ba3, %esi           # imm = 0x2BA3
ja 0x8d15
shrl $0x2, %esi
imulq $0x24924925, %rsi, %rsi # imm = 0x24924925
shrq $0x20, %rsi
leal (%rsi,%rsi,8), %ebp
leal (%rbp,%rbp,2), %ebp
addl %esi, %ebp
negl %ebp
leal (%r9,%rbp), %esi
addl $0xffff5400, %esi       # imm = 0xFFFF5400
testl %esi, %esi
jne 0x8d15
leal -0x11c3(%r12), %esi
xorl %ebp, %ebp
cmpl $-0x1c, %esi
jb 0x8d0c
addl %r12d, %r9d
addl $0xffffee59, %r9d       # imm = 0xFFFFEE59
movl %r9d, (%r10)
movl $0x7, %ebp
xorl %r14d, %r14d
cmpl $-0x1d, %esi
ja 0x8dad
testq %r14, %r14
jne 0x8d49
movl (%r10), %esi
movzbl %sil, %r9d
sarl $0x8, %esi
movslq %esi, %rsi
leaq 0x9c4b2(%rip), %rdi     # 0xa51e0
movzwl (%rdi,%rsi,2), %esi
addl %esi, %r9d
leaq 0x9e6a4(%rip), %rsi     # 0xa73e0
movzwl (%rsi,%r9,2), %esi
leaq (%rsi,%rsi,8), %rsi
leaq (%r8,%rsi,4), %r14
movl 0x18(%r14), %esi
xorl %ebp, %ebp
testl %esi, %esi
js 0x8dad
movl 0x1c(%r13), %r9d
testl %r9d, %r9d
js 0x8dad
addl %esi, %r9d
leaq 0xeb62a(%rip), %rsi     # 0xf4390
movl (%rsi,%r9,4), %r9d
testl %r9d, %r9d
js 0x8dad
testb $0x2, %dl
je 0x8da2
movl %r9d, %esi
shrl $0x8, %esi
leaq 0x9c45f(%rip), %rdi     # 0xa51e0
movzwl (%rdi,%rsi,2), %edi
movzbl %r9b, %esi
addl %edi, %esi
leaq 0x9e64e(%rip), %rdi     # 0xa73e0
movzwl (%rdi,%rsi,2), %esi
leaq (%rsi,%rsi,8), %rsi
testb $0x2, 0x20(%r8,%rsi,4)
jne 0x8dad
movl %r9d, (%r10)
movl $0x7, %ebp
xorl %r14d, %r14d
testl %ebp, %ebp
jne 0x8dea
leaq (%rbx,%r15,4), %rsi
movl %r12d, (%rsi)
movzwl 0x2(%r13), %r9d
cmpw %cx, %r9w
movl %r9d, %ebp
cmovlel %ecx, %ebp
cmpw $0x1, %r9w
movl $0x0, %ecx
sbbl %ecx, %ecx
orl %ebp, %ecx
testw %r9w, %r9w
movl $0x0, %r9d
cmoveq %r9, %r14
cmoveq %rsi, %r10
incq %r15
incq %r11
cmpq %r11, %rax
jne 0x8c17
btl $0xb, %edx
jb 0x8e28
testq %r15, %r15
jle 0x8f24
xorl %r14d, %r14d
xorl %r12d, %r12d
movl (%rbx,%r12,4), %edi
leaq (%rbx,%r14), %rsi
callq 0x80e1
addq %rax, %r14
incq %r12
cmpq %r12, %r15
jne 0x8e0b
jmp 0x8f27
testq %r15, %r15
jle 0x8f24
xorl %r14d, %r14d
xorl %eax, %eax
movl (%rbx,%rax,4), %ecx
testl %ecx, %ecx
js 0x8f11
cmpl $0x7f, %ecx
jg 0x8e54
movb %cl, (%rbx,%r14)
movl $0x1, %ecx
jmp 0x8f13
cmpl $0x7ff, %ecx            # imm = 0x7FF
jg 0x8e7d
movl %ecx, %edx
shrl $0x6, %edx
addb $-0x40, %dl
movb %dl, (%rbx,%r14)
andb $0x3f, %cl
orb $-0x80, %cl
movb %cl, 0x1(%rbx,%r14)
movl $0x2, %ecx
jmp 0x8f13
cmpl $0xfffe, %ecx           # imm = 0xFFFE
je 0x8e94
cmpl $0xffff, %ecx           # imm = 0xFFFF
jne 0x8e9b
movb $-0x1, (%rbx,%r14)
jmp 0x8e4a
movb $-0x2, (%rbx,%r14)
jmp 0x8e4a
jg 0x8ecb
movl %ecx, %edx
shrl $0xc, %edx
addb $-0x20, %dl
movb %dl, (%rbx,%r14)
movl %ecx, %edx
shrl $0x6, %edx
andb $0x3f, %dl
orb $-0x80, %dl
movb %dl, 0x1(%rbx,%r14)
andb $0x3f, %cl
orb $-0x80, %cl
movb %cl, 0x2(%rbx,%r14)
movl $0x3, %ecx
jmp 0x8f13
cmpl $0x10ffff, %ecx         # imm = 0x10FFFF
jg 0x8f11
movl %ecx, %edx
shrl $0x12, %edx
addb $-0x10, %dl
movb %dl, (%rbx,%r14)
movl %ecx, %edx
shrl $0xc, %edx
andb $0x3f, %dl
orb $-0x80, %dl
movb %dl, 0x1(%rbx,%r14)
movl %ecx, %edx
shrl $0x6, %edx
andb $0x3f, %dl
orb $-0x80, %dl
movb %dl, 0x2(%rbx,%r14)
andb $0x3f, %cl
orb $-0x80, %cl
movb %cl, 0x3(%rbx,%r14)
movl $0x4, %ecx
jmp 0x8f13
xorl %ecx, %ecx
addq %rcx, %r14
incq %rax
cmpq %rax, %r15
jne 0x8e36
jmp 0x8f27
xorl %r14d, %r14d
movb $0x0, (%rbx,%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq