// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %r8, %rbp
shrq $0x3, %rbp
movl %r8d, %r12d
andl $0x7, %r12d
xorl %ebx, %ebx
cmpq %rcx, %rbp
cmovbq %rbp, %rbx
cmovaeq %r8, %r12
jae 0x23828
movq %r9, %r14
movq %rdx, %r15
movq %r13, 0x8(%rsp)
subq %rbx, %r13
cmpq $0x0, (%r9)
jne 0x23713
movq 0x8(%rdi), %rdi
leaq 0x4d38(%rip), %rsi      # 0x28438
callq 0xd1a0
testl %eax, %eax
jne 0x23713
movq 0x7a138(%rip), %rax     # 0x9d848
movq %rax, (%r14)
movq (%r14), %rax
addq %r12, %rax
shlq $0x3, %r13
cmpq %r13, %rax
jbe 0x23728
subq %r12, %r13
movq %r13, (%r14)
movq %rbp, (%rsp)
leaq 0x77fbf(%rip), %rax     # 0x9b6f2
cmpb $0x1, (%rax)
jne 0x23746
leaq 0x17942(%rip), %rdi     # 0x3b081
xorl %eax, %eax
callq 0x226ec
movq (%r14), %rax
addq $0x7, %rax
cmpq $0x8, %rax
jb 0x23805
addq %rbx, %r15
movq (%r14), %r13
leaq -0x8(%r12), %rax
movq %rax, 0x10(%rsp)
leaq 0x7c30(%rip), %rsi      # 0x2b39e
leaq 0x7c94(%rip), %rbx      # 0x2b409
xorl %ebp, %ebp
testq %r12, %r12
sete %cl
movzbl (%r15,%rbp), %eax
testq %rbp, %rbp
setne %dl
orb %cl, %dl
jne 0x237bb
movl %r12d, %ecx
shrl %cl, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r13d, %ecx
shll %cl, %edx
leaq (%r12,%r13), %rcx
cmpq $0x8, %rcx
notl %edx
movl $0xff, %ecx
cmovael %ecx, %edx
andl %eax, %edx
movl %r12d, %ecx
shll %cl, %edx
addq 0x10(%rsp), %r13
jmp 0x237da
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %r13d, %ecx
shll %cl, %edx
subq $0x8, %r13
notb %dl
movzbl %dl, %ecx
movl $0xff, %edx
cmovael %edx, %ecx
andl %ecx, %eax
movl %eax, %edx
movzbl %dl, %edx
leaq 0x17712(%rip), %rdi     # 0x3aef6
xorl %eax, %eax
callq 0x226ec
incq %rbp
movq (%r14), %rax
addq $0x7, %rax
shrq $0x3, %rax
movq %rbx, %rsi
cmpq %rax, %rbp
jb 0x23777
leaq 0x77ee6(%rip), %rax     # 0x9b6f2
cmpb $0x1, (%rax)
movq 0x8(%rsp), %r13
movq (%rsp), %rbp
jne 0x23828
leaq 0x17860(%rip), %rdi     # 0x3b081
xorl %eax, %eax
callq 0x226ec
cmpq %r13, %rbp
setb %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq