// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %edx, %r14d
testb $0x3, %r14b
jne 0x86e5
movq %rsi, %r15
movq %rdi, %r13
movl %r14d, %edx
callq 0x858f
movl %eax, %r12d
leal 0x1(%r12), %eax
movslq %eax, %rsi
movq %r13, %rdi
callq 0x5281
leal -0x3(%r14), %esi
xorl %edi, %edi
leaq 0x58b1(%rip), %rdx      # 0xdf00
movq %rax, %rcx
movsbq (%r15,%rdi), %r8
movsbl (%r8,%rdx), %r9d
testb $-0x40, %r9b
jne 0x86c7
movsbq 0x1(%r15,%rdi), %r8
movsbl (%r8,%rdx), %r10d
testb $-0x40, %r10b
jne 0x86cc
movsbq 0x2(%r15,%rdi), %r8
movsbl (%r8,%rdx), %ebx
testb $-0x40, %bl
jne 0x86d1
movsbq 0x3(%r15,%rdi), %r8
movsbl (%r8,%rdx), %r8d
testb $-0x40, %r8b
jne 0x86d4
shll $0x12, %r9d
shll $0xc, %r10d
orl %r9d, %r10d
shll $0x6, %ebx
orl %r8d, %ebx
orl %r10d, %ebx
movl %ebx, %r9d
shrl $0x10, %r9d
movb %r9b, (%rcx)
movb %bh, 0x1(%rcx)
movb %bl, 0x2(%rcx)
addq $0x3, %rcx
addq $0x4, %rdi
cmpq %rsi, %rdi
jb 0x8652
jmp 0x86d4
movl %r9d, %r8d
jmp 0x86d4
movl %r10d, %r8d
jmp 0x86d4
movl %ebx, %r8d
cmpl $0x40, %r8d
jbe 0x86f1
movq %r13, %rdi
movq %rax, %rsi
callq 0x5293
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movslq %r12d, %rdi
imulq $0x55555556, %rdi, %rdi # imm = 0x55555556
movq %rdi, %r8
shrq $0x3f, %r8
shrq $0x20, %rdi
addl %r8d, %edi
leal (%rdi,%rdi,2), %edi
subl %edi, %r12d
cmpl $0x2, %r12d
je 0x8768
cmpl $0x1, %r12d
jne 0x87cf
leal -0x4(%r14), %edi
movsbq (%r15,%rdi), %rdi
movsbl (%rdi,%rdx), %edi
testb $-0x40, %dil
jne 0x86da
movsbq (%r15,%rsi), %rsi
movsbl (%rsi,%rdx), %edx
testb $-0x40, %dl
jne 0x86da
shll $0x2, %edi
shrl $0x4, %edx
orl %edi, %edx
movb %dl, (%rcx)
leal -0x2(%r14), %edx
cmpb $0x3d, (%r15,%rdx)
jne 0x86da
decl %r14d
cmpb $0x3d, (%r15,%r14)
jne 0x86da
incq %rcx
jmp 0x87cf
leal -0x4(%r14), %edi
movsbq (%r15,%rdi), %rdi
movsbl (%rdi,%rdx), %edi
testb $-0x40, %dil
jne 0x86da
movsbq (%r15,%rsi), %rsi
movsbl (%rsi,%rdx), %esi
testb $-0x40, %sil
jne 0x86da
leal -0x2(%r14), %r8d
movsbq (%r15,%r8), %r8
movsbl (%r8,%rdx), %edx
testb $-0x40, %dl
jne 0x86da
shll $0xa, %edi
shll $0x4, %esi
orl %edi, %esi
shrl $0x2, %edx
orl %esi, %edx
rolw $0x8, %dx
movw %dx, (%rcx)
decl %r14d
cmpb $0x3d, (%r15,%r14)
jne 0x86da
addq $0x2, %rcx
movb $0x0, (%rcx)
jmp 0x86e7
nop