// File: /workspace/github_c_makefile_star2_O1/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 0x408e9
callq 0xc170
movq (%rax), %rax
movsbq (%r14), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x408d0
incq %r14
cmpq %r15, %r14
jb 0x408bb
jmp 0x408e9
movzbl %cl, %eax
cmpl $0x2b, %eax
je 0x408dd
cmpl $0x2d, %eax
jne 0x408e9
cmpl $0x2d, %eax
sete %r12b
incq %r14
jmp 0x408ec
xorl %r12d, %r12d
leaq -0x2(%r15), %rax
cmpq %rax, %r14
jae 0x40917
cmpb $0x30, (%r14)
jne 0x40917
movzbl 0x1(%r14), %eax
orl $0x20, %eax
cmpl $0x62, %eax
jne 0x40917
addq $0x2, %r14
jmp 0x40917
cmpb $0x30, (%r14)
jne 0x4091c
incq %r14
cmpq %r15, %r14
jb 0x4090e
cmpq %r15, %r14
jae 0x409d5
leaq 0x3(%r14), %rax
movl $0x3, %ecx
xorl %r13d, %r13d
movzbl -0x3(%rax), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x409da
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
leaq -0x2(%rax), %rdx
cmpq %r15, %rdx
jae 0x409e3
movzbl (%rdx), %esi
movl %esi, %edi
andb $-0x2, %dil
cmpb $0x30, %dil
jne 0x409d0
leaq (%rsi,%r13,2), %r13
addq $-0x30, %r13
leaq -0x1(%rax), %rdx
cmpq %r15, %rdx
jae 0x409d0
movzbl (%rdx), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x409e8
leaq (%rdx,%r13,2), %r13
addq $-0x30, %r13
cmpq %r15, %rax
jae 0x409ee
cmpl $0x3e, %ecx
jg 0x409de
movzbl (%rax), %edx
movl %edx, %esi
andb $-0x2, %sil
cmpb $0x30, %sil
jne 0x409de
leaq (%rdx,%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 0x40931
addq $-0x3, %rdx
movq %rdx, %r14
jmp 0x409f2
xorl %r13d, %r13d
jmp 0x409f2
addq $-0x3, %rax
movq %rax, %r14
jmp 0x409f2
incq %r14
jmp 0x409f2
addq $0x2, %r14
jmp 0x409f2
addq $0x3, %r14
cmpq %r15, %r14
jae 0x40a20
callq 0xc170
movq (%rax), %rax
movsbq (%r14), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x40a20
incq %r14
cmpq %r15, %r14
jae 0x40a20
movsbq (%r14), %rcx
incq %r14
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x40a0d
testq %rbx, %rbx
je 0x40a3f
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