// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/n2kd/gps_ais.c
// Function: aisToNmea0183
static void aisToNmea0183(StringBuffer *msg183, int src, char *aisTalkerId, char channel, aisVector *bitVec)
{
  static char   sequenceId = '0';
  int           opos       = 0;
  unsigned char padding    = 0;
  int           fragments;
  int           fragCntr = 1;

  fragments = bitVec->pos / 360;
  if (bitVec->pos % 360)
  {
    fragments++;
  }
  // We maintain 10 sequential message ID for multi-sentence messages
  if (fragments > 1)
  {
    sequenceId = (((sequenceId - '0') + 1) % 10) + '0';
  }

  while (fragCntr <= fragments)
  {
    char payload[61];
    int  i = 0;

    while (i < 60 && opos <= bitVec->pos)
    {
      payload[i] = nextPayloadChar(bitVec, &opos, &padding);
      if (payload[i] == '\0')
      {
        break;
      }
      i++;
    }
    payload[i] = '\0';

    if (fragments > 1)
    {
      nmea0183CreateMessage(
          msg183, src, "%s,%d,%d,%c,%c,%s,%d", aisTalkerId, fragments, fragCntr, sequenceId, channel, payload, padding);
    }
    else
    {
      nmea0183CreateMessage(msg183, src, "%s,%d,%d,,%c,%s,%d", aisTalkerId, fragments, fragCntr, channel, payload, padding);
    }

    fragCntr++;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xa8, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movb $0x0, -0x35(%rbp)
movl $0x1, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl 0xe4(%rax), %eax
movl $0x168, %ecx            # imm = 0x168
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movl 0xe4(%rax), %eax
movl $0x168, %ecx            # imm = 0x168
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x86f7
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x3c(%rbp)
jle 0x871d
movsbl 0x8c90(%rip), %eax      # 0x11394
subl $0x30, %eax
addl $0x1, %eax
movl $0xa, %ecx
cltd
idivl %ecx
addl $0x30, %edx
movb %dl, %al
movb %al, 0x8c77(%rip)       # 0x11394
jmp 0x871f
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x884d
movl $0x0, -0x84(%rbp)
xorl %eax, %eax
cmpl $0x3c, -0x84(%rbp)
movb %al, -0x85(%rbp)
jge 0x875c
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0xe4(%rcx), %eax
setle %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
testb $0x1, %al
jne 0x8768
jmp 0x87aa
movq -0x30(%rbp), %rdi
leaq -0x34(%rbp), %rsi
leaq -0x35(%rbp), %rdx
callq 0x8860
movb %al, %cl
movslq -0x84(%rbp), %rax
movb %cl, -0x80(%rbp,%rax)
movslq -0x84(%rbp), %rax
movsbl -0x80(%rbp,%rax), %eax
cmpl $0x0, %eax
jne 0x8799
jmp 0x87aa
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x8735
movslq -0x84(%rbp), %rax
movb $0x0, -0x80(%rbp,%rax)
cmpl $0x1, -0x3c(%rbp)
jle 0x8804
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rcx
movl -0x3c(%rbp), %r8d
movl -0x40(%rbp), %r9d
movsbl 0x8bbe(%rip), %ebx      # 0x11394
movsbl -0x21(%rbp), %r11d
leaq -0x80(%rbp), %r10
movzbl -0x35(%rbp), %eax
leaq 0x4deb(%rip), %rdx      # 0xd5d5
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x89b0
jmp 0x883f
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rcx
movl -0x3c(%rbp), %r8d
movl -0x40(%rbp), %r9d
movsbl -0x21(%rbp), %r11d
leaq -0x80(%rbp), %r10
movzbl -0x35(%rbp), %eax
leaq 0x4dbf(%rip), %rdx      # 0xd5ea
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x89b0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x871f
addq $0xa8, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)