// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x45abd
movq %rdx, %r14
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
je 0x45abd
movl %esi, %r15d
leaq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x297ed
movl (%r12), %edx
testl %edx, %edx
jle 0x45abd
leaq -0xc0(%rbp), %rdi
movq %rax, %rsi
callq 0x3db7b
testl %eax, %eax
je 0x45adb
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %r15d
jne 0x45cb3
movq %rbx, %rdi
callq 0x2a2b0
movq %rax, %r14
movq %rbx, %rdi
callq 0x2a26a
movq %rax, %r12
testq %r14, %r14
setne %al
testq %r12, %r12
setne %cl
testb %cl, %al
je 0x45ceb
movq %r12, %r15
movl -0x68(%rbp), %edx
testl %edx, %edx
je 0x45b37
movq -0x70(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x1ec5b(%rip), %rsi     # 0x64787
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
addq $0x18, %r12
movq %r12, %rdi
callq 0x31b1e
movl -0xb8(%rbp), %edx
testl %edx, %edx
je 0x45b6e
movq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x20846(%rip), %rsi     # 0x663a9
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %r12, %rdi
callq 0x31b1e
movl -0xa8(%rbp), %esi
testl %esi, %esi
je 0x45bb6
leaq -0x2c(%rbp), %r13
andl $0x0, (%r13)
movq -0xb0(%rbp), %rdi
movq %r13, %rdx
callq 0x3d82f
movl (%r13), %esi
movq %r15, %rdi
callq 0x29489
leaq 0x22854(%rip), %rsi     # 0x683ff
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %r12, %rdi
callq 0x31b1e
movl -0x58(%rbp), %edx
testl %edx, %edx
je 0x45be3
movq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x2284a(%rip), %rsi     # 0x68422
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %r12, %rdi
callq 0x31b1e
movl -0x48(%rbp), %edx
testl %edx, %edx
je 0x45c10
movq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x207a9(%rip), %rsi     # 0x663ae
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %r12, %rdi
callq 0x31b1e
movl -0x98(%rbp), %edx
testl %edx, %edx
je 0x45c43
movq -0xa0(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x219c2(%rip), %rsi     # 0x675fa
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %r12, %rdi
callq 0x31b1e
movl -0x88(%rbp), %edx
testl %edx, %edx
je 0x45c76
movq -0x90(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x20748(%rip), %rsi     # 0x663b3
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %r12, %rdi
callq 0x31b1e
movl -0x78(%rbp), %edx
testl %edx, %edx
je 0x45ca3
movq -0x80(%rbp), %rsi
movq %r15, %rdi
callq 0x29588
leaq 0x20721(%rip), %rsi     # 0x663b9
movq %r14, %rdi
movq %r15, %rdx
callq 0x29c6c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x299d3
jmp 0x45ac7
movq 0x8(%r14), %rdi
callq 0x29772
decl %eax
cmpl $0x7, %eax
ja 0x45da9
leaq 0x1cb4e(%rip), %rcx     # 0x6281c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x68(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0x70(%rbp), %rsi
jmp 0x45d9c
leaq 0x20693(%rip), %rdx     # 0x66385
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
jmp 0x45abd
movl -0x48(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0x50(%rbp), %rsi
jmp 0x45d9c
movl -0xa8(%rbp), %esi
testl %esi, %esi
je 0x45da9
leaq -0x2c(%rbp), %r14
andl $0x0, (%r14)
movq -0xb0(%rbp), %rdi
movq %r14, %rdx
callq 0x3d82f
movl (%r14), %esi
movq %rbx, %rdi
callq 0x2987c
jmp 0x45ac7
movl -0x58(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0x60(%rbp), %rsi
jmp 0x45d9c
movl -0x78(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0x80(%rbp), %rsi
jmp 0x45d9c
movl -0xb8(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0xc0(%rbp), %rsi
jmp 0x45d9c
movl -0x98(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0xa0(%rbp), %rsi
jmp 0x45d9c
movl -0x88(%rbp), %edx
testl %edx, %edx
je 0x45da9
movq -0x90(%rbp), %rsi
movq %rbx, %rdi
callq 0x29903
jmp 0x45ac7
movq %rbx, %rdi
callq 0x298e8
jmp 0x45ac7