// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movl %esi, %r13d
addq %rdi, %r13
testl %esi, %esi
je 0x3fc75
callq 0xc170
movq (%rax), %rax
movsbq (%rbx), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x3fc5a
incq %rbx
cmpq %r13, %rbx
jb 0x3fc45
jmp 0x3fc75
movzbl %cl, %eax
cmpl $0x2b, %eax
je 0x3fc67
cmpl $0x2d, %eax
jne 0x3fc75
cmpl $0x2d, %eax
sete %al
movl %eax, -0x34(%rbp)
incq %rbx
jmp 0x3fc7c
movl $0x0, -0x34(%rbp)
leaq -0x2(%r13), %rax
cmpq %rax, %rbx
jae 0x3fca4
cmpb $0x30, (%rbx)
jne 0x3fca4
movzbl 0x1(%rbx), %eax
orl $0x20, %eax
cmpl $0x78, %eax
jne 0x3fca4
addq $0x2, %rbx
jmp 0x3fca4
cmpb $0x30, (%rbx)
jne 0x3fca9
incq %rbx
cmpq %r13, %rbx
jb 0x3fc9c
cmpq %r13, %rbx
jae 0x3fdf8
movq %r13, -0x40(%rbp)
movq %r12, -0x30(%rbp)
callq 0xc170
movq (%rax), %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbx, -0x48(%rbp)
movsbq (%rbx,%r12), %rdi
movq -0x50(%rbp), %rax
testb $0x10, 0x1(%rax,%rdi,2)
je 0x3fdf0
cmpl $0xf, %r12d
jg 0x3fdf0
shlq $0x4, %r13
callq 0x40450
movslq %eax, %r15
addq %r13, %r15
leaq (%rbx,%r12), %r14
incq %r14
movq -0x40(%rbp), %r13
cmpq %r13, %r14
jae 0x3fe00
leal 0x1(%r12), %eax
cmpl $0xf, %eax
jg 0x3fe21
movsbq (%r14), %rdi
movq -0x50(%rbp), %rax
movzwl (%rax,%rdi,2), %eax
andl $0x1000, %eax           # imm = 0x1000
je 0x3fe21
shlq $0x4, %r15
callq 0x40450
movq %r13, %rcx
movslq %eax, %r13
addq %r15, %r13
leaq (%rbx,%r12), %r14
addq $0x2, %r14
cmpq %rcx, %r14
jae 0x3fe0c
movq -0x48(%rbp), %rax
addq $0x2, %rax
leal 0x2(%r12), %ecx
cmpl $0xf, %ecx
jg 0x3fe09
movsbq (%r14), %rdi
movq -0x50(%rbp), %rcx
movzwl (%rcx,%rdi,2), %ecx
andl $0x1000, %ecx           # imm = 0x1000
je 0x3fe09
shlq $0x4, %r13
callq 0x40450
movslq %eax, %r15
addq %r13, %r15
leaq (%rbx,%r12), %r14
addq $0x3, %r14
movq -0x40(%rbp), %r13
cmpq %r13, %r14
jae 0x3fe19
leal 0x3(%r12), %eax
cmpl $0xf, %eax
jg 0x3fe21
movsbq (%r14), %rdi
movq -0x50(%rbp), %rax
movzwl (%rax,%rdi,2), %eax
andl $0x1000, %eax           # imm = 0x1000
je 0x3fe21
shlq $0x4, %r15
callq 0x40450
movq %r13, %rcx
movslq %eax, %r13
addq %r15, %r13
addq $0x4, -0x48(%rbp)
leaq (%rbx,%r12), %rax
addq $0x4, %rax
addq $0x4, %r12
cmpq %rcx, %rax
jb 0x3fcd0
addq %r12, %rbx
movq %rbx, %r14
jmp 0x3fe0c
xorl %r15d, %r15d
movq %rbx, %r14
jmp 0x3fe25
movq -0x48(%rbp), %r14
incq %r14
jmp 0x3fe21
movq %rax, %r14
movq %r13, %r15
movq -0x30(%rbp), %r12
movq -0x40(%rbp), %r13
jmp 0x3fe25
movq -0x48(%rbp), %r14
addq $0x3, %r14
movq -0x30(%rbp), %r12
cmpq %r13, %r14
jae 0x3fe4d
callq 0xc170
movq (%rax), %rax
incq %r14
movsbq -0x1(%r14), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
je 0x3fe4d
leaq 0x1(%r14), %rcx
cmpq %r13, %r14
movq %rcx, %r14
jb 0x3fe35
testq %r12, %r12
je 0x3fe6e
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