// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0x96028
movq -0x10(%rbp), %rdi
callq 0x583b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x95f48
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x9619d
movl $0x0, -0x44(%rbp)
leaq 0x2fbf5(%rip), %rax     # 0xc5b4b
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x95f74
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x44(%rbp), %rsi
callq 0x56e20
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x44(%rbp)
jge 0x95fb7
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x58780
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x58780
movq -0x10(%rbp), %rdi
callq 0x58420
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x9619d
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rdx
movl -0x44(%rbp), %ecx
leaq -0x40(%rbp), %r8
callq 0x9c320
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x96013
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x58780
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x58780
movq -0x10(%rbp), %rdi
callq 0x58420
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
jmp 0x96023
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x57180
jmp 0x96196
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x64(%rbp), %rsi
callq 0x56e20
movq %rax, -0x50(%rbp)
movq %rax, -0x58(%rbp)
cmpl $0x1, -0x64(%rbp)
jge 0x9605d
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x9619d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x44(%rbp), %rsi
callq 0x56e20
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x44(%rbp)
jge 0x9608a
leaq 0x2f3e6(%rip), %rax     # 0xc5465
movq %rax, -0x30(%rbp)
movl $0x5, -0x44(%rbp)
movq -0x50(%rbp), %rsi
movslq -0x64(%rbp), %rax
addq %rax, %rsi
movq -0x30(%rbp), %rdx
movl -0x44(%rbp), %ecx
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r8
callq 0x9c320
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x960c9
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x9619d
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x57180
movq -0x10(%rbp), %rdi
movl $0x18, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x58640
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x96194
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movl -0x64(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
cmpl $0x1, -0x64(%rbp)
jge 0x9612e
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x58780
movl $0x0, -0x4(%rbp)
jmp 0x9619d
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
addl $0x1, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x58640
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x96192
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl -0x64(%rbp), %edx
callq 0x5d570
movq -0x60(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movslq -0x64(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x58350
jmp 0x96194
jmp 0x96196
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)