// File: /workspace/github_c_makefile_star2_O3/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 0x50530
movq %rdx, %r13
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x5057e
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x25ea0(%rip), %rcx     # 0x763e2
movl $0x1, %edx
callq 0x40afa
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 $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, -0x3c(%rbp)
leaq -0x5c(%rbp), %r15
movq %r15, %rsi
callq 0x30577
movq %rax, %r14
movslq (%r15), %r12
movq 0x60(%rbx), %rax
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x31231
movq %rax, %r15
movq %rbx, %rdi
callq 0x311eb
movq %rax, %rdx
movq %r15, -0x38(%rbp)
testq %r15, %r15
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x505df
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x25cf6(%rip), %rcx     # 0x762d0
jmp 0x50542
movq -0x30(%rbp), %rax
movl 0x3d8(%rax), %ecx
testq %rcx, %rcx
je 0x5070c
movq %r13, -0x48(%rbp)
movq 0x3d0(%rax), %rsi
leaq (%rsi,%rcx), %r15
movq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movq %rdx, -0x78(%rbp)
movq %rsi, -0x88(%rbp)
movq %r15, -0x80(%rbp)
movq %rbx, -0x68(%rbp)
testl %r12d, %r12d
jle 0x506dc
addq %r14, %r12
movq %rdx, -0x58(%rbp)
movq %rcx, -0x30(%rbp)
movq %rsi, %r13
callq 0xc170
movq %r13, %rdi
movq -0x30(%rbp), %rsi
incq %rdi
movq %rdi, -0x50(%rbp)
movsbq (%r14), %r9
movl %r9d, -0x40(%rbp)
leaq 0x1(%r14), %r13
movq (%rax), %rcx
testb $0x8, (%rcx,%r9,2)
je 0x506d0
xorl %r8d, %r8d
cmpq %r12, %r13
jae 0x50687
cmpb $0x3a, (%r13)
jne 0x50687
leaq 0x2(%r14), %r13
movl $0x1, %r8d
cmpq %r12, %r13
jae 0x50687
leaq 0x3(%r14), %rcx
cmpb $0x3a, 0x2(%r14)
cmoveq %rcx, %r13
movq %rsi, %rcx
movq %rdi, %rdx
cmpb $0x2d, -0x1(%rdx)
jne 0x5069d
cmpq %r15, %rdx
jae 0x5069d
cmpb %r9b, (%rdx)
je 0x506a7
incq %rdx
decq %rcx
jne 0x5068d
jmp 0x506d0
leaq -0x40(%rbp), %rcx
movq %rcx, (%rsp)
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %r15, %rcx
movq %rax, %r14
movq %rbx, %r9
callq 0x51608
movq %r14, %rax
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %r13, %r14
cmpq %r12, %r13
jb 0x50646
cmpl $0x1, -0x3c(%rbp)
je 0x5070c
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
testb $0x40, 0x8(%rax)
je 0x5070c
movq (%rax), %rdi
cmpl $0x0, 0x2c(%rdi)
je 0x5070c
leaq 0x1267(%rip), %rsi      # 0x51967
leaq -0x88(%rbp), %rdx
callq 0x5134a
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
callq 0x307f4
jmp 0x5056d