// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/base64.c
// Function: base64Encode
char *base64Encode(char *input, size_t inplen)
/* Use base64 to encode a string.  Returns one long encoded
 * string which need to be freeMem'd. Note: big-endian algorithm.
 * For some applications you may need to break the base64 output
 * of this function into lines no longer than 76 chars.
 */
{
char b64[] = B64CHARS;
int words = (inplen+2)/3;
int remains = inplen % 3;
char *result = (char *)needMem(4*words+1);
size_t i=0, j=0;
int word = 0;
unsigned char *p = (unsigned char*) input;  
/* p must be unsigned char*,  because without "unsigned",
sign extend messes up last group outputted
when the value of the chars following last in input
happens to be char 0x80 or higher */
for(i=1; i<=words; i++)
    {
    word = 0;
    word |= *p++;
    word <<= 8;
    word |= *p++;
    word <<= 8;
    word |= *p++;
    if (i==words && remains>0)
	{
	word &= 0x00FFFF00;
    	if (remains==1)
    	    word &= 0x00FF0000;
	}
    result[j++]=b64[word >> 18 & 0x3F];
    result[j++]=b64[word >> 12 & 0x3F];
    result[j++]=b64[word >> 6 & 0x3F];
    result[j++]=b64[word & 0x3F];
    }
result[j] = 0;
if (remains >0) result[j-1] = '=';    
if (remains==1) result[j-2] = '=';    
return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0x7eaf2(%rip), %rsi     # 0xdf3d0
movl $0x41, %edx
callq 0x6570
movq -0x10(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
shll $0x2, %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x40c50
movq %rax, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x1, -0x78(%rbp)
movq -0x78(%rbp), %rax
movslq -0x64(%rbp), %rcx
cmpq %rcx, %rax
ja 0x60ae2
movl $0x0, -0x84(%rbp)
movq -0x90(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x90(%rbp)
movzbl (%rax), %eax
orl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x84(%rbp)
movq -0x90(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x90(%rbp)
movzbl (%rax), %eax
orl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x84(%rbp)
movq -0x90(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x90(%rbp)
movzbl (%rax), %eax
orl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x78(%rbp), %rax
movslq -0x64(%rbp), %rcx
cmpq %rcx, %rax
jne 0x60a34
cmpl $0x0, -0x68(%rbp)
jle 0x60a34
movl -0x84(%rbp), %eax
andl $0xffff00, %eax         # imm = 0xFFFF00
movl %eax, -0x84(%rbp)
cmpl $0x1, -0x68(%rbp)
jne 0x60a32
movl -0x84(%rbp), %eax
andl $0xff0000, %eax         # imm = 0xFF0000
movl %eax, -0x84(%rbp)
jmp 0x60a34
movl -0x84(%rbp), %eax
sarl $0x12, %eax
andl $0x3f, %eax
cltq
movb -0x60(%rbp,%rax), %dl
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x80(%rbp)
movb %dl, (%rax,%rcx)
movl -0x84(%rbp), %eax
sarl $0xc, %eax
andl $0x3f, %eax
cltq
movb -0x60(%rbp,%rax), %dl
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x80(%rbp)
movb %dl, (%rax,%rcx)
movl -0x84(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
cltq
movb -0x60(%rbp,%rax), %dl
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x80(%rbp)
movb %dl, (%rax,%rcx)
movl -0x84(%rbp), %eax
andl $0x3f, %eax
cltq
movb -0x60(%rbp,%rax), %dl
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x80(%rbp)
movb %dl, (%rax,%rcx)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x60952
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
movb $0x0, (%rax,%rcx)
cmpl $0x0, -0x68(%rbp)
jle 0x60b04
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
subq $0x1, %rcx
movb $0x3d, (%rax,%rcx)
cmpl $0x1, -0x68(%rbp)
jne 0x60b1a
movq -0x70(%rbp), %rax
movq -0x80(%rbp), %rcx
subq $0x2, %rcx
movb $0x3d, (%rax,%rcx)
movq -0x70(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)