// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/analyzer/analyzer-explain.c
// Function: getMinimalPgnLength
static unsigned int getMinimalPgnLength(Pgn *pgn, bool *isVariable)
{
  // Count all fields until the first repeating field
  uint32_t     fieldCount = pgn->fieldCount;
  unsigned int length     = 0;

  *isVariable = false;
  if (pgn->repeatingCount1 > 0)
  {
    fieldCount -= pgn->repeatingCount1 + pgn->repeatingCount2;
    *isVariable = true;
  }

  logDebug("PGN %u fieldCount=%u (was %u)\n", pgn->pgn, fieldCount, pgn->fieldCount);

  for (uint32_t i = 0; i < fieldCount; i++)
  {
    Field *f = &pgn->fieldList[i];

    if (f->size == LEN_VARIABLE)
    {
      *isVariable = true;
    }
    else
    {
      length += f->size;
    }
  }

  if (length % 8 != 0)
  {
    logAbort("PGN %u '%s' has a length of %u bits that does not fill bytes exactly\n", pgn->pgn, pgn->description, length);
  }

  length /= 8; // Bits to bytes

  if (pgn->type == PACKET_SINGLE && length != 8 && pgn->pgn != 59904)
  {
    logAbort("PGN %u '%s' has a length %u bytes but a single-frame PGN should be 8 bytes\n", pgn->pgn, pgn->description, length);
  }

  logDebug("PGN %u len=%u\n", pgn->pgn, length);
  return length;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x15c0(%rax), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rax
movzbl 0x15eb(%rax), %eax
cmpl $0x0, %eax
jle 0xf182
movq -0x8(%rbp), %rax
movzbl 0x15eb(%rax), %ecx
movq -0x8(%rbp), %rax
movzbl 0x15ec(%rax), %eax
addl %eax, %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x14(%rbp), %edx
movq -0x8(%rbp), %rax
movl 0x15c0(%rax), %ecx
leaq 0x18bb2(%rip), %rdi     # 0x27d4f
movb $0x0, %al
callq 0x1f670
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0xf1f9
movq -0x8(%rbp), %rax
addq $0x18, %rax
movl -0x1c(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xf1df
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0xf1ec
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0xf1ee
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf1ab
movl -0x18(%rbp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0xf223
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rdx
movl -0x18(%rbp), %ecx
leaq 0x18b52(%rip), %rdi     # 0x27d6e
movb $0x0, %al
callq 0x1f7d0
movl -0x18(%rbp), %eax
shrl $0x3, %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0xf268
cmpl $0x8, -0x18(%rbp)
je 0xf268
movq -0x8(%rbp), %rax
cmpl $0xea00, 0x8(%rax)      # imm = 0xEA00
je 0xf268
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rdx
movl -0x18(%rbp), %ecx
leaq 0x18b53(%rip), %rdi     # 0x27db4
movb $0x0, %al
callq 0x1f7d0
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x18(%rbp), %edx
leaq 0x18b87(%rip), %rdi     # 0x27e00
movb $0x0, %al
callq 0x1f670
movl -0x18(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)