// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_explode
static int jx9Builtin_explode(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zDelim, *zString, *zCur, *zEnd;
	int nDelim, nStrlen, iLimit;
	jx9_value *pArray;
	jx9_value *pValue;
	sxu32 nOfft;
	sxi32 rc;
	if( nArg < 2 ){
		/* Missing arguments, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the delimiter */
	zDelim = jx9_value_to_string(apArg[0], &nDelim);
	if( nDelim < 1 ){
		/* Empty delimiter, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the string */
	zString = jx9_value_to_string(apArg[1], &nStrlen);
	if( nStrlen < 1 ){
		/* Empty delimiter, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Point to the end of the string */
	zEnd = &zString[nStrlen];
	/* Create the array */
	pArray =  jx9_context_new_array(pCtx);
	pValue = jx9_context_new_scalar(pCtx);
	if( pArray == 0 || pValue == 0 ){
		/* Out of memory, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Set a defualt limit */
	iLimit = SXI32_HIGH;
	if( nArg > 2 ){
		iLimit = jx9_value_to_int(apArg[2]);
		 if( iLimit < 0 ){
			iLimit = -iLimit;
		}
		if( iLimit == 0 ){
			iLimit = 1;
		}
		iLimit--;
	}
	/* Start exploding */
	for(;;){
		if( zString >= zEnd ){
			/* No more entry to process */
			break;
		}
		rc = SyBlobSearch(zString, (sxu32)(zEnd-zString), zDelim, nDelim, &nOfft);
		if( rc != SXRET_OK || iLimit <= (int)jx9_array_count(pArray) ){
			/* Limit reached, insert the rest of the string and break */
			if( zEnd > zString ){
				jx9_value_string(pValue, zString, (int)(zEnd-zString));
				jx9_array_add_elem(pArray, 0/* Automatic index assign*/, pValue);
			}
			break;
		}
		/* Point to the desired offset */
		zCur = &zString[nOfft];
		if( zCur > zString ){
			/* Perform the store operation */
			jx9_value_string(pValue, zString, (int)(zCur-zString));
			jx9_array_add_elem(pArray, 0/* Automatic index assign*/, pValue);
		}
		/* Point beyond the delimiter */
		zString = &zCur[nDelim];
		/* Reset the cursor */
		jx9_value_reset_string_cursor(pValue);
	}
	/* Return the freshly created array */
	jx9_result_value(pCtx, pArray);
	/* NOTE that every allocated jx9_value will be automatically 
	 * released as soon we return from this foregin function.
	 */
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
cmpl $0x1, %esi
jle 0x4998a
movq %rdx, %r13
movl %esi, %ebx
movq (%rdx), %rdi
leaq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x297ed
movq %rax, -0x58(%rbp)
cmpl $0x0, (%r14)
jle 0x4998a
movq 0x8(%r13), %rdi
leaq -0x5c(%rbp), %r14
movq %r14, %rsi
callq 0x297ed
movslq (%r14), %r14
testq %r14, %r14
jle 0x4998a
movq %rax, %r12
movq %r15, %rdi
callq 0x2a2b0
movq %r15, %rdi
movq %rax, %r15
movq %rdi, -0x48(%rbp)
callq 0x2a26a
testq %r15, %r15
sete %dl
movq %rax, -0x38(%rbp)
testq %rax, %rax
sete %cl
orb %dl, %cl
cmpb $0x1, %cl
jne 0x499a5
movq -0x48(%rbp), %rdi
jmp 0x4998d
movq %r15, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
cmpl $0x2, %ebx
je 0x499ca
movq 0x10(%r13), %rdi
callq 0x29772
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1, %ecx
adcl $-0x1, %ecx
movl %ecx, -0x2c(%rbp)
addq %r12, %r14
movq -0x38(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %r13
cmpq %r14, %r12
jae 0x49a6e
movl %r14d, %ebx
subl %r12d, %ebx
movl -0x30(%rbp), %ecx
movq %r12, %rdi
movl %ebx, %esi
movq -0x58(%rbp), %rdx
leaq -0x3c(%rbp), %r8
callq 0x4d7da
testl %eax, %eax
jne 0x49a50
xorl %eax, %eax
testb $0x40, 0x8(%r15)
je 0x49a14
movq (%r15), %rax
movl 0x2c(%rax), %eax
cmpl %eax, -0x2c(%rbp)
jle 0x49a50
movl -0x3c(%rbp), %ebx
testq %rbx, %rbx
je 0x49a3b
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x29588
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x29c4b
addq %rbx, %r12
movslq -0x30(%rbp), %rax
addq %rax, %r12
movq -0x50(%rbp), %rdi
callq 0x31b1e
jmp 0x499dd
movq -0x38(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x29588
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x29c4b
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x299d3
jmp 0x49994