// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: SyHexStrToInt64
JX9_PRIVATE sxi32 SyHexStrToInt64(const char *zSrc, sxu32 nLen, void * pOutVal, const char **zRest)
{
	const char *zIn, *zEnd;
	int isNeg = FALSE;
	sxi64 nVal = 0;
#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 == '-' || *zSrc == '+' ) ){
		isNeg = (zSrc[0] == '-') ? TRUE :FALSE;
		zSrc++;
	}
	if( zSrc < &zEnd[-2] && zSrc[0] == '0' && (zSrc[1] == 'x' || zSrc[1] == 'X') ){
		/* Bypass hex prefix */
		zSrc += sizeof(char) * 2;
	}	
	/* Skip leading zero */
	while(zSrc < zEnd && zSrc[0] == '0' ){
		zSrc++;
	}
	zIn = zSrc;
	for(;;){
		if(zSrc >= zEnd || !SyisHex(zSrc[0]) || (int)(zSrc-zIn) > 15) break; nVal = nVal * 16 + SyHexToint(zSrc[0]);  zSrc++ ;
		if(zSrc >= zEnd || !SyisHex(zSrc[0]) || (int)(zSrc-zIn) > 15) break; nVal = nVal * 16 + SyHexToint(zSrc[0]);  zSrc++ ;
		if(zSrc >= zEnd || !SyisHex(zSrc[0]) || (int)(zSrc-zIn) > 15) break; nVal = nVal * 16 + SyHexToint(zSrc[0]);  zSrc++ ;
		if(zSrc >= zEnd || !SyisHex(zSrc[0]) || (int)(zSrc-zIn) > 15) break; nVal = nVal * 16 + SyHexToint(zSrc[0]);  zSrc++ ;
	}
	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
subq $0x28, %rsp
movq %rdx, %r12
movq %rdi, %r14
movl %esi, %r13d
addq %rdi, %r13
testl %esi, %esi
je 0x40685
callq 0xc170
movq (%rax), %rax
movsbq (%r14), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x4066a
incq %r14
cmpq %r13, %r14
jb 0x40655
jmp 0x40685
movzbl %cl, %eax
cmpl $0x2b, %eax
je 0x40677
cmpl $0x2d, %eax
jne 0x40685
cmpl $0x2d, %eax
sete %al
movl %eax, -0x34(%rbp)
incq %r14
jmp 0x4068c
movl $0x0, -0x34(%rbp)
leaq -0x2(%r13), %rax
cmpq %rax, %r14
jae 0x406b7
cmpb $0x30, (%r14)
jne 0x406b7
movzbl 0x1(%r14), %eax
orl $0x20, %eax
cmpl $0x78, %eax
jne 0x406b7
addq $0x2, %r14
jmp 0x406b7
cmpb $0x30, (%r14)
jne 0x406bc
incq %r14
cmpq %r13, %r14
jb 0x406ae
cmpq %r13, %r14
jae 0x40813
movq %r12, -0x30(%rbp)
callq 0xc170
movq (%rax), %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r14, -0x48(%rbp)
movq %r13, -0x40(%rbp)
movsbq (%r14,%r12), %rdi
movq -0x50(%rbp), %rax
testb $0x10, 0x1(%rax,%rdi,2)
je 0x4080b
cmpl $0xf, %r12d
jg 0x4080b
shlq $0x4, %r15
callq 0x40e77
movq %r13, %rcx
movslq %eax, %r13
addq %r15, %r13
leaq (%r14,%r12), %rbx
incq %rbx
cmpq %rcx, %rbx
jae 0x4081e
movq -0x48(%rbp), %rax
incq %rax
leal 0x1(%r12), %ecx
cmpl $0xf, %ecx
jg 0x4081b
movsbq (%rbx), %rdi
movq -0x50(%rbp), %rcx
movzwl (%rcx,%rdi,2), %ecx
andl $0x1000, %ecx           # imm = 0x1000
je 0x4081b
shlq $0x4, %r13
callq 0x40e77
movslq %eax, %r15
addq %r13, %r15
leaq (%r14,%r12), %rbx
addq $0x2, %rbx
movq -0x40(%rbp), %r13
cmpq %r13, %rbx
jae 0x4082b
leal 0x2(%r12), %eax
cmpl $0xf, %eax
jg 0x40833
movsbq (%rbx), %rdi
movq -0x50(%rbp), %rax
movzwl (%rax,%rdi,2), %eax
andl $0x1000, %eax           # imm = 0x1000
je 0x40833
shlq $0x4, %r15
callq 0x40e77
movq %r13, %rcx
movslq %eax, %r13
addq %r15, %r13
leaq (%r14,%r12), %rbx
addq $0x3, %rbx
cmpq %rcx, %rbx
jae 0x4081e
movq -0x48(%rbp), %rax
addq $0x3, %rax
leal 0x3(%r12), %ecx
cmpl $0xf, %ecx
jg 0x4081b
movsbq (%rbx), %rdi
movq -0x50(%rbp), %rcx
movzwl (%rcx,%rdi,2), %ecx
andl $0x1000, %ecx           # imm = 0x1000
je 0x4081b
shlq $0x4, %r13
callq 0x40e77
movslq %eax, %r15
addq %r13, %r15
addq $0x4, -0x48(%rbp)
leaq (%r14,%r12), %rax
addq $0x4, %rax
addq $0x4, %r12
movq -0x40(%rbp), %r13
cmpq %r13, %rax
jb 0x406e3
addq %r12, %r14
movq %r14, %rbx
jmp 0x40833
xorl %r15d, %r15d
movq %r14, %rbx
jmp 0x40837
movq %rax, %rbx
movq %r13, %r15
movq -0x30(%rbp), %r12
movq -0x40(%rbp), %r13
jmp 0x40837
movq -0x48(%rbp), %rbx
addq $0x2, %rbx
movq -0x30(%rbp), %r12
cmpq %r13, %rbx
jae 0x40865
callq 0xc170
movq (%rax), %rax
movsbq (%rbx), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x40865
incq %rbx
cmpq %r13, %rbx
jae 0x40865
movsbq (%rbx), %rcx
incq %rbx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x40852
testq %r12, %r12
je 0x40886
movq %r15, %rax
negq %rax
setb %cl
testb $0x1, %cl
cmoveq %r15, %rax
cmpb $0x0, -0x34(%rbp)
cmoveq %r15, %rax
movq %rax, (%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq