// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/ikonvert-serial/../common/b64.c
// Function: sbAppendDecodeBase64
void sbAppendDecodeBase64(StringBuffer *sb, const char *data, size_t len, enum Base64Encoding encoding)
{
  const uint8_t *s    = (const uint8_t *) data;
  const uint8_t *end  = s + len;
  uint8_t       *d    = 0;
  uint32_t       n    = 0;
  int            iter = 0;
  const int     *decodeTable;

  switch (encoding)
  {
    case BASE64_AIS:
      decodeTable = AISDecodeTable;
      break;
    case BASE64_RFC:
    default:
      decodeTable = B64DecodeTable;
      break;
  }

  sbEnsureCapacity(sb, len * 3 / 4 + 8 + sbGetLength(sb));
  d = (uint8_t *) sbGet(sb) + sbGetLength(sb);

  while (s < end)
  {
    int c = decodeTable[*s++];

    switch (c)
    {
      case -2: // Whitespace
        continue;
      case -1: // Invalid
        break;
      case 64: // = pad character, end of data
        s = end;
        continue; // instead of double break
      default:
        n = n << 6 | c; // Add 6 more bits to n

        iter++;
        if (iter == 4) // Every 4 characters we have 24 bits of output data
        {
          *d++ = (uint8_t) (n >> 16);
          *d++ = (uint8_t) (n >> 8);
          *d++ = (uint8_t) (n);
          n    = 0;
          iter = 0;
        }
    }
  }

  // Handle any remainder
  if (iter == 3)
  {
    *d++ = (uint8_t) (n >> 10);
    *d++ = (uint8_t) (n >> 2);
  }
  else if (iter == 2)
  {
    *d++ = (uint8_t) (n >> 4);
  }

  sb->len = d - (uint8_t *) sbGet(sb);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0x80e7
jmp 0x80d0
movl -0x50(%rbp), %eax
subl $0x1, %eax
jne 0x80e9
jmp 0x80da
leaq 0x412f(%rip), %rax      # 0xc210
movq %rax, -0x48(%rbp)
jmp 0x80f4
jmp 0x80e9
leaq 0x4520(%rip), %rax      # 0xc610
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
imulq $0x3, -0x18(%rbp), %rsi
shrq $0x2, %rsi
addq $0x8, %rsi
movq -0x8(%rbp), %rax
addq 0x8(%rax), %rsi
callq 0x4a20
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8129
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x8136
leaq 0x161d(%rip), %rax      # 0x974d
movq %rax, -0x58(%rbp)
jmp 0x8136
movq -0x58(%rbp), %rax
movq -0x8(%rbp), %rcx
addq 0x8(%rcx), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x8216
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
incq %rdx
movq %rdx, -0x28(%rbp)
movzbl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x5c(%rbp)
subl $-0x2, %eax
je 0x8190
jmp 0x817c
movl -0x5c(%rbp), %eax
subl $-0x1, %eax
je 0x8192
jmp 0x8186
movl -0x5c(%rbp), %eax
subl $0x40, %eax
je 0x8194
jmp 0x819e
jmp 0x8146
jmp 0x8211
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x8146
movl -0x3c(%rbp), %eax
shll $0x6, %eax
orl -0x4c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
cmpl $0x4, -0x40(%rbp)
jne 0x820f
movl -0x3c(%rbp), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
jmp 0x8211
jmp 0x8146
cmpl $0x3, -0x40(%rbp)
jne 0x8250
movl -0x3c(%rbp), %eax
shrl $0xa, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
movl -0x3c(%rbp), %eax
shrl $0x2, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
jmp 0x8271
cmpl $0x2, -0x40(%rbp)
jne 0x826f
movl -0x3c(%rbp), %eax
shrl $0x4, %eax
movb %al, %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
jmp 0x8271
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8290
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x829d
leaq 0x14b6(%rip), %rax      # 0x974d
movq %rax, -0x70(%rbp)
jmp 0x829d
movq -0x68(%rbp), %rcx
movq -0x70(%rbp), %rax
subq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0x70, %rsp
popq %rbp
retq