// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_str_split
static int jx9Builtin_str_split(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zString, *zEnd;
	jx9_value *pArray, *pValue;
	int split_len;
	int nLen;
	if( nArg < 1 ){
		/* Missing arguments, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Point to the target string */
	zString = jx9_value_to_string(apArg[0], &nLen);
	if( nLen < 1 ){
		/* Nothing to process, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	split_len = (int)sizeof(char);
	if( nArg > 1 ){
		/* Split length */
		split_len = jx9_value_to_int(apArg[1]);
		if( split_len < 1 ){
			/* Invalid length, return FALSE */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		if( split_len > nLen ){
			split_len = nLen;
		}
	}
	/* Create the array and the scalar value */
	pArray = jx9_context_new_array(pCtx);
	/*Chunk value */
	pValue = jx9_context_new_scalar(pCtx);
	if( pValue == 0 || pArray == 0 ){
		/* Return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Point to the end of the string */
	zEnd = &zString[nLen];
	/* Perform the requested operation */
	for(;;){
		int nMax;
		if( zString >= zEnd ){
			/* No more input to process */
			break;
		}
		nMax = (int)(zEnd-zString);
		if( nMax < split_len ){
			split_len = nMax;
		}
		/* Copy the current chunk */
		jx9_value_string(pValue, zString, split_len);
		/* Insert it */
		jx9_array_add_elem(pArray, 0, pValue); /* Will make it's own copy */
		/* reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		/* Update position */
		zString += split_len;
	}
	/* 
	 * Return the array.
	 * Don't worry about freeing memory, everything will be automatically released
	 * upon we return from this function.
	 */
	jx9_result_value(pCtx, pArray);
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x56aeb
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x30577
cmpl $0x0, (%r15)
jle 0x56aeb
movq %rax, %r14
movl $0x1, %r15d
cmpl $0x1, %r13d
je 0x56ac2
movq 0x8(%r12), %r15
movq %r15, %rdi
callq 0x3f362
movl (%r15), %r15d
testl %r15d, %r15d
jle 0x56aeb
movl -0x2c(%rbp), %eax
cmpl %r15d, %eax
cmovll %eax, %r15d
movq %rbx, %rdi
callq 0x31231
movq %rax, %r12
movq %rbx, %rdi
callq 0x311eb
movq %rax, %r13
testq %rax, %rax
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x56b1d
movq 0x8(%rbx), %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 $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, -0x38(%rbp)
movslq -0x2c(%rbp), %rbx
testq %rbx, %rbx
jle 0x56b93
addq %r14, %rbx
movl %r15d, %eax
movl %ebx, %r15d
subl %r14d, %r15d
cmpl %r15d, %eax
cmovll %eax, %r15d
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x302f6
testb $0x40, 0x8(%r12)
je 0x56b61
movq (%r12), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x3ef1d
movl $0x0, 0x28(%r13)
movl 0x30(%r13), %eax
testb $0x4, %al
je 0x56b88
movq $0x0, 0x20(%r13)
movl $0x0, 0x2c(%r13)
andl $-0x5, %eax
movl %eax, 0x30(%r13)
movslq %r15d, %rax
addq %rax, %r14
cmpq %rbx, %r14
jb 0x56b2d
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x307f4
jmp 0x56b0c