// File: /workspace/github_c_makefile_star2_O3/michaelnmmeyer[P]gourgandine/src/lib/utf8proc.c
// Function: utf8proc_decompose
UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose(
  const utf8proc_uint8_t *str, utf8proc_ssize_t strlen,
  utf8proc_int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options
) {
  /* strlen will be ignored, if UTF8PROC_NULLTERM is set in options */
  utf8proc_ssize_t wpos = 0;
  if ((options & UTF8PROC_COMPOSE) && (options & UTF8PROC_DECOMPOSE))
    return UTF8PROC_ERROR_INVALIDOPTS;
  if ((options & UTF8PROC_STRIPMARK) &&
      !(options & UTF8PROC_COMPOSE) && !(options & UTF8PROC_DECOMPOSE))
    return UTF8PROC_ERROR_INVALIDOPTS;
  {
    utf8proc_int32_t uc;
    utf8proc_ssize_t rpos = 0;
    utf8proc_ssize_t decomp_result;
    int boundclass = UTF8PROC_BOUNDCLASS_START;
    while (1) {
      if (options & UTF8PROC_NULLTERM) {
        rpos += utf8proc_iterate(str + rpos, -1, &uc);
        /* checking of return value is not necessary,
           as 'uc' is < 0 in case of error */
        if (uc < 0) return UTF8PROC_ERROR_INVALIDUTF8;
        if (rpos < 0) return UTF8PROC_ERROR_OVERFLOW;
        if (uc == 0) break;
      } else {
        if (rpos >= strlen) break;
        rpos += utf8proc_iterate(str + rpos, strlen - rpos, &uc);
        if (uc < 0) return UTF8PROC_ERROR_INVALIDUTF8;
      }
      decomp_result = utf8proc_decompose_char(
        uc, buffer + wpos, (bufsize > wpos) ? (bufsize - wpos) : 0, options,
        &boundclass
      );
      if (decomp_result < 0) return decomp_result;
      wpos += decomp_result;
      /* prohibiting integer overflows due to too long strings: */
      if (wpos < 0 ||
          wpos > (utf8proc_ssize_t)(SSIZE_MAX/sizeof(utf8proc_int32_t)/2))
        return UTF8PROC_ERROR_OVERFLOW;
    }
  }
  if ((options & (UTF8PROC_COMPOSE|UTF8PROC_DECOMPOSE)) && bufsize >= wpos) {
    utf8proc_ssize_t pos = 0;
    while (pos < wpos-1) {
      utf8proc_int32_t uc1, uc2;
      const utf8proc_property_t *property1, *property2;
      uc1 = buffer[pos];
      uc2 = buffer[pos+1];
      property1 = unsafe_get_property(uc1);
      property2 = unsafe_get_property(uc2);
      if (property1->combining_class > property2->combining_class &&
          property2->combining_class > 0) {
        buffer[pos] = uc2;
        buffer[pos+1] = uc1;
        if (pos > 0) pos--; else pos++;
      } else {
        pos++;
      }
    }
  }
  return wpos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, %r14
movq %rsi, 0x20(%rsp)
movl %r8d, %edx
andl $0x18, %edx
cmpl $0x18, %edx
sete %al
movl %r8d, %ecx
andl $0x2018, %ecx           # imm = 0x2018
cmpl $0x2000, %ecx           # imm = 0x2000
sete %cl
orb %al, %cl
movq $-0x5, %rbx
jne 0x8825
movl %r8d, %ebp
movq %rdi, %r13
movl %edx, 0x10(%rsp)
leaq 0x14(%rsp), %rax
movl $0x0, (%rax)
xorl %r15d, %r15d
xorl %ebx, %ebx
testb $0x1, %bpl
jne 0x86df
movq 0x20(%rsp), %rsi
subq %r15, %rsi
jle 0x8763
leaq (%r15,%r13), %rdi
leaq 0xc(%rsp), %rdx
callq 0x7be6
movl 0xc(%rsp), %edi
testl %edi, %edi
js 0x8757
movq %rax, %r12
addq %r15, %r12
jmp 0x8708
leaq (%r15,%r13), %rdi
movq $-0x1, %rsi
leaq 0xc(%rsp), %rdx
callq 0x7be6
movl 0xc(%rsp), %edi
testl %edi, %edi
js 0x8757
movq %rax, %r12
addq %r15, %r12
js 0x874b
testl %edi, %edi
je 0x8763
leaq (%r14,%rbx,4), %rsi
movq 0x18(%rsp), %rdx
subq %rbx, %rdx
movl $0x0, %eax
cmovleq %rax, %rdx
movl %ebp, %ecx
leaq 0x14(%rsp), %r8
callq 0x80d9
testq %rax, %rax
js 0x8822
addq %rax, %rbx
movq %r12, %r15
movabsq $0x1000000000000000, %rax # imm = 0x1000000000000000
cmpq %rax, %rbx
jl 0x86a9
movq $-0x2, %rbx
jmp 0x8825
movq $-0x3, %rbx
jmp 0x8825
cmpl $0x0, 0x10(%rsp)
je 0x8825
cmpq %rbx, 0x18(%rsp)
jl 0x8825
cmpq $0x2, %rbx
jl 0x8825
leaq -0x1(%rbx), %rax
xorl %r9d, %r9d
leaq 0x9ba4f(%rip), %rcx     # 0xa41e0
movl $0xff, %edx
leaq 0x9dc43(%rip), %rsi     # 0xa63e0
leaq 0xb023c(%rip), %rdi     # 0xb89e0
movl (%r14,%r9,4), %r10d
movl 0x4(%r14,%r9,4), %r11d
leaq 0x1(%r9), %r8
movl %r10d, %ebp
sarl $0x8, %ebp
movslq %ebp, %r15
movzwl (%rcx,%r15,2), %ebp
movl %r10d, %r15d
andl %edx, %r15d
addl %ebp, %r15d
movzwl (%rsi,%r15,2), %r15d
movl %r11d, %ebp
sarl $0x8, %ebp
movslq %ebp, %r12
movzwl (%rcx,%r12,2), %ebp
movl %r11d, %r12d
andl %edx, %r12d
addl %ebp, %r12d
movzwl (%rsi,%r12,2), %r12d
leaq (%r15,%r15,8), %r15
leaq (%r12,%r12,8), %r12
movzwl 0x2(%rdi,%r12,4), %ebp
cmpw %bp, 0x2(%rdi,%r15,4)
jle 0x8818
testw %bp, %bp
jle 0x8818
movl %r11d, (%r14,%r9,4)
movl %r10d, 0x4(%r14,%r9,4)
leaq -0x1(%r9), %r10
testq %r9, %r9
cmovgq %r10, %r8
movq %r8, %r9
cmpq %rax, %r8
jl 0x87a4
jmp 0x8825
movq %rax, %rbx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq