// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/actisense-serial/actisense-serial.c
// Function: readNGT1Byte
static bool readNGT1Byte(unsigned char c)
{
  static enum MSG_State prev_state = MSG_MESSAGE;
  static enum MSG_State state      = MSG_START;
  static bool           noEscape   = false;
  static unsigned char  buf[500];
  static unsigned char *head = buf;

  logDebug("readNGT1Byte isFile=%d isEBL=%d state=%d c=0x%02x\n", isFile, isEBL, state, c);

  if (state == MSG_START && isFile && !isEBL && c == ESC)
  {
    noEscape = true;
  }

  if (state == MSG_ESCAPE)
  {
    if (c == SOH && isEBL)
    {
      head  = buf;
      state = MSG_HEADER;
    }
    else if (c == LF && isEBL)
    {
      headerReceived(buf, head - buf);
      head  = buf;
      state = MSG_START;
    }
    else if (c == ETX)
    {
      messageReceived(buf, head - buf);
      head  = buf;
      state = MSG_START;
    }
    else if (c == STX)
    {
      head  = buf;
      state = MSG_MESSAGE;
    }
    else if ((c == DLE) || ((c == ESC) && isFile) || noEscape)
    {
      if (head < buf + sizeof(buf))
      {
        *head++ = c;
      }
      state = prev_state;
    }
    else
    {
      logError("DLE followed by unexpected char %02X, ignore message\n", c);
      state = MSG_START;
    }
  }
  else if (state == MSG_MESSAGE)
  {
    if (c == DLE || (isFile && (c == ESC) && !noEscape))
    {
      prev_state = state;
      state      = MSG_ESCAPE;
    }
    else if (head < buf + sizeof(buf))
    {
      *head++ = c;
    }
  }
  else if (state == MSG_HEADER)
  {
    if (c == ESC)
    {
      prev_state = state;
      state      = MSG_ESCAPE;
    }
    else if (head < buf + sizeof(buf))
    {
      *head++ = c;
    }
  }
  else
  {
    if (c == DLE || (isFile && (c == ESC) && !noEscape))
    {
      prev_state = state;
      state      = MSG_ESCAPE;
    }
  }

  return state == MSG_START;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movb 0x7ae8(%rip), %al       # 0xb24c
andb $0x1, %al
movzbl %al, %esi
movb 0x7ade(%rip), %al       # 0xb24d
andb $0x1, %al
movzbl %al, %edx
movl 0x7aee(%rip), %ecx      # 0xb268
movzbl -0x1(%rbp), %r8d
leaq 0x5117(%rip), %rdi      # 0x889d
movb $0x0, %al
callq 0x42e0
cmpl $0x0, 0x7ad4(%rip)      # 0xb268
jne 0x37b8
testb $0x1, 0x7aaf(%rip)      # 0xb24c
je 0x37b8
testb $0x1, 0x7aa7(%rip)      # 0xb24d
jne 0x37b8
movzbl -0x1(%rbp), %eax
cmpl $0x1b, %eax
jne 0x37b8
movb $0x1, 0x7ab4(%rip)      # 0xb26c
cmpl $0x1, 0x7aa9(%rip)      # 0xb268
jne 0x3934
movzbl -0x1(%rbp), %eax
cmpl $0x1, %eax
jne 0x37f4
testb $0x1, 0x7a78(%rip)      # 0xb24d
je 0x37f4
leaq 0x7a92(%rip), %rax      # 0xb270
movq %rax, 0x79fb(%rip)      # 0xb1e0
movl $0x2, 0x7a79(%rip)      # 0xb268
jmp 0x392f
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0x3840
testb $0x1, 0x7a49(%rip)      # 0xb24d
je 0x3840
movq 0x79d3(%rip), %rsi      # 0xb1e0
leaq 0x7a5c(%rip), %rax      # 0xb270
subq %rax, %rsi
leaq 0x7a52(%rip), %rdi      # 0xb270
callq 0x3a60
leaq 0x7a46(%rip), %rax      # 0xb270
movq %rax, 0x79af(%rip)      # 0xb1e0
movl $0x0, 0x7a2d(%rip)      # 0xb268
jmp 0x392d
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x3883
movq 0x7990(%rip), %rsi      # 0xb1e0
leaq 0x7a19(%rip), %rax      # 0xb270
subq %rax, %rsi
leaq 0x7a0f(%rip), %rdi      # 0xb270
callq 0x3b50
leaq 0x7a03(%rip), %rax      # 0xb270
movq %rax, 0x796c(%rip)      # 0xb1e0
movl $0x0, 0x79ea(%rip)      # 0xb268
jmp 0x392b
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x38a9
leaq 0x79dd(%rip), %rax      # 0xb270
movq %rax, 0x7946(%rip)      # 0xb1e0
movl $0x3, 0x79c4(%rip)      # 0xb268
jmp 0x3929
movzbl -0x1(%rbp), %eax
cmpl $0x10, %eax
je 0x38cd
movzbl -0x1(%rbp), %eax
cmpl $0x1b, %eax
jne 0x38c4
testb $0x1, 0x798a(%rip)      # 0xb24c
jne 0x38cd
testb $0x1, 0x79a1(%rip)      # 0xb26c
je 0x390b
leaq 0x799c(%rip), %rax      # 0xb270
addq $0x1f4, %rax            # imm = 0x1F4
cmpq %rax, 0x78ff(%rip)      # 0xb1e0
jae 0x38fd
movb -0x1(%rbp), %cl
movq 0x78f3(%rip), %rax      # 0xb1e0
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x78e5(%rip)      # 0xb1e0
movb %cl, (%rax)
movl 0x78d5(%rip), %eax      # 0xb1d8
movl %eax, 0x795f(%rip)      # 0xb268
jmp 0x3927
movzbl -0x1(%rbp), %esi
leaq 0x4fba(%rip), %rdi      # 0x88d0
movb $0x0, %al
callq 0x4390
movl $0x0, 0x7941(%rip)      # 0xb268
jmp 0x3929
jmp 0x392b
jmp 0x392d
jmp 0x392f
jmp 0x3a4e
cmpl $0x3, 0x792d(%rip)      # 0xb268
jne 0x39b0
movzbl -0x1(%rbp), %eax
cmpl $0x10, %eax
je 0x3961
testb $0x1, 0x78ff(%rip)      # 0xb24c
je 0x3979
movzbl -0x1(%rbp), %eax
cmpl $0x1b, %eax
jne 0x3979
testb $0x1, 0x790d(%rip)      # 0xb26c
jne 0x3979
movl 0x7901(%rip), %eax      # 0xb268
movl %eax, 0x786b(%rip)      # 0xb1d8
movl $0x1, 0x78f1(%rip)      # 0xb268
jmp 0x39ab
leaq 0x78f0(%rip), %rax      # 0xb270
addq $0x1f4, %rax            # imm = 0x1F4
cmpq %rax, 0x7853(%rip)      # 0xb1e0
jae 0x39a9
movb -0x1(%rbp), %cl
movq 0x7847(%rip), %rax      # 0xb1e0
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x7839(%rip)      # 0xb1e0
movb %cl, (%rax)
jmp 0x39ab
jmp 0x3a4c
cmpl $0x2, 0x78b1(%rip)      # 0xb268
jne 0x3a0e
movzbl -0x1(%rbp), %eax
cmpl $0x1b, %eax
jne 0x39da
movl 0x78a0(%rip), %eax      # 0xb268
movl %eax, 0x780a(%rip)      # 0xb1d8
movl $0x1, 0x7890(%rip)      # 0xb268
jmp 0x3a0c
leaq 0x788f(%rip), %rax      # 0xb270
addq $0x1f4, %rax            # imm = 0x1F4
cmpq %rax, 0x77f2(%rip)      # 0xb1e0
jae 0x3a0a
movb -0x1(%rbp), %cl
movq 0x77e6(%rip), %rax      # 0xb1e0
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x77d8(%rip)      # 0xb1e0
movb %cl, (%rax)
jmp 0x3a0c
jmp 0x3a4a
movzbl -0x1(%rbp), %eax
cmpl $0x10, %eax
je 0x3a32
testb $0x1, 0x782e(%rip)      # 0xb24c
je 0x3a48
movzbl -0x1(%rbp), %eax
cmpl $0x1b, %eax
jne 0x3a48
testb $0x1, 0x783c(%rip)      # 0xb26c
jne 0x3a48
movl 0x7830(%rip), %eax      # 0xb268
movl %eax, 0x779a(%rip)      # 0xb1d8
movl $0x1, 0x7820(%rip)      # 0xb268
jmp 0x3a4a
jmp 0x3a4c
jmp 0x3a4e
cmpl $0x0, 0x7813(%rip)      # 0xb268
sete %al
andb $0x1, %al
addq $0x10, %rsp
popq %rbp
retq