// File: /workspace/github_cpp_makefile_star2_O2/mbourand[P]webserv/srcs/Utils/Base64.cpp
// Function: base64_encode[abi:cxx11](char const*, unsigned long)
std::string	base64_encode(const char *str, size_t len)
{
	std::string		result;
	unsigned char	bytes[3];
	size_t			new_len;
	int 			i = 0;

	if ((new_len = (4 * ((len + 2) / 3))) < len)
		return (result);
	result.reserve(new_len);
	while (len--)
	{
		bytes[i++] = *(str++);
		if (i == 3)
		{
			result.push_back(base64_chars[((bytes[0] & 0b11111100) >> 2)]);
			result.push_back(base64_chars[((bytes[0] & 0b11) << 4) + ((bytes[1] & 0b11110000) >> 4)]);
			result.push_back(base64_chars[((bytes[1] & 0b1111) << 2) + ((bytes[2] & 0b11000000) >> 6)]);
			result.push_back(base64_chars[((bytes[2] & 0b111111))]);
			i = 0;
		}
	}
	switch (i)
	{
	case 1:
		result.push_back(base64_chars[((bytes[0] & 0b11111100) >> 2)]);
		result.push_back(base64_chars[((bytes[0] & 0b11) << 4)]);
		result += "==";
		break;
	case 2:
		result.push_back(base64_chars[((bytes[0] & 0b11111100) >> 2)]);
		result.push_back(base64_chars[((bytes[0] & 0b11) << 4) + ((bytes[1] & 0b11110000) >> 4)]);
		result.push_back(base64_chars[((bytes[1] & 0b1111) << 2)]);
		result += "=";
		break;
	default:
		break;
	}
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
leaq 0x2(%rdx), %rax
pushq $0x3
popq %rcx
xorl %edx, %edx
divq %rcx
shlq $0x2, %rax
cmpq %r14, %rax
jb 0xfd62
movq %rsi, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7760
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq %r12, %r14
je 0xfca0
movb (%r15,%r12), %al
movl %ebp, %ecx
incl %ebp
movb %al, 0x5(%rsp,%rcx)
cmpl $0x3, %ebp
jne 0xfc98
movzbl 0x5(%rsp), %ebp
movl %ebp, %eax
shrl $0x2, %eax
movq 0x33948(%rip), %rcx     # 0x43570
movsbl (%rcx,%rax), %esi
movq %rbx, %rdi
callq 0x7480
shll $0x4, %ebp
andl $0x30, %ebp
movzbl 0x6(%rsp), %r13d
movl %r13d, %eax
shrl $0x4, %eax
orl %ebp, %eax
movq 0x33921(%rip), %rcx     # 0x43570
movsbl (%rcx,%rax), %esi
movq %rbx, %rdi
callq 0x7480
andl $0xf, %r13d
movzbl 0x7(%rsp), %ebp
movl %ebp, %eax
shrl $0x6, %eax
leal (%rax,%r13,4), %eax
movq 0x338fc(%rip), %rcx     # 0x43570
movsbl (%rcx,%rax), %esi
movq %rbx, %rdi
callq 0x7480
andl $0x3f, %ebp
movq 0x338e6(%rip), %rax     # 0x43570
movsbl (%rax,%rbp), %esi
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x7480
incq %r12
jmp 0xfbf9
cmpl $0x2, %ebp
je 0xfcf2
cmpl $0x1, %ebp
jne 0xfd62
movzbl 0x5(%rsp), %r14d
movl %r14d, %eax
shrl $0x2, %eax
movq 0x338af(%rip), %rcx     # 0x43570
movsbl (%rcx,%rax), %esi
movq %rbx, %rdi
callq 0x7480
shll $0x4, %r14d
andl $0x30, %r14d
movq 0x33894(%rip), %rax     # 0x43570
movsbl (%rax,%r14), %esi
movq %rbx, %rdi
callq 0x7480
leaq 0x1cd5a(%rip), %rsi     # 0x2ca4a
jmp 0xfd5a
movzbl 0x5(%rsp), %r14d
movl %r14d, %eax
shrl $0x2, %eax
movq 0x3386b(%rip), %rcx     # 0x43570
movsbl (%rcx,%rax), %esi
movq %rbx, %rdi
callq 0x7480
shll $0x4, %r14d
andl $0x30, %r14d
movzbl 0x6(%rsp), %r15d
movl %r15d, %eax
shrl $0x4, %eax
orl %r14d, %eax
movq 0x33841(%rip), %rcx     # 0x43570
movsbl (%rcx,%rax), %esi
movq %rbx, %rdi
callq 0x7480
andl $0xf, %r15d
movq 0x3382a(%rip), %rax     # 0x43570
movsbl (%rax,%r15,4), %esi
movq %rbx, %rdi
callq 0x7480
leaq 0x1ccf1(%rip), %rsi     # 0x2ca4b
movq %rbx, %rdi
callq 0x7920
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfd76
movq %rax, %r14
movq %rbx, %rdi
callq 0x79b8
movq %r14, %rdi
callq 0x7860
nopl (%rax)