// File: /workspace/github_c_makefile_star2_O1/cktan[P]tomlc99/toml.c
// Function: toml_utf8_to_ucs
int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret) {
  const unsigned char *buf = (const unsigned char *)orig;
  unsigned i = *buf++;
  int64_t v;

  /* 0x00000000 - 0x0000007F:
     0xxxxxxx
  */
  if (0 == (i >> 7)) {
    if (len < 1)
      return -1;
    v = i;
    return *ret = v, 1;
  }
  /* 0x00000080 - 0x000007FF:
     110xxxxx 10xxxxxx
  */
  if (0x6 == (i >> 5)) {
    if (len < 2)
      return -1;
    v = i & 0x1f;
    for (int j = 0; j < 1; j++) {
      i = *buf++;
      if (0x2 != (i >> 6))
        return -1;
      v = (v << 6) | (i & 0x3f);
    }
    return *ret = v, (const char *)buf - orig;
  }

  /* 0x00000800 - 0x0000FFFF:
     1110xxxx 10xxxxxx 10xxxxxx
  */
  if (0xE == (i >> 4)) {
    if (len < 3)
      return -1;
    v = i & 0x0F;
    for (int j = 0; j < 2; j++) {
      i = *buf++;
      if (0x2 != (i >> 6))
        return -1;
      v = (v << 6) | (i & 0x3f);
    }
    return *ret = v, (const char *)buf - orig;
  }

  /* 0x00010000 - 0x001FFFFF:
     11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  */
  if (0x1E == (i >> 3)) {
    if (len < 4)
      return -1;
    v = i & 0x07;
    for (int j = 0; j < 3; j++) {
      i = *buf++;
      if (0x2 != (i >> 6))
        return -1;
      v = (v << 6) | (i & 0x3f);
    }
    return *ret = v, (const char *)buf - orig;
  }

  /* 0x00200000 - 0x03FFFFFF:
     111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  */
  if (0x3E == (i >> 2)) {
    if (len < 5)
      return -1;
    v = i & 0x03;
    for (int j = 0; j < 4; j++) {
      i = *buf++;
      if (0x2 != (i >> 6))
        return -1;
      v = (v << 6) | (i & 0x3f);
    }
    return *ret = v, (const char *)buf - orig;
  }

  /* 0x04000000 - 0x7FFFFFFF:
     1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  */
  if (0x7e == (i >> 1)) {
    if (len < 6)
      return -1;
    v = i & 0x01;
    for (int j = 0; j < 5; j++) {
      i = *buf++;
      if (0x2 != (i >> 6))
        return -1;
      v = (v << 6) | (i & 0x3f);
    }
    return *ret = v, (const char *)buf - orig;
  }
  return -1;
}

