// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/analyzer/print.c
// Function: fieldPrintStringLAU
extern bool fieldPrintStringLAU(const Field   *field,
                                const char    *fieldName,
                                const uint8_t *data,
                                size_t         dataLen,
                                size_t         startBit,
                                size_t        *bits)
{
  // STRINGLAU format is <len> <control> [ <data> ... ]
  // where <control> == 0 = UTF16
  //       <control> == 1 = ASCII(?) or maybe UTF8?
  int     control;
  size_t  len;
  size_t  utf8_len;
  utf8_t *utf8 = NULL;
  bool    r;

  if (!adjustDataLenStart(&data, &dataLen, &startBit))
  {
    return false;
  }
  logDebug("fieldPrintStringLAU: <%s> data=%p len=%zu startBit=%zu bits=%zu\n", fieldName, data, dataLen, startBit, *bits);

  len     = *data++;
  control = *data++;
  if (len < 2 || dataLen < 2)
  {
    logError("field '%s': Invalid string length %u in STRING_LAU field\n", fieldName, len);
    return false;
  }
  len = CB_MIN(len, dataLen) - 2;

  *bits = BYTES(len + 2);

  if (control == 0)
  {
    utf8_len = utf16_to_utf8((const utf16_t *) data, len / 2, NULL, 0);
    utf8     = malloc(utf8_len + 1);

    if (utf8 == NULL)
    {
      die("Out of memory");
    }
    logDebug("fieldprintStringLAU: UTF16 len %zu requires %zu utf8 bytes\n", len / 2, utf8_len);
    len  = utf16_to_utf8((const utf16_t *) data, len / 2, utf8, utf8_len + 1);
    data = utf8;
  }
  else if (control > 1)
  {
    logError("Unhandled string type %d in PGN\n", control);
    return false;
  }

  r = printString(fieldName, data, len);
  if (utf8 != NULL)
  {
    free(utf8);
  }
  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %rbp
shrq $0x3, %rbp
xorl %r13d, %r13d
movl $0x0, %eax
cmpq %rcx, %rbp
cmovbq %rbp, %rax
jae 0x24313
movq %r9, %r12
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbx
subq %rax, %r14
andl $0x7, %r8d
addq %rbp, %rdx
movq (%r9), %r9
leaq 0x16bfc(%rip), %rdi     # 0x3ae10
movq %r14, %rcx
xorl %eax, %eax
callq 0x254dd
movzbl (%r15,%rbp), %edx
cmpq $0x2, %rdx
setae %al
cmpq $0x2, %r14
setae %cl
testb %al, %cl
jne 0x2424e
leaq 0x16c15(%rip), %rdi     # 0x3ae51
xorl %r13d, %r13d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x25570
jmp 0x24313
addq %rbp, %r15
addq $0x2, %r15
movzbl -0x1(%r15), %esi
cmpq %rdx, %r14
cmovbq %r14, %rdx
leaq -0x2(%rdx), %r14
shll $0x3, %edx
movq %rdx, (%r12)
cmpl $0x1, %esi
je 0x242dd
testl %esi, %esi
jne 0x24302
shrq %r14
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x277d4
movq %rax, %rbp
movq %rax, %r13
incq %r13
movq %r13, %rdi
callq 0xd200
movq %rax, %r12
testq %rax, %rax
jne 0x242b0
leaq 0x16be0(%rip), %rdi     # 0x3ae8b
callq 0x256b3
leaq 0x16be2(%rip), %rdi     # 0x3ae99
movq %r14, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x254dd
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x277d4
movq %rax, %r14
movq %r12, %rbp
jmp 0x242e2
xorl %ebp, %ebp
movq %r15, %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2407f
movb $0x1, %r13b
testq %rbp, %rbp
je 0x24313
movq %rbp, %rdi
callq 0xd040
jmp 0x24313
leaq 0x16bcc(%rip), %rdi     # 0x3aed5
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x25570
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq