// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl 0xd9d(%rip), %eax       # 0x3276
movl %eax, -0x39(%rbp)
movw 0xd97(%rip), %ax        # 0x327a
movw %ax, -0x35(%rbp)
movb 0xd8f(%rip), %al        # 0x327c
movb %al, -0x33(%rbp)
movb $0x0, -0x31(%rbp)
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
jne 0x2529
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x24fd
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x2712
movq $0x0, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
xorl %eax, %eax
cmpl $0x8, -0x2c(%rbp)
movb %al, -0x3a(%rbp)
jae 0x2569
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
setb %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x2575
jmp 0x263a
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x41, %eax
jl 0x2595
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x5a, %eax
jle 0x25b5
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x32, %eax
jl 0x25ff
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x37, %eax
jg 0x25ff
movb $0x0, -0x32(%rbp)
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x32(%rbp), %ecx
movl %ecx, %edx
leaq 0x2b2f(%rip), %rcx      # 0x5100
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x25e5
jmp 0x25db
movb -0x32(%rbp), %al
addb $0x1, %al
movb %al, -0x32(%rbp)
jmp 0x25b9
movzbl -0x32(%rbp), %eax
orq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
shlq $0x5, %rax
movq %rax, -0x20(%rbp)
jmp 0x2621
movq 0x29f2(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0xab6(%rip), %rsi       # 0x30c6
movb $0x0, %al
callq 0x1080
movl $0x1, %edi
callq 0x10c0
jmp 0x2623
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2552
movl $0x8, %eax
subl -0x2c(%rbp), %eax
imull $0x5, %eax, %ecx
addl $0x13, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
shlq %cl, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
shrq $0x38, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
shlq $0x8, %rax
shrq $0x38, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
shlq $0x10, %rax
shrq $0x38, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
shlq $0x18, %rax
shrq $0x38, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
shlq $0x20, %rax
shrq $0x38, %rax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x28(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2537
movl -0x14(%rbp), %eax
shrl $0x3, %eax
imull $0x5, %eax, %eax
movzbl -0x31(%rbp), %ecx
movzbl -0x39(%rbp,%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x30(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)