// File: /workspace/github_c_makefile_star2_O2/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, %r12
movl %esi, %r15d
addq %rdi, %r15
cmpq %r15, %r12
jae 0x37879
callq 0xc190
movq (%rax), %rcx
movsbq (%r12), %rax
testb $0x20, 0x1(%rcx,%rax,2)
je 0x3785e
incq %r12
jmp 0x37840
movzbl %al, %eax
cmpl $0x2b, %eax
je 0x3786b
cmpl $0x2d, %eax
jne 0x37879
cmpl $0x2d, %eax
sete %al
movl %eax, -0x2c(%rbp)
incq %r12
jmp 0x37880
movl $0x0, -0x2c(%rbp)
leaq -0x2(%r15), %rax
cmpq %rax, %r12
jae 0x378ae
cmpb $0x30, (%r12)
jne 0x378ae
movzbl 0x1(%r12), %eax
orl $0x20, %eax
cmpl $0x62, %eax
jne 0x378ae
addq $0x2, %r12
jmp 0x378ae
cmpb $0x30, (%r12)
jne 0x378b3
incq %r12
cmpq %r15, %r12
jb 0x378a4
leaq 0x1(%r12), %rax
pushq $0x3
popq %rcx
xorl %r13d, %r13d
leaq -0x1(%rax), %r14
cmpq %r15, %r14
jae 0x37971
movzbl (%r14), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x3796e
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
cmpq %r15, %rax
jae 0x3795a
movzbl (%rax), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x3795f
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
leaq 0x1(%rax), %r14
cmpq %r15, %r14
jae 0x37971
movzbl (%r14), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x37964
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
leaq 0x2(%rax), %r14
cmpq %r15, %r14
jae 0x3796a
cmpl $0x3e, %ecx
jg 0x37971
movzbl (%r14), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x37971
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
addq $0x4, %r12
addq $0x4, %rax
addl $0x4, %ecx
jmp 0x378be
incq %r12
jmp 0x3796e
movq %rax, %r14
jmp 0x37971
addq $0x2, %r12
jmp 0x3796e
addq $0x3, %r12
movq %r12, %r14
cmpq %r15, %r14
jae 0x3798c
callq 0xc190
movq (%rax), %rax
movsbq (%r14), %rcx
incq %r14
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x37971
testq %rbx, %rbx
je 0x379ac
movq %r13, %rax
negq %rax
setb %cl
testb $0x1, %cl
cmoveq %r13, %rax
cmpb $0x0, -0x2c(%rbp)
cmoveq %r13, %rax
movq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq