// File: /workspace/github_c_makefile_star2_O1/orestesleal[P]base64/base64.c
// Function: b32_dec
unsigned int b32_dec(unsigned char *s, char *b, unsigned int len)
{
	unsigned long long x;
	unsigned int i,w,z, rtsize;
	unsigned char pad;
	unsigned char t;
	/* 	lookup table used as an index with the value of 'pad' 
		to help calculate the size of the encoded data */
	unsigned char lkpad[7] = {0,4,0,3,2,0,1};

	/* in base32 there is a maximum of 6 padding characters
	   in this case this loop gets rid of them anyway 

	   rfc4648 sect 3.3:
	   if more than the allowed number of pad characters is found at
	   the end of the string (e.g., a base 64 string terminated with 
	   "==="), the excess pad characters MAY also be ignored
	*/
	for (pad = 0,i = len-1; s[i] == PAD; i--) {
		++pad;
		--len;
	}

	w = 0;
	for (i = 0; i < len; i++) {
		for (x = 0, z = 0; z < 8 && 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;
				continue;
			}
			*/
			/* rfc4648 sec. 3.3
				Implementations MUST reject the encoded data if it contains
				characters outside the base alphabet when interpreting base-encoded
				data
	    	*/
			if ((s[i] >= 'A' && s[i] <= 'Z') ||  
				(s[i] >= '2' && s[i] <= '7')) {	 
				for (t = 0; s[i] != b32_alp[t]; t++);
				x |= t;
				x <<= 5;
			} else {
				fprintf(stderr, "b32_dec: error non alphabet char found\n");
				exit(EXIT_FAILURE);
			}
		}
		/* 	compute the shifting needed to align the input
			into the msb */
		x <<= (19 + ((8-z)*5)); 
		b[w++] = x >> 56; 
		b[w++] = (x << 8) >> 56;
		b[w++] = (x << 16) >> 56;
		b[w++] = (x << 24) >> 56;
		b[w++] = (x << 32) >> 56;
		--i;
	}
	/* divide the length by 8 and multiply the result
	   by 5, then adding the value of 'pad' indexed into
	   'lkpad' computes the size of the encoded data.
	   shr by 3 is the same as "len / 8" */
	rtsize = (len >> 3) * 5 + lkpad[pad]; 
	b[rtsize] = '\0';
	return rtsize;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
leal -0x1(%rdx), %eax
cmpb $0x3d, (%rdi,%rax)
jne 0x1e14
xorl %eax, %eax
movl %edx, %ecx
incb %al
leal -0x1(%rcx), %edx
addl $-0x2, %ecx
cmpb $0x3d, (%rdi,%rcx)
je 0x1dfe
movzbl %al, %r8d
jmp 0x1e17
xorl %r8d, %r8d
testl %edx, %edx
je 0x1ee2
xorl %eax, %eax
leaq 0x32e8(%rip), %r9       # 0x5110
xorl %r10d, %r10d
xorl %ebx, %ebx
xorl %r11d, %r11d
movl %ebx, %ecx
movl %r10d, %ebx
movb (%rdi,%rbx), %bl
leal -0x41(%rbx), %r14d
cmpb $0x1a, %r14b
setae %r14b
leal -0x32(%rbx), %r15d
cmpb $0x6, %r15b
setae %r15b
testb %r15b, %r14b
jne 0x1f06
xorl %r15d, %r15d
movzbl %r15b, %r14d
movl %r14d, %r15d
incb %r15b
cmpb (%r14,%r9), %bl
jne 0x1e5c
orq %r14, %r11
shlq $0x5, %r11
incl %r10d
cmpl $0x6, %ecx
ja 0x1e83
leal 0x1(%rcx), %ebx
cmpl %edx, %r10d
jb 0x1e30
movb $0x7, %bl
subb %cl, %bl
movzbl %bl, %ecx
leal (%rcx,%rcx,4), %ecx
addb $0x13, %cl
shlq %cl, %r11
movq %r11, %rcx
shrq $0x38, %rcx
leal 0x1(%rax), %ebx
movl %eax, %r14d
movb %cl, (%rsi,%r14)
movq %r11, %rcx
shrq $0x30, %rcx
leal 0x2(%rax), %r14d
movb %cl, (%rsi,%rbx)
movq %r11, %rcx
shrq $0x28, %rcx
leal 0x3(%rax), %ebx
movb %cl, (%rsi,%r14)
movq %r11, %rcx
shrq $0x20, %rcx
leal 0x4(%rax), %r14d
movb %cl, (%rsi,%rbx)
shrl $0x18, %r11d
addl $0x5, %eax
movb %r11b, (%rsi,%r14)
cmpl %edx, %r10d
jb 0x1e2b
shrl $0x3, %edx
leal (%rdx,%rdx,4), %eax
leaq 0x1376(%rip), %rcx      # 0x3265
movzbl (%r8,%rcx), %ecx
addq %rcx, %rax
movb $0x0, (%rsi,%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x11a8