// File: tomfunkhouser[P]gaps/pkgs/RNBasics/json.cpp
// Function: Json::codePointToUTF8[abi:cxx11](unsigned int)
static inline std::string codePointToUTF8(unsigned int cp) {
  std::string result;

  // based on description from http://en.wikipedia.org/wiki/UTF-8

  if (cp <= 0x7f) {
    result.resize(1);
    result[0] = static_cast<char>(cp);
  } else if (cp <= 0x7FF) {
    result.resize(2);
    result[1] = static_cast<char>(0x80 | (0x3f & cp));
    result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
  } else if (cp <= 0xFFFF) {
    result.resize(3);
    result[2] = static_cast<char>(0x80 | (0x3f & cp));
    result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
    result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
  } else if (cp <= 0x10FFFF) {
    result.resize(4);
    result[3] = static_cast<char>(0x80 | (0x3f & cp));
    result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
    result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
    result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
  }

  return result;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rdi, %rax
movq %rax, 0xb0(%rsp)
movq %rdi, 0xd0(%rsp)
movl %esi, 0xcc(%rsp)
movb $0x0, 0xcb(%rsp)
callq 0x129f0
cmpl $0x7f, 0xcc(%rsp)
ja 0xe3c19
movq 0xa8(%rsp), %rdi
movl $0x1, %esi
callq 0x129e0
jmp 0xe3bb4
movq 0xa8(%rsp), %rdi
movb 0xcc(%rsp), %al
movb %al, 0x9f(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x12dd0
movq %rax, 0xa0(%rsp)
jmp 0xe3bdd
movq 0xa0(%rsp), %rax
movb 0x9f(%rsp), %cl
movb %cl, (%rax)
jmp 0xe3e84
movq 0xa8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc0(%rsp)
movl %eax, 0xbc(%rsp)
callq 0x12430
jmp 0xe3eb3
cmpl $0x7ff, 0xcc(%rsp) # imm = 0x7FF
ja 0xe3cbd
movq 0xa8(%rsp), %rdi
movl $0x2, %esi
callq 0x129e0
jmp 0xe3c3e
movq 0xa8(%rsp), %rdi
movb 0xcc(%rsp), %al
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x8f(%rsp)
movl $0x1, %esi
callq 0x12dd0
movq %rax, 0x90(%rsp)
jmp 0xe3c6c
movq 0xa8(%rsp), %rdi
movq 0x90(%rsp), %rax
movb 0x8f(%rsp), %cl
movb %cl, (%rax)
movl 0xcc(%rsp), %eax
shrl $0x6, %eax
andb $0x1f, %al
orb $-0x40, %al
movb %al, 0x7f(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x12dd0
movq %rax, 0x80(%rsp)
jmp 0xe3caa
movq 0x80(%rsp), %rax
movb 0x7f(%rsp), %cl
movb %cl, (%rax)
jmp 0xe3e82
cmpl $0xffff, 0xcc(%rsp) # imm = 0xFFFF
ja 0xe3d85
movq 0xa8(%rsp), %rdi
movl $0x3, %esi
callq 0x129e0
jmp 0xe3ce2
movq 0xa8(%rsp), %rdi
movb 0xcc(%rsp), %al
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x6f(%rsp)
movl $0x2, %esi
callq 0x12dd0
movq %rax, 0x70(%rsp)
jmp 0xe3d0a
movq 0xa8(%rsp), %rdi
movq 0x70(%rsp), %rax
movb 0x6f(%rsp), %cl
movb %cl, (%rax)
movl 0xcc(%rsp), %eax
shrl $0x6, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x5f(%rsp)
movl $0x1, %esi
callq 0x12dd0
movq %rax, 0x60(%rsp)
jmp 0xe3d40
movq 0xa8(%rsp), %rdi
movq 0x60(%rsp), %rax
movb 0x5f(%rsp), %cl
movb %cl, (%rax)
movl 0xcc(%rsp), %eax
shrl $0xc, %eax
andb $0xf, %al
orb $-0x20, %al
movb %al, 0x4f(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x12dd0
movq %rax, 0x50(%rsp)
jmp 0xe3d75
movq 0x50(%rsp), %rax
movb 0x4f(%rsp), %cl
movb %cl, (%rax)
jmp 0xe3e80
cmpl $0x10ffff, 0xcc(%rsp) # imm = 0x10FFFF
ja 0xe3e7e
movq 0xa8(%rsp), %rdi
movl $0x4, %esi
callq 0x129e0
jmp 0xe3daa
movq 0xa8(%rsp), %rdi
movb 0xcc(%rsp), %al
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x3f(%rsp)
movl $0x3, %esi
callq 0x12dd0
movq %rax, 0x40(%rsp)
jmp 0xe3dd2
movq 0xa8(%rsp), %rdi
movq 0x40(%rsp), %rax
movb 0x3f(%rsp), %cl
movb %cl, (%rax)
movl 0xcc(%rsp), %eax
shrl $0x6, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x2f(%rsp)
movl $0x2, %esi
callq 0x12dd0
movq %rax, 0x30(%rsp)
jmp 0xe3e08
movq 0xa8(%rsp), %rdi
movq 0x30(%rsp), %rax
movb 0x2f(%rsp), %cl
movb %cl, (%rax)
movl 0xcc(%rsp), %eax
shrl $0xc, %eax
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x1f(%rsp)
movl $0x1, %esi
callq 0x12dd0
movq %rax, 0x20(%rsp)
jmp 0xe3e3e
movq 0xa8(%rsp), %rdi
movq 0x20(%rsp), %rax
movb 0x1f(%rsp), %cl
movb %cl, (%rax)
movl 0xcc(%rsp), %eax
shrl $0x12, %eax
andb $0x7, %al
orb $-0x10, %al
movb %al, 0xf(%rsp)
xorl %eax, %eax
movl %eax, %esi
callq 0x12dd0
movq %rax, 0x10(%rsp)
jmp 0xe3e73
movq 0x10(%rsp), %rax
movb 0xf(%rsp), %cl
movb %cl, (%rax)
jmp 0xe3e80
jmp 0xe3e82
jmp 0xe3e84
movb $0x1, 0xcb(%rsp)
testb $0x1, 0xcb(%rsp)
jne 0xe3ea3
movq 0xa8(%rsp), %rdi
callq 0x12430
movq 0xb0(%rsp), %rax
addq $0xd8, %rsp
retq
movq 0xc0(%rsp), %rdi
callq 0x12c20