// File: /workspace/github_cpp_makefile_star2_O3/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
movabsq $-0x5555555555555555, %r11 # imm = 0xAAAAAAAAAAAAAAAB
movq %rsi, %rax
mulq %r11
testq %rsi, %rsi
je 0x1545
shrq %rdx
leaq (%rdx,%rdx,2), %rdx
movq %rsi, %rax
subq %rdx, %rax
movl $0x2, %edx
xorl %r10d, %r10d
leaq 0xc63(%rip), %rbx       # 0x20b0
movzbl -0x2(%rdi,%rdx), %r14d
shll $0x10, %r14d
leaq -0x1(%rdx), %r15
cmpq %rsi, %r15
jae 0x146d
movzbl -0x1(%rdi,%rdx), %r9d
shll $0x8, %r9d
orl %r9d, %r14d
cmpq %rsi, %rdx
jae 0x147a
movzbl (%rdi,%rdx), %r9d
addl %r9d, %r14d
movl $0x1, %r9d
cmpq %rcx, %r10
jae 0x155b
movl %r14d, %r12d
shrl $0x12, %r12d
andl $0x3f, %r12d
movb (%r12,%rbx), %r12b
leaq 0x1(%r10), %r13
movb %r12b, (%r8,%r10)
cmpq %rcx, %r13
jae 0x155b
movl %r14d, %r13d
shrl $0xc, %r13d
andl $0x3f, %r13d
leaq 0x2(%r10), %r12
movb (%r13,%rbx), %r13b
movb %r13b, 0x1(%r8,%r10)
cmpq %rsi, %r15
jae 0x14eb
cmpq %rcx, %r12
jae 0x155b
movl %r14d, %r15d
shrl $0x6, %r15d
andl $0x3f, %r15d
movb (%r15,%rbx), %r15b
movb %r15b, 0x2(%r8,%r10)
addq $0x3, %r10
movq %r10, %r12
cmpq %rsi, %rdx
jae 0x1504
cmpq %rcx, %r12
jae 0x155b
andl $0x3f, %r14d
movb (%r14,%rbx), %r10b
movb %r10b, (%r8,%r12)
incq %r12
movq %r12, %r10
leaq 0x3(%rdx), %r14
incq %rdx
cmpq %rsi, %rdx
movq %r14, %rdx
jb 0x144d
testq %rax, %rax
je 0x1548
movq %rsi, %rax
mulq %r11
shrq %rdx
leal (%rdx,%rdx,2), %eax
notl %eax
addl %esi, %eax
cmpq %rcx, %r10
jae 0x155b
movb $0x3d, (%r8,%r10)
incq %r10
incl %eax
cmpl $0x2, %eax
jb 0x152f
jmp 0x1548
xorl %r10d, %r10d
movl $0x1, %r9d
cmpq %rcx, %r10
jae 0x155b
movb $0x0, (%r8,%r10)
xorl %r9d, %r9d
movl %r9d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq