// File: /workspace/github_c_makefile_star2_O1/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 0x51c2e
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x51c7c
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x26797(%rip), %rcx     # 0x783d7
movl $0x1, %edx
callq 0x4153c
movq 0x8(%rbx), %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 $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, -0x34(%rbp)
movq %rdx, -0x58(%rbp)
leaq -0x5c(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
movq %rax, %r15
movslq (%r14), %r12
movq 0x60(%rbx), %r14
movq %rbx, %rdi
callq 0x317eb
movq %rax, %r13
movq %rbx, %rdi
callq 0x317a5
movq %r13, -0x30(%rbp)
testq %r13, %r13
sete %dl
movq %rax, -0x48(%rbp)
testq %rax, %rax
sete %cl
orb %dl, %cl
cmpb $0x1, %cl
jne 0x51cde
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x265ec(%rip), %rcx     # 0x782c5
jmp 0x51c40
movl 0x3d8(%r14), %ecx
testq %rcx, %rcx
je 0x51e02
movq 0x3d0(%r14), %rdx
leaq (%rdx,%rcx), %r14
movq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %rdx, -0x50(%rbp)
movq %rdx, -0x88(%rbp)
movq %r14, -0x80(%rbp)
movq %rbx, -0x68(%rbp)
testl %r12d, %r12d
jle 0x51dcf
addq %r15, %r12
movq %rcx, -0x40(%rbp)
callq 0xc170
movq -0x40(%rbp), %rsi
incq -0x50(%rbp)
movsbq (%r15), %rdi
movl %edi, -0x38(%rbp)
leaq 0x1(%r15), %r13
movq (%rax), %rcx
testb $0x8, (%rcx,%rdi,2)
je 0x51dc3
xorl %r8d, %r8d
cmpq %r12, %r13
jae 0x51d78
cmpb $0x3a, (%r13)
jne 0x51d78
leaq 0x2(%r15), %r13
movl $0x1, %r8d
cmpq %r12, %r13
jae 0x51d78
leaq 0x3(%r15), %rcx
cmpb $0x3a, 0x2(%r15)
cmoveq %rcx, %r13
movq %rsi, %rcx
movq -0x50(%rbp), %rdx
cmpb $0x2d, -0x1(%rdx)
jne 0x51d8f
cmpq %r14, %rdx
jae 0x51d8f
cmpb %dil, (%rdx)
je 0x51d99
incq %rdx
decq %rcx
jne 0x51d7f
xorl %edx, %edx
testq %rdx, %rdx
je 0x51dc3
leaq -0x38(%rbp), %rcx
movq %rcx, (%rsp)
movq %rax, %r15
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq %r14, %rcx
movq %rbx, %r9
callq 0x52d7a
movq %r15, %rax
movq -0x40(%rbp), %rsi
movq %r13, %r15
cmpq %r12, %r13
jb 0x51d39
cmpl $0x1, -0x34(%rbp)
je 0x51e02
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
testb $0x40, 0x8(%rax)
je 0x51e02
movq (%rax), %rcx
cmpl $0x0, 0x2c(%rcx)
je 0x51e02
movq (%rax), %rdi
leaq 0x12d8(%rip), %rsi      # 0x530ce
leaq -0x88(%rbp), %rdx
callq 0x52ab1
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x30d83
jmp 0x51c6b