// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_strtok
static int jx9Builtin_strtok(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	strtok_aux_data *pAux;
	const char *zMask;
	SyString sToken; 
	int nMasklen;
	sxi32 rc;
	if( nArg < 2 ){
		/* Extract top aux data */
		pAux = (strtok_aux_data *)jx9_context_peek_aux_data(pCtx);
		if( pAux == 0 ){
			/* No aux data, return FALSE */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		nMasklen = 0;
		zMask = ""; /* cc warning */
		if( nArg > 0 ){
			/* Extract the mask */
			zMask = jx9_value_to_string(apArg[0], &nMasklen);
		}
		if( nMasklen < 1 ){
			/* Invalid mask, return FALSE */
			jx9_context_free_chunk(pCtx, (void *)pAux->zDup);
			jx9_context_free_chunk(pCtx, pAux);
			(void)jx9_context_pop_aux_data(pCtx);
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		/* Extract the token */
		rc = ExtractToken(&pAux->zIn, pAux->zEnd, zMask, nMasklen, &sToken);
		if( rc != SXRET_OK ){
			/* EOF , discard the aux data */
			jx9_context_free_chunk(pCtx, (void *)pAux->zDup);
			jx9_context_free_chunk(pCtx, pAux);
			(void)jx9_context_pop_aux_data(pCtx);
			jx9_result_bool(pCtx, 0);
		}else{
			/* Return the extracted token */
			jx9_result_string(pCtx, sToken.zString, (int)sToken.nByte);
		}
	}else{
		const char *zInput, *zCur;
		char *zDup;
		int nLen;
		/* Extract the raw input */
		zCur = zInput = jx9_value_to_string(apArg[0], &nLen);
		if( nLen < 1 ){
			/* Empty input, return FALSE */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		/* Extract the mask */
		zMask = jx9_value_to_string(apArg[1], &nMasklen);
		if( nMasklen < 1 ){
			/* Set a default mask */
#define TOK_MASK " \n\t\r\f" 
			zMask = TOK_MASK;
			nMasklen = (int)sizeof(TOK_MASK) - 1;
#undef TOK_MASK
		}
		/* Extract a single token */
		rc = ExtractToken(&zInput, &zInput[nLen], zMask, nMasklen, &sToken);
		if( rc != SXRET_OK ){
			/* Empty input */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}else{
			/* Return the extracted token */
			jx9_result_string(pCtx, sToken.zString, (int)sToken.nByte);
		}
		/* Create our auxilliary data and copy the input */
		pAux = (strtok_aux_data *)jx9_context_alloc_chunk(pCtx, sizeof(strtok_aux_data), TRUE, FALSE);
		if( pAux ){
			nLen -= (int)(zInput-zCur);
			if( nLen < 1 ){
				jx9_context_free_chunk(pCtx, pAux);
				return JX9_OK;
			}
			/* Duplicate input */
			zDup = (char *)jx9_context_alloc_chunk(pCtx, (unsigned int)(nLen+1), TRUE, FALSE);
			if( zDup  ){
				SyMemcpy(zInput, zDup, (sxu32)nLen);
				/* Register the aux data */
				pAux->zDup = pAux->zIn = zDup;
				pAux->zEnd = &zDup[nLen];
				jx9_context_push_aux_data(pCtx, pAux);
			}
		}
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdx, %r15
movq %rdi, %rbx
cmpl $0x1, %esi
jg 0x57322
movq (%rbx), %rcx
movl 0x38(%rcx), %eax
testl %eax, %eax
je 0x57384
movq 0x30(%rcx), %rdx
testq %rdx, %rdx
je 0x57384
decl %eax
imull 0x40(%rcx), %eax
movq (%rdx,%rax), %r14
testq %r14, %r14
je 0x57384
movl $0x0, -0x28(%rbp)
cmpl $0x1, %esi
jne 0x572fb
movq (%r15), %rdi
leaq -0x28(%rbp), %r15
movq %r15, %rsi
callq 0x30577
movl (%r15), %ecx
testl %ecx, %ecx
jle 0x572fb
leaq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
leaq -0x40(%rbp), %r8
movq %rax, %rdx
callq 0x5b8c9
testl %eax, %eax
je 0x57459
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x313b9
movq %rbx, %rdi
movq %r14, %rsi
callq 0x313b9
movq (%rbx), %rax
movl 0x38(%rax), %ecx
testl %ecx, %ecx
je 0x57384
decl %ecx
movl %ecx, 0x38(%rax)
jmp 0x57384
movq (%r15), %rdi
leaq -0x24(%rbp), %r12
movq %r12, %rsi
callq 0x30577
movq %rax, -0x30(%rbp)
cmpl $0x0, (%r12)
jle 0x57384
movq %rax, %r14
movq 0x8(%r15), %rdi
leaq -0x28(%rbp), %r15
movq %r15, %rsi
callq 0x30577
movl (%r15), %ecx
testl %ecx, %ecx
jg 0x57369
movl $0x5, -0x28(%rbp)
leaq 0x1fc28(%rip), %rax     # 0x76f8c
movl $0x5, %ecx
movslq -0x24(%rbp), %rsi
addq %r14, %rsi
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %r8
movq %rax, %rdx
callq 0x5b8c9
testl %eax, %eax
je 0x573b4
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x8, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %rsi
movl -0x38(%rbp), %edx
movq 0x8(%rbx), %rdi
callq 0x302f6
movq %rbx, %rdi
movl $0x18, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x312d8
testq %rax, %rax
je 0x573a5
movq %rax, %r15
movq -0x30(%rbp), %r12
subl %r12d, %r14d
addl -0x24(%rbp), %r14d
movl %r14d, -0x24(%rbp)
testl %r14d, %r14d
jle 0x57449
incl %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x312d8
testq %rax, %rax
je 0x573a5
movq %rax, %r14
movl -0x24(%rbp), %edx
movq %r12, %rdi
movq %rax, %rsi
callq 0x34893
movq %r14, 0x8(%r15)
movq %r14, (%r15)
movslq -0x24(%rbp), %rax
addq %r14, %rax
movq %rax, 0x10(%r15)
movq (%rbx), %rdi
leaq -0x48(%rbp), %rsi
movq %r15, (%rsi)
addq $0x28, %rdi
callq 0x33094
jmp 0x573a5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x313b9
jmp 0x573a5
movq -0x40(%rbp), %rsi
movl -0x38(%rbp), %edx
movq 0x8(%rbx), %rdi
callq 0x302f6
jmp 0x573a5