// File: /workspace/github_c_makefile_star2_O3/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 %rbx
cmpq $0x3, %rsi
jb 0x4cb3
xorl %r9d, %r9d
leaq 0x43d6(%rip), %rax      # 0x9010
leaq 0x4(%r9), %r8
cmpq %rcx, %r8
ja 0x4d6f
movzbl 0x2(%rdi), %ebx
movzbl 0x1(%rdi), %r11d
movzbl (%rdi), %r14d
movl %ebx, %r10d
andl $0x3f, %r10d
movl %r11d, %r15d
andl $0xf, %r15d
shrl $0x6, %ebx
leal (%rbx,%r15,4), %ebx
movl %r14d, %ebp
shll $0x4, %ebp
andl $0x30, %ebp
shrl $0x4, %r11d
orl %ebp, %r11d
shrl $0x2, %r14d
addq $-0x3, %rsi
addq $0x3, %rdi
movb (%r14,%rax), %bpl
movb %bpl, (%rdx,%r9)
movb (%r11,%rax), %r11b
movb %r11b, 0x1(%rdx,%r9)
movb (%rbx,%rax), %r11b
movb %r11b, 0x2(%rdx,%r9)
movb (%r10,%rax), %r10b
movb %r10b, 0x3(%rdx,%r9)
movq %r8, %r9
cmpq $0x2, %rsi
ja 0x4c3a
jmp 0x4cb6
xorl %r8d, %r8d
testq %rsi, %rsi
je 0x4d5a
movb $0x0, -0x1(%rsp)
movw $0x0, -0x3(%rsp)
xorl %eax, %eax
movb (%rdi,%rax), %r9b
movb %r9b, -0x3(%rsp,%rax)
incq %rax
cmpq %rax, %rsi
jne 0x4ccd
leaq 0x4(%r8), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rcx, %rdi
ja 0x4d74
movzbl -0x2(%rsp), %eax
movzbl -0x1(%rsp), %r9d
movzbl -0x3(%rsp), %r10d
movl %r10d, %r11d
shll $0x4, %r11d
andl $0x30, %r11d
movl %eax, %ebx
shrl $0x4, %ebx
orl %r11d, %ebx
shrl $0x2, %r10d
leaq 0x42f1(%rip), %r11      # 0x9010
movb (%r10,%r11), %r10b
movb %r10b, (%rdx,%r8)
movb (%rbx,%r11), %bl
movq %r8, %r10
orq $0x2, %r10
movb %bl, 0x1(%rdx,%r8)
movb $0x3d, %bl
cmpq $0x1, %rsi
je 0x4d4e
andl $0xf, %eax
shrl $0x6, %r9d
leal (%r9,%rax,4), %eax
movb (%rax,%r11), %bl
movb %bl, (%rdx,%r10)
movb $0x3d, 0x3(%rdx,%r8)
jmp 0x4d5d
movq %r8, %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rcx, %rdi
jae 0x4d74
movb $0x0, (%rdx,%rdi)
movl %edi, %eax
jmp 0x4d74
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop