// File: /workspace/github_cpp_makefile_star2_O3/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 %rbx
movb (%rsi), %r10b
xorl %eax, %eax
testb %r10b, %r10b
je 0x2e74
leal -0x1(%rdx), %ecx
xorl %r8d, %r8d
cmpl %ecx, %r8d
jge 0x2e7d
movzbl %r10b, %r9d
testb %r9b, %r9b
js 0x2c5f
incq %rsi
movslq %r8d, %r10
incl %r8d
movw %r9w, (%rdi,%r10,2)
jmp 0x2d80
movl %r9d, %r11d
andl $-0x20, %r11d
cmpl $0xc0, %r11d
jne 0x2caa
cmpb $-0x3e, %r10b
jb 0x2e7d
movzbl 0x1(%rsi), %r10d
movl %r10d, %r11d
andl $-0x40, %r11d
cmpl $0x80, %r11d
jne 0x2e7d
andl $0x1f, %r9d
shll $0x6, %r9d
addq $0x2, %rsi
andl $0x3f, %r10d
orl %r9d, %r10d
jmp 0x2d75
movl %r9d, %r11d
andl $-0x10, %r11d
cmpl $0xe0, %r11d
jne 0x2cdd
movzbl 0x1(%rsi), %r11d
cmpb $-0x13, %r10b
je 0x2d26
cmpl $0xe0, %r9d
jne 0x2d30
leal 0x40(%r11), %r10d
cmpb $-0x20, %r10b
jae 0x2d30
jmp 0x2e7d
cmpb $-0xc, %r10b
ja 0x2e7d
movl %r9d, %r11d
andl $-0x8, %r11d
cmpl $0xf0, %r11d
jne 0x2e7d
movzbl 0x1(%rsi), %r11d
cmpb $-0xc, %r10b
je 0x2d91
cmpl $0xf0, %r9d
jne 0x2d9b
leal 0x40(%r11), %r9d
cmpb $-0x30, %r9b
jae 0x2d9b
jmp 0x2e7d
cmpb $-0x61, %r11b
ja 0x2e7d
movl %r11d, %r10d
andl $-0x40, %r10d
cmpl $0x80, %r10d
jne 0x2e7d
movzbl 0x2(%rsi), %r10d
movl %r10d, %ebx
andl $-0x40, %ebx
cmpl $0x80, %ebx
jne 0x2e7d
shll $0xc, %r9d
andl $0x3f, %r11d
shll $0x6, %r11d
orl %r9d, %r11d
addq $0x3, %rsi
andl $0x3f, %r10d
orl %r11d, %r10d
movslq %r8d, %r9
incl %r8d
movw %r10w, (%rdi,%r9,2)
movb (%rsi), %r10b
testb %r10b, %r10b
jne 0x2c3a
jmp 0x2e71
cmpb $-0x71, %r11b
ja 0x2e7d
movl %r11d, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x2e7d
movzbl 0x2(%rsi), %r9d
movl %r9d, %ebx
andl $-0x40, %ebx
cmpl $0x80, %ebx
jne 0x2e7d
movzbl 0x3(%rsi), %ebx
movl %ebx, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x2e7d
andb $0x7, %r10b
movzbl %r10b, %r10d
shll $0x12, %r10d
andl $0x3f, %r11d
shll $0xc, %r11d
orl %r10d, %r11d
shll $0x6, %r9d
movl %r9d, %r10d
andl $0xfc0, %r10d           # imm = 0xFC0
orl %r11d, %r10d
movl %r10d, %ebp
andl $0x1ff800, %ebp         # imm = 0x1FF800
cmpl $0xd800, %ebp           # imm = 0xD800
je 0x2e7d
addq $0x4, %rsi
cmpl $0x10000, %r11d         # imm = 0x10000
jb 0x2d80
leal 0x2(%r8), %r11d
cmpl %edx, %r11d
jge 0x2e7d
andl $0x3f, %ebx
addl $0xf0000, %r10d         # imm = 0xF0000
shrl $0xa, %r10d
andl $0x3ff, %r10d           # imm = 0x3FF
orl $0xd800, %r10d          # imm = 0xD800
movslq %r8d, %r8
movw %r10w, (%rdi,%r8,2)
andl $0x3c0, %r9d            # imm = 0x3C0
addl %ebx, %r9d
addl $0xdc00, %r9d           # imm = 0xDC00
movw %r9w, 0x2(%rdi,%r8,2)
movl %r11d, %r8d
jmp 0x2d80
movslq %r8d, %rax
movw $0x0, (%rdi,%rax,2)
movq %rdi, %rax
popq %rbx
popq %rbp
retq