// File: /workspace/github_c_makefile_star2_O2/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
subq $0x28, %rsp
movq %rdi, %rbx
testw $0x380, %dx             # imm = 0x380
je 0x7e79
leaq -0x1(%rsi), %rax
xorl %r9d, %r9d
xorl %ecx, %ecx
cmpq %rsi, %rcx
jge 0x7e76
movl (%rbx,%rcx,4), %r10d
cmpl $0xd, %r10d
sete %dil
cmpq %rax, %rcx
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x7dce
cmpl $0xa, 0x4(%rbx,%rcx,4)
jne 0x7df2
incq %rcx
jmp 0x7df2
cmpl $0xa, %r10d
je 0x7df2
cmpl $0xd, %r10d
je 0x7df2
cmpl $0x85, %r10d
je 0x7df2
btl $0x9, %edx
jae 0x7e2e
leal -0xb(%r10), %edi
cmpl $0x1, %edi
ja 0x7e2e
leaq 0x1(%r9), %rdi
testb %dl, %dl
js 0x7e0a
btl $0x8, %edx
jb 0x7e1a
movl $0x20, (%rbx,%r9,4)
jmp 0x7e6b
btl $0x8, %edx
jb 0x7e24
movl $0x2028, (%rbx,%r9,4)   # imm = 0x2028
jmp 0x7e6b
movl $0x2029, (%rbx,%r9,4)   # imm = 0x2029
jmp 0x7e6b
movl $0xa, (%rbx,%r9,4)
jmp 0x7e6b
btl $0x9, %edx
jae 0x7e61
cmpl $0x20, %r10d
setl %dil
leal -0x7f(%r10), %r8d
cmpl $0x21, %r8d
setb %r8b
orb %dil, %r8b
cmpb $0x1, %r8b
jne 0x7e61
cmpl $0x9, %r10d
jne 0x7e68
movl $0x20, (%rbx,%r9,4)
jmp 0x7e65
movl %r10d, (%rbx,%r9,4)
incq %r9
movq %r9, %rdi
incq %rcx
movq %rdi, %r9
jmp 0x7d9d
movq %r9, %rsi
testb $0x8, %dl
je 0x800d
movl %edx, 0x4(%rsp)
xorl %eax, %eax
testq %rsi, %rsi
cmovleq %rax, %rsi
movw $0xffff, %r15w          # imm = 0xFFFF
xorl %ebp, %ebp
movq $0x0, 0x18(%rsp)
xorl %eax, %eax
xorl %r8d, %r8d
movq %rsi, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
cmpq %rbp, %rsi
je 0x8004
movq %rax, 0x20(%rsp)
movl (%rbx,%rbp,4), %r12d
movl %r12d, %edi
movq %r8, %rbx
callq 0x765f
movq %rbx, %r8
movzwl 0x2(%rax), %r14d
testq %rbx, %rbx
je 0x7fb1
cmpw %r15w, %r14w
jle 0x7fb1
movq %rax, %r13
movl (%r8), %edi
leal -0x1176(%r12), %eax
cmpl $-0x15, %eax
jb 0x7f26
leal -0x1113(%rdi), %eax
cmpl $-0x13, %eax
jb 0x7f26
imull $0x15, %edi, %eax
addl %r12d, %eax
imull $0x1c, %eax, %eax
addl $0xffd7b964, %eax       # imm = 0xFFD7B964
movl %eax, (%r8)
xorl %eax, %eax
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rbx
jmp 0x7ffc
leal -0xac00(%rdi), %eax
cmpl $0x2ba3, %eax           # imm = 0x2BA3
ja 0x7f59
xorl %edx, %edx
movw $0x1c, %cx
divw %cx
leal -0x11c3(%r12), %eax
cmpl $-0x1c, %eax
jb 0x7f59
testw %dx, %dx
jne 0x7f59
leal (%r12,%rdi), %eax
addl $0xffffee59, %eax       # imm = 0xFFFFEE59
jmp 0x7f12
movq 0x20(%rsp), %rax
testq %rax, %rax
jne 0x7f6b
callq 0x765f
movq %rbx, %r8
movl 0x18(%rax), %edx
testl %edx, %edx
movq %rax, 0x20(%rsp)
js 0x7fb1
movl 0x1c(%r13), %ecx
testl %ecx, %ecx
js 0x7fb1
addl %edx, %ecx
leaq 0xeb408(%rip), %rax     # 0xf3390
movl (%rax,%rcx,4), %r13d
testl %r13d, %r13d
js 0x7fb1
testb $0x2, 0x4(%rsp)
je 0x7fa9
movl %r13d, %edi
callq 0x765f
movq %rbx, %r8
testb $0x2, 0x20(%rax)
jne 0x7fb1
movl %r13d, (%r8)
jmp 0x7f15
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rbx
leaq (%rbx,%rsi,4), %rcx
movl %r12d, (%rcx)
cmpw %r15w, %r14w
cmovgl %r14d, %r15d
cmpw $0x1, %r14w
movl $0x0, %edx
sbbl %edx, %edx
orl %r15d, %edx
testw %r14w, %r14w
movl $0x0, %eax
cmovneq 0x20(%rsp), %rax
cmoveq %rcx, %r8
incq %rsi
movq %rsi, 0x18(%rsp)
movl %edx, %r15d
movq 0x10(%rsp), %rsi
incq %rbp
jmp 0x7eae
movq 0x18(%rsp), %rsi
movl 0x4(%rsp), %edx
xorl %r15d, %r15d
testq %rsi, %rsi
cmovgq %rsi, %r15
btl $0xb, %edx
jb 0x8041
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpq %r12, %r15
je 0x815e
movl (%rbx,%r12,4), %edi
leaq (%rbx,%r14), %rsi
callq 0x75ae
addq %rax, %r14
incq %r12
jmp 0x8023
xorl %eax, %eax
pushq $0x1
popq %rcx
pushq $0x2
popq %rdx
pushq $0x3
popq %rsi
pushq $0x4
popq %rdi
xorl %r14d, %r14d
cmpq %rax, %r15
je 0x815e
movl (%rbx,%rax,4), %r8d
testl %r8d, %r8d
js 0x8150
cmpl $0x7f, %r8d
ja 0x807a
movb %r8b, (%rbx,%r14)
movq %rcx, %r8
jmp 0x8153
cmpl $0x7ff, %r8d            # imm = 0x7FF
ja 0x80a7
movl %r8d, %r9d
shrl $0x6, %r9d
orb $-0x40, %r9b
movb %r9b, (%rbx,%r14)
andb $0x3f, %r8b
orb $-0x80, %r8b
movb %r8b, 0x1(%rbx,%r14)
movq %rdx, %r8
jmp 0x8153
cmpl $0xfffe, %r8d           # imm = 0xFFFE
je 0x80c0
cmpl $0xffff, %r8d           # imm = 0xFFFF
jne 0x80c7
movb $-0x1, (%rbx,%r14)
jmp 0x8072
movb $-0x2, (%rbx,%r14)
jmp 0x8072
ja 0x80fe
movl %r8d, %r9d
shrl $0xc, %r9d
orb $-0x20, %r9b
movb %r9b, (%rbx,%r14)
movl %r8d, %r9d
shrl $0x6, %r9d
andb $0x3f, %r9b
orb $-0x80, %r9b
movb %r9b, 0x1(%rbx,%r14)
andb $0x3f, %r8b
orb $-0x80, %r8b
movb %r8b, 0x2(%rbx,%r14)
movq %rsi, %r8
jmp 0x8153
cmpl $0x10ffff, %r8d         # imm = 0x10FFFF
ja 0x8150
movl %r8d, %r9d
shrl $0x12, %r9d
orb $-0x10, %r9b
movb %r9b, (%rbx,%r14)
movl %r8d, %r9d
shrl $0xc, %r9d
andb $0x3f, %r9b
orb $-0x80, %r9b
movb %r9b, 0x1(%rbx,%r14)
movl %r8d, %r9d
shrl $0x6, %r9d
andb $0x3f, %r9b
orb $-0x80, %r9b
movb %r9b, 0x2(%rbx,%r14)
andb $0x3f, %r8b
orb $-0x80, %r8b
movb %r8b, 0x3(%rbx,%r14)
movq %rdi, %r8
jmp 0x8153
xorl %r8d, %r8d
addq %r8, %r14
incq %rax
jmp 0x8052
movb $0x0, (%rbx,%r14)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq