// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x1b0e0
testb $0x1, %al
jne 0x1c67e
movb $0x0, -0x1(%rbp)
jmp 0x1c81d
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1c6af
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7e39(%rip), %rsi      # 0x244d0
callq 0xd190
cmpl $0x0, %eax
jne 0x1c6af
movq 0x77120(%rip), %rcx     # 0x937c8
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
addq (%rcx), %rax
movq -0x28(%rbp), %rcx
shlq $0x3, %rcx
cmpq %rcx, %rax
jbe 0x1c6da
movq -0x28(%rbp), %rcx
shlq $0x3, %rcx
subq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
leaq 0x74f91(%rip), %rax     # 0x91672
testb $0x1, (%rax)
je 0x1c6f4
leaq 0x14b5c(%rip), %rdi     # 0x31249
movb $0x0, %al
callq 0x1ade0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
leaq 0xb24f(%rip), %rax      # 0x27955
movq %rax, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
addq $0x7, %rcx
shrq $0x3, %rcx
cmpq %rcx, %rax
jae 0x1c7ff
movq -0x20(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x51(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x1c7a1
cmpq $0x0, -0x30(%rbp)
je 0x1c7a1
movzbl -0x51(%rbp), %eax
movq -0x30(%rbp), %rcx
sarl %cl, %eax
movb %al, -0x51(%rbp)
movq -0x48(%rbp), %rax
addq -0x30(%rbp), %rax
cmpq $0x8, %rax
jae 0x1c77e
movzbl -0x51(%rbp), %eax
movq -0x48(%rbp), %rcx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movb %al, -0x51(%rbp)
movzbl -0x51(%rbp), %eax
movq -0x30(%rbp), %rcx
shll %cl, %eax
movb %al, -0x51(%rbp)
movl $0x8, %ecx
subq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x1c7cd
cmpq $0x8, -0x48(%rbp)
jae 0x1c7c1
movzbl -0x51(%rbp), %eax
movq -0x48(%rbp), %rcx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movb %al, -0x51(%rbp)
movq -0x48(%rbp), %rax
subq $0x8, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rsi
movzbl -0x51(%rbp), %edx
leaq 0x148e2(%rip), %rdi     # 0x310be
movb $0x0, %al
callq 0x1ade0
leaq 0xb37e(%rip), %rax      # 0x27b68
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1c712
leaq 0x74e6c(%rip), %rax     # 0x91672
testb $0x1, (%rax)
je 0x1c819
leaq 0x14a37(%rip), %rdi     # 0x31249
movb $0x0, %al
callq 0x1ade0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)