// File: /workspace/github_c_makefile_star2_O2/pali[P]bmfdec/./bmfparse.c
// Function: parse_string
static char *parse_string(char *buf, uint32_t size) {
  uint16_t *buf2 = (uint16_t *)buf;
  if (size % 2 != 0) error("Invalid size");
  char *out = malloc(size+1);
  if (!out) error("malloc failed");
  uint32_t i, j;
  for (i=0, j=0; i<size/2; ++i) {
    if (buf2[i] == 0) {
      break;
    } else if (buf2[i] < 0x80) {
      out[j++] = buf2[i];
    } else if (buf2[i] < 0x800) {
      out[j++] = 0xC0 | (buf2[i] >> 6);
      out[j++] = 0x80 | (buf2[i] & 0x3F);
    } else if (buf2[i] >= 0xD800 && buf2[i] <= 0xDBFF && i+1 < size/2 && buf2[i+1] >= 0xDC00 && buf2[i+1] <= 0xDFFF) {
      uint32_t c = 0x10000 + ((buf2[i] - 0xD800) << 10) + (buf2[i+1] - 0xDC00);
      ++i;
      out[j++] = 0xF0 | (c >> 18);
      out[j++] = 0x80 | ((c >> 12) & 0x3F);
      out[j++] = 0x80 | ((c >> 6) & 0x3F);
      out[j++] = 0x80 | (c & 0x3F);
    } else {
      out[j++] = 0xE0 | (buf2[i] >> 12);
      out[j++] = 0x80 | ((buf2[i] >> 6) & 0x3F);
      out[j++] = 0x80 | (buf2[i] & 0x3F);
    }
  }
  out[j] = 0;
  return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
testb $0x1, %bl
jne 0x51a0
movq %rdi, %r14
movl %ebx, %edi
orl $0x1, %edi
callq 0x1130
testq %rax, %rax
je 0x51c7
shrl %ebx
xorl %ecx, %ecx
pushq $0x1
popq %rdx
pushq $0x2
popq %rsi
pushq $0x4
popq %rdi
pushq $0x3
popq %r8
xorl %r9d, %r9d
movl %ecx, %r11d
cmpl %ebx, %r9d
jae 0x5192
movl %r9d, %r10d
movzwl (%r14,%r10,2), %r10d
testl %r10d, %r10d
je 0x5192
cmpw $0x7f, %r10w
ja 0x508f
movl %edx, %r11d
movl %ecx, %r12d
jmp 0x5180
movl %r10d, %ebp
cmpw $0x7ff, %r10w           # imm = 0x7FF
ja 0x50b9
shrl $0x6, %ebp
orb $-0x40, %bpl
leal 0x1(%rcx), %r12d
movb %bpl, (%rax,%r11)
andb $0x3f, %r10b
orb $-0x80, %r10b
movl %esi, %r11d
jmp 0x5180
andl $0xfc00, %ebp           # imm = 0xFC00
cmpw $0xd800, %bp            # imm = 0xD800
jne 0x514c
leal 0x1(%r9), %ebp
cmpl %ebx, %ebp
jae 0x514c
movl %ebp, %r15d
movzwl (%r14,%r15,2), %r15d
movl %r15d, %r12d
andl $0xfc00, %r12d          # imm = 0xFC00
cmpw $0xdc00, %r12w          # imm = 0xDC00
jne 0x514c
shll $0xa, %r10d
leal (%r10,%r15), %r9d
addl $0xfca02400, %r9d       # imm = 0xFCA02400
movl %r9d, %r10d
shrl $0x12, %r10d
orb $-0x10, %r10b
leal 0x1(%rcx), %r12d
movb %r10b, (%rax,%r11)
movl %r9d, %r10d
shrl $0xc, %r10d
andb $0x3f, %r10b
orb $-0x80, %r10b
leal 0x2(%rcx), %r11d
movb %r10b, (%rax,%r12)
shrl $0x6, %r9d
andb $0x3f, %r9b
orb $-0x80, %r9b
leal 0x3(%rcx), %r12d
movb %r9b, (%rax,%r11)
andb $0x3f, %r15b
orb $-0x80, %r15b
movl %edi, %r11d
movl %r15d, %r10d
movl %ebp, %r9d
jmp 0x5180
movl %r10d, %ebp
shrl $0xc, %ebp
orb $-0x20, %bpl
leal 0x1(%rcx), %r15d
movb %bpl, (%rax,%r11)
movl %r10d, %r11d
shrl $0x6, %r11d
andb $0x3f, %r11b
orb $-0x80, %r11b
leal 0x2(%rcx), %r12d
movb %r11b, (%rax,%r15)
andb $0x3f, %r10b
orb $-0x80, %r10b
movl %r8d, %r11d
addl %r11d, %ecx
movl %r12d, %r11d
movb %r10b, (%rax,%r11)
incl %r9d
jmp 0x5060
movb $0x0, (%rax,%r11)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x3e51(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x1147(%rip), %rsi      # 0x62f8
leaq 0x1184(%rip), %rdx      # 0x633c
leaq 0x13c3(%rip), %rcx      # 0x6582
movl $0x80, %r8d
jmp 0x51ec
movq 0x3e2a(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x1120(%rip), %rsi      # 0x62f8
leaq 0x13b0(%rip), %rdx      # 0x658f
leaq 0x139c(%rip), %rcx      # 0x6582
movl $0x82, %r8d
xorl %eax, %eax
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1170