// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: SyBase64Encode
JX9_PRIVATE sxi32 SyBase64Encode(const char *zSrc, sxu32 nLen, ProcConsumer xConsumer, void *pUserData)
{
	static const unsigned char zBase64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	unsigned char *zIn = (unsigned char *)zSrc;
	unsigned char z64[4];
	sxu32 i;
	sxi32 rc;
#if defined(UNTRUST)
	if( SX_EMPTY_STR(zSrc) || xConsumer == 0){
		return SXERR_EMPTY;
	}
#endif
	for(i = 0; i + 2 < nLen; i += 3){
		z64[0] = zBase64[(zIn[i] >> 2) & 0x3F];
		z64[1] = zBase64[( ((zIn[i] & 0x03) << 4)   | (zIn[i+1] >> 4)) & 0x3F]; 
		z64[2] = zBase64[( ((zIn[i+1] & 0x0F) << 2) | (zIn[i + 2] >> 6) ) & 0x3F];
		z64[3] = zBase64[ zIn[i + 2] & 0x3F];
		
		rc = xConsumer((const void *)z64, sizeof(z64), pUserData);
		if( rc != SXRET_OK ){return SXERR_ABORT;}

	}	
	if ( i+1 < nLen ){
		z64[0] = zBase64[(zIn[i] >> 2) & 0x3F];
		z64[1] = zBase64[( ((zIn[i] & 0x03) << 4)   | (zIn[i+1] >> 4)) & 0x3F]; 
		z64[2] = zBase64[(zIn[i+1] & 0x0F) << 2 ];
		z64[3] = '=';
		
		rc = xConsumer((const void *)z64, sizeof(z64), pUserData);
		if( rc != SXRET_OK ){return SXERR_ABORT;}

	}else if( i < nLen ){
		z64[0] = zBase64[(zIn[i] >> 2) & 0x3F];
		z64[1]   = zBase64[(zIn[i] & 0x03) << 4];
		z64[2] = '=';
		z64[3] = '=';
		
		rc = xConsumer((const void *)z64, sizeof(z64), pUserData);
		if( rc != SXRET_OK ){return SXERR_ABORT;}
	}

	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $0x2, %eax
cmpl -0x14(%rbp), %eax
jae 0x9e258
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
sarl $0x2, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x23500(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x34(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x3, %eax
shll $0x4, %eax
movq -0x30(%rbp), %rcx
movl -0x38(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
sarl $0x4, %ecx
orl %ecx, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x234c7(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x33(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0xf, %eax
shll $0x2, %eax
movq -0x30(%rbp), %rcx
movl -0x38(%rbp), %edx
addl $0x2, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
sarl $0x6, %ecx
orl %ecx, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x23489(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x32(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x23466(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x31(%rbp)
movq -0x20(%rbp), %rax
leaq -0x34(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x4, %esi
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x9e248
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x9e397
jmp 0x9e24a
movl -0x38(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x38(%rbp)
jmp 0x9e156
movl -0x38(%rbp), %eax
addl $0x1, %eax
cmpl -0x14(%rbp), %eax
jae 0x9e315
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
sarl $0x2, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x233fe(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x34(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x3, %eax
shll $0x4, %eax
movq -0x30(%rbp), %rcx
movl -0x38(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
sarl $0x4, %ecx
orl %ecx, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x233c5(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x33(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0xf, %eax
shll $0x2, %eax
movslq %eax, %rcx
leaq 0x2339f(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x32(%rbp)
movb $0x3d, -0x31(%rbp)
movq -0x20(%rbp), %rax
leaq -0x34(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x4, %esi
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x9e313
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x9e397
jmp 0x9e390
movl -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x9e38e
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
sarl $0x2, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x23348(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x34(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
movzbl (%rax,%rcx), %eax
andl $0x3, %eax
shll $0x4, %eax
movslq %eax, %rcx
leaq 0x23327(%rip), %rax     # 0xc1680
movb (%rax,%rcx), %al
movb %al, -0x33(%rbp)
movb $0x3d, -0x32(%rbp)
movb $0x3d, -0x31(%rbp)
movq -0x20(%rbp), %rax
leaq -0x34(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x4, %esi
callq *%rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x9e38c
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x9e397
jmp 0x9e38e
jmp 0x9e390
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq