// File: /workspace/github_c_makefile_star2_O1/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 0x56a50
movq %rdx, %r15
movl %esi, %ebx
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
movq %rax, -0x58(%rbp)
cmpl $0x0, (%r14)
jle 0x56a50
movq 0x8(%r15), %rdi
leaq -0x5c(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
movq %rax, %r12
movslq (%r14), %rax
testq %rax, %rax
jle 0x56a50
movq %rax, -0x38(%rbp)
movq %r13, %rdi
callq 0x317eb
movq %rax, %r14
movq %r13, %rdi
callq 0x317a5
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 0x56a82
movq 0x8(%rdx), %rbx
jmp 0x56a54
movq 0x8(%r13), %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 $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 0x56abd
movq 0x10(%r15), %rbx
movq %rbx, %rdi
movq %rax, %r14
callq 0x3fd5f
movl (%rbx), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movq %r14, %rax
cmpl $0x1, %ecx
adcl $-0x1, %ecx
movl %ecx, -0x38(%rbp)
movq -0x50(%rbp), %r15
movq %rax, %r14
movl %eax, %ebx
subl %r12d, %ebx
movl -0x2c(%rbp), %ecx
movq %r12, %rdi
movl %ebx, %esi
movq -0x58(%rbp), %rdx
leaq -0x3c(%rbp), %r8
callq 0x5b678
testl %eax, %eax
jne 0x56b5f
xorl %eax, %eax
testb $0x40, 0x8(%r15)
je 0x56af1
movq (%r15), %rax
movl 0x2c(%rax), %eax
cmpl %eax, -0x38(%rbp)
jle 0x56b5f
movl -0x3c(%rbp), %ebx
testq %rbx, %rbx
je 0x56b1f
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x3087c
testb $0x40, 0x8(%r15)
je 0x56b1f
movq (%r15), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x3f924
movslq -0x2c(%rbp), %rax
movl $0x0, 0x28(%r13)
movl 0x30(%r13), %ecx
testb $0x4, %cl
je 0x56b4b
movq $0x0, 0x20(%r13)
movl $0x0, 0x2c(%r13)
andl $-0x5, %ecx
movl %ecx, 0x30(%r13)
addq %rbx, %r12
addq %rax, %r12
movq %r14, %rax
cmpq %r14, %r12
jb 0x56ac1
jmp 0x56b80
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x3087c
testb $0x40, 0x8(%r15)
je 0x56b80
movq (%r15), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x3f924
movq -0x48(%rbp), %rdi
movq %r15, %rsi
callq 0x30d83
jmp 0x56a71