// File: /workspace/github_c_makefile_star2_O2/uhlin[P]enhanced-duc/source/b64_encode.c
// Function: b64_encode
int
b64_encode(uint8_t const *src, size_t srclength, char *target, size_t targsize)
{
	size_t datalength = 0;
	uint8_t input[3];
	uint8_t output[4];
	size_t i;

	while (2 < srclength) {
		input[0] = *src++;
		input[1] = *src++;
		input[2] = *src++;
		srclength -= 3;

		output[0] = input[0] >> 2;
		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
		output[3] = input[2] & 0x3f;
		Assert(output[0] < 64);
		Assert(output[1] < 64);
		Assert(output[2] < 64);
		Assert(output[3] < 64);

		if (datalength + 4 > targsize)
			return (-1);
		target[datalength++] = Base64[output[0]];
		target[datalength++] = Base64[output[1]];
		target[datalength++] = Base64[output[2]];
		target[datalength++] = Base64[output[3]];
	}

	/* Now we worry about padding. */
	if (0 != srclength) {
		/* Get what's left. */
		input[0] = input[1] = input[2] = '\0';
		for (i = 0; i < srclength; i++)
			input[i] = *src++;

		output[0] = input[0] >> 2;
		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
		Assert(output[0] < 64);
		Assert(output[1] < 64);
		Assert(output[2] < 64);

		if (datalength + 4 > targsize)
			return (-1);
		target[datalength++] = Base64[output[0]];
		target[datalength++] = Base64[output[1]];
		if (srclength == 1)
			target[datalength++] = Pad64;
		else
			target[datalength++] = Base64[output[2]];
		target[datalength++] = Pad64;
	}
	if (datalength >= targsize)
		return (-1);
	target[datalength] = '\0';	/* Returned value doesn't count \0. */
	return (datalength);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
xorl %r10d, %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq 0x441f(%rip), %r8       # 0x9030
movq %rsi, %r11
xorl %r9d, %r9d
cmpq $0x3, %r11
jb 0x4c95
leaq 0x4(%r9), %rbx
cmpq %rcx, %rbx
ja 0x4d38
movzbl 0x2(%rdi,%r10), %r15d
movzbl 0x1(%rdi,%r10), %r12d
movzbl (%rdi,%r10), %r13d
movl %r15d, %r14d
andl $0x3f, %r14d
movl %r12d, %ebp
andl $0xf, %ebp
shrl $0x6, %r15d
leal (%r15,%rbp,4), %r15d
movl %r13d, %ebp
shll $0x4, %ebp
andl $0x30, %ebp
shrl $0x4, %r12d
orl %ebp, %r12d
shrl $0x2, %r13d
addq $-0x3, %r11
movb (%r13,%r8), %bpl
movb %bpl, (%rdx,%r9)
movb (%r12,%r8), %bpl
movb %bpl, 0x1(%rdx,%r9)
movb (%r15,%r8), %bpl
movb %bpl, 0x2(%rdx,%r9)
movb (%r14,%r8), %bpl
movb %bpl, 0x3(%rdx,%r9)
addq $0x3, %r10
movq %rbx, %r9
jmp 0x4c17
cmpq %r10, %rsi
jne 0x4ca2
movq %r9, %rdi
jmp 0x4d2d
decq %rsi
movb $0x0, -0x1(%rsp)
andw $0x0, -0x3(%rsp)
xorl %ebx, %ebx
cmpq %rbx, %r11
je 0x4cc9
leaq (%rdi,%rbx), %r14
movb (%r14,%r10), %bpl
movb %bpl, -0x3(%rsp,%rbx)
incq %rbx
jmp 0x4cb2
leaq 0x4(%r9), %rdi
cmpq %rcx, %rdi
ja 0x4d38
movzbl -0x2(%rsp), %r11d
movzbl -0x1(%rsp), %ebx
movzbl -0x3(%rsp), %r14d
movl %r14d, %ebp
shll $0x4, %ebp
andl $0x30, %ebp
movl %r11d, %r15d
shrl $0x4, %r15d
orl %ebp, %r15d
shrl $0x2, %r14d
movb (%r14,%r8), %bpl
movb %bpl, (%rdx,%r9)
movb (%r15,%r8), %bpl
movb %bpl, 0x1(%rdx,%r9)
movb $0x3d, %bpl
cmpq %r10, %rsi
je 0x4d22
andl $0xf, %r11d
shrl $0x6, %ebx
leal (%rbx,%r11,4), %esi
movb (%rsi,%r8), %bpl
movb %bpl, 0x2(%rdx,%r9)
movb $0x3d, 0x3(%rdx,%r9)
cmpq %rcx, %rdi
jae 0x4d38
movb $0x0, (%rdx,%rdi)
movl %edi, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop