// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/n2kd/gps_ais.c
// Function: addAisString
static int addAisString(char *string, int len, aisVector *payload)
{
  int           i, k;
  unsigned char nextchar;

  if (string == NULL)
  {
    return 0;
  }

  while (len >= 6)
  {
    // Encode current char to 6-bit ascii
    // 32 -> 63 => 32 -> 63, 64 -> 95 => 0 -> 31
    nextchar = *string;
    if (nextchar == '\0')
    {
      nextchar = 0;
    }
    else if (nextchar < 32 || nextchar > 95)
    {
      nextchar = 32;
    }
    else if (nextchar >= 64)
    {
      nextchar -= 64;
    }
    // Add 6-bit ascii char to payload
    i = payload->pos / 8;
    k = 8 - payload->pos % 8;
    payload->bitVector[i] &= ~(unsigned char) ((1 << k) - 1);
    if (k >= 6)
    {
      payload->bitVector[i] |= ((1 << k) - 1) & (nextchar << (k - 6));
    }
    else
    {
      payload->bitVector[i] |= ((1 << k) - 1) & (nextchar >> (6 - k));
      payload->bitVector[i + 1] = nextchar << (2 + k);
    }
    payload->pos += 6;
    len -= 6;
    if (*string != '\0')
    {
      string++;
    }
  }
  // A string can be padded with extra bits. These should reasonably be cleared
  payload->bitVector[(payload->pos / 8) + 1] = 0;
  payload->pos += len;
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x81d2
movl $0x0, -0x4(%rbp)
jmp 0x8377
jmp 0x81d4
cmpl $0x6, -0x14(%rbp)
jl 0x8333
movq -0x10(%rbp), %rax
movb (%rax), %al
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
jne 0x81f6
movb $0x0, -0x29(%rbp)
jmp 0x8225
movzbl -0x29(%rbp), %eax
cmpl $0x20, %eax
jl 0x8208
movzbl -0x29(%rbp), %eax
cmpl $0x5f, %eax
jle 0x820e
movb $0x20, -0x29(%rbp)
jmp 0x8223
movzbl -0x29(%rbp), %eax
cmpl $0x40, %eax
jl 0x8221
movzbl -0x29(%rbp), %eax
subl $0x40, %eax
movb %al, -0x29(%rbp)
jmp 0x8223
jmp 0x8225
movq -0x20(%rbp), %rax
movl 0xe4(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl 0xe4(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl $0x8, %eax
subl %edx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movzbl %al, %esi
xorl $-0x1, %esi
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
cmpl $0x6, -0x28(%rbp)
jl 0x82ae
movl -0x28(%rbp), %ecx
movl $0x1, %esi
shll %cl, %esi
subl $0x1, %esi
movzbl -0x29(%rbp), %eax
movl -0x28(%rbp), %ecx
subl $0x6, %ecx
shll %cl, %eax
andl %eax, %esi
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x82fa
movl -0x28(%rbp), %ecx
movl $0x1, %esi
shll %cl, %esi
subl $0x1, %esi
movzbl -0x29(%rbp), %eax
movl $0x6, %ecx
subl -0x28(%rbp), %ecx
sarl %cl, %eax
andl %eax, %esi
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movzbl -0x29(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x2, %ecx
shll %cl, %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl 0xe4(%rax), %ecx
addl $0x6, %ecx
movl %ecx, 0xe4(%rax)
movl -0x14(%rbp), %eax
subl $0x6, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x832e
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x81d4
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl 0xe4(%rax), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rbp), %rax
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
addl 0xe4(%rax), %ecx
movl %ecx, 0xe4(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)