// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/actisense-serial/actisense-serial.c
// Function: n2kMessageReceived
static void n2kMessageReceived(const unsigned char *msg, size_t msgLen, const unsigned char command)
{
  unsigned int prio, src, dst;
  unsigned int pgn;
  size_t       i;
  unsigned int len;
  char         line[800];
  char        *p;
  char         dateStr[DATE_LENGTH];
  size_t       headerLen = (command == N2K_MSG_SEND) ? 6 : 11;

  if (msgLen < headerLen)
  {
    logError("Ignoring N2K message - too short\n");
    return;
  }
  prio = msg[0];
  pgn  = (unsigned int) msg[1] + 256 * ((unsigned int) msg[2] + 256 * (unsigned int) msg[3]);
  dst  = msg[4];
  if (command == N2K_MSG_SEND)
  {
    src = 0;
    len = msg[5];
  }
  else
  {
    src = msg[5];
    /* Skip the timestamp logged by the NGT-1-A in bytes 6-9 */
    len = msg[10];
  }

  if (len > 223)
  {
    logError("Ignoring N2K message - too long (%u)\n", len);
    return;
  }

  p = line;
  snprintf(p, sizeof(line), "%s,%u,%u,%u,%u,%u", fmtTimestamp(dateStr, timestamp), prio, pgn, src, dst, len);
  p += strlen(line);

  i = headerLen;
  len += i;
  if (len > msgLen)
  {
    len = msgLen;
  }
  for (; i < len; i++)
  {
    snprintf(p, line + sizeof(line) - p, ",%02x", msg[i]);
    p += strlen(p);
  }

  puts(line);
  fflush(stdout);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movzbl -0x11(%rbp), %edx
movl $0xb, %eax
movl $0x6, %ecx
cmpl $0x94, %edx
cmovel %ecx, %eax
cltq
movq %rax, -0x3b8(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x3b8(%rbp), %rax
jae 0x3cb8
leaq 0x4d45(%rip), %rdi      # 0x89f1
movb $0x0, %al
callq 0x4390
jmp 0x3e7e
movq -0x8(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
movq -0x8(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
movq -0x8(%rbp), %rdx
movzbl 0x3(%rdx), %edx
shll $0x8, %edx
addl %edx, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x4(%rax), %eax
movl %eax, -0x20(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x94, %eax
jne 0x3d11
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x5(%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x3d27
movq -0x8(%rbp), %rax
movzbl 0x5(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xa(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0xdf, -0x34(%rbp)
jbe 0x3d46
movl -0x34(%rbp), %esi
leaq 0x4cd9(%rip), %rdi      # 0x8a13
movb $0x0, %al
callq 0x4390
jmp 0x3e7e
leaq -0x360(%rbp), %rax
movq %rax, -0x368(%rbp)
movq -0x368(%rbp), %rax
movq %rax, -0x3c0(%rbp)
leaq -0x3b0(%rbp), %rdi
movq 0x76f8(%rip), %rsi      # 0xb468
callq 0x40a0
movq -0x3c0(%rbp), %rdi
movq %rax, %rcx
movl -0x18(%rbp), %r8d
movl -0x24(%rbp), %r9d
movl -0x1c(%rbp), %r11d
movl -0x20(%rbp), %r10d
movl -0x34(%rbp), %eax
movl $0x320, %esi            # imm = 0x320
leaq 0x4c9b(%rip), %rdx      # 0x8a39
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x2100
leaq -0x360(%rbp), %rdi
callq 0x20c0
addq -0x368(%rbp), %rax
movq %rax, -0x368(%rbp)
movq -0x3b8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpq -0x10(%rbp), %rax
jbe 0x3df4
movq -0x10(%rbp), %rax
movl %eax, -0x34(%rbp)
jmp 0x3df6
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
cmpq %rcx, %rax
jae 0x3e63
movq -0x368(%rbp), %rdi
leaq -0x360(%rbp), %rsi
addq $0x320, %rsi            # imm = 0x320
movq -0x368(%rbp), %rax
subq %rax, %rsi
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
leaq 0x4c17(%rip), %rdx      # 0x8a4b
movb $0x0, %al
callq 0x2100
movq -0x368(%rbp), %rdi
callq 0x20c0
addq -0x368(%rbp), %rax
movq %rax, -0x368(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3df6
leaq -0x360(%rbp), %rdi
callq 0x2090
movq 0x7162(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2200
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
nopw (%rax,%rax)