// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/ikonvert-serial/ikonvert-serial.c
// Function: processInBuffer
static void processInBuffer(StringBuffer *in, StringBuffer *out)
{
  RawMessage msg;
  char      *p;

  while ((p = strchr(sbGet(in), '\n')) != 0)
  {
    if (!readonly && parseFastFormat(in, &msg) && msg.pgn < CANBOAT_PGN_START)
    {
      // Format msg as iKonvert message
      sbAppendFormat(out, TX_PGN_MSG_PREFIX, msg.pgn, msg.dst);
      if (hexMode)
      {
        sbAppendEncodeHex(out, msg.data, msg.len, 0);
      }
      else
      {
        sbAppendEncodeBase64(out, msg.data, msg.len, 0);
      }
      sbAppendFormat(out, "\r\n");
      logDebug("SendBuffer [%s]\n", sbGet(out));
    }
    else if (!readonly && msg.len > sizeof("$PDGY") && memcmp(msg.data, "$PDGY", sizeof("$PDGY")) == 0)
    {
      sbAppendData(out, msg.data, msg.len);
      sbAppendFormat(out, "\r\n");
      logDebug("SendBuffer [%s]\n", sbGet(out));
    }

    if (passthru)
    {
      ssize_t r = write(STDOUT, sbGet(in), p + 1 - sbGet(in));

      if (r <= 0)
      {
        logAbort("Cannot write to output\n");
      }
    }
    sbDelete(in, 0, p + 1 - sbGet(in));
  }

  if (!p)
  {
    if (sbGetLength(in) > sizeof("2019-01-20T14:42:04.636Z,0,129540,") + 3 * FASTPACKET_MAX_SIZE)
    {
      sbEmpty(in);
    }
    return;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x300d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x150(%rbp)
jmp 0x301d
leaq 0x6739(%rip), %rax      # 0x974d
movq %rax, -0x150(%rbp)
jmp 0x301d
movq -0x150(%rbp), %rdi
movl $0xa, %esi
callq 0x20d0
movq %rax, -0x140(%rbp)
cmpq $0x0, %rax
je 0x3313
testb $0x1, 0x99d4(%rip)      # 0xca1a
jne 0x3133
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x74b0
testb $0x1, %al
jne 0x3065
jmp 0x3133
cmpl $0x40000, -0xf8(%rbp)   # imm = 0x40000
jae 0x3133
movq -0x10(%rbp), %rdi
movl -0xf8(%rbp), %edx
movzbl -0xf4(%rbp), %ecx
leaq 0x68a2(%rip), %rsi      # 0x992f
movb $0x0, %al
callq 0x4e10
testb $0x1, 0x9981(%rip)      # 0xca1c
je 0x30be
movq -0x10(%rbp), %rdi
leaq -0x138(%rbp), %rsi
addq $0x47, %rsi
movzbl -0xf2(%rbp), %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x4d40
jmp 0x30dd
movq -0x10(%rbp), %rdi
leaq -0x138(%rbp), %rsi
addq $0x47, %rsi
movzbl -0xf2(%rbp), %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x7d40
movq -0x10(%rbp), %rdi
leaq 0x696c(%rip), %rsi      # 0x9a54
movb $0x0, %al
callq 0x4e10
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3109
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x158(%rbp)
jmp 0x3119
leaq 0x663d(%rip), %rax      # 0x974d
movq %rax, -0x158(%rbp)
jmp 0x3119
movq -0x158(%rbp), %rsi
leaq 0x6815(%rip), %rdi      # 0x993c
movb $0x0, %al
callq 0x4640
jmp 0x31e2
testb $0x1, 0x98e0(%rip)      # 0xca1a
jne 0x31e0
movzbl -0xf2(%rbp), %eax
cmpq $0x6, %rax
jbe 0x31e0
leaq -0x138(%rbp), %rdi
addq $0x47, %rdi
leaq 0x67ea(%rip), %rsi      # 0x994d
movl $0x6, %edx
callq 0x2190
cmpl $0x0, %eax
jne 0x31e0
movq -0x10(%rbp), %rdi
leaq -0x138(%rbp), %rsi
addq $0x47, %rsi
movzbl -0xf2(%rbp), %eax
movl %eax, %edx
callq 0x4c90
movq -0x10(%rbp), %rdi
leaq 0x68ba(%rip), %rsi      # 0x9a54
movb $0x0, %al
callq 0x4e10
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x31bb
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x160(%rbp)
jmp 0x31cb
leaq 0x658b(%rip), %rax      # 0x974d
movq %rax, -0x160(%rbp)
jmp 0x31cb
movq -0x160(%rbp), %rsi
leaq 0x6763(%rip), %rdi      # 0x993c
movb $0x0, %al
callq 0x4640
jmp 0x31e2
testb $0x1, 0x9830(%rip)      # 0xca19
je 0x32a6
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3209
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x168(%rbp)
jmp 0x3219
leaq 0x653d(%rip), %rax      # 0x974d
movq %rax, -0x168(%rbp)
jmp 0x3219
movq -0x168(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x170(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3253
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x180(%rbp)
jmp 0x3263
leaq 0x64f3(%rip), %rax      # 0x974d
movq %rax, -0x180(%rbp)
jmp 0x3263
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
movq -0x180(%rbp), %rax
subq %rax, %rdx
movl $0x1, %edi
callq 0x20a0
movq %rax, -0x148(%rbp)
cmpq $0x0, -0x148(%rbp)
jg 0x32a4
leaq 0x66b6(%rip), %rdi      # 0x9953
movb $0x0, %al
callq 0x47a0
jmp 0x32a6
movq -0x8(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x188(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x32dd
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x198(%rbp)
jmp 0x32ed
leaq 0x6469(%rip), %rax      # 0x974d
movq %rax, -0x198(%rbp)
jmp 0x32ed
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rdx
movq -0x198(%rbp), %rax
subq %rax, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x4b50
jmp 0x2ff3
cmpq $0x0, -0x140(%rbp)
jne 0x3381
movq -0x8(%rbp), %rax
cmpq $0x2c0, 0x8(%rax)       # imm = 0x2C0
jbe 0x337f
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq 0x8(%rcx), %rax
jae 0x3342
xorl %eax, %eax
movq %rax, -0x1a0(%rbp)
jmp 0x3351
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1a0(%rbp)
movq -0x1a0(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x337d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x337f
jmp 0x3381
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw (%rax,%rax)