// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/analyzer/analyzer.c
// Function: showBytesOrBits
static void showBytesOrBits(const uint8_t *data, size_t startBit, size_t bits)
{
  int64_t     value;
  int64_t     maxValue;
  size_t      i;
  size_t      remaining_bits;
  const char *s;
  uint8_t     byte;

  logDebug("showBytesOrBits(%p, %zu, %zu)\n", data, startBit, bits);

  if (showJson)
  {
    size_t location = mlocation();

    if (location == 0 || mchr(location - 1) != '{')
    {
      mprintf(",");
    }
    mprintf("\"bytes\":\"");
  }
  else
  {
    mprintf(" (bytes = \"");
  }
  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 = " ";
  }
  mprintf("\"");

  if (startBit != 0 || ((bits & 7) != 0))
  {
    extractNumber(NULL, data, (bits + 7) >> 3, startBit, bits, &value, &maxValue);
    if (showJson)
    {
      mprintf(",\"bits\":\"");
    }
    else
    {
      mprintf(", bits = \"");
    }

    for (i = bits; i > 0;)
    {
      i--;
      byte = (value >> (i >> 3)) & 0xff;
      mprintf("%c", (byte & (1 << (i & 7))) ? '1' : '0');
    }
    mprintf("\"");
  }

  if (!showJson)
  {
    mprintf(")");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x1079b(%rip), %rdi     # 0x20112
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x19a95
cmpb $0x1, 0x7993a(%rip)     # 0x892c8
jne 0xf9c0
callq 0x16e5d
testq %rax, %rax
je 0xf9a9
decq %rax
movq %rax, %rdi
callq 0x16da6
cmpb $0x7b, %al
je 0xf9b7
leaq 0x1fe75(%rip), %rdi     # 0x2f825
xorl %eax, %eax
callq 0x16cd0
leaq 0x10773(%rip), %rdi     # 0x20131
jmp 0xf9c7
leaq 0x10774(%rip), %rdi     # 0x2013b
xorl %eax, %eax
callq 0x16cd0
leaq 0x7(%rbx), %rax
movq %rax, %r12
shrq $0x3, %r12
cmpq $0x8, %rax
jb 0xfa7e
leaq -0x8(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0xfc76(%rip), %rsi      # 0x1f669
xorl %r13d, %r13d
movq %rbx, %rbp
testq %r14, %r14
sete %cl
movzbl (%r15,%r13), %eax
testq %r13, %r13
setne %dl
orb %cl, %dl
jne 0xfa3c
movl %r14d, %ecx
shrl %cl, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %edx
leaq (%r14,%rbp), %rcx
cmpq $0x8, %rcx
notl %edx
movl $0xff, %ecx
cmovael %ecx, %edx
andl %eax, %edx
movl %r14d, %ecx
shll %cl, %edx
addq 0x10(%rsp), %rbp
jmp 0xfa5a
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %ebp, %ecx
shll %cl, %edx
subq $0x8, %rbp
notb %dl
movzbl %dl, %ecx
movl $0xff, %edx
cmovael %edx, %ecx
andl %ecx, %eax
movl %eax, %edx
movzbl %dl, %edx
leaq 0x106e3(%rip), %rdi     # 0x20147
xorl %eax, %eax
callq 0x16cd0
incq %r13
leaq 0x10056(%rip), %rsi     # 0x1facb
cmpq %r13, %r12
jne 0xf9f9
leaq 0x106c0(%rip), %rdi     # 0x20145
xorl %eax, %eax
callq 0x16cd0
movl %ebx, %eax
andl $0x7, %eax
orq %r14, %rax
je 0xfb24
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
leaq 0x18(%rsp), %r9
xorl %edi, %edi
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x16f1b
leaq 0x1068e(%rip), %rax     # 0x20150
leaq 0x10691(%rip), %rdi     # 0x2015a
cmpb $0x0, 0x797f8(%rip)     # 0x892c8
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x16cd0
testq %rbx, %rbx
je 0xfb16
leaq 0xfcc7(%rip), %r14      # 0x1f7ae
decq %rbx
movq 0x18(%rsp), %rax
movl %ebx, %ecx
shrl $0x3, %ecx
sarq %cl, %rax
movl %ebx, %ecx
andl $0x7, %ecx
btl %ecx, %eax
movl $0x0, %esi
adcl $0x30, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x16cd0
testq %rbx, %rbx
jne 0xfae7
leaq 0x10628(%rip), %rdi     # 0x20145
xorl %eax, %eax
callq 0x16cd0
cmpb $0x0, 0x7979d(%rip)     # 0x892c8
jne 0xfb3b
leaq 0x1d1f8(%rip), %rdi     # 0x2cd2c
xorl %eax, %eax
callq 0x16cd0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop