// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: vm_builtin_getopt
static int vm_builtin_getopt(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zIn, *zEnd, *zArg, *zArgIn, *zArgEnd;
	struct getopt_long_opt sLong;
	jx9_value *pArray, *pWorker;
	SyBlob *pArg;
	int nByte;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_ERR, "Missing/Invalid option arguments");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract option arguments */
	zIn  = jx9_value_to_string(apArg[0], &nByte);
	zEnd = &zIn[nByte];
	/* Point to the string representation of the $argv[] array */
	pArg = &pCtx->pVm->sArgv;
	/* Create a new empty array and a worker variable */
	pArray = jx9_context_new_array(pCtx);
	pWorker = jx9_context_new_scalar(pCtx);
	if( pArray == 0 || pWorker == 0 ){
		jx9_context_throw_error(pCtx,JX9_CTX_ERR, "JX9 is running out of memory");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	if( SyBlobLength(pArg) < 1 ){
		/* Empty command line, return the empty array*/
		jx9_result_value(pCtx, pArray);
		/* Everything will be released automatically when we return 
		 * from this function.
		 */
		return JX9_OK;
	}
	zArgIn = (const char *)SyBlobData(pArg);
	zArgEnd = &zArgIn[SyBlobLength(pArg)];
	/* Fill the long option structure */
	sLong.pArray = pArray;
	sLong.pWorker = pWorker;
	sLong.zArgIn =  zArgIn;
	sLong.zArgEnd = zArgEnd;
	sLong.pCtx = pCtx;
	/* Start processing */
	while( zIn < zEnd ){
		int c = zIn[0];
		int need_val = 0;
		/* Advance the stream cursor */
		zIn++;
		/* Ignore non-alphanum characters */
		if( !SyisAlphaNum(c) ){
			continue;
		}
		if( zIn < zEnd && zIn[0] == ':' ){
			zIn++;
			need_val = 1;
			if( zIn < zEnd && zIn[0] == ':' ){
				zIn++;
			}
		}
		/* Find option */
		zArg = VmFindShortOpt(c, zArgIn, zArgEnd);
		if( zArg == 0 ){
			/* No such option */
			continue;
		}
		/* Extract option argument value */
		VmExtractOptArgValue(pArray, pWorker, zArg, zArgEnd, need_val, pCtx, (const char *)&c);	
	}
	if( nArg > 1 && jx9_value_is_json_array(apArg[1]) && jx9_array_count(apArg[1]) > 0 ){
		/* Process long options */
		jx9_array_walk(apArg[1], VmProcessLongOpt, &sLong);
	}
	/* Return the option array */
	jx9_result_value(pCtx, pArray);
	/* 
	 * Don't worry about freeing memory, everything will be released
	 * automatically as soon we return from this foreign function.
	 */
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x45f18
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x45f45
leaq 0x204a3(%rip), %rdx     # 0x663c2
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, -0x3c(%rbp)
movq %rdx, -0x50(%rbp)
movq %rbx, -0x30(%rbp)
leaq -0x5c(%rbp), %r15
movq %r15, %rsi
callq 0x297ed
movq %rax, %r13
movslq (%r15), %r14
movq -0x30(%rbp), %r15
movq 0x60(%r15), %rbx
movq %r15, %rdi
callq 0x2a2b0
movq %rax, %r12
movq %r15, %rdi
callq 0x2a26a
movq %r12, -0x38(%rbp)
testq %r12, %r12
sete %dl
movq %rax, -0x48(%rbp)
testq %rax, %rax
sete %cl
orb %dl, %cl
cmpb $0x1, %cl
jne 0x45fb2
leaq 0x20311(%rip), %rdx     # 0x662b0
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x2a0db
movq %r15, %rdi
jmp 0x45f2d
movl 0x3d8(%rbx), %r15d
testq %r15, %r15
je 0x460b8
addq %r13, %r14
movq 0x3d0(%rbx), %rcx
addq %rcx, %r15
movq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %rcx, -0x88(%rbp)
movq %r15, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
incq %rcx
movq %rcx, -0x58(%rbp)
cmpq %r14, %r13
jae 0x46088
movsbq (%r13), %rbx
movl %ebx, -0x40(%rbp)
leaq 0x1(%r13), %r12
callq 0xc190
movq (%rax), %rax
testb $0x8, (%rax,%rbx,2)
jne 0x46021
movq %r12, %r13
jmp 0x45ff9
xorl %r8d, %r8d
cmpq %r14, %r12
jae 0x4604a
cmpb $0x3a, (%r12)
jne 0x4604a
leaq 0x2(%r13), %r12
cmpq %r14, %r12
jae 0x46046
cmpb $0x3a, 0x2(%r13)
leaq 0x3(%r13), %rax
cmoveq %rax, %r12
pushq $0x1
popq %r8
movq -0x58(%rbp), %rdx
leaq -0x1(%rdx), %rax
cmpq %r15, %rax
jae 0x4601c
cmpb $0x2d, (%rax)
jne 0x46065
cmpq %r15, %rdx
jae 0x46065
cmpb %bl, (%rdx)
je 0x4606a
incq %rdx
jmp 0x4604e
leaq -0x40(%rbp), %rax
movq %rax, (%rsp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %r15, %rcx
movq -0x30(%rbp), %r9
callq 0x46ea7
jmp 0x4601c
cmpl $0x1, -0x3c(%rbp)
je 0x460b8
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
testb $0x40, 0x8(%rdi)
je 0x460b8
movq (%rdi), %rax
cmpl $0x0, 0x2c(%rax)
je 0x460b8
leaq 0x107b(%rip), %rsi      # 0x47127
leaq -0x88(%rbp), %rdx
callq 0x29c1e
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x299d3
jmp 0x45f34