// File: yhirose[P]fizzbuzzlang/./peglib.h
// Function: peg::encode_codepoint(char32_t, char*)
inline size_t encode_codepoint(char32_t cp, char *buff) {
  if (cp < 0x0080) {
    buff[0] = static_cast<char>(cp & 0x7F);
    return 1;
  } else if (cp < 0x0800) {
    buff[0] = static_cast<char>(0xC0 | ((cp >> 6) & 0x1F));
    buff[1] = static_cast<char>(0x80 | (cp & 0x3F));
    return 2;
  } else if (cp < 0xD800) {
    buff[0] = static_cast<char>(0xE0 | ((cp >> 12) & 0xF));
    buff[1] = static_cast<char>(0x80 | ((cp >> 6) & 0x3F));
    buff[2] = static_cast<char>(0x80 | (cp & 0x3F));
    return 3;
  } else if (cp < 0xE000) {
    // D800 - DFFF is invalid...
    return 0;
  } else if (cp < 0x10000) {
    buff[0] = static_cast<char>(0xE0 | ((cp >> 12) & 0xF));
    buff[1] = static_cast<char>(0x80 | ((cp >> 6) & 0x3F));
    buff[2] = static_cast<char>(0x80 | (cp & 0x3F));
    return 3;
  } else if (cp < 0x110000) {
    buff[0] = static_cast<char>(0xF0 | ((cp >> 18) & 0x7));
    buff[1] = static_cast<char>(0x80 | ((cp >> 12) & 0x3F));
    buff[2] = static_cast<char>(0x80 | ((cp >> 6) & 0x3F));
    buff[3] = static_cast<char>(0x80 | (cp & 0x3F));
    return 4;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
cmpl $0x80, -0xc(%rbp)
jae 0x64bef
movl -0xc(%rbp), %eax
andl $0x7f, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x64d6d
cmpl $0x800, -0xc(%rbp)      # imm = 0x800
jae 0x64c2f
movl -0xc(%rbp), %eax
shrl $0x6, %eax
andl $0x1f, %eax
orl $0xc0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq $0x2, -0x8(%rbp)
jmp 0x64d6d
cmpl $0xd800, -0xc(%rbp)     # imm = 0xD800
jae 0x64c86
movl -0xc(%rbp), %eax
shrl $0xc, %eax
andl $0xf, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0xc(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq $0x3, -0x8(%rbp)
jmp 0x64d6d
cmpl $0xe000, -0xc(%rbp)     # imm = 0xE000
jae 0x64c9c
movq $0x0, -0x8(%rbp)
jmp 0x64d6d
cmpl $0x10000, -0xc(%rbp)    # imm = 0x10000
jae 0x64cf0
movl -0xc(%rbp), %eax
shrl $0xc, %eax
andl $0xf, %eax
orl $0xe0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0xc(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq $0x3, -0x8(%rbp)
jmp 0x64d6d
cmpl $0x110000, -0xc(%rbp)   # imm = 0x110000
jae 0x64d5b
movl -0xc(%rbp), %eax
shrl $0x12, %eax
andl $0x7, %eax
orl $0xf0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0xc(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0xc(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0xc(%rbp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movq $0x4, -0x8(%rbp)
jmp 0x64d6d
jmp 0x64d5d
jmp 0x64d5f
jmp 0x64d61
jmp 0x64d63
jmp 0x64d65
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)