// File: /workspace/github_cpp_makefile_star2_O2/akw0088[P]openssl/base64.c
// Function: base64encode
int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize)
{
	const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	const uint8_t *data = (const uint8_t *)data_buf;
	size_t resultIndex = 0;
	size_t x;
	uint32_t n = 0;
	int padCount = dataLength % 3;
	uint8_t n0, n1, n2, n3;

	/* increment over the length of the string, three characters at a time */
	for (x = 0; x < dataLength; x += 3)
	{
		/* these three 8-bit (ASCII) characters become one 24-bit number */
		n = ((uint32_t)data[x]) << 16; //parenthesis needed, compiler depending on flags can do the shifting before conversion to uint32_t, resulting to 0

		if ((x + 1) < dataLength)
			n += ((uint32_t)data[x + 1]) << 8;//parenthesis needed, compiler depending on flags can do the shifting before conversion to uint32_t, resulting to 0

		if ((x + 2) < dataLength)
			n += data[x + 2];

		/* this 24-bit number gets separated into four 6-bit numbers */
		n0 = (uint8_t)(n >> 18) & 63;
		n1 = (uint8_t)(n >> 12) & 63;
		n2 = (uint8_t)(n >> 6) & 63;
		n3 = (uint8_t)n & 63;

		/*
		* if we have one byte available, then its encoding is spread
		* out over two characters
		*/
		if (resultIndex >= resultSize) return 1;   /* indicate failure: buffer too small */
		result[resultIndex++] = base64chars[n0];
		if (resultIndex >= resultSize) return 1;   /* indicate failure: buffer too small */
		result[resultIndex++] = base64chars[n1];

		/*
		* if we have only two bytes available, then their encoding is
		* spread out over three chars
		*/
		if ((x + 1) < dataLength)
		{
			if (resultIndex >= resultSize) return 1;   /* indicate failure: buffer too small */
			result[resultIndex++] = base64chars[n2];
		}

		/*
		* if we have all three bytes available, then their encoding is spread
		* out over four characters
		*/
		if ((x + 2) < dataLength)
		{
			if (resultIndex >= resultSize) return 1;   /* indicate failure: buffer too small */
			result[resultIndex++] = base64chars[n3];
		}
	}

	/*
	* create and add padding that is required if we did not have a multiple of 3
	* number of characters available
	*/
	if (padCount > 0)
	{
		for (; padCount < 3; padCount++)
		{
			if (resultIndex >= resultSize) return 1;   /* indicate failure: buffer too small */
			result[resultIndex++] = '=';
		}
	}
	if (resultIndex >= resultSize) return 1;   /* indicate failure: buffer too small */
	result[resultIndex] = 0;
	return 0;   /* indicate success */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r8
movq %rsi, %r9
xorl %r12d, %r12d
movabsq $0x3, %r11
movq %rsi, %rax
xorl %edx, %edx
divq %r11
movl $0x1, %esi
leaq 0xc84(%rip), %rax       # 0x20b0
xorl %r10d, %r10d
cmpq %r9, %r12
jae 0x14f5
movzbl (%rdi,%r12), %ebx
shll $0x10, %ebx
leaq 0x1(%r12), %r15
cmpq %r9, %r15
jae 0x1457
movzbl 0x1(%rdi,%r12), %r14d
shll $0x8, %r14d
orl %r14d, %ebx
leaq 0x1(%r15), %r14
cmpq %r9, %r14
jae 0x1469
movzbl 0x2(%rdi,%r12), %r12d
addl %r12d, %ebx
cmpq %rcx, %r10
jae 0x152a
movl %ebx, %r12d
shrl $0x12, %r12d
andl $0x3f, %r12d
movb (%r12,%rax), %r12b
leaq 0x1(%r10), %r13
movb %r12b, (%r8,%r10)
cmpq %rcx, %r13
jae 0x152a
movl %ebx, %r12d
shrl $0xc, %r12d
andl $0x3f, %r12d
leaq 0x2(%r10), %r13
movb (%r12,%rax), %r12b
movb %r12b, 0x1(%r8,%r10)
cmpq %r9, %r15
jae 0x14cf
cmpq %rcx, %r13
jae 0x152a
movl %ebx, %r15d
shrl $0x6, %r15d
andl $0x3f, %r15d
movb (%r15,%rax), %r15b
movb %r15b, 0x2(%r8,%r10)
addq $0x3, %r10
movq %r10, %r13
cmpq %r9, %r14
jae 0x14e7
cmpq %rcx, %r13
jae 0x152a
andl $0x3f, %ebx
movb (%rbx,%rax), %r10b
movb %r10b, (%r8,%r13)
incq %r13
incq %r14
movq %r14, %r12
movq %r13, %r10
jmp 0x142f
testq %rdx, %rdx
je 0x151e
movq %r9, %rax
xorl %edx, %edx
divq %r11
leal (%rax,%rax,2), %eax
notl %eax
addl %r9d, %eax
cmpq %rcx, %r10
jae 0x152a
movb $0x3d, (%r8,%r10)
incq %r10
incl %eax
cmpl $0x2, %eax
jb 0x150a
cmpq %rcx, %r10
jae 0x152a
movb $0x0, (%r8,%r10)
xorl %esi, %esi
movl %esi, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq