// File: /workspace/github_c_makefile_star2_O3/canboat[P]canboat/analyzer/print.c
// Function: fieldPrintBinary
extern bool fieldPrintBinary(const Field   *field,
                             const char    *fieldName,
                             const uint8_t *data,
                             size_t         dataLen,
                             size_t         startBit,
                             size_t        *bits)
{
  size_t      i;
  size_t      remaining_bits;
  const char *s;

  if (!adjustDataLenStart(&data, &dataLen, &startBit))
  {
    return false;
  }

  if (*bits == 0 && strcmp(field->fieldType, "BINARY") == 0)
  {
    // The length is in the previous field. This is heuristically defined right now, it might change.
    // The only PGNs where this happens are AIS PGNs 129792, 129795 and 129797.
    *bits = g_previousFieldValue;
  }

  if (startBit + *bits > dataLen * 8)
  {
    *bits = dataLen * 8 - startBit;
  }

  if (showJson)
  {
    mprintf("\"");
  }
  remaining_bits = *bits;
  s              = "";
  for (i = 0; i < (*bits + 7) >> 3; i++)
  {
    uint8_t byte = data[i];

    if (i == 0 && startBit != 0)
    {
      byte = byte >> startBit; // Shift off older bits
      if (remaining_bits + startBit < 8)
      {
        byte = byte & ((1 << remaining_bits) - 1);
      }
      byte = byte << startBit; // Shift zeros back in
      remaining_bits -= (8 - startBit);
    }
    else
    {
      if (remaining_bits < 8)
      {
        // only the lower remaining_bits should be used
        byte = byte & ((1 << remaining_bits) - 1);
      }
      remaining_bits -= 8;
    }
    mprintf("%s%2.02X", s, byte);
    s = " ";
  }
  if (showJson)
  {
    mprintf("\"");
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r15
movq %r8, %r13
shrq $0x3, %r13
movq %rcx, %rbx
subq %r13, %rbx
jbe 0x1b18c
movq %r9, %r14
movq %rdx, %r12
movq %r13, (%rsp)
movq %r8, 0x8(%rsp)
movl %r8d, %r13d
andl $0x7, %r13d
movq (%r9), %rbp
testq %rbp, %rbp
jne 0x1b06f
movq 0x8(%rdi), %rdi
leaq 0x53e0(%rip), %rsi      # 0x20438
callq 0xd1a0
testl %eax, %eax
je 0x1b065
xorl %ebp, %ebp
jmp 0x1b06f
movq 0x757dc(%rip), %rbp     # 0x90848
movq %rbp, (%r14)
movq %rbp, %rax
addq %r13, %rax
shlq $0x3, %rbx
cmpq %rbx, %rax
jbe 0x1b087
subq %r13, %rbx
movq %rbx, (%r14)
movq %rbx, %rbp
movq %r15, 0x10(%rsp)
leaq 0x7365f(%rip), %rax     # 0x8e6f2
cmpb $0x1, (%rax)
jne 0x1b0a9
leaq 0x12d52(%rip), %rdi     # 0x2ddf1
xorl %eax, %eax
callq 0x1a07c
movq (%r14), %rbp
leaq 0x7(%rbp), %rax
cmpq $0x8, %rax
jb 0x1b169
addq (%rsp), %r12
orq $-0x8, 0x8(%rsp)
leaq 0x82d6(%rip), %rsi      # 0x2339e
leaq 0x833a(%rip), %r15      # 0x23409
xorl %ebx, %ebx
testq %r13, %r13
sete %cl
movzbl (%r12,%rbx), %eax
testq %rbx, %rbx
setne %dl
orb %cl, %dl
jne 0x1b116
movl %r13d, %ecx
shrl %cl, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %edx
movq %rbp, %rcx
addq %r13, %rcx
cmpq $0x8, %rcx
notl %edx
movl $0xff, %ecx
cmovael %ecx, %edx
andl %eax, %edx
movl %r13d, %ecx
shll %cl, %edx
movq 0x8(%rsp), %rcx
jmp 0x1b13b
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %edx
cmpq $0x8, %rbp
notb %dl
movzbl %dl, %ecx
movl $0xff, %edx
cmovael %edx, %ecx
andl %ecx, %eax
movq $-0x8, %rcx
movl %eax, %edx
addq %rcx, %rbp
movzbl %dl, %edx
leaq 0x12b1e(%rip), %rdi     # 0x2dc66
xorl %eax, %eax
callq 0x1a07c
incq %rbx
movq (%r14), %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %r15, %rsi
cmpq %rax, %rbx
jb 0x1b0d1
leaq 0x73582(%rip), %rax     # 0x8e6f2
cmpb $0x1, (%rax)
movq 0x10(%rsp), %r15
movq (%rsp), %r13
jne 0x1b18c
leaq 0x12c6c(%rip), %rdi     # 0x2ddf1
xorl %eax, %eax
callq 0x1a07c
cmpq %r13, %r15
seta %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq