// File: /workspace/github_c_makefile_star2_O2/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
incl %edx
movb $-0x1, %r8b
leal -0x2(%rdx), %eax
decl %edx
incb %r8b
cmpb $0x3d, (%rdi,%rax)
je 0x1b82
xorl %eax, %eax
leaq 0x3567(%rip), %r9       # 0x5100
xorl %r10d, %r10d
cmpl %edx, %eax
jae 0x1c56
xorl %r11d, %r11d
xorl %ecx, %ecx
cmpl $0x7, %ecx
ja 0x1bf8
cmpl %edx, %eax
jae 0x1bf8
movl %eax, %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 0x1c7d
xorl %r15d, %r15d
movzbl %r15b, %r14d
movl %r14d, %r15d
incb %r15b
cmpb (%r14,%r9), %bl
jne 0x1bdb
orq %r14, %r11
shlq $0x5, %r11
incl %ecx
incl %eax
jmp 0x1ba9
movb $0x8, %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(%r10), %ebx
movl %r10d, %r14d
movb %cl, (%rsi,%r14)
movq %r11, %rcx
shrq $0x30, %rcx
leal 0x2(%r10), %r14d
movb %cl, (%rsi,%rbx)
movq %r11, %rcx
shrq $0x28, %rcx
leal 0x3(%r10), %ebx
movb %cl, (%rsi,%r14)
movq %r11, %rcx
shrq $0x20, %rcx
leal 0x4(%r10), %r14d
movb %cl, (%rsi,%rbx)
shrl $0x18, %r11d
addl $0x5, %r10d
movb %r11b, (%rsi,%r14)
jmp 0x1b9c
shrl $0x3, %edx
leal (%rdx,%rdx,4), %eax
movzbl %r8b, %ecx
leaq 0x15fe(%rip), %rdx      # 0x3265
movzbl (%rcx,%rdx), %ecx
addq %rcx, %rax
movb $0x0, (%rsi,%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x3374(%rip), %rax      # 0x4ff8
movq (%rax), %rcx
leaq 0x1427(%rip), %rdi      # 0x30b5
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x10d0
pushq $0x1
popq %rdi
callq 0x10c0