// File: Alcaro[P]bridges/arlib/base64enc.cpp
// Function: base64_enc_raw(arrayvieww<unsigned char>, arrayview<unsigned char>)
void base64_enc_raw(arrayvieww<uint8_t> out, arrayview<uint8_t> bytes)
{
	if (!bytes.size()) return;
	
	uint8_t* outp = out.ptr();
	const uint8_t* inp = bytes.ptr();
	const uint8_t* inpe = inp + bytes.size();
	
	while (inp+4 <= inpe)
	{
		uint32_t three = readu_be32(inp) >> 8;
		outp[0] = encode[(three>>18)   ];
		outp[1] = encode[(three>>12)&63];
		outp[2] = encode[(three>>6 )&63];
		outp[3] = encode[(three>>0 )&63];
		inp += 3;
		outp += 4;
	}
	
	uint32_t three = inp[0]<<16;
	if (inp+1 < inpe) three |= inp[1]<<8;
	if (inp+2 < inpe) three |= inp[2]<<0;
	
	outp[0] = encode[(three>>18)   ];
	outp[1] = encode[(three>>12)&63];
	outp[2] = encode[(three>>6 )&63];
	outp[3] = encode[(three>>0 )&63];
	
	if (inp+1 >= inpe) outp[2] = '='; // don't move the outp[2,3] above into elses, it optimizes better this way
	if (inp+2 >= inpe) outp[3] = '=';
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x50(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x18(%rbp)
movq %rdi, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x6290
cmpq $0x0, %rax
jne 0x757c
jmp 0x775f
movq -0x50(%rbp), %rdi
callq 0x7490
movq %rax, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x62c0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x6290
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x4, %rax
cmpq -0x40(%rbp), %rax
ja 0x7674
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
bswapl %eax
shrl $0x8, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
shrl $0x12, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bbfc(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movl -0x44(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bbdf(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x44(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bbc1(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x44(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bba3(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x38(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
jmp 0x75b5
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
shll $0x10, %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x40(%rbp), %rax
jae 0x76a0
movq -0x38(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x8, %eax
orl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x2, %rax
cmpq -0x40(%rbp), %rax
jae 0x76bf
movq -0x38(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0x0, %eax
orl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
shrl $0x12, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bb20(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movl -0x48(%rbp), %eax
shrl $0xc, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bb03(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x48(%rbp), %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bae5(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x48(%rbp), %eax
shrl $0x0, %eax
andl $0x3f, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x5bac7(%rip), %rax     # 0x631f0
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x40(%rbp), %rax
jb 0x7749
movq -0x30(%rbp), %rax
movb $0x3d, 0x2(%rax)
movq -0x38(%rbp), %rax
addq $0x2, %rax
cmpq -0x40(%rbp), %rax
jb 0x775f
movq -0x30(%rbp), %rax
movb $0x3d, 0x3(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)