// File: /workspace/github_c_makefile_star2_O2/orestesleal[P]base64/base64.c
// Function: b64_dec
unsigned int b64_dec(unsigned char *s, char b[], unsigned int len)
{
	unsigned int x,w,i,rtsize,z;
	unsigned char pad,t,l = 0;
	t = l = pad = 0;

	/* this is non-standard behavior:
		if the input file or stream contains a LINE FEED or CARRIAGE
		RETURN characters  at the end of the file (maybe generated by
		an editor) remove it to allow the padding trimming do his job */
	for (i = len-1; s[i] == '\r' || s[i] == '\n'; i--, --len); 

	/* remove trailing padding and count them, 1 or 2 '='s 
	   for base64 */	
	for (i = len-1; s[i] == PAD; --i) {
		++pad;
		--len;
	}
	w = 0;
	for (i = 0; i < len; i++) {
		for (x = 0, z = 0; z < 4 && i < len; z++, i++) {
			/* if the rfc is modified to include ignoring CRLF or 
			   PAD's in between encoded data the next block of code
			   should be uncommented
		       rfc4648 sec 3.3: */
			/*
			if (s[i] == PAD || 
				s[i] == '\n' || 
				s[i] == '\r') {
				--z;
				--i;
				continue;
			}
			*/

			/*	rfc4648 section 3.3 */ 
			if ((s[i] >= 'A' && s[i] <= 'z') || 
   		   		(s[i] >= '0' && s[i] <= '9') || 
	       		(s[i] == '+' || s[i] == '/') ) {

				/* since the input is in range within the alphabet
				   there is not possibility of failure, loop and 
				   find the position */
				for (t = 0; s[i] != b64_alp[t]; t++);
				x |= t;
				z < 3 && i+1 < len ? x <<= 6 : 0;
			} else {
				fprintf(stderr, "b64_dec: error, non alphabet char found -> %c -> %d\n",
																			s[i], s[i]);
				exit(EXIT_FAILURE);
			}
		}
		for (;z < 4; z++, x <<= 6);
		x <<= 8;
		b[w++] = x >> 24;
		b[w++] = (x << 8) >> 24;
		b[w++] = (x << 16) >> 24;
		--i;
	}
	rtsize = (len >> 2) * 3;
	if (pad) {
		rtsize += pad == 2 ? 1 : 2;
	}
	b[rtsize] = '\0';
	return rtsize; /* number of decoded bytes */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
incl %edx
leal -0x2(%rdx), %eax
movzbl (%rdi,%rax), %eax
cmpl $0xa, %eax
je 0x18e8
cmpl $0xd, %eax
jne 0x18ec
decl %edx
jmp 0x18d7
movb $0x3, %r8b
leal -0x2(%rdx), %eax
decl %edx
decb %r8b
cmpb $0x3d, (%rdi,%rax)
je 0x18ef
movl %edx, %r14d
xorl %r9d, %r9d
leaq 0x3776(%rip), %r11      # 0x5080
xorl %r12d, %r12d
cmpl %edx, %r12d
jae 0x19b8
movl %r12d, %r12d
xorl %eax, %eax
pushq $0x4
popq %r15
xorl %ebx, %ebx
cmpl $0x3, %ebx
ja 0x198f
cmpq %r14, %r12
jae 0x198f
movzbl (%rdi,%r12), %ecx
leal -0x41(%rcx), %r10d
cmpb $0x3a, %r10b
setb %r10b
leal -0x30(%rcx), %r13d
cmpb $0xa, %r13b
setb %r13b
orb %r10b, %r13b
jne 0x195e
movl %ecx, %r10d
orl $0x4, %r10d
cmpl $0x2f, %r10d
jne 0x19e7
movb $-0x1, %r13b
incb %r13b
movzbl %r13b, %r10d
cmpb (%r10,%r11), %cl
jne 0x1961
orl %r10d, %eax
incq %r12
movl %eax, %ecx
shll $0x6, %ecx
cmpl %r12d, %edx
cmovbel %eax, %ecx
cmpl $0x3, %ebx
cmovbl %ecx, %eax
incl %ebx
decl %r15d
jmp 0x1921
shll $0x6, %eax
subl $0x1, %r15d
jae 0x198c
movl %eax, %ecx
shrl $0x10, %ecx
leal 0x1(%r9), %ebx
movl %r9d, %r10d
movb %cl, (%rsi,%r10)
leal 0x2(%r9), %ecx
movb %ah, (%rsi,%rbx)
addl $0x3, %r9d
movb %al, (%rsi,%rcx)
jmp 0x190d
shrl $0x2, %edx
cmpb $0x1, %r8b
pushq $0x2
popq %rcx
sbbl $0x0, %ecx
xorl %eax, %eax
cmpb $0x2, %r8b
cmovnel %ecx, %eax
leal (%rdx,%rdx,2), %ecx
addq %rcx, %rax
movb $0x0, (%rsi,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x360a(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1688(%rip), %rsi      # 0x3080
movl %ecx, %edx
xorl %eax, %eax
callq 0x1080
pushq $0x1
popq %rdi
callq 0x10c0