// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/analyzer/analyzer.c
// Function: detectFormat
static enum RawFormats detectFormat(const char *const msg)
{
  const char  *p;
  unsigned int len;

  if (msg[0] == '$' && strncmp(msg, "$PCDIN", 6) == 0)
  {
    logInfo("Detected Chetco protocol with all data on one line\n");
    multiPackets = MULTIPACKETS_COALESCED;
    return RAWFORMAT_CHETCO;
  }

  if (strcmp(msg, "Sequence #,Timestamp,PGN,Name,Manufacturer,Remote Address,Local Address,Priority,Single Frame,Size,Packet\n")
      == 0)
  {
    logInfo("Detected Garmin CSV protocol with relative timestamps\n");
    multiPackets = MULTIPACKETS_COALESCED;
    return RAWFORMAT_GARMIN_CSV1;
  }

  if (strcmp(msg,
             "Sequence #,Month_Day_Year_Hours_Minutes_Seconds_msTicks,PGN,Processed PGN,Name,Manufacturer,Remote Address,Local "
             "Address,Priority,Single Frame,Size,Packet\n")
      == 0)
  {
    logInfo("Detected Garmin CSV protocol with absolute timestamps\n");
    multiPackets = MULTIPACKETS_COALESCED;
    return RAWFORMAT_GARMIN_CSV2;
  }

  p = strchr(msg, ' ');
  if (p && (p[1] == '-' || p[2] == '-'))
  {
    logInfo("Detected Airmar protocol with all data on one line\n");
    multiPackets = MULTIPACKETS_COALESCED;
    return RAWFORMAT_AIRMAR;
  }

  len = getMessageByteCount(msg);
  if (len > 0)
  {
    if (len > 8)
    {
      logInfo("Detected FAST format with all frames on one line\n");
      multiPackets = MULTIPACKETS_COALESCED;
      return RAWFORMAT_FAST;
    }
    logInfo("Assuming PLAIN_OR_FAST format with one line per frame or one line per message\n");
    return RAWFORMAT_PLAIN_OR_FAST;
  }

  {
    int  a, b, c, d, f;
    char e;
    if (sscanf(msg, "%d:%d:%d.%d %c %02X ", &a, &b, &c, &d, &e, &f) == 6 && (e == 'R' || e == 'T'))
    {
      logInfo("Detected YDWG-02 protocol with one line per frame\n");
      multiPackets = MULTIPACKETS_SEPARATE;
      return RAWFORMAT_YDWG02;
    }
  }

  {
    int a, b, c, d;
    if (sscanf(msg, "A%d.%d %x %x ", &a, &b, &c, &d) == 4 || sscanf(msg, "A%d %x %x ", &a, &b, &c) == 3)
    {
      logInfo("Detected Actisense N2K Ascii protocol with all frames on one line\n");
      multiPackets = MULTIPACKETS_COALESCED;
      return RAWFORMAT_ACTISENSE_N2K_ASCII;
    }
  }

  return RAWFORMAT_UNKNOWN;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x24, %eax
jne 0xcf86
movq -0x10(%rbp), %rdi
leaq 0x1d251(%rip), %rsi     # 0x2a1a4
movl $0x6, %edx
callq 0xb070
cmpl $0x0, %eax
jne 0xcf86
leaq 0x1d242(%rip), %rdi     # 0x2a1ab
movb $0x0, %al
callq 0x22420
movl $0x0, 0x8123e(%rip)     # 0x8e1b8
movl $0x6, -0x4(%rbp)
jmp 0xd182
movq -0x10(%rbp), %rdi
leaq 0x1d24e(%rip), %rsi     # 0x2a1df
callq 0xb1b0
cmpl $0x0, %eax
jne 0xcfbf
leaq 0x1d2a8(%rip), %rdi     # 0x2a24a
movb $0x0, %al
callq 0x22420
movl $0x0, 0x81205(%rip)     # 0x8e1b8
movl $0x7, -0x4(%rbp)
jmp 0xd182
movq -0x10(%rbp), %rdi
leaq 0x1d2b7(%rip), %rsi     # 0x2a281
callq 0xb1b0
cmpl $0x0, %eax
jne 0xcff8
leaq 0x1d342(%rip), %rdi     # 0x2a31d
movb $0x0, %al
callq 0x22420
movl $0x0, 0x811cc(%rip)     # 0x8e1b8
movl $0x8, -0x4(%rbp)
jmp 0xd182
movq -0x10(%rbp), %rdi
movl $0x20, %esi
callq 0xb0e0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xd04f
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
je 0xd02b
movq -0x18(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2d, %eax
jne 0xd04f
leaq 0x1d322(%rip), %rdi     # 0x2a354
movb $0x0, %al
callq 0x22420
movl $0x0, 0x81175(%rip)     # 0x8e1b8
movl $0x5, -0x4(%rbp)
jmp 0xd182
movq -0x10(%rbp), %rdi
callq 0xd190
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jbe 0xd0a5
cmpl $0x8, -0x1c(%rbp)
jbe 0xd08b
leaq 0x1d31a(%rip), %rdi     # 0x2a388
movb $0x0, %al
callq 0x22420
movl $0x0, 0x81139(%rip)     # 0x8e1b8
movl $0x2, -0x4(%rbp)
jmp 0xd182
leaq 0x1d328(%rip), %rdi     # 0x2a3ba
movb $0x0, %al
callq 0x22420
movl $0x3, -0x4(%rbp)
jmp 0xd182
movq -0x10(%rbp), %rdi
leaq 0x1d359(%rip), %rsi     # 0x2a409
leaq -0x20(%rbp), %rdx
leaq -0x24(%rbp), %rcx
leaq -0x28(%rbp), %r8
leaq -0x2c(%rbp), %r9
leaq -0x31(%rbp), %r10
leaq -0x30(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0xb250
cmpl $0x6, %eax
jne 0xd110
movsbl -0x31(%rbp), %eax
cmpl $0x52, %eax
je 0xd0ef
movsbl -0x31(%rbp), %eax
cmpl $0x54, %eax
jne 0xd110
leaq 0x1d328(%rip), %rdi     # 0x2a41e
movb $0x0, %al
callq 0x22420
movl $0x1, 0x810b1(%rip)     # 0x8e1b8
movl $0x9, -0x4(%rbp)
jmp 0xd182
movq -0x10(%rbp), %rdi
leaq 0x1d336(%rip), %rsi     # 0x2a451
leaq -0x38(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
leaq -0x40(%rbp), %r8
leaq -0x44(%rbp), %r9
movb $0x0, %al
callq 0xb250
cmpl $0x4, %eax
je 0xd15a
movq -0x10(%rbp), %rdi
leaq 0x1d31d(%rip), %rsi     # 0x2a45f
leaq -0x38(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
leaq -0x40(%rbp), %r8
movb $0x0, %al
callq 0xb250
cmpl $0x3, %eax
jne 0xd17b
leaq 0x1d309(%rip), %rdi     # 0x2a46a
movb $0x0, %al
callq 0x22420
movl $0x0, 0x81046(%rip)     # 0x8e1b8
movl $0xa, -0x4(%rbp)
jmp 0xd182
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)