// File: akw0088[P]openssl/base64.c
// Function: base64decode
int base64decode(char *in, size_t inLen, unsigned char *out, size_t *outLen)
{
	char *end = in + inLen;
	char iter = 0;
	uint32_t buf = 0;
	size_t len = 0;

	while (in < end) {
		unsigned char c = d[*in++];

		switch (c) {
		case WHITESPACE: continue;   /* skip whitespace */
		case INVALID:    return 1;   /* invalid input, return error */
		case EQUALS:                 /* pad character, end of data */
			in = end;
			continue;
		default:
			buf = buf << 6 | c;
			iter++; // increment the number of iteration
					/* If the buffer is full, split it into bytes */
			if (iter == 4) {
				if ((len += 3) > *outLen) return 1; /* buffer overflow */
				*(out++) = (buf >> 16) & 255;
				*(out++) = (buf >> 8) & 255;
				*(out++) = buf & 255;
				buf = 0; iter = 0;

			}
		}
	}

	if (iter == 3) {
		if ((len += 2) > *outLen) return 1; /* buffer overflow */
		*(out++) = (buf >> 10) & 255;
		*(out++) = (buf >> 2) & 255;
	}
	else if (iter == 2) {
		if (++len > *outLen) return 1; /* buffer overflow */
		*(out++) = (buf >> 4) & 255;
	}

	*outLen = len; /* modify to reflect the actual output size */
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movb $0x0, -0x31(%rbp)
movl $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x18d8
movq -0x10(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x10(%rbp)
movsbq (%rax), %rax
leaq 0x916(%rip), %rcx       # 0x2100
movb (%rax,%rcx), %al
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
movl %eax, -0x48(%rbp)
subl $0x40, %eax
je 0x1812
jmp 0x17fe
movl -0x48(%rbp), %eax
subl $0x41, %eax
je 0x1820
jmp 0x1808
movl -0x48(%rbp), %eax
subl $0x42, %eax
je 0x1814
jmp 0x182a
jmp 0x17c3
movl $0x1, -0x4(%rbp)
jmp 0x1999
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x17c3
movl -0x38(%rbp), %eax
shll $0x6, %eax
movzbl -0x41(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
cmpl $0x4, %eax
jne 0x18d1
movq -0x40(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0x186f
movl $0x1, -0x4(%rbp)
jmp 0x1999
movl -0x38(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
movl -0x38(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
movl -0x38(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
movl $0x0, -0x38(%rbp)
movb $0x0, -0x31(%rbp)
jmp 0x18d3
jmp 0x17c3
movsbl -0x31(%rbp), %eax
cmpl $0x3, %eax
jne 0x1940
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0x1902
movl $0x1, -0x4(%rbp)
jmp 0x1999
movl -0x38(%rbp), %eax
shrl $0xa, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
movl -0x38(%rbp), %eax
shrl $0x2, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
jmp 0x1987
movsbl -0x31(%rbp), %eax
cmpl $0x2, %eax
jne 0x1985
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0x1967
movl $0x1, -0x4(%rbp)
jmp 0x1999
movl -0x38(%rbp), %eax
shrl $0x4, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movb %cl, (%rax)
jmp 0x1987
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq