// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/actisense-serial/actisense-serial.c
// Function: readNGT1
static int readNGT1(int handle)
{
  size_t        i;
  ssize_t       r;
  unsigned char c;
  unsigned char buf[500];
  bool          finish;

  do
  {
    r = read(handle, buf, sizeof(buf));
    logDebug("NGT read = %d\n", (int) r);

    if (r < 0 && errno == EAGAIN)
    {
      usleep(25000);
      continue;
    }
    if (r <= 0) /* No char read, abort message read */
    {
      if (!isFile)
      {
        logAbort("Unable to read from NGT1 device, errno=%d\n", errno);
      }
      exit(0);
    }

    if (isLogLevelEnabled(LOGLEVEL_DEBUG))
    {
      StringBuffer sb = sbNew;

      sbAppendEncodeHex(&sb, buf, r, ' ');
      logDebug("NGT data: %s\n", sbGet(&sb));
      sbClean(&sb);
    }

    for (i = 0; i < r; i++)
    {
      c      = buf[i];
      finish = readNGT1Byte(c);
    }
  } while (!finish);

  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x658, %rsp            # imm = 0x658
movl %edi, 0xc(%rsp)
leaq 0x3a24(%rip), %rbp      # 0x68f1
leaq 0x314c(%rip), %rbx      # 0x6020
movl $0x1f4, %edx            # imm = 0x1F4
movl 0xc(%rsp), %edi
leaq 0x460(%rsp), %rsi
callq 0x2190
movq %rax, %r12
leaq 0x39b5(%rip), %rdi      # 0x68a9
movl %r12d, %esi
xorl %eax, %eax
callq 0x384d
testq %r12, %r12
jns 0x2f1c
callq 0x2050
cmpl $0xb, (%rax)
jne 0x2f1c
movl $0x61a8, %edi           # imm = 0x61A8
callq 0x2340
jmp 0x35cd
testq %r12, %r12
jle 0x35ec
movl $0x3, %edi
callq 0x3a84
testb %al, %al
je 0x2fac
leaq 0x654e(%rip), %rcx      # 0x9488
movq 0x10(%rcx), %rax
movq %rax, 0x80(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x70(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x460(%rsp), %rsi
movq %r12, %rdx
movl $0x20, %ecx
callq 0x3c2d
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
leaq 0x36b7(%rip), %rax      # 0x662e
cmoveq %rax, %rsi
leaq 0x3961(%rip), %rdi      # 0x68e3
xorl %eax, %eax
callq 0x384d
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2fa1
callq 0x2030
movq $0x0, 0x70(%rsp)
leaq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
cmpq $0x1, %r12
movq %r12, 0x28(%rsp)
adcq $0x0, %r12
xorl %r14d, %r14d
movb 0x460(%rsp,%r14), %r15b
movzbl %r15b, %r13d
movzbl 0x624a(%rip), %esi      # 0x9219
movzbl 0x6244(%rip), %edx      # 0x921a
movl 0x625c(%rip), %ecx      # 0x9238
movq %rbp, %rdi
movl %r13d, %r8d
xorl %eax, %eax
callq 0x384d
movl 0x6249(%rip), %eax      # 0x9238
cmpq $0x3, %rax
ja 0x30cb
movslq (%rbx,%rax,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
cmpb $0x1, 0x6210(%rip)      # 0x9219
jne 0x3021
cmpb $0x1b, %r15b
jne 0x3021
testb $0x1, 0x6202(%rip)      # 0x921a
jne 0x3021
movb $0x1, 0x621b(%rip)      # 0x923c
cmpl $0x3, %eax
je 0x308a
cmpl $0x2, %eax
je 0x3078
cmpl $0x1, %eax
jne 0x30cb
leal -0x1(%r13), %eax
cmpl $0x9, %eax
ja 0x320f
leaq 0x2fe8(%rip), %rcx      # 0x6030
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x61c2(%rip)      # 0x921a
jne 0x310c
leaq 0x61db(%rip), %rax      # 0x9240
movq %rax, 0x616c(%rip)      # 0x91d8
movl $0x2, 0x61c2(%rip)      # 0x9238
jmp 0x30e1
cmpb $0x1b, %r15b
jne 0x30a8
movl $0x2, 0x6148(%rip)      # 0x91d0
jmp 0x30d7
cmpb $0x10, %r15b
je 0x30d1
cmpb $0x1b, %r15b
jne 0x30a8
cmpb $0x0, 0x617c(%rip)      # 0x9219
je 0x30a8
cmpb $0x0, 0x6196(%rip)      # 0x923c
je 0x30d1
movq 0x6129(%rip), %rax      # 0x91d8
leaq 0x637e(%rip), %rcx      # 0x9434
cmpq %rcx, %rax
jae 0x30e1
leaq 0x1(%rax), %rcx
movq %rcx, 0x6112(%rip)      # 0x91d8
movb %r15b, (%rax)
jmp 0x30e1
cmpb $0x10, %r15b
jne 0x30f2
movl %eax, 0x60f9(%rip)      # 0x91d0
movl $0x1, 0x6157(%rip)      # 0x9238
incq %r14
cmpq %r12, %r14
jne 0x2fbc
jmp 0x35bd
cmpb $0x1b, %r15b
jne 0x30e1
cmpb $0x0, 0x611a(%rip)      # 0x9219
je 0x30e1
cmpb $0x0, 0x6134(%rip)      # 0x923c
je 0x30d1
jmp 0x30e1
cmpl $0x9, %r13d
jle 0x31d1
cmpl $0x1b, %r13d
je 0x321b
cmpl $0x10, %r13d
je 0x322d
cmpl $0xa, %r13d
jne 0x3224
cmpb $0x1, 0x60df(%rip)      # 0x921a
jne 0x31cb
movzbl 0x60f7(%rip), %r15d     # 0x9240
leaq 0x60f0(%rip), %rax      # 0x9240
notl %eax
addl 0x6080(%rip), %eax      # 0x91d8
movzbl %al, %r13d
leaq 0x37f7(%rip), %rdi      # 0x695a
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x384d
cmpl $0x1, %r15d
je 0x3329
cmpl $0x3, %r15d
jne 0x3339
cmpl $0x8, %r13d
jne 0x3611
movabsq $0x346dc5d63886594b, %rax # imm = 0x346DC5D63886594B
mulq 0x60a2(%rip)            # 0x9241
shrq $0xb, %rdx
movabsq $-0xa9730b66800, %rax   # imm = 0xFFFFF568CF499800
leaq (%rdx,%rax), %rsi
movq %rsi, 0x6280(%rip)      # 0x9438
leaq 0x37de(%rip), %rdi      # 0x699d
xorl %eax, %eax
callq 0x384d
jmp 0x334a
cmpl $0xf, %r13d
jg 0x320f
cmpl $0x2, %r13d
je 0x325f
cmpl $0x3, %r13d
jne 0x3224
movq 0x5ff0(%rip), %rsi      # 0x91d8
leaq 0x6051(%rip), %r15      # 0x9240
subq %r15, %rsi
cmpq $0x3, %rsi
jae 0x3292
leaq 0x37d9(%rip), %rdi      # 0x69dc
xorl %eax, %eax
callq 0x38e0
jmp 0x35a7
cmpl $0x10, %r13d
je 0x322d
cmpl $0x1b, %r13d
jne 0x3224
cmpb $0x0, 0x5ff7(%rip)      # 0x9219
jne 0x322d
cmpb $0x1, 0x6011(%rip)      # 0x923c
jne 0x327c
movq 0x5fa4(%rip), %rax      # 0x91d8
leaq 0x61f9(%rip), %rcx      # 0x9434
cmpq %rcx, %rax
jae 0x324e
leaq 0x1(%rax), %rcx
movq %rcx, 0x5f8d(%rip)      # 0x91d8
movb %r15b, (%rax)
movl 0x5f7c(%rip), %eax      # 0x91d0
movl %eax, 0x5fde(%rip)      # 0x9238
jmp 0x30e1
leaq 0x5fda(%rip), %rax      # 0x9240
movq %rax, 0x5f6b(%rip)      # 0x91d8
movl $0x3, 0x5fc1(%rip)      # 0x9238
jmp 0x30e1
leaq 0x36a1(%rip), %rdi      # 0x6924
movl %r13d, %esi
xorl %eax, %eax
callq 0x38e0
jmp 0x35ae
xorl %eax, %eax
xorl %ecx, %ecx
addb (%rax,%r15), %cl
incq %rax
cmpq %rax, %rsi
jne 0x3296
testb %cl, %cl
je 0x32b9
leaq 0x374f(%rip), %rdi      # 0x69fc
xorl %eax, %eax
callq 0x38e0
jmp 0x35a7
movzbl 0x5f7f(%rip), %r15d     # 0x9240
movzbl 0x5f78(%rip), %r13d     # 0x9241
leaq 0x3754(%rip), %rdi      # 0x6a24
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x384d
cmpl $0x93, %r15d
je 0x32fd
cmpb $-0x6c, %r15b
jne 0x338e
cmpb $0x0, 0x5f22(%rip)      # 0x9219
je 0x338e
movl %r13d, %edx
xorl %eax, %eax
cmpb $-0x6c, %r15b
setne %al
leaq (%rax,%rax,4), %r13
addq $0x6, %r13
cmpq %rdx, %r13
jbe 0x335d
leaq 0x3728(%rip), %rdi      # 0x6a45
xorl %eax, %eax
callq 0x38e0
jmp 0x35a0
leaq 0x3680(%rip), %rdi      # 0x69b0
xorl %eax, %eax
callq 0x384d
jmp 0x334a
leaq 0x367d(%rip), %rdi      # 0x69bd
movl %r15d, %esi
xorl %eax, %eax
callq 0x38e0
leaq 0x5eef(%rip), %rax      # 0x9240
movq %rax, 0x5e80(%rip)      # 0x91d8
jmp 0x35ae
movzbl 0x5ee3(%rip), %eax      # 0x9247
movl %eax, %ecx
cmpb $-0x6c, %r15b
je 0x3372
movl 0x5eda(%rip), %ecx      # 0x924c
movzbl %cl, %esi
cmpb $-0x20, %sil
jb 0x33b8
leaq 0x36e5(%rip), %rdi      # 0x6a67
xorl %eax, %eax
callq 0x38e0
jmp 0x35a0
cmpb $-0x60, %r15b
leaq 0x5ea7(%rip), %r15      # 0x9240
jne 0x35a7
cmpb $0xb, %r13b
ja 0x34ce
leaq 0x36f5(%rip), %rdi      # 0x6aa5
movq %r13, %rsi
jmp 0x3203
cmpb $-0x6c, %r15b
movzbl %al, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
movzbl %al, %eax
movq %rax, (%rsp)
movzbl 0x5e71(%rip), %eax      # 0x9246
movq %rax, 0x20(%rsp)
movzbl 0x5e64(%rip), %eax      # 0x9245
shll $0x10, %eax
movzbl 0x5e59(%rip), %ecx      # 0x9244
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0x5e4b(%rip), %r15d     # 0x9243
orl %ecx, %r15d
movzbl 0x5e40(%rip), %eax      # 0x9242
movl %eax, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x6026(%rip), %rsi      # 0x9438
leaq 0x30(%rsp), %rdi
movq %rdx, 0x18(%rsp)
callq 0x3687
subq $0x8, %rsp
movl $0x320, %esi            # imm = 0x320
leaq 0x78(%rsp), %rdi
leaq 0x3657(%rip), %rdx      # 0x6a8d
movq %rax, %rcx
movl 0x10(%rsp), %r8d
movl %r15d, %r9d
xorl %eax, %eax
movq 0x18(%rsp), %r15
pushq %r15
pushq 0x30(%rsp)
pushq 0x18(%rsp)
callq 0x2100
addq $0x20, %rsp
movl %r15d, %eax
addq %r13, %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
movq %rax, (%rsp)
cmpq %rax, %r13
jae 0x3587
leaq 0x70(%rsp), %rdi
callq 0x20d0
leaq (%rsp,%rax), %r15
addq $0x70, %r15
leaq 0x390(%rsp), %rsi
subq %r15, %rsi
leaq 0x5da2(%rip), %rax      # 0x9240
movzbl 0x2(%r13,%rax), %ecx
movq %r15, %rdi
leaq 0x35f1(%rip), %rdx      # 0x6a9f
xorl %eax, %eax
callq 0x2100
movq %r15, %rdi
callq 0x20d0
addq %rax, %r15
incq %r13
cmpq %r13, (%rsp)
jne 0x348c
jmp 0x3587
movq 0x5f63(%rip), %rsi      # 0x9438
leaq 0x30(%rsp), %rdi
callq 0x3687
movzbl 0x5d5b(%rip), %r8d      # 0x9242
orl $0x40000, %r8d          # imm = 0x40000
movl %r13d, %r10d
decl %r10d
leaq 0x70(%rsp), %r15
movq %r15, %rdi
leaq 0x358a(%rip), %rsi      # 0x6a8d
movq %rax, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r10
pushq $0x0
callq 0x22b0
addq $0x10, %rsp
movq %r15, %rdi
callq 0x20d0
movq %rax, %r15
cmpq $0x3e2, %rax            # imm = 0x3E2
jg 0x357c
movq %r13, (%rsp)
movl $0x2, %r13d
leaq (%rsp,%r15), %rdi
addq $0x70, %rdi
leaq 0x5cfa(%rip), %rax      # 0x9240
movzbl 0x1(%r13,%rax), %edx
leaq 0x354c(%rip), %rsi      # 0x6a9f
xorl %eax, %eax
callq 0x22b0
leaq 0x3(%r15), %rax
cmpq (%rsp), %r13
jae 0x3573
incq %r13
cmpq $0x3e0, %r15            # imm = 0x3E0
movq %rax, %r15
jl 0x3537
addq %rsp, %rax
addq $0x70, %rax
jmp 0x3584
leaq (%rsp,%r15), %rax
addq $0x70, %rax
movb $0x0, (%rax)
leaq 0x70(%rsp), %rdi
callq 0x20a0
movq 0x5a40(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
callq 0x2200
leaq 0x5c99(%rip), %r15      # 0x9240
movq %r15, 0x5c2a(%rip)      # 0x91d8
movl $0x0, 0x5c80(%rip)      # 0x9238
jmp 0x30e1
cmpl $0x0, 0x5c74(%rip)      # 0x9238
sete %r14b
movq 0x28(%rsp), %r12
testb $0x1, %r14b
je 0x2ed4
movl %r12d, %eax
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x5c26(%rip)      # 0x9219
jne 0x360a
callq 0x2050
movl (%rax), %esi
leaq 0x32b5(%rip), %rdi      # 0x68b8
xorl %eax, %eax
callq 0x3973
xorl %edi, %edi
callq 0x22c0
leaq 0x3363(%rip), %rdi      # 0x697b
movl %r13d, %esi
xorl %eax, %eax
callq 0x38e0
movl $0x3, %edi
callq 0x22c0