// File: /workspace/github_c_makefile_star2_O3/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 0x8932
testq %rsi, %rsi
jle 0x8b1b
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 0x8889
cmpl $0xa, 0x4(%rbx,%rdi,4)
jne 0x88aa
incq %rdi
jmp 0x88aa
cmpl $0xa, %eax
je 0x88aa
cmpl $0xd, %eax
je 0x88aa
cmpl $0x85, %eax
je 0x88aa
btl $0x9, %edx
jae 0x88e6
leal -0xb(%rax), %r9d
cmpl $0x1, %r9d
ja 0x88e6
leaq 0x1(%r8), %rax
testb %dl, %dl
js 0x88c2
btl $0x8, %edx
jb 0x88d2
movl $0x20, (%rbx,%r8,4)
jmp 0x8921
btl $0x8, %edx
jb 0x88dc
movl $0x2028, (%rbx,%r8,4)   # imm = 0x2028
jmp 0x8921
movl $0x2029, (%rbx,%r8,4)   # imm = 0x2029
jmp 0x8921
movl $0xa, (%rbx,%r8,4)
jmp 0x8921
btl $0x9, %edx
jae 0x8917
cmpl $0x20, %eax
setl %r9b
leal -0x7f(%rax), %r10d
cmpl $0x21, %r10d
setb %r10b
orb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x8917
cmpl $0x9, %eax
jne 0x891e
movl $0x20, (%rbx,%r8,4)
jmp 0x891b
movl %eax, (%rbx,%r8,4)
incq %r8
movq %r8, %rax
incq %rdi
movq %rax, %r8
cmpq %rsi, %rdi
jl 0x8863
jmp 0x8935
movq %rsi, %rax
testb $0x8, %dl
jne 0x8942
movq %rax, %r15
jmp 0x8b1e
xorl %r15d, %r15d
testq %rax, %rax
jle 0x8b1e
movw $0xffff, %r10w          # imm = 0xFFFF
leaq 0x9b886(%rip), %rdi     # 0xa41e0
xorl %r9d, %r9d
xorl %r14d, %r14d
xorl %r11d, %r11d
movl (%rbx,%r11,4), %r12d
movl %r12d, %ecx
sarl $0x8, %ecx
movslq %ecx, %rcx
movzwl (%rdi,%rcx,2), %ecx
movzbl %r12b, %r8d
addl %ecx, %r8d
leaq 0x9da5e(%rip), %rcx     # 0xa63e0
movzwl (%rcx,%r8,2), %ecx
leaq (%rcx,%rcx,8), %r13
leaq 0xb004e(%rip), %rcx     # 0xb89e0
movzwl 0x2(%rcx,%r13,4), %ebp
testq %r9, %r9
je 0x8ad6
cmpw %r10w, %bp
jle 0x8ad6
movl (%r9), %r8d
leal -0x1176(%r12), %ecx
cmpl $-0x15, %ecx
jb 0x89ee
leal -0x1113(%r8), %ecx
cmpl $-0x13, %ecx
jb 0x89ee
leal (%r8,%r8,4), %ecx
leal (%r8,%rcx,4), %ecx
addl %r12d, %ecx
leal (%rcx,%rcx,8), %r8d
leal (%r8,%r8,2), %r8d
addl %r8d, %ecx
addl $0xffd7b964, %ecx       # imm = 0xFFD7B964
movl %ecx, (%r9)
xorl %r8d, %r8d
jmp 0x8b0a
leal -0xac00(%r8), %ecx
cmpl $0x2ba3, %ecx           # imm = 0x2BA3
ja 0x8a3b
leal -0x11c3(%r12), %esi
cmpl $-0x1c, %esi
jb 0x8a3b
movzwl %cx, %esi
shrl $0x2, %esi
imull $0x4925, %esi, %esi     # imm = 0x4925
shrl $0x11, %esi
leal (%rsi,%rsi,8), %edi
leal (%rdi,%rdi,2), %edi
addl %esi, %edi
subl %edi, %ecx
leaq 0x9b7b6(%rip), %rdi     # 0xa41e0
testw %cx, %cx
jne 0x8a3b
leal (%r12,%r8), %ecx
addl $0xffffee59, %ecx       # imm = 0xFFFFEE59
jmp 0x89e3
testq %r14, %r14
jne 0x8a6d
movl %r8d, %ecx
sarl $0x8, %ecx
movslq %ecx, %rcx
movzwl (%rdi,%rcx,2), %ecx
movzbl %r8b, %esi
addl %ecx, %esi
leaq 0x9d986(%rip), %rcx     # 0xa63e0
movzwl (%rcx,%rsi,2), %ecx
leaq (%rcx,%rcx,8), %rcx
leaq 0xaff77(%rip), %rsi     # 0xb89e0
leaq (%rsi,%rcx,4), %r14
movl 0x18(%r14), %ecx
testl %ecx, %ecx
js 0x8ad6
leaq 0xaff64(%rip), %rsi     # 0xb89e0
leaq (%rsi,%r13,4), %rsi
movl 0x1c(%rsi), %r8d
testl %r8d, %r8d
js 0x8ad6
addl %ecx, %r8d
leaq 0xea8fd(%rip), %rcx     # 0xf3390
movl (%rcx,%r8,4), %r8d
testl %r8d, %r8d
js 0x8ad6
testb $0x2, %dl
je 0x8ace
movl %r8d, %ecx
shrl $0x8, %ecx
movzwl (%rdi,%rcx,2), %ecx
movzbl %r8b, %esi
addl %ecx, %esi
leaq 0x9d928(%rip), %rcx     # 0xa63e0
movzwl (%rcx,%rsi,2), %ecx
leaq (%rcx,%rcx,8), %rcx
leaq 0xaff19(%rip), %rsi     # 0xb89e0
testb $0x2, 0x20(%rsi,%rcx,4)
jne 0x8ad6
movl %r8d, (%r9)
jmp 0x89e6
leaq (%rbx,%r15,4), %rcx
movl %r12d, (%rcx)
cmpw %r10w, %bp
cmovgl %ebp, %r10d
cmpw $0x1, %bp
movl $0x0, %esi
sbbl %esi, %esi
orl %r10d, %esi
testw %bp, %bp
movl $0x0, %r8d
cmovneq %r14, %r8
cmoveq %rcx, %r9
incq %r15
movl %esi, %r10d
incq %r11
movq %r8, %r14
cmpq %r11, %rax
jne 0x8963
jmp 0x8b1e
xorl %r15d, %r15d
btl $0xb, %edx
jb 0x8b50
testq %r15, %r15
jle 0x8c4c
xorl %r14d, %r14d
xorl %r12d, %r12d
movl (%rbx,%r12,4), %edi
leaq (%rbx,%r14), %rsi
callq 0x7d65
addq %rax, %r14
incq %r12
cmpq %r12, %r15
jne 0x8b33
jmp 0x8c4f
testq %r15, %r15
jle 0x8c4c
xorl %r14d, %r14d
xorl %eax, %eax
movl (%rbx,%rax,4), %ecx
testl %ecx, %ecx
js 0x8c39
cmpl $0x7f, %ecx
ja 0x8b7c
movb %cl, (%rbx,%r14)
movl $0x1, %ecx
jmp 0x8c3b
cmpl $0x7ff, %ecx            # imm = 0x7FF
ja 0x8ba5
movl %ecx, %edx
shrl $0x6, %edx
orb $-0x40, %dl
movb %dl, (%rbx,%r14)
andb $0x3f, %cl
orb $-0x80, %cl
movb %cl, 0x1(%rbx,%r14)
movl $0x2, %ecx
jmp 0x8c3b
cmpl $0xfffe, %ecx           # imm = 0xFFFE
je 0x8bbc
cmpl $0xffff, %ecx           # imm = 0xFFFF
jne 0x8bc3
movb $-0x1, (%rbx,%r14)
jmp 0x8b72
movb $-0x2, (%rbx,%r14)
jmp 0x8b72
ja 0x8bf3
movl %ecx, %edx
shrl $0xc, %edx
orb $-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 0x8c3b
cmpl $0x10ffff, %ecx         # imm = 0x10FFFF
ja 0x8c39
movl %ecx, %edx
shrl $0x12, %edx
orb $-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 0x8c3b
xorl %ecx, %ecx
addq %rcx, %r14
incq %rax
cmpq %rax, %r15
jne 0x8b5e
jmp 0x8c4f
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