// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/n2kd/nmea0183.c
// Function: nmea0183CreateMessage
extern void nmea0183CreateMessage(StringBuffer *msg183, int src, const char *format, ...)
{
  uint8_t chk;
  size_t  i;
  char    first, second;
  va_list ap;

  va_start(ap, format);

  // Convert the 8 bit value 'n' into a valid NMEA0183 style sender.
  // The first implementation sent out a 2 digit hexadecimal number,
  // but that throws some implementations of receivers off as they
  // cannot handle numeric senders. So now we produce a 2 character
  // code with the src value 0-255 translated into
  // A..Q A..P with A representing 0, B representing 1, etc.
  // P is skipped for the initial letter, as that represents 'proprietary'
  // and OpenCPN does not allow this.

  first  = 'A' + ((src >> 4) & 0xf);
  second = 'A' + ((src) & 0xf);
  if (first >= 'P')
  {
    first++;
  }

  // Prepare for calculation of checksum
  i = msg183->len;

  if (src > 255)
    sbAppendFormat(msg183, "!%c%c", first, second);
  else
    sbAppendFormat(msg183, "$%c%c", first, second);
  sbAppendFormatV(msg183, format, ap);

  va_end(ap);

  chk = 0;
  for (i++; i < msg183->len; i++)
  {
    chk ^= (uint8_t) msg183->data[i];
  }
  sbAppendFormat(msg183, "*%02X\r\n", chk);
  logDebug("nmea0183 = %s", sbGet(msg183));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
testb %al, %al
je 0x89ee
movaps %xmm0, -0xd0(%rbp)
movaps %xmm1, -0xc0(%rbp)
movaps %xmm2, -0xb0(%rbp)
movaps %xmm3, -0xa0(%rbp)
movaps %xmm4, -0x90(%rbp)
movaps %xmm5, -0x80(%rbp)
movaps %xmm6, -0x70(%rbp)
movaps %xmm7, -0x60(%rbp)
movq %r9, -0xd8(%rbp)
movq %r8, -0xe0(%rbp)
movq %rcx, -0xe8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x50(%rbp), %rax
leaq -0x100(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x18, (%rax)
movl -0xc(%rbp), %eax
sarl $0x4, %eax
andl $0xf, %eax
addl $0x41, %eax
movb %al, -0x29(%rbp)
movl -0xc(%rbp), %eax
andl $0xf, %eax
addl $0x41, %eax
movb %al, -0x2a(%rbp)
movsbl -0x29(%rbp), %eax
cmpl $0x50, %eax
jl 0x8a5e
movb -0x29(%rbp), %al
addb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
cmpl $0xff, -0xc(%rbp)
jle 0x8a8f
movq -0x8(%rbp), %rdi
movsbl -0x29(%rbp), %edx
movsbl -0x2a(%rbp), %ecx
leaq 0x4ba2(%rip), %rsi      # 0xd628
movb $0x0, %al
callq 0xa2b0
jmp 0x8aa9
movq -0x8(%rbp), %rdi
movsbl -0x29(%rbp), %edx
movsbl -0x2a(%rbp), %ecx
leaq 0x4b8c(%rip), %rsi      # 0xd62e
movb $0x0, %al
callq 0xa2b0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0xa570
leaq -0x50(%rbp), %rax
movb $0x0, -0x19(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x8b02
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
movzbl -0x19(%rbp), %eax
xorl %ecx, %eax
movb %al, -0x19(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x8ace
movq -0x8(%rbp), %rdi
movzbl -0x19(%rbp), %edx
leaq 0x4b23(%rip), %rsi      # 0xd634
movb $0x0, %al
callq 0xa2b0
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8b32
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
jmp 0x8b42
leaq 0x3cd6(%rip), %rax      # 0xc80f
movq %rax, -0x108(%rbp)
jmp 0x8b42
movq -0x108(%rbp), %rsi
leaq 0x4aec(%rip), %rdi      # 0xd63c
xorl %eax, %eax
callq 0x9ae0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq