// File: /workspace/github_cpp_makefile_star2_O1/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, %r9 # imm = 0xAAAAAAAAAAAAAAAB
movq %rsi, %rax
mulq %r9
testq %rsi, %rsi
je 0x151a
movl $0x2, %r10d
xorl %r15d, %r15d
leaq 0xc5f(%rip), %r11       # 0x20b0
movzbl -0x2(%rdi,%r10), %r14d
shll $0x10, %r14d
leaq -0x1(%r10), %r12
cmpq %rsi, %r12
jae 0x1470
movzbl -0x1(%rdi,%r10), %eax
shll $0x8, %eax
orl %eax, %r14d
cmpq %rsi, %r10
jae 0x147d
movzbl (%rdi,%r10), %eax
addl %eax, %r14d
movl $0x1, %eax
cmpq %rcx, %r15
jae 0x1567
movl %r14d, %ebx
shrl $0x12, %ebx
andl $0x3f, %ebx
movb (%rbx,%r11), %bl
leaq 0x1(%r15), %r13
movb %bl, (%r8,%r15)
cmpq %rcx, %r13
jae 0x1567
movl %r14d, %r13d
shrl $0xc, %r13d
andl $0x3f, %r13d
leaq 0x2(%r15), %rbx
movb (%r13,%r11), %r13b
movb %r13b, 0x1(%r8,%r15)
cmpq %rsi, %r12
jae 0x14e9
cmpq %rcx, %rbx
jae 0x1567
movl %r14d, %ebx
shrl $0x6, %ebx
andl $0x3f, %ebx
movb (%rbx,%r11), %bl
movb %bl, 0x2(%r8,%r15)
addq $0x3, %r15
movq %r15, %rbx
cmpq %rsi, %r10
jae 0x1502
cmpq %rcx, %rbx
jae 0x1567
andl $0x3f, %r14d
movb (%r14,%r11), %al
movb %al, (%r8,%rbx)
incq %rbx
leaq 0x3(%r10), %rax
incq %r10
movq %rbx, %r15
cmpq %rsi, %r10
movq %rax, %r10
jb 0x1451
jmp 0x151c
xorl %ebx, %ebx
shrq %rdx
leaq (%rdx,%rdx,2), %rax
movq %rsi, %rdx
subq %rax, %rdx
je 0x154f
movq %rsi, %rax
mulq %r9
shrq %rdx
leal (%rdx,%rdx,2), %eax
notl %eax
addl %esi, %eax
cmpq %rcx, %rbx
jae 0x1562
movb $0x3d, (%r8,%rbx)
incq %rbx
incl %eax
cmpl $0x2, %eax
jb 0x153b
movl $0x1, %eax
cmpq %rcx, %rbx
jae 0x1567
movb $0x0, (%r8,%rbx)
xorl %eax, %eax
jmp 0x1567
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq