// File: /workspace/github_c_makefile_star2_O1/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: vm_builtin_parse_url
static int vm_builtin_parse_url(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zStr; /* Input string */
	SyString *pComp;  /* Pointer to the URI component */
	SyhttpUri sURI;   /* Parse of the given URI */
	int nLen;
	sxi32 rc;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the given URI */
	zStr = jx9_value_to_string(apArg[0], &nLen);
	if( nLen < 1 ){
		/* Nothing to process, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Get a parse */
	rc = VmHttpSplitURI(&sURI, zStr, (sxu32)nLen);
	if( rc != SXRET_OK ){
		/* Malformed input, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	if( nArg > 1 ){
		int nComponent = jx9_value_to_int(apArg[1]);
		/* Refer to constant.c for constants values */
		switch(nComponent){
		case 1: /* JX9_URL_SCHEME */
			pComp = &sURI.sScheme;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		case 2: /* JX9_URL_HOST */
			pComp = &sURI.sHost;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		case 3: /* JX9_URL_PORT */
			pComp = &sURI.sPort;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				int iPort = 0;
				/* Cast the value to integer */
				SyStrToInt32(pComp->zString, pComp->nByte, (void *)&iPort, 0);
				jx9_result_int(pCtx, iPort);
			}
			break;
		case 4: /* JX9_URL_USER */
			pComp = &sURI.sUser;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		case 5: /* JX9_URL_PASS */
			pComp = &sURI.sPass;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		case 7: /* JX9_URL_QUERY */
			pComp = &sURI.sQuery;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		case 8: /* JX9_URL_FRAGMENT */
			pComp = &sURI.sFragment;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		case 6: /*  JX9_URL_PATH */
			pComp = &sURI.sPath;
			if( pComp->nByte < 1 ){
				/* No available value, return NULL */
				jx9_result_null(pCtx);
			}else{
				jx9_result_string(pCtx, pComp->zString, (int)pComp->nByte);
			}
			break;
		default:
			/* No such entry, return NULL */
			jx9_result_null(pCtx);
			break;
		}
	}else{
		jx9_value *pArray, *pValue;
		/* Return an associative array */
		pArray = jx9_context_new_array(pCtx);  /* Empty array */
		pValue = jx9_context_new_scalar(pCtx); /* Array value */
		if( pArray == 0 || pValue == 0 ){
			/* Out of memory */
			jx9_context_throw_error(pCtx, JX9_CTX_ERR, "jx9 engine is running out of memory");
			/* Return false */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		/* Fill the array */
		pComp = &sURI.sScheme;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "scheme", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sHost;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "host", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sPort;
		if( pComp->nByte > 0 ){
			int iPort = 0;/* cc warning */
			/* Convert to integer */
			SyStrToInt32(pComp->zString, pComp->nByte, (void *)&iPort, 0);
			jx9_value_int(pValue, iPort);
			jx9_array_add_strkey_elem(pArray, "port", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sUser;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "user", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sPass;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "pass", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sPath;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "path", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sQuery;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "query", pValue); /* Will make it's own copy */
		}
		/* Reset the string cursor */
		jx9_value_reset_string_cursor(pValue);
		pComp = &sURI.sFragment;
		if( pComp->nByte > 0 ){
			jx9_value_string(pValue, pComp->zString, (int)pComp->nByte);
			jx9_array_add_strkey_elem(pArray, "fragment", pValue); /* Will make it's own copy */
		}
		/* Return the created array */
		jx9_result_value(pCtx, pArray);
		/* NOTE:
		 * Don't worry about freeing 'pValue', everything will be released
		 * automatically as soon we return from this function.
		 */
	}
	/* All done */
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x516cb
movq %rdx, %r14
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
je 0x516cb
movl %esi, %r15d
leaq -0x28(%rbp), %r12
movq %r12, %rsi
callq 0x30b04
movl (%r12), %edx
testl %edx, %edx
jle 0x516cb
leaq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0x47f89
testl %eax, %eax
je 0x516fe
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 $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %r15d
jne 0x519bb
movq %rbx, %rdi
callq 0x317eb
movq %rax, %r14
movq %rbx, %rdi
callq 0x317a5
movq %rax, %r15
testq %r14, %r14
setne %al
testq %r15, %r15
setne %cl
testb %cl, %al
je 0x519f9
movl -0x60(%rbp), %edx
testl %edx, %edx
je 0x51757
movq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x25053(%rip), %rsi     # 0x7679f
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x5177e
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0xb0(%rbp), %edx
testl %edx, %edx
je 0x517a9
movq -0xb8(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x26c20(%rip), %rsi     # 0x783be
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x517d0
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0xa0(%rbp), %esi
testl %esi, %esi
je 0x51826
leaq -0x24(%rbp), %r12
movl $0x0, (%r12)
movq -0xa8(%rbp), %rdi
movq %r12, %rdx
callq 0x47be1
movslq (%r12), %r12
movq %r15, %rdi
callq 0x309f2
movq %r12, (%r15)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r15), %eax
orl $0x2, %eax
movl %eax, 0x8(%r15)
leaq 0x28c04(%rip), %rsi     # 0x7a41f
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x5184d
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0x50(%rbp), %edx
testl %edx, %edx
je 0x51872
movq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x28bdb(%rip), %rsi     # 0x7a442
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x51899
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0x40(%rbp), %edx
testl %edx, %edx
je 0x518be
movq -0x48(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x26b10(%rip), %rsi     # 0x783c3
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x518e5
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0x90(%rbp), %edx
testl %edx, %edx
je 0x51910
movq -0x98(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x27d0a(%rip), %rsi     # 0x7960f
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x51937
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0x80(%rbp), %edx
testl %edx, %edx
je 0x5195f
movq -0x88(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x26a74(%rip), %rsi     # 0x783c8
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movl $0x0, 0x28(%r15)
movl 0x30(%r15), %eax
testb $0x4, %al
je 0x51986
movq $0x0, 0x20(%r15)
movl $0x0, 0x2c(%r15)
andl $-0x5, %eax
movl %eax, 0x30(%r15)
movl -0x70(%rbp), %edx
testl %edx, %edx
je 0x519ab
movq -0x78(%rbp), %rsi
movq %r15, %rdi
callq 0x3087c
leaq 0x26a2e(%rip), %rsi     # 0x783ce
movq %r14, %rdi
movq %r15, %rdx
callq 0x3106a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x30d83
jmp 0x516ec
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x3fd5f
movl (%r14), %eax
decl %eax
cmpl $0x7, %eax
ja 0x51ad4
leaq 0x22e50(%rip), %rcx     # 0x7482c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x60(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0x68(%rbp), %rsi
jmp 0x51ac6
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x2698f(%rip), %rcx     # 0x7839a
movl $0x1, %edx
callq 0x4153c
jmp 0x516cb
movl -0x40(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0x48(%rbp), %rsi
jmp 0x51ac6
movl -0xa0(%rbp), %esi
testl %esi, %esi
je 0x51ad4
leaq -0x24(%rbp), %r14
movl $0x0, (%r14)
movq -0xa8(%rbp), %rdi
movq %r14, %rdx
callq 0x47be1
movslq (%r14), %r14
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x309f2
movq %r14, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x2, %eax
jmp 0x516e9
movl -0x50(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0x58(%rbp), %rsi
jmp 0x51ac6
movl -0x70(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0x78(%rbp), %rsi
jmp 0x51ac6
movl -0xb0(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0xb8(%rbp), %rsi
jmp 0x51ac6
movl -0x90(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0x98(%rbp), %rsi
jmp 0x51ac6
movl -0x80(%rbp), %edx
testl %edx, %edx
je 0x51ad4
movq -0x88(%rbp), %rsi
movq 0x8(%rbx), %rdi
callq 0x3087c
jmp 0x516ec
movq 0x8(%rbx), %rdi
callq 0x309f2
jmp 0x516ec