// File: /workspace/github_c_makefile_star2_O2/liuhaotian[P]xmppsh/libstrophe/src/sasl.c
// Function: base64_decode
unsigned char *base64_decode(xmpp_ctx_t *ctx,
			     const char * const buffer, const unsigned len)
{
    int dlen;
    unsigned char *dbuf, *d;
    uint32_t word, hextet;
    int i;

    /* len must be a multiple of 4 */
    if (len & 0x03) return NULL;

    dlen = base64_decoded_len(ctx, buffer, len);
    dbuf = xmpp_alloc(ctx, dlen + 1);
    if (dbuf != NULL) {
	d = dbuf;
	/* loop over each set of 4 characters, decoding 3 bytes */
	for (i = 0; i < len - 3; i += 4) {
	    hextet = _base64_invcharmap[(int)buffer[i]];
	    if (hextet & 0xC0) break;
	    word = hextet << 18;
	    hextet = _base64_invcharmap[(int)buffer[i+1]];
	    if (hextet & 0xC0) break;
	    word |= hextet << 12;
	    hextet = _base64_invcharmap[(int)buffer[i+2]];
	    if (hextet & 0xC0) break;
	    word |= hextet << 6;
	    hextet = _base64_invcharmap[(int)buffer[i+3]];
	    if (hextet & 0xC0) break;
	    word |= hextet;
	    *d++ = (word & 0x00FF0000) >> 16;
	    *d++ = (word & 0x0000FF00) >> 8;
	    *d++ = (word & 0x000000FF);
	}
	if (hextet > 64) goto _base64_decode_error;
	/* handle the remainder */
	switch (dlen % 3) {
	    case 0:
		/* nothing to do */
		break;
	    case 1:
		/* redo the last quartet, checking for correctness */
		hextet = _base64_invcharmap[(int)buffer[len-4]];
		if (hextet & 0xC0) goto _base64_decode_error;
		word = hextet << 2;
		hextet = _base64_invcharmap[(int)buffer[len-3]];
		if (hextet & 0xC0) goto _base64_decode_error;
		word |= hextet >> 4;
		*d++ = word & 0xFF;
		hextet = _base64_invcharmap[(int)buffer[len-2]];
		if (hextet != 64) goto _base64_decode_error;
		hextet = _base64_invcharmap[(int)buffer[len-1]];
		if (hextet != 64) goto _base64_decode_error;
		break;
	    case 2:
		/* redo the last quartet, checking for correctness */
		hextet = _base64_invcharmap[(int)buffer[len-4]];
		if (hextet & 0xC0) goto _base64_decode_error;
		word = hextet << 10;		
		hextet = _base64_invcharmap[(int)buffer[len-3]];
		if (hextet & 0xC0) goto _base64_decode_error;
		word |= hextet << 4;		
		hextet = _base64_invcharmap[(int)buffer[len-2]];
		if (hextet & 0xC0) goto _base64_decode_error;
		word |= hextet >> 2;
		*d++ = (word & 0xFF00) >> 8;
		*d++ = (word & 0x00FF);		
		hextet = _base64_invcharmap[(int)buffer[len-1]];
		if (hextet != 64) goto _base64_decode_error;
		break;
	}
    }
    *d = '\0';
    return dbuf;

_base64_decode_error:	
    /* invalid character; abort decoding! */
    xmpp_free(ctx, dbuf);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r14d
testb $0x3, %r14b
jne 0x8318
movq %rsi, %r15
movq %rdi, %rbx
movl %r14d, %edx
callq 0x81dd
movl %eax, %ebp
incl %eax
movslq %eax, %rsi
movq %rbx, %rdi
callq 0x518f
movq %rax, %rsi
leal -0x3(%r14), %r8d
movq %rax, %rcx
incq %rcx
xorl %eax, %eax
leaq 0x4c77(%rip), %rdi      # 0xcf00
cmpq %r8, %rax
jae 0x830a
movsbq (%r15,%rax), %rdx
movsbl (%rdx,%rdi), %r10d
testb $-0x40, %r10b
jne 0x82fd
movsbq 0x1(%r15,%rax), %rdx
movsbl (%rdx,%rdi), %r11d
testb $-0x40, %r11b
jne 0x8302
movsbq 0x2(%r15,%rax), %rdx
movsbl (%rdx,%rdi), %edx
testb $-0x40, %dl
jne 0x8307
movsbq 0x3(%r15,%rax), %r9
movsbl (%r9,%rdi), %r9d
testb $-0x40, %r9b
jne 0x830a
shll $0x12, %r10d
shll $0xc, %r11d
orl %r10d, %r11d
shll $0x6, %edx
orl %r9d, %edx
orl %r11d, %edx
movl %edx, %r10d
shrl $0x10, %r10d
movb %r10b, -0x1(%rcx)
movb %dh, (%rcx)
movb %dl, 0x1(%rcx)
addq $0x4, %rax
addq $0x3, %rcx
jmp 0x8289
movl %r10d, %r9d
jmp 0x830a
movl %r11d, %r9d
jmp 0x830a
movl %edx, %r9d
cmpl $0x40, %r9d
jbe 0x8328
movq %rbx, %rdi
callq 0x51a1
xorl %esi, %esi
movq %rsi, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq -0x1(%rcx), %r9
pushq $0x3
popq %r10
movl %ebp, %eax
cltd
idivl %r10d
cmpl $0x1, %edx
je 0x83a2
cmpl $0x2, %edx
jne 0x83f4
leal -0x4(%r14), %eax
movsbq (%r15,%rax), %rax
movsbl (%rax,%rdi), %eax
testb $-0x40, %al
jne 0x8310
movsbq (%r15,%r8), %rdx
movsbl (%rdx,%rdi), %edx
testb $-0x40, %dl
jne 0x8310
leal -0x2(%r14), %r8d
movsbq (%r15,%r8), %r8
movsbl (%r8,%rdi), %edi
testb $-0x40, %dil
jne 0x8310
shll $0xa, %eax
shll $0x4, %edx
orl %eax, %edx
shrl $0x2, %edi
orl %edx, %edi
rolw $0x8, %di
movw %di, -0x1(%rcx)
decl %r14d
cmpb $0x3d, (%r15,%r14)
jne 0x8310
incq %rcx
movq %rcx, %r9
jmp 0x83f4
leal -0x4(%r14), %eax
movsbq (%r15,%rax), %rax
movsbl (%rax,%rdi), %eax
testb $-0x40, %al
jne 0x8310
movsbq (%r15,%r8), %rdx
movsbl (%rdx,%rdi), %edx
testb $-0x40, %dl
jne 0x8310
shll $0x2, %eax
shrl $0x4, %edx
orl %eax, %edx
movb %dl, (%r9)
leal -0x2(%r14), %eax
cmpb $0x3d, (%r15,%rax)
jne 0x8310
decl %r14d
cmpb $0x3d, (%r15,%r14)
movq %rcx, %r9
jne 0x8310
movb $0x0, (%r9)
jmp 0x831a