// File: /workspace/github_c_makefile_star2_O2/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 $0x648, %rsp            # imm = 0x648
movl %edi, 0x4(%rsp)
leaq 0x450(%rsp), %r14
leaq 0x31ea(%rip), %rbx      # 0x6004
movl $0x1f4, %edx            # imm = 0x1F4
movl 0x4(%rsp), %edi
movq %r14, %rsi
callq 0x2190
movq %rax, %r12
leaq 0x3a58(%rip), %rdi      # 0x688d
movl %r12d, %esi
xorl %eax, %eax
callq 0x36d4
testq %r12, %r12
js 0x3473
je 0x34a1
pushq $0x3
popq %rdi
callq 0x38ff
testb %al, %al
je 0x2eb0
leaq 0x7627(%rip), %rcx      # 0xa488
movq 0x10(%rcx), %rax
movq %rax, 0x70(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
pushq $0x20
popq %rcx
callq 0x3a82
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
leaq 0x377e(%rip), %rax      # 0x6612
cmoveq %rax, %rsi
leaq 0x3a28(%rip), %rdi      # 0x68c7
xorl %eax, %eax
callq 0x36d4
movq 0x60(%rsp), %rdi
callq 0x2030
xorl %ebp, %ebp
xorl %eax, %eax
cmpq %r12, %rbp
je 0x3461
movb 0x450(%rsp,%rbp), %r14b
movzbl %r14b, %r15d
movzbl 0x7349(%rip), %esi      # 0xa219
movzbl 0x7343(%rip), %edx      # 0xa21a
movl 0x735b(%rip), %ecx      # 0xa238
leaq 0x39f1(%rip), %rdi      # 0x68d5
movl %r15d, %r8d
xorl %eax, %eax
callq 0x36d4
movl 0x7343(%rip), %r13d     # 0xa238
cmpq $0x3, %r13
ja 0x2f26
movslq (%rbx,%r13,4), %rax
addq %rbx, %rax
jmpq *%rax
movb 0x730f(%rip), %al       # 0xa219
cmpb $0x1, %al
jne 0x2f26
cmpb $0x1b, %r14b
jne 0x2f26
testb $0x1, 0x72ff(%rip)      # 0xa21a
jne 0x2f26
movb $0x1, 0x7318(%rip)      # 0xa23c
jmp 0x2f32
cmpb $0x10, %r14b
je 0x2f45
movb 0x72e7(%rip), %al       # 0xa219
cmpb $0x1b, %r14b
jne 0x2f84
testb $0x1, %al
je 0x2f84
cmpb $0x0, 0x72f9(%rip)      # 0xa23c
jne 0x2f84
movl %r13d, 0x7284(%rip)     # 0xa1d0
jmp 0x2f74
cmpb $0x1b, %r14b
jne 0x2fea
movl $0x2, 0x726e(%rip)      # 0xa1d0
jmp 0x2f74
cmpb $0x10, %r14b
jne 0x2fd2
movl $0x3, 0x725c(%rip)      # 0xa1d0
movl $0x1, 0x72ba(%rip)      # 0xa238
pushq $0x3
popq %rax
movl %eax, %r13d
testl %r13d, %r13d
sete %al
incq %rbp
jmp 0x2eb4
leal -0x1(%r15), %eax
cmpl $0x9, %eax
ja 0x3016
leaq 0x3072(%rip), %rcx      # 0x6014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x7268(%rip)      # 0xa21a
jne 0x30cf
leaq 0x7281(%rip), %rax      # 0xa240
movq %rax, 0x7212(%rip)      # 0xa1d8
movl $0x2, 0x7268(%rip)      # 0xa238
jmp 0x2f7e
cmpb $0x1b, %r14b
jne 0x2fea
cmpb $0x0, 0x723a(%rip)      # 0xa219
je 0x2fea
cmpb $0x0, 0x7254(%rip)      # 0xa23c
je 0x2f6a
movq 0x71e7(%rip), %rax      # 0xa1d8
pushq $0x3
popq %rcx
movl %ecx, %r13d
leaq 0x7436(%rip), %rcx      # 0xa434
cmpq %rcx, %rax
jae 0x2f84
leaq 0x1(%rax), %rcx
movq %rcx, 0x71ca(%rip)      # 0xa1d8
movb %r14b, (%rax)
jmp 0x2f7e
cmpl $0x10, %r15d
je 0x30d8
cmpl $0x1b, %r15d
jne 0x30cf
cmpb $0x0, 0x71e8(%rip)      # 0xa219
je 0x30cf
jmp 0x30d8
cmpb $0x1, 0x71d7(%rip)      # 0xa21a
jne 0x30cf
movzbl 0x71ef(%rip), %r14d     # 0xa240
leaq 0x71e8(%rip), %rax      # 0xa240
notl %eax
addl 0x7178(%rip), %eax      # 0xa1d8
movzbl %al, %r15d
leaq 0x38d3(%rip), %rdi      # 0x693e
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x36d4
cmpl $0x1, %r14d
je 0x320c
cmpl $0x3, %r14d
jne 0x321c
cmpl $0x8, %r15d
jne 0x34c6
movq 0x71a4(%rip), %rax      # 0xa241
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
divq %rcx
movabsq $-0xa9730b66800, %rcx   # imm = 0xFFFFF568CF499800
leaq (%rax,%rcx), %rsi
movq %rsi, 0x737c(%rip)      # 0xa438
leaq 0x38be(%rip), %rdi      # 0x6981
xorl %eax, %eax
callq 0x36d4
jmp 0x322d
cmpb $0x1, 0x7166(%rip)      # 0xa23c
jne 0x310c
movq 0x70f9(%rip), %rax      # 0xa1d8
leaq 0x734e(%rip), %rcx      # 0xa434
cmpq %rcx, %rax
jae 0x30f9
leaq 0x1(%rax), %rcx
movq %rcx, 0x70e2(%rip)      # 0xa1d8
movb %r14b, (%rax)
movl 0x70d0(%rip), %r13d     # 0xa1d0
movl %r13d, 0x7131(%rip)     # 0xa238
jmp 0x2f84
xorl %r13d, %r13d
leaq 0x37f2(%rip), %rdi      # 0x6908
movl %r15d, %esi
xorl %eax, %eax
callq 0x3765
andl $0x0, 0x7111(%rip)      # 0xa238
jmp 0x2f84
leaq 0x710d(%rip), %rax      # 0xa240
movq %rax, 0x709e(%rip)      # 0xa1d8
movl $0x3, 0x70f4(%rip)      # 0xa238
jmp 0x2f7e
movq 0x7088(%rip), %rsi      # 0xa1d8
leaq 0x70e9(%rip), %r14      # 0xa240
subq %r14, %rsi
cmpq $0x3, %rsi
jae 0x3173
leaq 0x3859(%rip), %rdi      # 0x69c0
xorl %eax, %eax
callq 0x3765
jmp 0x344b
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %rsi
je 0x3185
addb (%rcx,%r14), %al
incq %rcx
jmp 0x3177
testb %al, %al
je 0x319c
leaq 0x3850(%rip), %rdi      # 0x69e0
xorl %eax, %eax
callq 0x3765
jmp 0x344b
movzbl 0x709c(%rip), %r14d     # 0xa240
movzbl 0x7095(%rip), %r15d     # 0xa241
leaq 0x3855(%rip), %rdi      # 0x6a08
movl %r14d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x36d4
cmpl $0x93, %r14d
je 0x31e0
cmpb $-0x6c, %r14b
jne 0x3275
cmpb $0x0, 0x703f(%rip)      # 0xa219
je 0x3275
movl %r15d, %edx
xorl %eax, %eax
cmpb $-0x6c, %r14b
setne %al
leaq (%rax,%rax,4), %r15
addq $0x6, %r15
cmpq %rdx, %r15
jbe 0x3240
leaq 0x3829(%rip), %rdi      # 0x6a29
xorl %eax, %eax
callq 0x3765
jmp 0x3444
leaq 0x3781(%rip), %rdi      # 0x6994
xorl %eax, %eax
callq 0x36d4
jmp 0x322d
leaq 0x377e(%rip), %rdi      # 0x69a1
movl %r14d, %esi
xorl %eax, %eax
callq 0x3765
leaq 0x700c(%rip), %rax      # 0xa240
movq %rax, 0x6f9d(%rip)      # 0xa1d8
jmp 0x3452
movzbl 0x7000(%rip), %eax      # 0xa247
movl %eax, %ecx
cmpb $-0x6c, %r14b
je 0x3255
movl 0x6ff7(%rip), %ecx      # 0xa24c
movzbl %cl, %r13d
cmpb $-0x20, %r13b
jb 0x329f
leaq 0x37e5(%rip), %rdi      # 0x6a4b
movl %r13d, %esi
xorl %eax, %eax
callq 0x3765
jmp 0x3444
cmpb $-0x60, %r14b
leaq 0x6fc0(%rip), %r14      # 0xa240
jne 0x344b
cmpb $0xb, %r15b
ja 0x3392
leaq 0x37f2(%rip), %rdi      # 0x6a89
movq %r15, %rsi
jmp 0x3167
cmpb $-0x6c, %r14b
movzbl %al, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
movzbl %al, %eax
movq %rax, 0x10(%rsp)
movzbl 0x6f89(%rip), %eax      # 0xa246
movq %rax, 0x8(%rsp)
movzwl 0x6f7b(%rip), %eax      # 0xa244
shll $0x8, %eax
movzbl 0x6f6f(%rip), %r14d     # 0xa243
orl %eax, %r14d
movzbl 0x6f64(%rip), %eax      # 0xa242
movl %eax, (%rsp)
movq 0x7150(%rip), %rsi      # 0xa438
leaq 0x20(%rsp), %rdi
movq %rdx, 0x18(%rsp)
callq 0x352d
subq $0x8, %rsp
movl $0x320, %esi            # imm = 0x320
leaq 0x68(%rsp), %rdi
leaq 0x3765(%rip), %rdx      # 0x6a71
movq %rax, %rcx
movl 0x8(%rsp), %r8d
movl %r14d, %r9d
xorl %eax, %eax
pushq %r13
pushq 0x18(%rsp)
pushq 0x28(%rsp)
callq 0x2100
addq $0x20, %rsp
leaq 0x60(%rsp), %rdi
callq 0x20d0
leaq (%rsp,%rax), %r14
addq $0x60, %r14
movl %r13d, %r13d
addq %r15, %r13
movq 0x18(%rsp), %rax
cmpq %rax, %r13
cmovaeq %rax, %r13
cmpq %r13, %r15
jae 0x342b
leaq 0x380(%rsp), %rsi
subq %r14, %rsi
leaq 0x6ed5(%rip), %rax      # 0xa240
movzbl 0x2(%r15,%rax), %ecx
movq %r14, %rdi
leaq 0x3708(%rip), %rdx      # 0x6a83
xorl %eax, %eax
callq 0x2100
movq %r14, %rdi
callq 0x20d0
addq %rax, %r14
incq %r15
jmp 0x3350
movq 0x709f(%rip), %rsi      # 0xa438
leaq 0x20(%rsp), %rdi
callq 0x352d
movzbl 0x6e97(%rip), %r8d      # 0xa242
orl $0x40000, %r8d          # imm = 0x40000
movl %r15d, %r10d
decl %r10d
leaq 0x60(%rsp), %r14
movq %r14, %rdi
leaq 0x36aa(%rip), %rsi      # 0x6a71
movq %rax, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
xorl %eax, %eax
pushq %r10
pushq $0x0
callq 0x22b0
popq %rcx
popq %rdx
movq %r14, %rdi
callq 0x20d0
movq %rax, %r14
pushq $0x1
popq %r13
cmpq %r15, %r13
jae 0x3425
cmpq $0x3e2, %r14            # imm = 0x3E2
jg 0x3425
leaq (%rsp,%r14), %rdi
addq $0x60, %rdi
leaq 0x6e38(%rip), %rax      # 0xa240
movzbl 0x2(%r13,%rax), %edx
leaq 0x366e(%rip), %rsi      # 0x6a83
xorl %eax, %eax
callq 0x22b0
addq $0x3, %r14
incq %r13
jmp 0x33eb
movb $0x0, 0x60(%rsp,%r14)
leaq 0x60(%rsp), %rdi
callq 0x20a0
movq 0x6b9c(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
callq 0x2200
leaq 0x6df5(%rip), %r14      # 0xa240
movq %r14, 0x6d86(%rip)      # 0xa1d8
andl $0x0, 0x6ddf(%rip)      # 0xa238
xorl %r13d, %r13d
jmp 0x2f84
testb $0x1, %al
leaq 0x450(%rsp), %r14
je 0x2e1a
jmp 0x348c
callq 0x2050
cmpl $0xb, (%rax)
jne 0x34a1
movl $0x61a8, %edi           # imm = 0x61A8
callq 0x2340
jmp 0x2e1a
movl %r12d, %eax
addq $0x648, %rsp            # imm = 0x648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x6d71(%rip)      # 0xa219
jne 0x34bf
callq 0x2050
movl (%rax), %esi
leaq 0x33e4(%rip), %rdi      # 0x689c
xorl %eax, %eax
callq 0x37f6
xorl %edi, %edi
callq 0x22c0
leaq 0x3492(%rip), %rdi      # 0x695f
movl %r15d, %esi
xorl %eax, %eax
callq 0x3765
pushq $0x3
popq %rdi
callq 0x22c0
nop