// File: /workspace/github_c_makefile_star2_O1/liuhaotian[P]xmppsh/libstrophe/src/sasl.c
// Function: base64_encode
char *base64_encode(xmpp_ctx_t *ctx, 
		    const unsigned char * const buffer, const unsigned len)
{
    int clen;
    char *cbuf, *c;
    uint32_t word, hextet;
    int i;

    clen = base64_encoded_len(ctx, len);
    cbuf = xmpp_alloc(ctx, clen + 1);
    if (cbuf != NULL) {
	c = cbuf;
	/* loop over data, turning every 3 bytes into 4 characters */
	for (i = 0; i < len - 2; i += 3) {
	    word = buffer[i] << 16 | buffer[i+1] << 8 | buffer[i+2];
	    hextet = (word & 0x00FC0000) >> 18;
	    *c++ = _base64_charmap[hextet];
	    hextet = (word & 0x0003F000) >> 12;
	    *c++ = _base64_charmap[hextet];
	    hextet = (word & 0x00000FC0) >> 6;
	    *c++ = _base64_charmap[hextet];
	    hextet = (word & 0x000003F);
	    *c++ = _base64_charmap[hextet];
	}
	/* zero, one or two bytes left */
	switch (len - i) {
	    case 0:
		break;
	    case 1:
		hextet = (buffer[len-1] & 0xFC) >> 2;
		*c++ = _base64_charmap[hextet];
		hextet = (buffer[len-1] & 0x03) << 4;
		*c++ = _base64_charmap[hextet];
		*c++ = _base64_charmap[64]; /* pad */
		*c++ = _base64_charmap[64]; /* pad */
		break;
	    case 2:
		hextet = (buffer[len-2] & 0xFC) >> 2;
		*c++ = _base64_charmap[hextet];
		hextet = ((buffer[len-2] & 0x03) << 4) |
			 ((buffer[len-1] & 0xF0) >> 4);
		*c++ = _base64_charmap[hextet];
		hextet = (buffer[len-1] & 0x0F) << 2;
		*c++ = _base64_charmap[hextet];
		*c++ = _base64_charmap[64]; /* pad */
		break;
	}
	/* add a terminal null */
	*c = '\0';
    }

    return cbuf;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r14
leal 0x2(%rbx), %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rax, %rcx
shrq $0x20, %rcx
andl $-0x2, %ecx
leal 0x1(,%rcx,2), %eax
movslq %eax, %rsi
callq 0x5281
testq %rax, %rax
je 0x7b28
movl %ebx, %edx
addl $-0x2, %edx
je 0x7a9a
movl %edx, %edi
xorl %esi, %esi
leaq 0x6482(%rip), %r8       # 0xdeb0
movq %rax, %rcx
movzbl (%r14,%rsi), %r9d
movl %r9d, %r10d
shll $0x10, %r10d
movzbl 0x1(%r14,%rsi), %r11d
shll $0x8, %r11d
movzbl 0x2(%r14,%rsi), %r15d
leal (%r11,%r15), %r12d
orl %r10d, %r11d
shrl $0x2, %r9d
movb (%r9,%r8), %r9b
movb %r9b, (%rcx)
shrl $0xc, %r11d
andl $0x3f, %r11d
movb (%r11,%r8), %r9b
movb %r9b, 0x1(%rcx)
shrl $0x6, %r12d
andl $0x3f, %r12d
movb (%r12,%r8), %r9b
movb %r9b, 0x2(%rcx)
andl $0x3f, %r15d
movb (%r15,%r8), %r9b
movb %r9b, 0x3(%rcx)
addq $0x4, %rcx
addq $0x3, %rsi
cmpq %rdi, %rsi
jb 0x7a31
jmp 0x7a9f
xorl %esi, %esi
movq %rax, %rcx
movl %ebx, %edi
subl %esi, %edi
cmpl $0x2, %edi
je 0x7ada
cmpl $0x1, %edi
jne 0x7b25
decl %ebx
movzbl (%r14,%rbx), %edx
shrl $0x2, %edx
leaq 0x63f2(%rip), %rsi      # 0xdeb0
movb (%rdx,%rsi), %dl
movb %dl, (%rcx)
movzbl (%r14,%rbx), %edx
shll $0x4, %edx
andl $0x30, %edx
movb (%rdx,%rsi), %dl
movb %dl, 0x1(%rcx)
movb $0x3d, 0x2(%rcx)
jmp 0x7b1d
movl %edx, %edx
movzbl (%r14,%rdx), %esi
shrl $0x2, %esi
leaq 0x63c5(%rip), %rdi      # 0xdeb0
movb (%rsi,%rdi), %sil
movb %sil, (%rcx)
movzbl (%r14,%rdx), %edx
shll $0x4, %edx
andl $0x30, %edx
decl %ebx
movzbl (%r14,%rbx), %esi
shrl $0x4, %esi
orl %edx, %esi
movb (%rsi,%rdi), %dl
movb %dl, 0x1(%rcx)
movzbl (%r14,%rbx), %edx
andl $0xf, %edx
movb (%rdi,%rdx,4), %dl
movb %dl, 0x2(%rcx)
movb $0x3d, 0x3(%rcx)
addq $0x4, %rcx
movb $0x0, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq