// File: planaria[P]cb_tree/tests/test_util.hpp
// Function: encode_base64(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
inline std::string encode_base64(const std::string& str)
{
	static const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

	const unsigned char* const s = reinterpret_cast<const unsigned char*>(str.c_str());
	std::string result((str.size() + 2) / 3 * 4, '=');
	std::size_t src_pos = 0;
	std::size_t dst_pos = 0;

	while (true)
	{
		if (src_pos == str.size())
			break;

		result[dst_pos] = table[(s[src_pos] & 0xfc) >> 2];

		if (src_pos == str.size() - 1)
		{
			result[dst_pos + 1] = table[(s[src_pos] & 0x03) << 4];
			break;
		}

		result[dst_pos + 1] = table[((s[src_pos] & 0x03) << 4) | ((s[src_pos + 1] & 0xf0) >> 4)];

		if (src_pos == str.size() - 2)
		{
			result[dst_pos + 2] = table[(s[src_pos + 1] & 0x0f) << 2];
			break;
		}

		result[dst_pos + 2] = table[((s[src_pos + 1] & 0x0f) << 2) | ((s[src_pos + 2] & 0xc0) >> 6)];
		result[dst_pos + 3] = table[s[src_pos + 2] & 0x3f];

		dst_pos += 4;
		src_pos += 3;
	}

	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x58(%rbp)
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc220
movq %rax, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc3e0
addq $0x2, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %rax
addq %rax, %rax
andq $-0x4, %rax
movq %rax, -0x50(%rbp)
leaq -0x1a(%rbp), %rdi
movq %rdi, -0x48(%rbp)
callq 0xc9c0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rcx
movl $0x3d, %edx
callq 0x2ec50
jmp 0x2e73c
leaq -0x1a(%rbp), %rdi
callq 0xc620
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
jmp 0x2e757
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc3e0
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jne 0x2e793
jmp 0x2e9de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1a(%rbp), %rdi
callq 0xc620
jmp 0x2e9fe
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shrl $0x2, %eax
leaq 0x83553(%rip), %rcx     # 0xb1d00
movb (%rax,%rcx), %al
movb %al, -0x71(%rbp)
movq -0x40(%rbp), %rsi
callq 0xcaa0
movq %rax, -0x70(%rbp)
jmp 0x2e7c2
movq -0x70(%rbp), %rax
movb -0x71(%rbp), %cl
movb %cl, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc3e0
movq %rax, %rcx
movq -0x80(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x2e855
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0x3, %eax
shll $0x4, %eax
leaq 0x834f7(%rip), %rcx     # 0xb1d00
movb (%rax,%rcx), %al
movb %al, -0x89(%rbp)
movq -0x40(%rbp), %rsi
incq %rsi
callq 0xcaa0
movq %rax, -0x88(%rbp)
jmp 0x2e827
movq -0x88(%rbp), %rax
movb -0x89(%rbp), %cl
movb %cl, (%rax)
jmp 0x2e9de
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0xcad8
jmp 0x2e9fe
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl 0x1(%rcx,%rdx), %ecx
shrl $0x4, %ecx
orl %ecx, %eax
leaq 0x83484(%rip), %rcx     # 0xb1d00
movb (%rax,%rcx), %al
movb %al, -0x99(%rbp)
movq -0x40(%rbp), %rsi
incq %rsi
callq 0xcaa0
movq %rax, -0x98(%rbp)
jmp 0x2e89a
movq -0x98(%rbp), %rax
movb -0x99(%rbp), %cl
movb %cl, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc3e0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
subq $0x2, %rcx
cmpq %rcx, %rax
jne 0x2e920
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movzbl 0x1(%rax,%rcx), %eax
andl $0xf, %eax
movl %eax, %ecx
leaq 0x83413(%rip), %rax     # 0xb1d00
movb (%rax,%rcx,4), %al
movb %al, -0xb1(%rbp)
movq -0x40(%rbp), %rsi
addq $0x2, %rsi
callq 0xcaa0
movq %rax, -0xb0(%rbp)
jmp 0x2e90c
movq -0xb0(%rbp), %rax
movb -0xb1(%rbp), %cl
movb %cl, (%rax)
jmp 0x2e9de
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
movzbl 0x1(%rcx,%rdx), %eax
andl $0xf, %eax
movzbl 0x2(%rcx,%rdx), %edx
shrl $0x6, %edx
movl %eax, %ecx
movl %edx, %eax
leal (%rax,%rcx,4), %eax
leaq 0x833b6(%rip), %rcx     # 0xb1d00
movb (%rax,%rcx), %al
movb %al, -0xc1(%rbp)
movq -0x40(%rbp), %rsi
addq $0x2, %rsi
callq 0xcaa0
movq %rax, -0xc0(%rbp)
jmp 0x2e969
movq -0x58(%rbp), %rdi
movq -0xc0(%rbp), %rax
movb -0xc1(%rbp), %cl
movb %cl, (%rax)
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movzbl 0x2(%rax,%rcx), %eax
andl $0x3f, %eax
leaq 0x8336d(%rip), %rcx     # 0xb1d00
movb (%rax,%rcx), %al
movb %al, -0xd1(%rbp)
movq -0x40(%rbp), %rsi
addq $0x3, %rsi
callq 0xcaa0
movq %rax, -0xd0(%rbp)
jmp 0x2e9b2
movq -0xd0(%rbp), %rax
movb -0xd1(%rbp), %cl
movb %cl, (%rax)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
jmp 0x2e755
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x2e9f1
movq -0x58(%rbp), %rdi
callq 0xcad8
movq -0x60(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0xc9b0
nopw (%rax,%rax)