// File: /workspace/github_c_makefile_star2_O1/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 0x58ac5
movq (%rbx), %rcx
movl 0x38(%rcx), %eax
testl %eax, %eax
je 0x58bcd
decl %eax
imull 0x40(%rcx), %eax
addq 0x30(%rcx), %rax
jmp 0x58bcf
movq (%r15), %rdi
leaq -0x24(%rbp), %r12
movq %r12, %rsi
callq 0x30b04
movq %rax, -0x30(%rbp)
cmpl $0x0, (%r12)
jle 0x58c46
movq %rax, %r14
movq 0x8(%r15), %rdi
leaq -0x28(%rbp), %r15
movq %r15, %rsi
callq 0x30b04
cmpl $0x0, (%r15)
jg 0x58b0a
movl $0x5, -0x28(%rbp)
leaq 0x20477(%rip), %rax     # 0x78f81
movslq -0x24(%rbp), %rsi
addq %r14, %rsi
movl -0x28(%rbp), %ecx
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %r8
movq %rax, %rdx
callq 0x5d1f8
testl %eax, %eax
jne 0x58c46
movq -0x40(%rbp), %rsi
movl -0x38(%rbp), %edx
movq 0x8(%rbx), %rdi
callq 0x3087c
movq %rbx, %rdi
movl $0x18, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x31892
testq %rax, %rax
je 0x58c67
movq %rax, %r15
movq -0x30(%rbp), %r12
subl %r12d, %r14d
addl -0x24(%rbp), %r14d
movl %r14d, -0x24(%rbp)
testl %r14d, %r14d
jle 0x58c88
incl %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x31892
testq %rax, %rax
je 0x58c67
movq %rax, %r14
movl -0x24(%rbp), %edx
movq %r12, %rdi
movq %rax, %rsi
callq 0x34fc5
movq %r14, 0x8(%r15)
movq %r14, (%r15)
movslq -0x24(%rbp), %rax
addq %r14, %rax
movq %rax, 0x10(%r15)
leaq -0x48(%rbp), %rsi
movq %r15, (%rsi)
movq (%rbx), %rdi
addq $0x28, %rdi
callq 0x336fc
jmp 0x58c67
xorl %eax, %eax
testq %rax, %rax
je 0x58bd9
movq (%rax), %r14
jmp 0x58bdc
xorl %r14d, %r14d
testq %r14, %r14
je 0x58c46
movl $0x0, -0x28(%rbp)
cmpl $0x1, %esi
jne 0x58bfe
movq (%r15), %rdi
leaq -0x28(%rbp), %rsi
callq 0x30b04
movq %rax, %rdx
jmp 0x58c05
leaq 0x20a62(%rip), %rdx     # 0x79667
movl -0x28(%rbp), %ecx
testl %ecx, %ecx
jle 0x58c21
leaq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
leaq -0x40(%rbp), %r8
callq 0x5d1f8
testl %eax, %eax
je 0x58c76
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x31975
movq %rbx, %rdi
movq %r14, %rsi
callq 0x31975
movq (%rbx), %rax
movl 0x38(%rax), %ecx
testl %ecx, %ecx
je 0x58c46
decl %ecx
movl %ecx, 0x38(%rax)
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
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 0x3087c
jmp 0x58c67
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31975
jmp 0x58c67