// File: /workspace/github_c_makefile_star2_O3/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 0x85d5
movq %rsi, %r15
movq %rdi, %r13
movl %r14d, %edx
callq 0x8495
movl %eax, %r12d
leal 0x1(%r12), %eax
movslq %eax, %rsi
movq %r13, %rdi
callq 0x5251
leal -0x3(%r14), %esi
xorl %edi, %edi
leaq 0x59c1(%rip), %rdx      # 0xdf00
movq %rax, %rcx
movsbq (%r15,%rdi), %r8
movsbl (%r8,%rdx), %r9d
testb $-0x40, %r9b
jne 0x85b7
movsbq 0x1(%r15,%rdi), %r8
movsbl (%r8,%rdx), %r10d
testb $-0x40, %r10b
jne 0x85bc
movsbq 0x2(%r15,%rdi), %r8
movsbl (%r8,%rdx), %ebx
testb $-0x40, %bl
jne 0x85c1
movsbq 0x3(%r15,%rdi), %r8
movsbl (%r8,%rdx), %r8d
testb $-0x40, %r8b
jne 0x85c4
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 0x8542
jmp 0x85c4
movl %r9d, %r8d
jmp 0x85c4
movl %r10d, %r8d
jmp 0x85c4
movl %ebx, %r8d
cmpl $0x40, %r8d
jbe 0x85e1
movq %r13, %rdi
movq %rax, %rsi
callq 0x5263
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 0x8658
cmpl $0x1, %r12d
jne 0x86bf
leal -0x4(%r14), %edi
movsbq (%r15,%rdi), %rdi
movsbl (%rdi,%rdx), %edi
testb $-0x40, %dil
jne 0x85ca
movsbq (%r15,%rsi), %rsi
movsbl (%rsi,%rdx), %edx
testb $-0x40, %dl
jne 0x85ca
shll $0x2, %edi
shrl $0x4, %edx
orl %edi, %edx
movb %dl, (%rcx)
leal -0x2(%r14), %edx
cmpb $0x3d, (%r15,%rdx)
jne 0x85ca
decl %r14d
cmpb $0x3d, (%r15,%r14)
jne 0x85ca
incq %rcx
jmp 0x86bf
leal -0x4(%r14), %edi
movsbq (%r15,%rdi), %rdi
movsbl (%rdi,%rdx), %edi
testb $-0x40, %dil
jne 0x85ca
movsbq (%r15,%rsi), %rsi
movsbl (%rsi,%rdx), %esi
testb $-0x40, %sil
jne 0x85ca
leal -0x2(%r14), %r8d
movsbq (%r15,%r8), %r8
movsbl (%r8,%rdx), %edx
testb $-0x40, %dl
jne 0x85ca
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 0x85ca
addq $0x2, %rcx
movb $0x0, (%rcx)
jmp 0x85d7
nop