// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: SyBinaryStrToInt64
JX9_PRIVATE sxi32 SyBinaryStrToInt64(const char *zSrc, sxu32 nLen, void * pOutVal, const char **zRest)
{
	const char *zIn, *zEnd;
	int isNeg = FALSE;
	sxi64 nVal = 0;
	int c;
#if defined(UNTRUST)
	if( SX_EMPTY_STR(zSrc) ){
		if( pOutVal ){
			*(sxi32 *)pOutVal = 0;
		}
		return SXERR_EMPTY;
	}
#endif
	zEnd = &zSrc[nLen];
	while(zSrc < zEnd && SyisSpace(zSrc[0]) ){
		zSrc++;
	}
	if( zSrc < zEnd && ( zSrc[0] == '-' || zSrc[0] == '+' ) ){
		isNeg = (zSrc[0] == '-') ? TRUE :FALSE;
		zSrc++;
	}
	if( zSrc < &zEnd[-2] && zSrc[0] == '0' && (zSrc[1] == 'b' || zSrc[1] == 'B') ){
		/* Bypass binary prefix */
		zSrc += sizeof(char) * 2;
	}
	/* Skip leading zero */
	while(zSrc < zEnd && zSrc[0] == '0' ){
		zSrc++; 
	}
	zIn = zSrc;
	for(;;){
		if(zSrc >= zEnd || (zSrc[0] != '1' && zSrc[0] != '0') || (int)(zSrc-zIn) > 62){ break; } c = zSrc[0] - '0'; nVal = (nVal << 1) + c; zSrc++;
		if(zSrc >= zEnd || (zSrc[0] != '1' && zSrc[0] != '0') || (int)(zSrc-zIn) > 62){ break; } c = zSrc[0] - '0'; nVal = (nVal << 1) + c; zSrc++;
		if(zSrc >= zEnd || (zSrc[0] != '1' && zSrc[0] != '0') || (int)(zSrc-zIn) > 62){ break; } c = zSrc[0] - '0'; nVal = (nVal << 1) + c; zSrc++;
		if(zSrc >= zEnd || (zSrc[0] != '1' && zSrc[0] != '0') || (int)(zSrc-zIn) > 62){ break; } c = zSrc[0] - '0'; nVal = (nVal << 1) + c; zSrc++;
	}
	/* Skip trailing spaces */
	while(zSrc < zEnd && SyisSpace(zSrc[0])){
		zSrc++;
	}
	if( zRest ){
		*zRest = zSrc;
	}	
	if( pOutVal ){
		if( isNeg == TRUE && nVal != 0 ){
			nVal = -nVal;
		}
		*(sxi64 *)pOutVal = nVal;
	}
	return (zSrc >= zEnd) ? SXRET_OK : SXERR_SYNTAX;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r14
movl %esi, %r15d
addq %rdi, %r15
testl %esi, %esi
je 0x3fed1
callq 0xc170
movq (%rax), %rax
movsbq (%r14), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x3feb8
incq %r14
cmpq %r15, %r14
jb 0x3fea3
jmp 0x3fed1
movzbl %cl, %eax
cmpl $0x2b, %eax
je 0x3fec5
cmpl $0x2d, %eax
jne 0x3fed1
cmpl $0x2d, %eax
sete %r12b
incq %r14
jmp 0x3fed4
xorl %r12d, %r12d
leaq -0x2(%r15), %rax
cmpq %rax, %r14
jae 0x3feff
cmpb $0x30, (%r14)
jne 0x3feff
movzbl 0x1(%r14), %eax
orl $0x20, %eax
cmpl $0x62, %eax
jne 0x3feff
addq $0x2, %r14
jmp 0x3feff
cmpb $0x30, (%r14)
jne 0x3ff04
incq %r14
cmpq %r15, %r14
jb 0x3fef6
cmpq %r15, %r14
jae 0x3ffbd
leaq 0x3(%r14), %rax
movl $0x3, %ecx
xorl %r13d, %r13d
movzbl -0x3(%rax), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x3ffc2
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
leaq -0x2(%rax), %rdx
cmpq %r15, %rdx
jae 0x3ffb8
movzbl (%rdx), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x3ffcb
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
leaq -0x1(%rax), %rdx
cmpq %r15, %rdx
jae 0x3ffd0
movzbl (%rdx), %esi
movl %esi, %edi
andb $-0x2, %dil
cmpb $0x30, %dil
jne 0x3ffb8
leaq (%rsi,%r13,2), %r13
addq $-0x30, %r13
cmpq %r15, %rax
jae 0x3ffc6
leaq 0x3(%r14), %rdx
cmpl $0x3e, %ecx
jg 0x3ffb8
movzbl (%rax), %esi
movl %esi, %edi
andb $-0x2, %dil
cmpb $0x30, %dil
jne 0x3ffb8
leaq (%rsi,%r13,2), %r13
addq $-0x30, %r13
addq $0x4, %r14
leaq 0x4(%rax), %rdx
incq %rax
addl $0x4, %ecx
cmpq %r15, %rax
movq %rdx, %rax
jb 0x3ff19
addq $-0x3, %rdx
movq %rdx, %r14
jmp 0x3ffd4
xorl %r13d, %r13d
jmp 0x3ffd4
addq $-0x3, %rax
movq %rax, %r14
jmp 0x3ffd4
incq %r14
jmp 0x3ffd4
addq $0x2, %r14
cmpq %r15, %r14
jae 0x3fffc
callq 0xc170
movq (%rax), %rax
incq %r14
movsbq -0x1(%r14), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x3fffc
leaq 0x1(%r14), %rcx
cmpq %r15, %r14
movq %rcx, %r14
jb 0x3ffe4
testq %rbx, %rbx
je 0x4001b
movq %r13, %rax
negq %rax
setb %cl
testb $0x1, %cl
cmoveq %r13, %rax
testb %r12b, %r12b
cmoveq %r13, %rax
movq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq