// File: /workspace/github_c_makefile_star2_O3/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:
movzbl (%rdi), %r9d
testb %r9b, %r9b
js 0x1d3c
testl %esi, %esi
jle 0x1d7d
movl %r9d, %ecx
movl $0x1, %esi
movq %rcx, (%rdx)
movl %esi, %eax
retq
leaq 0x1(%rdi), %r8
movl %r9d, %eax
andl $-0x20, %eax
cmpl $0xc0, %eax
jne 0x1d83
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x2, %esi
jl 0x1d3b
movzbl (%r8), %ecx
movl %ecx, %esi
andl $-0x40, %esi
cmpl $0x80, %esi
jne 0x1d3b
andl $0x1f, %r9d
shll $0x6, %r9d
andl $0x3f, %ecx
orl %r9d, %ecx
movl $0x2, %esi
jmp 0x1d36
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
retq
movl %r9d, %eax
andl $-0x10, %eax
cmpl $0xe0, %eax
jne 0x1de0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x3, %esi
jl 0x1d3b
andl $0xf, %r9d
movb $0x1, %sil
movq %r9, %rcx
movzbl (%r8), %edi
movl %edi, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x1d3b
incq %r8
movq %rcx, %r9
shlq $0x6, %r9
andl $0x3f, %edi
movq %rdi, %rcx
orq %r9, %rcx
testb $0x1, %sil
movl $0x0, %esi
jne 0x1da4
movl $0x3, %esi
jmp 0x1d36
movl %r9d, %eax
andl $-0x8, %eax
cmpl $0xf0, %eax
jne 0x1e3e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x4, %esi
jl 0x1d3b
andl $0x7, %r9d
movl $0x1, %r8d
movq %r9, %rcx
movzbl (%rdi,%r8), %esi
movl %esi, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x1d3b
shlq $0x6, %rcx
andl $0x3f, %esi
orq %rsi, %rcx
incq %r8
movl $0x4, %esi
cmpl $0x4, %r8d
jne 0x1e08
jmp 0x1d36
movl %r9d, %eax
andl $-0x4, %eax
cmpl $0xf8, %eax
jne 0x1e97
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x5, %esi
jl 0x1d3b
andl $0x3, %r9d
xorl %edi, %edi
movq %r9, %rcx
movzbl (%r8,%rdi), %esi
movl %esi, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x1d3b
shlq $0x6, %rcx
andl $0x3f, %esi
orq %rsi, %rcx
incq %rdi
movl $0x5, %esi
cmpl $0x4, %edi
jne 0x1e62
jmp 0x1d36
movl %r9d, %eax
andl $-0x2, %eax
cmpl $0xfc, %eax
setne %al
cmpl $0x6, %esi
setl %cl
orb %al, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0x1d3b
andl $0x1, %r9d
movl $0x1, %r8d
movq %r9, %rcx
movzbl (%rdi,%r8), %esi
movl %esi, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x1d3b
shlq $0x6, %rcx
andl $0x3f, %esi
orq %rsi, %rcx
incq %r8
movl $0x6, %esi
cmpl $0x6, %r8d
jne 0x1ec5
jmp 0x1d36