// File: /workspace/github_cpp_makefile_star2_O2/4n6ist[P]usn_analytics/lib/utils.cpp
// Function: UTF16toUTF8[abi:cxx11](char16_t*, int)
string UTF16toUTF8(char16_t *s, int n) {
  int half = 0;
  char *out = (char*)malloc(6);
  string res;

  for (int i = 0; i < n; ++i) {
    uint16_t c = s[i];
    char *t = out;
    memset(t, 0, 6);
    if (half) {
      if ((c >= 0xdc00) && (c < 0xe000)) {
        *t++ = 0xf0 + (((half + 64) >> 8) & 7);
        *t++ = 0x80 + (((half + 64) >> 2) & 63);
        *t++ = 0x80 + ((c >> 6) & 15) + ((half & 3) << 4);
        *t++ = 0x80 + (c & 63);
        half = 0;
      } else {
        return "<Can't Convert>";
      }
    } else if (c < 0x80) {
      *t++ = c;
    } else {
      if (c < 0x800) {
        *t++ = (0xc0 | ((c >> 6) & 0x3f));
        *t++ = 0x80 | (c & 0x3f);
      } else if (c < 0xd800) {
        *t++ = 0xe0 | (c >> 12);
        *t++ = 0x80 | ((c >> 6) & 0x3f);
        *t++ = 0x80 | (c & 0x3f);
      } else if (c < 0xdc00)
        half = c;
      else if (c >= 0xe000) {
        *t++ = 0xe0 | (c >> 12);
        *t++ = 0x80 | ((c >> 6) & 0x3f);
        *t++ = 0x80 | (c & 0x3f);
      } else {
        return "<Can't Convert>";
      }
    }
    res += string(out);
  }
  free(out);
  return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
pushq $0x6
popq %rdi
callq 0x3350
movq %rax, %r12
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
leaq 0x38(%rsp), %r13
xorl %ebx, %ebx
cmpq %rbp, %r14
je 0xb648
movzwl (%r15,%rbp,2), %eax
andw $0x0, 0x4(%r12)
andl $0x0, (%r12)
testl %ebx, %ebx
je 0xb59b
movl %eax, %ecx
andl $0xfc00, %ecx           # imm = 0xFC00
cmpw $0xdc00, %cx            # imm = 0xDC00
jne 0xb679
leal 0x40(%rbx), %ecx
movl %ecx, %edx
shrl $0x8, %edx
andb $0x7, %dl
orb $-0x10, %dl
movb %dl, (%r12)
shrb $0x2, %cl
orb $-0x80, %cl
movb %cl, 0x1(%r12)
movl %eax, %ecx
shrl $0x6, %ecx
andl $0xf, %ecx
shll $0x4, %ebx
andl $0x30, %ebx
orl %ecx, %ebx
orb $-0x80, %bl
movb %bl, 0x2(%r12)
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x3(%r12)
jmp 0xb619
cmpw $0x7f, %ax
ja 0xb5a7
movb %al, (%r12)
jmp 0xb619
cmpw $0x7ff, %ax             # imm = 0x7FF
ja 0xb5c4
movl %eax, %ecx
shrl $0x6, %ecx
orb $-0x40, %cl
movb %cl, (%r12)
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x1(%r12)
jmp 0xb619
cmpw $0xd7ff, %ax            # imm = 0xD7FF
ja 0xb5e3
movl %eax, %ecx
shrl $0xc, %ecx
orb $-0x20, %cl
movb %cl, (%r12)
movl %eax, %ecx
shrl $0x6, %ecx
andb $0x3f, %cl
orb $-0x80, %cl
jmp 0xb60b
cmpw $0xdc00, %ax            # imm = 0xDC00
jae 0xb5ed
movl %eax, %ebx
jmp 0xb61b
cmpw $0xe000, %ax            # imm = 0xE000
jb 0xb6cf
movl %eax, %ecx
shrl $0xc, %ecx
orb $-0x20, %cl
movb %cl, (%r12)
movl %eax, %ecx
shrl $0x6, %ecx
andb $-0x41, %cl
movb %cl, 0x1(%r12)
andb $0x3f, %al
orb $-0x80, %al
movb %al, 0x2(%r12)
xorl %ebx, %ebx
movq %r13, %rdi
movq %r12, %rsi
leaq 0xf(%rsp), %rdx
callq 0x7072
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x34e0
movq %r13, %rdi
callq 0x3100
incq %rbp
jmp 0xb52a
movq %r12, %rdi
callq 0x3300
movq 0x10(%rsp), %rbx
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x18(%rsp), %rcx
leaq 0x28(%rsp), %rdx
cmpq %rdx, %rcx
je 0xb694
movq %rcx, (%rbx)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0xb69a
leaq 0xb20(%rip), %rsi       # 0xc1a0
leaq 0x38(%rsp), %rdx
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x7072
jmp 0xb6b3
movups (%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %rdx, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x3100
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xaca(%rip), %rsi       # 0xc1a0
leaq 0x38(%rsp), %rdx
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x7072
jmp 0xb6b3
jmp 0xb6ee
jmp 0xb6ee
movq %rax, %rbx
jmp 0xb700
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x3100
leaq 0x18(%rsp), %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3480