// File: /workspace/github_c_makefile_star2_O0/cktan[P]tomlc99/toml.c
// Function: toml_ucs_to_utf8
int toml_ucs_to_utf8(int64_t code, char buf[6]) {
  /* http://stackoverflow.com/questions/6240055/manually-converting-unicode-codepoints-into-utf-8-and-utf-16
   */
  /* The UCS code values 0xd800–0xdfff (UTF-16 surrogates) as well
   * as 0xfffe and 0xffff (UCS noncharacters) should not appear in
   * conforming UTF-8 streams.
   */
  if (0xd800 <= code && code <= 0xdfff)
    return -1;
  if (0xfffe <= code && code <= 0xffff)
    return -1;

  /* 0x00000000 - 0x0000007F:
     0xxxxxxx
  */
  if (code < 0)
    return -1;
  if (code <= 0x7F) {
    buf[0] = (unsigned char)code;
    return 1;
  }

  /* 0x00000080 - 0x000007FF:
     110xxxxx 10xxxxxx
  */
  if (code <= 0x000007FF) {
    buf[0] = (unsigned char)(0xc0 | (code >> 6));
    buf[1] = (unsigned char)(0x80 | (code & 0x3f));
    return 2;
  }

  /* 0x00000800 - 0x0000FFFF:
     1110xxxx 10xxxxxx 10xxxxxx
  */
  if (code <= 0x0000FFFF) {
    buf[0] = (unsigned char)(0xe0 | (code >> 12));
    buf[1] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
    buf[2] = (unsigned char)(0x80 | (code & 0x3f));
    return 3;
  }

  /* 0x00010000 - 0x001FFFFF:
     11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  */
  if (code <= 0x001FFFFF) {
    buf[0] = (unsigned char)(0xf0 | (code >> 18));
    buf[1] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));
    buf[2] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
    buf[3] = (unsigned char)(0x80 | (code & 0x3f));
    return 4;
  }

  /* 0x00200000 - 0x03FFFFFF:
     111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  */
  if (code <= 0x03FFFFFF) {
    buf[0] = (unsigned char)(0xf8 | (code >> 24));
    buf[1] = (unsigned char)(0x80 | ((code >> 18) & 0x3f));
    buf[2] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));
    buf[3] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
    buf[4] = (unsigned char)(0x80 | (code & 0x3f));
    return 5;
  }

  /* 0x04000000 - 0x7FFFFFFF:
     1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
  */
  if (code <= 0x7FFFFFFF) {
    buf[0] = (unsigned char)(0xfc | (code >> 30));
    buf[1] = (unsigned char)(0x80 | ((code >> 24) & 0x3f));
    buf[2] = (unsigned char)(0x80 | ((code >> 18) & 0x3f));
    buf[3] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));
    buf[4] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
    buf[5] = (unsigned char)(0x80 | (code & 0x3f));
    return 6;
  }

  return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0xd800, %eax           # imm = 0xD800
cmpq -0x10(%rbp), %rax
jg 0x22dd
cmpq $0xdfff, -0x10(%rbp)    # imm = 0xDFFF
jg 0x22dd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2599
movl $0xfffe, %eax           # imm = 0xFFFE
cmpq -0x10(%rbp), %rax
jg 0x22fe
cmpq $0xffff, -0x10(%rbp)    # imm = 0xFFFF
jg 0x22fe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2599
cmpq $0x0, -0x10(%rbp)
jge 0x2311
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2599
cmpq $0x7f, -0x10(%rbp)
jg 0x2330
movq -0x10(%rbp), %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2599
cmpq $0x7ff, -0x10(%rbp)     # imm = 0x7FF
jg 0x2373
movq -0x10(%rbp), %rax
sarq $0x6, %rax
orq $0xc0, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl $0x2, -0x4(%rbp)
jmp 0x2599
cmpq $0xffff, -0x10(%rbp)    # imm = 0xFFFF
jg 0x23d1
movq -0x10(%rbp), %rax
sarq $0xc, %rax
orq $0xe0, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
sarq $0x6, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movl $0x3, -0x4(%rbp)
jmp 0x2599
cmpq $0x1fffff, -0x10(%rbp)  # imm = 0x1FFFFF
jg 0x244a
movq -0x10(%rbp), %rax
sarq $0x12, %rax
orq $0xf0, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
sarq $0xc, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
sarq $0x6, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x10(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movl $0x4, -0x4(%rbp)
jmp 0x2599
cmpq $0x3ffffff, -0x10(%rbp) # imm = 0x3FFFFFF
jg 0x24e2
movq -0x10(%rbp), %rax
sarq $0x18, %rax
orq $0xf8, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
sarq $0x12, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
sarq $0xc, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x10(%rbp), %rax
sarq $0x6, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x10(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movl $0x5, -0x4(%rbp)
jmp 0x2599
cmpq $0x7fffffff, -0x10(%rbp) # imm = 0x7FFFFFFF
jg 0x2592
movq -0x10(%rbp), %rax
sarq $0x1e, %rax
orq $0xfc, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
sarq $0x18, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
sarq $0x12, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x10(%rbp), %rax
sarq $0xc, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x10(%rbp), %rax
sarq $0x6, %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x10(%rbp), %rax
andq $0x3f, %rax
orq $0x80, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x5(%rax)
movl $0x6, -0x4(%rbp)
jmp 0x2599
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
popq %rbp
retq
nop