// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x60(%rbp)
movq %rdi, %rax
movq %rax, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x14(%rbp), %ecx
movl %ecx, -0x48(%rbp)
movq (%rax), %rdi
callq 0x71140
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jle 0xfca50
movq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x5da90
jmp 0xfcee9
cmpl $-0x1, -0x14(%rbp)
jne 0xfca65
movq -0x50(%rbp), %rax
movq (%rax), %rdi
callq 0x71140
movl %eax, -0x14(%rbp)
movq -0x60(%rbp), %rdi
movb $0x0, -0x15(%rbp)
xorl %esi, %esi
callq 0x5da90
cvtsi2sdl -0x14(%rbp), %xmm0
movsd 0x8aaaf(%rip), %xmm1    # 0x187530
divsd %xmm1, %xmm0
callq 0x5b240
movq %rax, -0x68(%rbp)
jmp 0xfca90
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movl %eax, %esi
shll $0x2, %esi
callq 0x5d4e0
movq %rax, -0x70(%rbp)
jmp 0xfcaa8
movq -0x70(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xfced4
movq -0x50(%rbp), %rax
movaps 0xa9020(%rip), %xmm0    # 0x1a5af0
movaps %xmm0, -0x40(%rbp)
movq (%rax), %rdi
movl -0x28(%rbp), %esi
callq 0x717e0
movq %rax, -0x78(%rbp)
jmp 0xfcae5
movq -0x50(%rbp), %rax
movq -0x78(%rbp), %rcx
movzbl (%rcx), %ecx
shrl $0x2, %ecx
movl %ecx, -0x40(%rbp)
movq (%rax), %rdi
movl -0x28(%rbp), %esi
callq 0x717e0
movq %rax, -0x80(%rbp)
jmp 0xfcb07
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
andl $0x3, %eax
shll $0x4, %eax
movl %eax, -0x84(%rbp)
movl -0x14(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0xfcb53
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x28(%rbp), %esi
incl %esi
callq 0x717e0
movq %rax, -0x90(%rbp)
jmp 0xfcb41
movq -0x90(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x94(%rbp)
jmp 0xfcb5d
xorl %eax, %eax
movl %eax, -0x94(%rbp)
jmp 0xfcb5d
movl -0x84(%rbp), %eax
movl -0x94(%rbp), %ecx
sarl $0x4, %ecx
orl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0xfcc26
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x28(%rbp), %esi
incl %esi
callq 0x717e0
movq %rax, -0xa0(%rbp)
jmp 0xfcb9c
movq -0xa0(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
shll $0x2, %eax
movl %eax, -0xa4(%rbp)
movl -0x14(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jle 0xfcbec
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x28(%rbp), %esi
addl $0x2, %esi
callq 0x717e0
movq %rax, -0xb0(%rbp)
jmp 0xfcbda
movq -0xb0(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0xb4(%rbp)
jmp 0xfcbf6
xorl %eax, %eax
movl %eax, -0xb4(%rbp)
jmp 0xfcbf6
movl -0xa4(%rbp), %eax
movl -0xb4(%rbp), %ecx
sarl $0x6, %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
jmp 0xfcc26
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x5df00
jmp 0xfcef6
movl -0x14(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jle 0xfcc5e
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x28(%rbp), %esi
addl $0x2, %esi
callq 0x717e0
movq %rax, -0xc0(%rbp)
jmp 0xfcc4e
movq -0xc0(%rbp), %rax
movzbl (%rax), %eax
andl $0x3f, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x4, -0x44(%rbp)
jge 0xfcec4
movslq -0x44(%rbp), %rax
cmpl $0x0, -0x40(%rbp,%rax,4)
jl 0xfccdd
movslq -0x44(%rbp), %rax
cmpl $0x19, -0x40(%rbp,%rax,4)
jg 0xfccdd
movq -0x60(%rbp), %rdi
movslq -0x44(%rbp), %rax
movl %eax, %ecx
movl -0x40(%rbp,%rax,4), %eax
addl $0x41, %eax
movl %eax, -0xcc(%rbp)
movslq -0x28(%rbp), %rax
imulq $0x55555556, %rax, %rdx # imm = 0x55555556
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,4), %esi
callq 0x5d4e0
movq %rax, -0xc8(%rbp)
jmp 0xfccc9
movq -0xc8(%rbp), %rax
movl -0xcc(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xfceb4
movslq -0x44(%rbp), %rax
cmpl $0x1a, -0x40(%rbp,%rax,4)
jl 0xfcd4b
movslq -0x44(%rbp), %rax
cmpl $0x33, -0x40(%rbp,%rax,4)
jg 0xfcd4b
movq -0x60(%rbp), %rdi
movslq -0x44(%rbp), %rax
movl %eax, %ecx
movl -0x40(%rbp,%rax,4), %eax
addl $0x47, %eax
movl %eax, -0xdc(%rbp)
movslq -0x28(%rbp), %rax
imulq $0x55555556, %rax, %rdx # imm = 0x55555556
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,4), %esi
callq 0x5d4e0
movq %rax, -0xd8(%rbp)
jmp 0xfcd37
movq -0xd8(%rbp), %rax
movl -0xdc(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xfceb2
movslq -0x44(%rbp), %rax
cmpl $0x34, -0x40(%rbp,%rax,4)
jl 0xfcdb9
movslq -0x44(%rbp), %rax
cmpl $0x3d, -0x40(%rbp,%rax,4)
jg 0xfcdb9
movq -0x60(%rbp), %rdi
movslq -0x44(%rbp), %rax
movl %eax, %ecx
movl -0x40(%rbp,%rax,4), %eax
addl $-0x4, %eax
movl %eax, -0xec(%rbp)
movslq -0x28(%rbp), %rax
imulq $0x55555556, %rax, %rdx # imm = 0x55555556
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x20, %rdx
addl %eax, %edx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,4), %esi
callq 0x5d4e0
movq %rax, -0xe8(%rbp)
jmp 0xfcda5
movq -0xe8(%rbp), %rax
movl -0xec(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xfceb0
movslq -0x44(%rbp), %rax
cmpl $0x3e, -0x40(%rbp,%rax,4)
jne 0xfce0c
movq -0x60(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
movl %ecx, %edx
addl %eax, %edx
movl -0x44(%rbp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,4), %esi
callq 0x5d4e0
movq %rax, -0xf8(%rbp)
jmp 0xfcdfa
movq -0xf8(%rbp), %rax
movl $0x2b, (%rax)
jmp 0xfceae
movslq -0x44(%rbp), %rax
cmpl $0x3f, -0x40(%rbp,%rax,4)
jne 0xfce5c
movq -0x60(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
movl %ecx, %edx
addl %eax, %edx
movl -0x44(%rbp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,4), %esi
callq 0x5d4e0
movq %rax, -0x100(%rbp)
jmp 0xfce4d
movq -0x100(%rbp), %rax
movl $0x2f, (%rax)
jmp 0xfceac
movslq -0x44(%rbp), %rax
cmpl $0x40, -0x40(%rbp,%rax,4)
jne 0xfceaa
movq -0x60(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
movl %ecx, %edx
addl %eax, %edx
movl -0x44(%rbp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,4), %esi
callq 0x5d4e0
movq %rax, -0x108(%rbp)
jmp 0xfce9d
movq -0x108(%rbp), %rax
movl $0x3d, (%rax)
jmp 0xfceac
jmp 0xfceae
jmp 0xfceb0
jmp 0xfceb2
jmp 0xfceb4
jmp 0xfceb6
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xfcc65
jmp 0xfcec6
movl -0x28(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x28(%rbp)
jmp 0xfcab9
movb $0x1, -0x15(%rbp)
testb $0x1, -0x15(%rbp)
jne 0xfcee7
movq -0x60(%rbp), %rdi
callq 0x5df00
jmp 0xfcee9
movq -0x58(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x5b6b0
nop