// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/misc/encoding/base64.cpp
// Function: smooth::Encoding::Base64::Encode(int) const
S::String S::Encoding::Base64::Encode(Int bytes) const
{
	if (bytes > buffer.Size()) return NIL;
	if (bytes == -1) bytes = buffer.Size();

	String	 b64;

	/* Set last byte to reserve memory and speed up processing.
	 */
	b64[(Int) Math::Ceil(bytes / 3.0) * 4] = 0;

	for (Int i = 0; i < bytes; i += 3)
	{
		Int	 val[4] = { 64, 64, 64, 64 };

				   val[0] = 						      buffer[i + 0]      >> 2;
				   val[1] = ((buffer[i + 0] &  3) << 4) | (((bytes > i + 1) ? buffer[i + 1] : 0) >> 4);
		if (bytes > i + 1) val[2] = ((buffer[i + 1] & 15) << 2) | (((bytes > i + 2) ? buffer[i + 2] : 0) >> 6);
		if (bytes > i + 2) val[3] =   buffer[i + 2] & 63;

		for (Int j = 0; j < 4; j++)
		{
			if	(val[j] >=  0 && val[j] <= 25)	b64[i / 3 * 4 + j] = 'A' + val[j] - 0;
			else if (val[j] >= 26 && val[j] <= 51)	b64[i / 3 * 4 + j] = 'a' + val[j] - 26;
			else if (val[j] >= 52 && val[j] <= 61)	b64[i / 3 * 4 + j] = '0' + val[j] - 52;
			else if (val[j] == 62)			b64[i / 3 * 4 + j] = '+';
			else if (val[j] == 63)			b64[i / 3 * 4 + j] = '/';
			else if (val[j] == 64)			b64[i / 3 * 4 + j] = '=';
		}
	}

	return b64;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq %rsi, 0x20(%rsp)
movq (%rsi), %rax
movl 0x10(%rax), %ebp
cmpl %edx, %ebp
jge 0xaab79
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58e20
jmp 0xaad06
cmpl $-0x1, %edx
cmovnel %edx, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58e20
cvtsi2sd %ebp, %xmm0
divsd 0x48a23(%rip), %xmm0    # 0xf35b8
callq 0x56cb0
shll $0x2, %eax
movq %rbx, %rdi
movl %eax, %esi
callq 0x58990
movl $0x0, (%rax)
testl %ebp, %ebp
jle 0xaad06
movl %ebp, %eax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movapd 0x67566(%rip), %xmm0    # 0x112130
movapd %xmm0, (%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movzbl (%rax,%r13), %ecx
movl %ecx, %edx
shrl $0x2, %edx
movl %edx, (%rsp)
shll $0x4, %ecx
andl $0x30, %ecx
leaq 0x1(%r13), %rdx
cmpq 0x18(%rsp), %rdx
jae 0xaac2c
movzbl 0x1(%rax,%r13), %edx
movl %edx, %esi
shrl $0x4, %esi
orl %ecx, %esi
movl %esi, 0x4(%rsp)
leaq 0x2(%r13), %rcx
xorl %esi, %esi
cmpl %ecx, %ebp
jle 0xaac1e
movzbl (%rax,%rcx), %esi
shrl $0x6, %esi
shll $0x2, %edx
andl $0x3c, %edx
orl %esi, %edx
movl %edx, 0x8(%rsp)
jmp 0xaac37
movzbl %cl, %ecx
movl %ecx, 0x4(%rsp)
leaq 0x2(%r13), %rcx
cmpl %ecx, %ebp
jle 0xaac46
movzbl (%rax,%rcx), %eax
andl $0x3f, %eax
movl %eax, 0xc(%rsp)
xorl %r14d, %r14d
movl (%rsp,%r14,4), %r15d
cmpl $0x19, %r15d
ja 0xaac65
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
addl $0x41, %r15d
jmp 0xaac99
leal -0x1a(%r15), %eax
cmpl $0x19, %eax
ja 0xaac80
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
addl $0x47, %r15d
jmp 0xaac99
leal -0x34(%r15), %eax
cmpl $0x9, %eax
ja 0xaaca7
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
addl $-0x4, %r15d
movl %r15d, (%rax)
incq %r14
cmpq $0x4, %r14
jne 0xaac49
jmp 0xaacf5
cmpl $0x40, %r15d
je 0xaace1
cmpl $0x3f, %r15d
je 0xaaccd
cmpl $0x3e, %r15d
jne 0xaac9c
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
movl $0x2b, (%rax)
jmp 0xaac9c
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
movl $0x2f, (%rax)
jmp 0xaac9c
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
movl $0x3d, (%rax)
jmp 0xaac9c
addq $0x3, %r13
addq $0x4, %r12
cmpl %r13d, %ebp
jg 0xaabc2
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaad1a
movq %rax, %r14
movq %rbx, %rdi
callq 0x59200
movq %r14, %rdi
callq 0x57090
nop