// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/analyzer/analyzer.c
// Function: printCanFormat
static void printCanFormat(RawMessage *msg)
{
  const Pgn *pgn;
  size_t     buffer;
  Packet    *p;

  if (onlySrc >= 0 && onlySrc != msg->src)
  {
    return;
  }
  if (onlyDst >= 0 && onlyDst != msg->dst)
  {
    return;
  }
  if (onlyPgn > 0 && onlyPgn != msg->pgn)
  {
    return;
  }

  pgn = searchForPgn(msg->pgn);
  if (multiPackets == MULTIPACKETS_SEPARATE && pgn == NULL)
  {
    pgn = searchForUnknownPgn(msg->pgn);
  }
  if (multiPackets == MULTIPACKETS_COALESCED || !pgn || pgn->type != PACKET_FAST || msg->len > 8)
  {
    // No reassembly needed
    printPgn(msg, msg->data, msg->len, showData, showJson);
    return;
  }

  // Fast packet requires re-asssembly
  // We only get here if we know for sure that the PGN is fast-packet
  // Possibly it is of unknown length when the PGN is unknown.

  for (buffer = 0; buffer < REASSEMBLY_BUFFER_SIZE; buffer++)
  {
    p = &reassemblyBuffer[buffer];

    if (p->used && p->pgn == msg->pgn && p->src == msg->src)
    {
      // Found existing slot
      break;
    }
  }
  if (buffer == REASSEMBLY_BUFFER_SIZE)
  {
    // Find a free slot
    for (buffer = 0; buffer < REASSEMBLY_BUFFER_SIZE; buffer++)
    {
      p = &reassemblyBuffer[buffer];
      if (!p->used)
      {
        break;
      }
    }
    if (buffer == REASSEMBLY_BUFFER_SIZE)
    {
      logError("Out of reassembly buffers; ignoring PGN %u\n", msg->pgn);
      return;
    }
    p->used   = true;
    p->src    = msg->src;
    p->pgn    = msg->pgn;
    p->frames = 0;
  }

  {
    // YDWG can receive frames out of order, so handle this.
    uint32_t frame    = msg->data[0] & 0x1f;
    uint32_t seq      = msg->data[0] & 0xe0;
    size_t   idx      = (frame == 0) ? 0 : FASTPACKET_BUCKET_0_SIZE + (frame - 1) * FASTPACKET_BUCKET_N_SIZE;
    size_t   frameLen = (frame == 0) ? FASTPACKET_BUCKET_0_SIZE : FASTPACKET_BUCKET_N_SIZE;
    size_t   msgIdx   = (frame == 0) ? FASTPACKET_BUCKET_0_OFFSET : FASTPACKET_BUCKET_N_OFFSET;

    if ((p->frames & (1 << frame)) != 0)
    {
      logError("Received incomplete fast packet PGN %u from source %u\n", msg->pgn, msg->src);
      p->frames = 0;
    }

    if (frame == 0 && p->frames == 0)
    {
      p->size      = msg->data[1];
      p->allFrames = (uint32_t) ((UINT64_C(1) << (1 + (p->size / 7))) - 1);
    }

    memcpy(&p->data[idx], &msg->data[msgIdx], frameLen);
    p->frames |= 1 << frame;

    logDebug("Using buffer %u for reassembly of PGN %u: size %zu frame %u sequence %u idx=%zu frames=%x mask=%x\n",
             buffer,
             msg->pgn,
             p->size,
             frame,
             seq,
             idx,
             p->frames,
             p->allFrames);
    if (p->frames == p->allFrames)
    {
      // Received all data
      printPgn(msg, p->data, p->size, showData, showJson);
      p->used   = false;
      p->frames = 0;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
cmpl $0x0, 0x80fc5(%rip)     # 0x8e1c8
jl 0xd21c
movl 0x80fbd(%rip), %eax     # 0x8e1c8
movq -0x8(%rbp), %rcx
movzbl 0x45(%rcx), %ecx
cmpl %ecx, %eax
je 0xd21c
jmp 0xd5fc
cmpl $0x0, 0x80fa9(%rip)     # 0x8e1cc
jl 0xd23c
movl 0x80fa1(%rip), %eax     # 0x8e1cc
movq -0x8(%rbp), %rcx
movzbl 0x44(%rcx), %ecx
cmpl %ecx, %eax
je 0xd23c
jmp 0xd5fc
cmpl $0x0, 0x87111(%rip)     # 0x94354
jle 0xd259
movl 0x87109(%rip), %eax     # 0x94354
movq -0x8(%rbp), %rcx
cmpl 0x40(%rcx), %eax
je 0xd259
jmp 0xd5fc
movq -0x8(%rbp), %rax
movl 0x40(%rax), %edi
callq 0xb4d0
movq %rax, -0x10(%rbp)
cmpl $0x1, 0x80f48(%rip)     # 0x8e1b8
jne 0xd289
cmpq $0x0, -0x10(%rbp)
jne 0xd289
movq -0x8(%rbp), %rax
movl 0x40(%rax), %edi
callq 0xb630
movq %rax, -0x10(%rbp)
cmpl $0x0, 0x80f28(%rip)     # 0x8e1b8
je 0xd2b0
cmpq $0x0, -0x10(%rbp)
je 0xd2b0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0xd2b0
movq -0x8(%rbp), %rax
movzbl 0x46(%rax), %eax
cmpl $0x8, %eax
jle 0xd2e6
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x47, %rsi
movq -0x8(%rbp), %rax
movzbl 0x46(%rax), %edx
movb 0x8707b(%rip), %cl      # 0x94345
movb 0x87078(%rip), %al      # 0x94348
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0xd9f0
jmp 0xd5fc
movq $0x0, -0x18(%rbp)
cmpq $0x40, -0x18(%rbp)
jae 0xd353
movq -0x18(%rbp), %rcx
leaq 0x87080(%rip), %rax     # 0x94380
shlq $0x8, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0xf8(%rax)
je 0xd343
movq -0x20(%rbp), %rax
movl 0xf0(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jne 0xd343
movq -0x20(%rbp), %rax
movl 0xf4(%rax), %eax
movq -0x8(%rbp), %rcx
movzbl 0x45(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd343
jmp 0xd353
jmp 0xd345
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xd2ee
cmpq $0x40, -0x18(%rbp)
jne 0xd3ff
movq $0x0, -0x18(%rbp)
cmpq $0x40, -0x18(%rbp)
jae 0xd3a2
movq -0x18(%rbp), %rcx
leaq 0x87008(%rip), %rax     # 0x94380
shlq $0x8, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0xf8(%rax)
jne 0xd392
jmp 0xd3a2
jmp 0xd394
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xd366
cmpq $0x40, -0x18(%rbp)
jne 0xd3c3
movq -0x8(%rbp), %rax
movl 0x40(%rax), %esi
leaq 0x1d16c(%rip), %rdi     # 0x2a523
movb $0x0, %al
callq 0x22620
jmp 0xd5fc
movq -0x20(%rbp), %rax
movb $0x1, 0xf8(%rax)
movq -0x8(%rbp), %rax
movzbl 0x45(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xf4(%rax)
movq -0x8(%rbp), %rax
movl 0x40(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xf0(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0xe8(%rax)
movq -0x8(%rbp), %rax
movzbl 0x47(%rax), %eax
andl $0x1f, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x47(%rax), %eax
andl $0xe0, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0xd42a
xorl %eax, %eax
movl %eax, -0x44(%rbp)
jmp 0xd439
movl -0x24(%rbp), %eax
subl $0x1, %eax
imull $0x7, %eax, %eax
addl $0x6, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %edx
movl $0x7, %eax
movl $0x6, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
cltq
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %edx
movl $0x1, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl 0xe8(%rax), %eax
movl -0x24(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xd4bc
movq -0x8(%rbp), %rax
movl 0x40(%rax), %esi
movq -0x8(%rbp), %rax
movzbl 0x45(%rax), %edx
leaq 0x1d0a8(%rip), %rdi     # 0x2a54f
movb $0x0, %al
callq 0x22620
movq -0x20(%rbp), %rax
movl $0x0, 0xe8(%rax)
cmpl $0x0, -0x24(%rbp)
jne 0xd510
movq -0x20(%rbp), %rax
cmpl $0x0, 0xe8(%rax)
jne 0xd510
movq -0x8(%rbp), %rax
movzbl 0x48(%rax), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl $0x7, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
addq $0x1, %rcx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xec(%rax)
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
addq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x47, %rsi
addq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xb1f0
movl -0x24(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
orl 0xe8(%rax), %ecx
movl %ecx, 0xe8(%rax)
movq -0x18(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0x40(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movl -0x24(%rbp), %r8d
movl -0x28(%rbp), %r9d
movq -0x30(%rbp), %r11
movq -0x20(%rbp), %rax
movl 0xe8(%rax), %r10d
movq -0x20(%rbp), %rax
movl 0xec(%rax), %eax
leaq 0x1cfff(%rip), %rdi     # 0x2a586
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x22570
movq -0x20(%rbp), %rax
movl 0xe8(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0xec(%rcx), %eax
jne 0xd5fc
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, %edx
movb 0x86d79(%rip), %cl      # 0x94345
movb 0x86d76(%rip), %al      # 0x94348
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %ecx
movzbl %al, %r8d
callq 0xd9f0
movq -0x20(%rbp), %rax
movb $0x0, 0xf8(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0xe8(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)