// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movq %rdx, %rbx
movq %rsi, 0x18(%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
je 0x7c2e
pushq $-0x5
jmp 0x7ce6
movl %r8d, %ebp
movq %rdi, %r13
movl %edx, 0x20(%rsp)
leaq 0x24(%rsp), %rax
andl $0x0, (%rax)
xorl %r15d, %r15d
xorl %r14d, %r14d
testb $0x1, %bpl
jne 0x7c78
movq 0x18(%rsp), %rsi
subq %r15, %rsi
jle 0x7cfa
leaq (%r15,%r13), %rdi
leaq 0xc(%rsp), %rdx
callq 0x743e
movl 0xc(%rsp), %edi
testl %edi, %edi
js 0x7ce4
movq %rax, %r12
addq %r15, %r12
jmp 0x7c9d
leaq (%r15,%r13), %rdi
pushq $-0x1
popq %rsi
leaq 0xc(%rsp), %rdx
callq 0x743e
movl 0xc(%rsp), %edi
testl %edi, %edi
js 0x7ce4
movq %rax, %r12
addq %r15, %r12
js 0x7ce0
testl %edi, %edi
je 0x7cfa
leaq (%rbx,%r14,4), %rsi
movq 0x10(%rsp), %rdx
subq %r14, %rdx
movl $0x0, %eax
cmovleq %rax, %rdx
movl %ebp, %ecx
leaq 0x24(%rsp), %r8
callq 0x7795
testq %rax, %rax
js 0x7d70
addq %rax, %r14
movq %r12, %r15
movabsq $0x1000000000000000, %rax # imm = 0x1000000000000000
cmpq %rax, %r14
jl 0x7c46
pushq $-0x2
jmp 0x7ce6
pushq $-0x3
popq %r14
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x20(%rsp)
je 0x7ce8
cmpq %r14, 0x10(%rsp)
jl 0x7ce8
movq %rbx, 0x10(%rsp)
leaq -0x1(%r14), %rax
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
cmpq 0x18(%rsp), %rbx
jge 0x7ce8
movq %rbx, %r13
movq 0x10(%rsp), %rax
movl (%rax,%rbx,4), %ebp
movl 0x4(%rax,%rbx,4), %r15d
incq %rbx
movl %ebp, %edi
callq 0x765f
movq %rax, %r12
movl %r15d, %edi
callq 0x765f
movzwl 0x2(%rax), %eax
cmpw %ax, 0x2(%r12)
jle 0x7d18
testw %ax, %ax
jle 0x7d18
movq 0x10(%rsp), %rax
movl %r15d, (%rax,%r13,4)
movl %ebp, 0x4(%rax,%r13,4)
leaq -0x1(%r13), %rax
testq %r13, %r13
cmovgq %rax, %rbx
jmp 0x7d18
movq %rax, %r14
jmp 0x7ce8