// File: /workspace/github_c_makefile_star2_O1/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 0xab8dd
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58e20
jmp 0xaba6a
cmpl $-0x1, %edx
cmovnel %edx, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58e20
cvtsi2sd %ebp, %xmm0
divsd 0x48c67(%rip), %xmm0    # 0xf4560
callq 0x56cb0
shll $0x2, %eax
movq %rbx, %rdi
movl %eax, %esi
callq 0x58990
movl $0x0, (%rax)
testl %ebp, %ebp
jle 0xaba6a
movl %ebp, %eax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movapd 0x67662(%rip), %xmm0    # 0x112f90
movapd %xmm0, (%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movzbl (%rax,%r13), %edx
movl %edx, %ecx
shrl $0x2, %ecx
movl %ecx, (%rsp)
shll $0x4, %edx
andl $0x30, %edx
leaq 0x1(%r13), %rcx
cmpq 0x18(%rsp), %rcx
jae 0xab990
movzbl 0x1(%rax,%r13), %ecx
movl %ecx, %esi
shrl $0x4, %esi
orl %edx, %esi
movl %esi, 0x4(%rsp)
leaq 0x2(%r13), %rsi
xorl %edx, %edx
cmpl %esi, %ebp
jle 0xab982
movzbl (%rax,%rsi), %edx
shrl $0x6, %edx
shll $0x2, %ecx
andl $0x3c, %ecx
orl %edx, %ecx
movl %ecx, 0x8(%rsp)
jmp 0xab997
movzbl %dl, %ecx
movl %ecx, 0x4(%rsp)
leaq 0x2(%r13), %rcx
cmpl %ecx, %ebp
jle 0xab9aa
movzbl (%rax,%rcx), %eax
andl $0x3f, %eax
movl %eax, 0xc(%rsp)
xorl %r14d, %r14d
movl (%rsp,%r14,4), %r15d
cmpl $0x19, %r15d
ja 0xab9c9
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
addl $0x41, %r15d
jmp 0xab9fd
leal -0x1a(%r15), %eax
cmpl $0x19, %eax
ja 0xab9e4
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
addl $0x47, %r15d
jmp 0xab9fd
leal -0x34(%r15), %eax
cmpl $0x9, %eax
ja 0xaba0b
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
addl $-0x4, %r15d
movl %r15d, (%rax)
incq %r14
cmpq $0x4, %r14
jne 0xab9ad
jmp 0xaba59
cmpl $0x40, %r15d
je 0xaba45
cmpl $0x3f, %r15d
je 0xaba31
cmpl $0x3e, %r15d
jne 0xaba00
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
movl $0x2b, (%rax)
jmp 0xaba00
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
movl $0x2f, (%rax)
jmp 0xaba00
leal (%r12,%r14), %esi
movq %rbx, %rdi
callq 0x58990
movl $0x3d, (%rax)
jmp 0xaba00
addq $0x3, %r13
addq $0x4, %r12
cmpl %r13d, %ebp
jg 0xab926
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaba7e
movq %rax, %r14
movq %rbx, %rdi
callq 0x59200
movq %r14, %rdi
callq 0x57090
nop