// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/ikonvert-serial/../common/b64.c
// Function: sbAppendEncodeBase64
void sbAppendEncodeBase64(StringBuffer *sb, const uint8_t *data, size_t len, enum Base64Encoding encoding)
{
  /*
   * Since every 3 input characters are translated into 4 output characters
   * following buffer is big enough to translate B64_CHUNKSIZE
   * input characters (including boundary effects)
   */
  char           otemp[((B64_CHUNKSIZE + 2) / 3) * 4 + 3];
  char          *optr;
  size_t         count;
  const uint8_t *in = data;
  unsigned char  u1, u2, u3;
  const char    *encodeTable;

  switch (encoding)
  {
    case BASE64_AIS:
      encodeTable = AISEncodeTable;
      break;
    case BASE64_RFC:
    default:
      encodeTable = B64EncodeTable;
      break;
  }

  sbEnsureCapacity(sb, len * 4 / 3 + 8);

  while (len > 0)
  {
    count = CB_MIN(B64_CHUNKSIZE, len);

    len -= count;

    optr = otemp;
    while (count >= 3)
    {
      u1      = *(in++);
      u2      = *(in++);
      u3      = *(in++);
      *optr++ = encodeTable[u1 >> 2];
      *optr++ = encodeTable[((u1 & 0x03) << 4) | (u2 >> 4)];
      *optr++ = encodeTable[((u2 & 0x0f) << 2) | (u3 >> 6)];
      *optr++ = encodeTable[u3 & 0x3f];
      count -= 3;
    }

    if (count)
    {
      if (count == 2)
      {
        u1      = *(in++);
        u2      = *(in++);
        *optr++ = encodeTable[u1 >> 2];
        *optr++ = encodeTable[(unsigned) (((u1 & 0x03) << 4) | ((u2 & 0xf0) >> 4))];
        *optr++ = encodeTable[(unsigned) ((u2 & 0x0f) << 2)];
        if (encoding == BASE64_AIS)
        {
          *optr++ = encodeTable[64];
        }
      }
      else
      {
        u1      = *(in++);
        *optr++ = encodeTable[u1 >> 2];
        *optr++ = encodeTable[(unsigned) ((u1 & 0x03) << 4)];
        if (encoding == BASE64_AIS)
        {
          *optr++ = encodeTable[64];
          *optr++ = encodeTable[64];
        }
      }
    }
    *optr = 0;

    sbAppendString(sb, otemp);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0x7d82
jmp 0x7d6b
movl -0x54(%rbp), %eax
subl $0x1, %eax
jne 0x7d84
jmp 0x7d75
leaq 0x2554(%rip), %rax      # 0xa2d0
movq %rax, -0x50(%rbp)
jmp 0x7d8f
jmp 0x7d84
leaq 0x2595(%rip), %rax      # 0xa320
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
shlq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
addq $0x8, %rsi
callq 0x4a20
cmpq $0x0, -0x18(%rbp)
jbe 0x8078
movl $0x6, %eax
cmpq -0x18(%rbp), %rax
jae 0x7dd2
movl $0x6, %eax
movq %rax, -0x60(%rbp)
jmp 0x7dda
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
leaq -0x27(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x3, -0x38(%rbp)
jb 0x7ef1
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %al
movb %al, -0x41(%rbp)
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %al
movb %al, -0x42(%rbp)
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %al
movb %al, -0x43(%rbp)
movq -0x50(%rbp), %rax
movzbl -0x41(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movzbl -0x41(%rbp), %ecx
andl $0x3, %ecx
shll $0x4, %ecx
movzbl -0x42(%rbp), %edx
sarl $0x4, %edx
orl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movzbl -0x42(%rbp), %ecx
andl $0xf, %ecx
shll $0x2, %ecx
movzbl -0x43(%rbp), %edx
sarl $0x6, %edx
orl %edx, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movzbl -0x43(%rbp), %ecx
andl $0x3f, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x38(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x38(%rbp)
jmp 0x7df9
cmpq $0x0, -0x38(%rbp)
je 0x805f
cmpq $0x2, -0x38(%rbp)
jne 0x7fcb
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %al
movb %al, -0x41(%rbp)
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %al
movb %al, -0x42(%rbp)
movq -0x50(%rbp), %rax
movzbl -0x41(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movzbl -0x41(%rbp), %ecx
andl $0x3, %ecx
shll $0x4, %ecx
movzbl -0x42(%rbp), %edx
andl $0xf0, %edx
sarl $0x4, %edx
orl %edx, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movzbl -0x42(%rbp), %ecx
andl $0xf, %ecx
shll $0x2, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
cmpl $0x1, -0x1c(%rbp)
jne 0x7fc6
movq -0x50(%rbp), %rax
movb 0x40(%rax), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
jmp 0x805d
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb (%rax), %al
movb %al, -0x41(%rbp)
movq -0x50(%rbp), %rax
movzbl -0x41(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movzbl -0x41(%rbp), %ecx
andl $0x3, %ecx
shll $0x4, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
cmpl $0x1, -0x1c(%rbp)
jne 0x805b
movq -0x50(%rbp), %rax
movb 0x40(%rax), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
movb 0x40(%rax), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
jmp 0x805d
jmp 0x805f
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
leaq -0x27(%rbp), %rsi
callq 0x5060
jmp 0x7db1
addq $0x60, %rsp
popq %rbp
retq
nop