// Assembly:
pushq %rbx
movzbl (%rdi), %ecx
testb %cl, %cl
js 0x1d6d
testl %esi, %esi
jle 0x1da9
movl %ecx, %eax
movq %rax, (%rdx)
movl $0x1, %eax
jmp 0x1dae
movl %ecx, %eax
andl $-0x20, %eax
cmpl $0xc0, %eax
jne 0x1db0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x2, %esi
jl 0x1dae
movzbl 0x1(%rdi), %esi
movl %esi, %edi
andl $-0x40, %edi
cmpl $0x80, %edi
jne 0x1dae
andl $0x1f, %ecx
shll $0x6, %ecx
andl $0x3f, %esi
orl %ecx, %esi
movq %rsi, (%rdx)
movl $0x2, %eax
jmp 0x1dae
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
retq
movl %ecx, %eax
andl $-0x10, %eax
cmpl $0xe0, %eax
jne 0x1e28
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x3, %esi
jl 0x1dae
andl $0xf, %ecx
leaq 0x2(%rdi), %rsi
movzbl 0x1(%rdi), %r10d
movl %r10d, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0x1f24
leaq 0x3(%rdi), %r9
xorl %r11d, %r11d
movl %r11d, %r8d
movq %rcx, %r11
shlq $0x6, %r11
andl $0x3f, %r10d
movq %r10, %rcx
orq %r11, %rcx
testb $0x1, %r8b
jne 0x1fac
movzbl (%rsi), %r10d
incq %rsi
movl %r10d, %ebx
andl $-0x40, %ebx
movb $0x1, %r11b
cmpl $0x80, %ebx
je 0x1ded
jmp 0x1faf
movl %ecx, %eax
andl $-0x8, %eax
cmpl $0xf0, %eax
jne 0x1ea6
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x4, %esi
jl 0x1dae
andl $0x7, %ecx
leaq 0x2(%rdi), %rsi
movzbl 0x1(%rdi), %r10d
movl %r10d, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0x1fa7
leaq 0x4(%rdi), %r9
xorl %r11d, %r11d
movq %r11, %r8
movq %rcx, %r11
shlq $0x6, %r11
andl $0x3f, %r10d
movq %r10, %rcx
orq %r11, %rcx
cmpl $0x2, %r8d
je 0x1fbb
movzbl (%rsi,%r8), %r10d
movl %r10d, %ebx
andl $-0x40, %ebx
leaq 0x1(%r8), %r11
cmpl $0x80, %ebx
je 0x1e69
addq %r11, %rsi
jmp 0x1fbe
movl %ecx, %eax
andl $-0x4, %eax
cmpl $0xf8, %eax
jne 0x1f2c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x5, %esi
jl 0x1dae
andl $0x3, %ecx
leaq 0x2(%rdi), %rsi
movzbl 0x1(%rdi), %r10d
movl %r10d, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0x1fa7
leaq 0x5(%rdi), %r9
xorl %r11d, %r11d
movq %r11, %r8
movq %rcx, %r11
shlq $0x6, %r11
andl $0x3f, %r10d
movq %r10, %rcx
orq %r11, %rcx
cmpl $0x3, %r8d
je 0x1fc4
movzbl (%rsi,%r8), %r10d
movl %r10d, %ebx
andl $-0x40, %ebx
leaq 0x1(%r8), %r11
cmpl $0x80, %ebx
je 0x1ee7
addq %r11, %rsi
jmp 0x1fc7
xorl %r8d, %r8d
jmp 0x1faf
movl %ecx, %eax
andl $-0x2, %eax
cmpl $0xfc, %eax
setne %al
cmpl $0x6, %esi
setl %sil
orb %al, %sil
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0x1dae
andl $0x1, %ecx
leaq 0x2(%rdi), %rsi
movzbl 0x1(%rdi), %r10d
movl %r10d, %r8d
andl $-0x40, %r8d
cmpl $0x80, %r8d
jne 0x1fa7
leaq 0x6(%rdi), %r9
xorl %r11d, %r11d
movq %r11, %r8
movq %rcx, %r11
shlq $0x6, %r11
andl $0x3f, %r10d
movq %r10, %rcx
orq %r11, %rcx
cmpl $0x4, %r8d
je 0x1fcd
movzbl (%rsi,%r8), %r10d
movl %r10d, %ebx
andl $-0x40, %ebx
leaq 0x1(%r8), %r11
cmpl $0x80, %ebx
je 0x1f71
addq %r11, %rsi
jmp 0x1fd0
xorl %r8d, %r8d
jmp 0x1fd8
movq %r9, %rsi
testb $0x1, %r8b
je 0x1dae
jmp 0x1fe1
movq %r9, %rsi
cmpl $0x2, %r8d
jmp 0x1fd4
movq %r9, %rsi
cmpl $0x3, %r8d
jmp 0x1fd4
movq %r9, %rsi
cmpl $0x4, %r8d
setae %r8b
testb %r8b, %r8b
je 0x1dae
movq %rcx, (%rdx)
subl %edi, %esi
movl %esi, %eax
jmp 0x1dae