// File: /workspace/github_c_makefile_star2_O2/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 %rcx, %r14
movq %r8, %r13
shrq $0x3, %r13
subq %r13, %r14
jbe 0x1abf4
movq %r9, %r12
movq %rdx, %r15
movq %rsi, %rbx
addq %r13, %rdx
andl $0x7, %r8d
movq (%r9), %r9
leaq 0x11fc5(%rip), %rdi     # 0x2cb80
movq %r14, %rcx
xorl %eax, %eax
callq 0x1bd48
movzbl (%r15,%r13), %edx
cmpq $0x2, %rdx
setae %al
cmpq $0x2, %r14
setae %cl
testb %al, %cl
jne 0x1abfb
leaq 0x11fde(%rip), %rdi     # 0x2cbc1
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1bdd9
jmp 0x1acbb
xorl %ebp, %ebp
jmp 0x1acbb
addq %r13, %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 0x1ac8a
testl %esi, %esi
jne 0x1acab
shrq %r14
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1de40
movq %rax, %rbp
movq %rax, %r13
incq %r13
movq %r13, %rdi
callq 0xd200
movq %rax, %r12
testq %rax, %rax
jne 0x1ac5d
leaq 0x11fa3(%rip), %rdi     # 0x2cbfb
callq 0x1bf18
leaq 0x11fa5(%rip), %rdi     # 0x2cc09
movq %r14, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1bd48
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1de40
movq %rax, %r14
movq %r12, %r13
jmp 0x1ac90
xorl %r13d, %r13d
movq %r15, %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1aa50
movq %r13, %rdi
callq 0xd040
movb $0x1, %bpl
jmp 0x1acbb
leaq 0x11f93(%rip), %rdi     # 0x2cc45
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x1bdd9
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq