// File: /workspace/github_c_makefile_star2_O3/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), %rbx
leaq 0x315f(%rip), %r14      # 0x6004
movl $0x1f4, %edx            # imm = 0x1F4
movl 0x4(%rsp), %edi
movq %rbx, %rsi
callq 0x2190
movq %rax, %r12
leaq 0x39cd(%rip), %rdi      # 0x688d
movl %r12d, %esi
xorl %eax, %eax
callq 0x37ed
testq %r12, %r12
js 0x355e
je 0x358c
movl $0x3, %edi
callq 0x3a20
testb %al, %al
je 0x2f44
leaq 0x659a(%rip), %rcx      # 0x9488
movq 0x10(%rcx), %rax
movq %rax, 0x70(%rsp)
movups (%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movl $0x20, %ecx
callq 0x3bab
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
leaq 0x36ef(%rip), %rax      # 0x6612
cmoveq %rax, %rsi
leaq 0x3999(%rip), %rdi      # 0x68c7
xorl %eax, %eax
callq 0x37ed
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2f44
callq 0x2030
movl 0x62ed(%rip), %r13d     # 0x9238
xorl %ebx, %ebx
movb 0x450(%rsp,%rbx), %bpl
movzbl %bpl, %r15d
movzbl 0x62b9(%rip), %esi      # 0x9219
movzbl 0x62b3(%rip), %edx      # 0x921a
leaq 0x3967(%rip), %rdi      # 0x68d5
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x37ed
movl 0x62b6(%rip), %r13d     # 0x9238
cmpq $0x3, %r13
ja 0x2fb3
movslq (%r14,%r13,4), %rax
addq %r14, %rax
jmpq *%rax
movb 0x6282(%rip), %al       # 0x9219
cmpb $0x1, %al
jne 0x2fb3
cmpb $0x1b, %bpl
jne 0x2fb3
testb $0x1, 0x6272(%rip)      # 0x921a
jne 0x2fb3
movb $0x1, 0x628b(%rip)      # 0x923c
jmp 0x2fbf
cmpb $0x10, %bpl
je 0x2fde
movb 0x625a(%rip), %al       # 0x9219
cmpb $0x1b, %bpl
jne 0x31ee
testb $0x1, %al
je 0x31ee
cmpb $0x0, 0x6264(%rip)      # 0x923c
jne 0x31ee
movl %r13d, 0x61eb(%rip)     # 0x91d0
jmp 0x3011
cmpb $0x1b, %bpl
jne 0x307d
movl $0x2, 0x61d5(%rip)      # 0x91d0
jmp 0x3011
cmpb $0x10, %bpl
jne 0x30b2
movl $0x3, 0x61bf(%rip)      # 0x91d0
movl $0x1, 0x621d(%rip)      # 0x9238
movl $0x3, %eax
movl $0x1, %r13d
jmp 0x3327
leal -0x1(%r15), %eax
cmpl $0x9, %eax
ja 0x30fe
leaq 0x2fd5(%rip), %rcx      # 0x6014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
leaq 0x61f3(%rip), %rdx      # 0x9240
jmpq *%rax
cmpb $0x1, 0x61c4(%rip)      # 0x921a
jne 0x31b6
movq %rdx, 0x6175(%rip)      # 0x91d8
movl $0x2, 0x61cb(%rip)      # 0x9238
movl $0x3, %eax
movl $0x2, %r13d
jmp 0x3327
movq 0x6154(%rip), %rcx      # 0x91d8
movl $0x3, %eax
movl $0x2, %r13d
leaq 0x639e(%rip), %rdx      # 0x9434
cmpq %rdx, %rcx
jae 0x3327
leaq 0x1(%rcx), %rdx
movq %rdx, 0x612e(%rip)      # 0x91d8
movb %bpl, (%rcx)
jmp 0x3327
cmpb $0x1b, %bpl
jne 0x30ce
cmpb $0x0, 0x615a(%rip)      # 0x9219
je 0x30ce
cmpb $0x0, 0x6174(%rip)      # 0x923c
je 0x3007
movq 0x6103(%rip), %rax      # 0x91d8
movl $0x3, %r13d
leaq 0x6352(%rip), %rcx      # 0x9434
cmpq %rcx, %rax
jae 0x3230
leaq 0x1(%rax), %rcx
movq %rcx, 0x60e2(%rip)      # 0x91d8
movb %bpl, (%rax)
jmp 0x3230
cmpl $0x10, %r15d
je 0x31bf
cmpl $0x1b, %r15d
jne 0x31b6
cmpb $0x0, 0x6100(%rip)      # 0x9219
jne 0x31bf
jmp 0x31b6
cmpb $0x1, 0x60ef(%rip)      # 0x921a
jne 0x31b6
movzbl 0x6107(%rip), %r15d     # 0x9240
movl %edx, %eax
notl %eax
addl 0x6095(%rip), %eax      # 0x91d8
movzbl %al, %r13d
leaq 0x37f0(%rip), %rdi      # 0x693e
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x37ed
cmpl $0x1, %r15d
je 0x32e9
cmpl $0x3, %r15d
jne 0x32f9
cmpl $0x8, %r13d
jne 0x35b1
movabsq $0x346dc5d63886594b, %rax # imm = 0x346DC5D63886594B
mulq 0x60b7(%rip)            # 0x9241
shrq $0xb, %rdx
movabsq $-0xa9730b66800, %rax   # imm = 0xFFFFF568CF499800
leaq (%rdx,%rax), %rsi
movq %rsi, 0x6295(%rip)      # 0x9438
leaq 0x37d7(%rip), %rdi      # 0x6981
xorl %eax, %eax
callq 0x37ed
jmp 0x330a
cmpb $0x1, 0x607f(%rip)      # 0x923c
jne 0x31f6
movq 0x6012(%rip), %rax      # 0x91d8
leaq 0x6267(%rip), %rcx      # 0x9434
cmpq %rcx, %rax
jae 0x31e0
leaq 0x1(%rax), %rcx
movq %rcx, 0x5ffb(%rip)      # 0x91d8
movb %bpl, (%rax)
movl 0x5fe9(%rip), %r13d     # 0x91d0
movl %r13d, 0x604a(%rip)     # 0x9238
movl %r13d, %eax
jmp 0x3327
xorl %r13d, %r13d
leaq 0x3708(%rip), %rdi      # 0x6908
movl %r15d, %esi
xorl %eax, %eax
callq 0x3880
movl $0x0, 0x6024(%rip)      # 0x9238
jmp 0x3325
movq %rdx, 0x5fb8(%rip)      # 0x91d8
movl $0x3, 0x600e(%rip)      # 0x9238
movl $0x3, %r13d
movl $0x3, %eax
jmp 0x3327
movq 0x5f97(%rip), %rsi      # 0x91d8
subq %rdx, %rsi
cmpq $0x3, %rsi
jae 0x325d
leaq 0x376f(%rip), %rdi      # 0x69c0
xorl %eax, %eax
callq 0x3880
jmp 0x330a
xorl %eax, %eax
xorl %ecx, %ecx
addb (%rax,%rdx), %cl
incq %rax
cmpq %rax, %rsi
jne 0x3261
testb %cl, %cl
je 0x3283
leaq 0x3769(%rip), %rdi      # 0x69e0
xorl %eax, %eax
callq 0x3880
jmp 0x330a
movzbl 0x5fb5(%rip), %r15d     # 0x9240
movzbl 0x5fae(%rip), %r13d     # 0x9241
leaq 0x376e(%rip), %rdi      # 0x6a08
movl %r15d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x37ed
cmpl $0x93, %r15d
je 0x32c7
cmpb $-0x6c, %r15b
jne 0x3363
cmpb $0x0, 0x5f58(%rip)      # 0x9219
je 0x3363
movl %r13d, %edx
xorl %eax, %eax
cmpb $-0x6c, %r15b
setne %al
leaq (%rax,%rax,4), %rbp
addq $0x6, %rbp
cmpq %rdx, %rbp
jbe 0x3338
leaq 0x3742(%rip), %rdi      # 0x6a29
jmp 0x3277
leaq 0x36a4(%rip), %rdi      # 0x6994
xorl %eax, %eax
callq 0x37ed
jmp 0x330a
leaq 0x36a1(%rip), %rdi      # 0x69a1
movl %r15d, %esi
xorl %eax, %eax
callq 0x3880
leaq 0x5f2f(%rip), %rax      # 0x9240
movq %rax, 0x5ec0(%rip)      # 0x91d8
movl $0x0, 0x5f16(%rip)      # 0x9238
xorl %r13d, %r13d
xorl %eax, %eax
incq %rbx
cmpq %r12, %rbx
jne 0x2f4d
jmp 0x354c
movzbl 0x5f08(%rip), %eax      # 0x9247
movl %eax, %ecx
cmpb $-0x6c, %r15b
je 0x334d
movl 0x5eff(%rip), %ecx      # 0x924c
movzbl %cl, %r13d
cmpb $-0x20, %r13b
jb 0x3382
leaq 0x36ed(%rip), %rdi      # 0x6a4b
movl %r13d, %esi
jmp 0x3303
cmpb $-0x60, %r15b
jne 0x330a
cmpb $0xb, %r13b
ja 0x347c
leaq 0x370f(%rip), %rdi      # 0x6a89
movq %r13, %rsi
jmp 0x3251
cmpb $-0x6c, %r15b
movzbl %al, %eax
movl $0x0, %ecx
cmovel %ecx, %eax
movzbl %al, %eax
movq %rax, 0x18(%rsp)
movzbl 0x5ea6(%rip), %eax      # 0x9246
movq %rax, 0x10(%rsp)
movzwl 0x5e98(%rip), %eax      # 0x9244
shll $0x8, %eax
movzbl 0x5e8c(%rip), %r15d     # 0x9243
orl %eax, %r15d
movzbl 0x5e81(%rip), %eax      # 0x9242
movl %eax, (%rsp)
movq 0x606d(%rip), %rsi      # 0x9438
leaq 0x20(%rsp), %rdi
movq %rdx, 0x8(%rsp)
callq 0x3627
subq $0x8, %rsp
movl $0x320, %esi            # imm = 0x320
leaq 0x68(%rsp), %rdi
leaq 0x3682(%rip), %rdx      # 0x6a71
movq %rax, %rcx
movl 0x8(%rsp), %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r13
pushq 0x20(%rsp)
pushq 0x30(%rsp)
callq 0x2100
addq $0x20, %rsp
movl %r13d, %r13d
addq %rbp, %r13
movq 0x8(%rsp), %rax
cmpq %rax, %r13
cmovaeq %rax, %r13
cmpq %r13, %rbp
jae 0x352e
leaq 0x60(%rsp), %rdi
callq 0x20d0
leaq (%rsp,%rax), %r15
addq $0x60, %r15
leaq 0x380(%rsp), %rsi
subq %r15, %rsi
leaq 0x5df2(%rip), %rax      # 0x9240
movzbl 0x2(%rbp,%rax), %ecx
movq %r15, %rdi
leaq 0x3626(%rip), %rdx      # 0x6a83
xorl %eax, %eax
callq 0x2100
movq %r15, %rdi
callq 0x20d0
addq %rax, %r15
incq %rbp
cmpq %rbp, %r13
jne 0x343c
jmp 0x352e
movq 0x5fb5(%rip), %rsi      # 0x9438
leaq 0x20(%rsp), %rdi
callq 0x3627
movzbl 0x5dad(%rip), %r8d      # 0x9242
orl $0x40000, %r8d          # imm = 0x40000
movl %r13d, %r10d
decl %r10d
leaq 0x60(%rsp), %r15
movq %r15, %rdi
leaq 0x35c0(%rip), %rsi      # 0x6a71
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 0x3523
movl $0x2, %ebp
leaq (%rsp,%r15), %rdi
addq $0x60, %rdi
leaq 0x5d51(%rip), %rax      # 0x9240
movzbl 0x1(%rbp,%rax), %edx
leaq 0x3588(%rip), %rsi      # 0x6a83
xorl %eax, %eax
callq 0x22b0
leaq 0x3(%r15), %rax
cmpq %r13, %rbp
jae 0x351a
incq %rbp
cmpq $0x3e0, %r15            # imm = 0x3E0
movq %rax, %r15
jl 0x34e0
addq %rsp, %rax
addq $0x60, %rax
jmp 0x352b
leaq (%rsp,%r15), %rax
addq $0x60, %rax
movb $0x0, (%rax)
leaq 0x60(%rsp), %rdi
callq 0x20a0
movq 0x5a99(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
callq 0x2200
jmp 0x330a
testl %eax, %eax
leaq 0x450(%rsp), %rbx
jne 0x2ea5
jmp 0x3577
callq 0x2050
cmpl $0xb, (%rax)
jne 0x358c
movl $0x61a8, %edi           # imm = 0x61A8
callq 0x2340
jmp 0x2ea5
movl %r12d, %eax
addq $0x648, %rsp            # imm = 0x648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x5c86(%rip)      # 0x9219
jne 0x35aa
callq 0x2050
movl (%rax), %esi
leaq 0x32f9(%rip), %rdi      # 0x689c
xorl %eax, %eax
callq 0x3913
xorl %edi, %edi
callq 0x22c0
leaq 0x33a7(%rip), %rdi      # 0x695f
movl %r13d, %esi
xorl %eax, %eax
callq 0x3880
movl $0x3, %edi
callq 0x22c0