// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rcx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movl %r8d, %eax
notl %eax
testb $0x18, %al
sete %al
movl %r8d, %ecx
andl $0x2018, %ecx           # imm = 0x2018
cmpl $0x2000, %ecx           # imm = 0x2000
sete %cl
orb %al, %cl
movq $-0x5, %rax
jne 0x8adb
movl %r8d, %ebp
movq %rdx, %rbx
movq %rdi, %r12
leaq 0x4(%rsp), %rax
movl $0x0, (%rax)
xorl %r14d, %r14d
xorl %r15d, %r15d
testb $0x1, %bpl
jne 0x8995
movq 0x10(%rsp), %rsi
subq %r14, %rsi
jle 0x8a10
leaq (%r12,%r14), %rdi
movq %rsp, %rdx
callq 0x7f62
cmpl $0x0, (%rsp)
js 0x8a04
movq %rax, %r13
addq %r14, %r13
jmp 0x89bb
leaq (%r12,%r14), %rdi
movq $-0x1, %rsi
movq %rsp, %rdx
callq 0x7f62
movq %rax, %r13
movl (%rsp), %eax
testl %eax, %eax
js 0x8a04
addq %r14, %r13
js 0x89fb
testl %eax, %eax
je 0x8a10
movl (%rsp), %edi
leaq (%rbx,%r15,4), %rsi
xorl %r14d, %r14d
movq 0x8(%rsp), %rdx
subq %r15, %rdx
cmovleq %r14, %rdx
movl %ebp, %ecx
leaq 0x4(%rsp), %r8
callq 0x845d
testq %rax, %rax
js 0x8a13
addq %rax, %r15
movq %r13, %r14
movabsq $0x1000000000000000, %rax # imm = 0x1000000000000000
cmpq %rax, %r15
jl 0x8967
movq $-0x2, %rax
jmp 0x8a0b
movq $-0x3, %rax
xorl %r14d, %r14d
jmp 0x8a13
movb $0x1, %r14b
testb %r14b, %r14b
je 0x8adb
testb $0x18, %bpl
je 0x8ad8
cmpq 0x8(%rsp), %r15
jg 0x8ad8
cmpq $0x2, %r15
jl 0x8ad8
leaq -0x1(%r15), %rax
xorl %r9d, %r9d
leaq 0x9c797(%rip), %rcx     # 0xa51e0
movl $0xff, %edx
leaq 0x9e98b(%rip), %rsi     # 0xa73e0
leaq 0xb0f84(%rip), %rdi     # 0xb99e0
movl (%rbx,%r9,4), %r10d
movl 0x4(%rbx,%r9,4), %r11d
leaq 0x1(%r9), %r8
movl %r10d, %ebp
sarl $0x8, %ebp
movslq %ebp, %r14
movzwl (%rcx,%r14,2), %ebp
movl %r10d, %r14d
andl %edx, %r14d
addl %ebp, %r14d
movzwl (%rsi,%r14,2), %r14d
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 (%r14,%r14,8), %r14
leaq (%r12,%r12,8), %r12
movzwl 0x2(%rdi,%r12,4), %ebp
cmpw %bp, 0x2(%rdi,%r14,4)
jle 0x8ad0
testw %bp, %bp
jle 0x8ad0
movl %r11d, (%rbx,%r9,4)
movl %r10d, 0x4(%rbx,%r9,4)
leaq -0x1(%r9), %r10
testq %r9, %r9
cmovgq %r10, %r8
movq %r8, %r9
cmpq %rax, %r8
jl 0x8a5c
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq