// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %r8, %r13
shrq $0x3, %r13
subq %r13, %r15
jbe 0x1bb7e
movq %r9, %r12
movq %rdx, %r14
movq %rsi, %rbx
addq %r13, %rdx
andl $0x7, %r8d
movq (%r9), %r9
leaq 0x1203b(%rip), %rdi     # 0x2db80
movq %r15, %rcx
xorl %eax, %eax
callq 0x1cd55
movzbl (%r14,%r13), %edx
cmpq $0x2, %rdx
setae %al
cmpq $0x2, %r15
setae %cl
testb %al, %cl
jne 0x1bb85
leaq 0x12054(%rip), %rdi     # 0x2dbc1
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1cde8
jmp 0x1bc76
xorl %ebp, %ebp
jmp 0x1bc76
addq %r13, %r14
addq $0x2, %r14
movzbl -0x1(%r14), %esi
cmpq %rdx, %r15
cmovbq %r15, %rdx
leaq -0x2(%rdx), %r15
shll $0x3, %edx
movq %rdx, (%r12)
testl %esi, %esi
je 0x1bbba
cmpl $0x1, %esi
jne 0x1bc22
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
jmp 0x1bc6e
shrq %r15
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1f008
movq %rax, %rbp
movq %rax, %r13
incq %r13
movq %r13, %rdi
callq 0xd200
movq %rax, %r12
testq %rax, %rax
je 0x1bc34
leaq 0x1201d(%rip), %rdi     # 0x2dc09
movq %r15, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1cd55
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1f008
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1b9c3
movq %r12, %rdi
callq 0xd040
jmp 0x1bc73
leaq 0x1201c(%rip), %rdi     # 0x2dc45
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x1cde8
jmp 0x1bc76
leaq 0x11fc0(%rip), %rdi     # 0x2dbfb
callq 0x1cf2b
leaq 0x11fc2(%rip), %rdi     # 0x2dc09
movq %r15, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1cd55
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1f008
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1b9c3
movb $0x1, %bpl
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq