// File: /workspace/github_cpp_makefile_star2_O2/attractivechaos[P]udb2/stb/./stb.h
// Function: stb_from_utf8
stb__wchar * stb_from_utf8(stb__wchar *buffer, char *ostr, int n)
{
   unsigned char *str = (unsigned char *) ostr;
   stb_uint32 c;
   int i=0;
   --n;
   while (*str) {
      if (i >= n)
         return NULL;
      if (!(*str & 0x80))
         buffer[i++] = *str++;
      else if ((*str & 0xe0) == 0xc0) {
         if (*str < 0xc2) return NULL;
         c = (*str++ & 0x1f) << 6;
         if ((*str & 0xc0) != 0x80) return NULL;
         buffer[i++] = c + (*str++ & 0x3f);
      } else if ((*str & 0xf0) == 0xe0) {
         if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return NULL;
         if (*str == 0xed && str[1] > 0x9f) return NULL; // str[1] < 0x80 is checked below
         c = (*str++ & 0x0f) << 12;
         if ((*str & 0xc0) != 0x80) return NULL;
         c += (*str++ & 0x3f) << 6;
         if ((*str & 0xc0) != 0x80) return NULL;
         buffer[i++] = c + (*str++ & 0x3f);
      } else if ((*str & 0xf8) == 0xf0) {
         if (*str > 0xf4) return NULL;
         if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return NULL;
         if (*str == 0xf4 && str[1] > 0x8f) return NULL; // str[1] < 0x80 is checked below
         c = (*str++ & 0x07) << 18;
         if ((*str & 0xc0) != 0x80) return NULL;
         c += (*str++ & 0x3f) << 12;
         if ((*str & 0xc0) != 0x80) return NULL;
         c += (*str++ & 0x3f) << 6;
         if ((*str & 0xc0) != 0x80) return NULL;
         c += (*str++ & 0x3f);
         // utf-8 encodings of values used in surrogate pairs are invalid
         if ((c & 0xFFFFF800) == 0xD800) return NULL;
         if (c >= 0x10000) {
            c -= 0x10000;
            if (i + 2 > n) return NULL;
            buffer[i++] = 0xD800 | (0x3ff & (c >> 10));
            buffer[i++] = 0xDC00 | (0x3ff & (c      ));
         }
      } else
         return NULL;
   }
   buffer[i] = 0;
   return buffer;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
leal -0x1(%rdx), %ecx
xorl %eax, %eax
xorl %r8d, %r8d
incq %rsi
movzbl -0x1(%rsi), %r11d
movslq %r8d, %r9
testw %r11w, %r11w
je 0x2ced
cmpl %ecx, %r8d
jge 0x2cf6
testb %r11b, %r11b
jns 0x2c74
movzwl %r11w, %r10d
movl %r10d, %ebx
andl $-0x20, %ebx
cmpl $0xc0, %ebx
je 0x2c42
movl %r10d, %r11d
andl $-0x10, %r11d
cmpl $0xe0, %r11d
je 0x2c81
cmpb $-0xc, %r10b
ja 0x2cf6
movl %r10d, %r11d
andl $-0x8, %r11d
cmpl $0xf0, %r11d
jne 0x2cf6
movzbl (%rsi), %ebx
cmpl $0xf4, %r10d
je 0x2b61
cmpl $0xf0, %r10d
jne 0x2b6a
leal 0x40(%rbx), %r11d
cmpb $-0x30, %r11b
jae 0x2b6a
jmp 0x2cf6
cmpb $-0x71, %bl
ja 0x2cf6
movl %ebx, %r11d
andl $-0x40, %r11d
cmpl $0x80, %r11d
jne 0x2cf6
movzbl 0x1(%rsi), %r11d
movl %r11d, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x2cf6
movzbl 0x2(%rsi), %r14d
movl %r14d, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x2cf6
andl $0x7, %r10d
shll $0x12, %r10d
andl $0x3f, %ebx
shll $0xc, %ebx
orl %r10d, %ebx
shll $0x6, %r11d
movl %r11d, %r10d
andl $0xfc0, %r10d           # imm = 0xFC0
orl %ebx, %r10d
movl %r10d, %ebp
andl $0x1ff800, %ebp         # imm = 0x1FF800
cmpl $0xd800, %ebp           # imm = 0xD800
je 0x2cf6
addq $0x4, %rsi
cmpl $0x10000, %ebx          # imm = 0x10000
jb 0x2ad1
addl $0x2, %r8d
cmpl %edx, %r8d
jge 0x2cf6
andl $0x3f, %r14d
decq %rsi
addl $0xf0000, %r10d         # imm = 0xF0000
shrl $0xa, %r10d
andl $0x3ff, %r10d           # imm = 0x3FF
orl $0xd800, %r10d          # imm = 0xD800
movw %r10w, (%rdi,%r9,2)
andl $0x3c0, %r11d           # imm = 0x3C0
leal (%r14,%r11), %r10d
addl $0xdc00, %r10d          # imm = 0xDC00
movw %r10w, 0x2(%rdi,%r9,2)
jmp 0x2ace
cmpb $-0x3e, %r11b
jb 0x2cf6
movzbl (%rsi), %r11d
movl %r11d, %ebx
andl $-0x40, %ebx
cmpl $0x80, %ebx
jne 0x2cf6
andl $0x1f, %r10d
shll $0x6, %r10d
incq %rsi
andl $0x3f, %r11d
orl %r10d, %r11d
incl %r8d
movw %r11w, (%rdi,%r9,2)
jmp 0x2ace
movzbl (%rsi), %r11d
cmpl $0xed, %r10d
je 0x2ca2
cmpl $0xe0, %r10d
jne 0x2ca8
leal 0x40(%r11), %ebx
cmpb $-0x20, %bl
jae 0x2ca8
jmp 0x2cf6
cmpb $-0x61, %r11b
ja 0x2cf6
movl %r11d, %ebx
andl $-0x40, %ebx
cmpl $0x80, %ebx
jne 0x2cf6
movzbl 0x1(%rsi), %ebx
movl %ebx, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x2cf6
shll $0xc, %r10d
andl $0x3f, %r11d
shll $0x6, %r11d
orl %r10d, %r11d
addq $0x2, %rsi
andl $0x3f, %ebx
orl %r11d, %ebx
incl %r8d
movw %bx, (%rdi,%r9,2)
jmp 0x2ace
andw $0x0, (%rdi,%r9,2)
movq %rdi, %rax
popq %rbx
popq %r14
popq %rbp
retq