// File: /workspace/github_c_makefile_star2_O3/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, %r13
cmpl $0x1, %esi
jle 0x552b7
movq %rdx, %r15
movl %esi, %ebx
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r14
movq %r14, %rsi
callq 0x30577
movq %rax, -0x58(%rbp)
cmpl $0x0, (%r14)
jle 0x552b7
movq 0x8(%r15), %rdi
leaq -0x5c(%rbp), %r14
movq %r14, %rsi
callq 0x30577
movq %rax, %r12
movslq (%r14), %rax
testq %rax, %rax
jle 0x552b7
movq %rax, -0x38(%rbp)
movq %r13, %rdi
callq 0x31231
movq %rax, %r14
movq %r13, %rdi
callq 0x311eb
movq %r13, %rdx
movq %rax, %r13
movq %r14, -0x50(%rbp)
testq %r14, %r14
sete %al
testq %r13, %r13
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x552e9
movq 0x8(%rdx), %rbx
jmp 0x552bb
movq 0x8(%r13), %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 $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq %r12, %rax
movl $0x7fffffff, -0x38(%rbp) # imm = 0x7FFFFFFF
cmpl $0x2, %ebx
je 0x55324
movq 0x10(%r15), %rbx
movq %rbx, %rdi
movq %rax, %r14
callq 0x3f362
movl (%rbx), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq %r14, %rax
cmpl $0x1, %ecx
adcl $-0x1, %ecx
movl %ecx, -0x38(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x50(%rbp), %r15
movq %rax, %r14
movl %eax, %ebx
subl %r12d, %ebx
movq %r12, %rdi
movl %ebx, %esi
movq -0x58(%rbp), %rdx
leaq -0x3c(%rbp), %r8
callq 0x59e90
testl %eax, %eax
jne 0x553c5
xorl %eax, %eax
testb $0x40, 0x8(%r15)
je 0x55358
movq (%r15), %rax
movl 0x2c(%rax), %eax
cmpl %eax, -0x38(%rbp)
jle 0x553c5
movl -0x3c(%rbp), %ebx
testq %rbx, %rbx
je 0x55386
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x302f6
testb $0x40, 0x8(%r15)
je 0x55386
movq (%r15), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x3ef1d
movslq -0x2c(%rbp), %rcx
movl $0x0, 0x28(%r13)
movl 0x30(%r13), %eax
testb $0x4, %al
je 0x553b1
movq $0x0, 0x20(%r13)
movl $0x0, 0x2c(%r13)
andl $-0x5, %eax
movl %eax, 0x30(%r13)
addq %rbx, %r12
addq %rcx, %r12
movq %r14, %rax
cmpq %r14, %r12
jb 0x5532b
jmp 0x553e6
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x302f6
testb $0x40, 0x8(%r15)
je 0x553e6
movq (%r15), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x3ef1d
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x307f4
jmp 0x552d8