// File: /workspace/github_cpp_makefile_star2_O1/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), %r9b
xorl %eax, %eax
testb %r9b, %r9b
je 0x2e95
leal -0x1(%rdx), %ecx
xorl %r8d, %r8d
cmpl %ecx, %r8d
jge 0x2e9e
movzbl %r9b, %r10d
testb %r10b, %r10b
js 0x2c6f
incq %rsi
movslq %r8d, %r9
incl %r8d
movw %r10w, (%rdi,%r9,2)
jmp 0x2e86
movl %r10d, %r11d
andl $-0x20, %r11d
cmpl $0xc0, %r11d
jne 0x2cc5
cmpb $-0x3e, %r9b
jb 0x2e9e
movzbl 0x1(%rsi), %r9d
movl %r9d, %r11d
andl $-0x40, %r11d
cmpl $0x80, %r11d
jne 0x2e9e
andl $0x1f, %r10d
shll $0x6, %r10d
addq $0x2, %rsi
andl $0x3f, %r9d
orl %r10d, %r9d
movslq %r8d, %r10
incl %r8d
movw %r9w, (%rdi,%r10,2)
jmp 0x2e86
movl %r10d, %r11d
andl $-0x10, %r11d
cmpl $0xe0, %r11d
jne 0x2d64
cmpb $-0x13, %r9b
je 0x2d00
cmpl $0xe0, %r10d
jne 0x2d0a
movb 0x1(%rsi), %r11b
addb $0x40, %r11b
cmpb $-0x20, %r11b
jb 0x2e9e
cmpb $-0x13, %r9b
jne 0x2d0a
cmpb $-0x61, 0x1(%rsi)
ja 0x2e9e
movzbl 0x1(%rsi), %r9d
movl %r9d, %r11d
andl $-0x40, %r11d
cmpl $0x80, %r11d
jne 0x2e9e
movzbl 0x2(%rsi), %r11d
movl %r11d, %ebx
andl $-0x40, %ebx
cmpl $0x80, %ebx
jne 0x2e9e
shll $0xc, %r10d
andl $0x3f, %r9d
shll $0x6, %r9d
orl %r10d, %r9d
addq $0x3, %rsi
andl $0x3f, %r11d
orl %r9d, %r11d
movslq %r8d, %r9
incl %r8d
movw %r11w, (%rdi,%r9,2)
jmp 0x2e86
cmpb $-0xc, %r9b
ja 0x2e9e
movl %r10d, %r11d
andl $-0x8, %r11d
cmpl $0xf0, %r11d
jne 0x2e9e
cmpb $-0xc, %r9b
je 0x2da9
cmpl $0xf0, %r10d
jne 0x2db3
movb 0x1(%rsi), %r10b
addb $0x40, %r10b
cmpb $-0x30, %r10b
jb 0x2e9e
cmpb $-0xc, %r9b
jne 0x2db3
cmpb $-0x71, 0x1(%rsi)
ja 0x2e9e
movzbl 0x1(%rsi), %ebx
movl %ebx, %r10d
andl $-0x40, %r10d
cmpl $0x80, %r10d
jne 0x2e9e
movzbl 0x2(%rsi), %r10d
movl %r10d, %r11d
andl $-0x40, %r11d
cmpl $0x80, %r11d
jne 0x2e9e
movzbl 0x3(%rsi), %r11d
movl %r11d, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x2e9e
andb $0x7, %r9b
movzbl %r9b, %r9d
shll $0x12, %r9d
andl $0x3f, %ebx
shll $0xc, %ebx
orl %r9d, %ebx
shll $0x6, %r10d
movl %r10d, %r9d
andl $0xfc0, %r9d            # imm = 0xFC0
orl %ebx, %r9d
movl %r9d, %ebp
andl $0x1ff800, %ebp         # imm = 0x1FF800
cmpl $0xd800, %ebp           # imm = 0xD800
je 0x2e9e
addq $0x4, %rsi
cmpl $0x10000, %ebx          # imm = 0x10000
jb 0x2e86
leal 0x2(%r8), %ebx
cmpl %edx, %ebx
jge 0x2e9e
andl $0x3f, %r11d
addl $0xf0000, %r9d          # imm = 0xF0000
shrl $0xa, %r9d
andl $0x3ff, %r9d            # imm = 0x3FF
orl $0xd800, %r9d           # imm = 0xD800
movslq %r8d, %r8
movw %r9w, (%rdi,%r8,2)
andl $0x3c0, %r10d           # imm = 0x3C0
leal (%r11,%r10), %r9d
addl $0xdc00, %r9d           # imm = 0xDC00
movw %r9w, 0x2(%rdi,%r8,2)
movl %ebx, %r8d
movb (%rsi), %r9b
testb %r9b, %r9b
jne 0x2c4a
movslq %r8d, %rax
movw $0x0, (%rdi,%rax,2)
movq %rdi, %rax
popq %rbx
popq %rbp
retq