// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_opendir
static int jx9Builtin_opendir(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	const char *zPath;
	io_private *pDev;
	int iLen, rc;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting a directory path");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the target path */
	zPath  = jx9_value_to_string(apArg[0], &iLen);
	/* Try to extract a stream */
	pStream = jx9VmGetStreamDevice(pCtx->pVm, &zPath, iLen);
	if( pStream == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING, 
			"No stream device is associated with the given path(%s)", zPath);
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	if( pStream->xOpenDir == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING, 
			"IO routine(%s) not implemented in the underlying stream(%s) device", 
			jx9_function_name(pCtx), pStream->zName
			);
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Allocate a new IO private instance */
	pDev = (io_private *)jx9_context_alloc_chunk(pCtx, sizeof(io_private), TRUE, FALSE);
	if( pDev == 0 ){
		jx9_context_throw_error(pCtx, JX9_CTX_ERR, "JX9 is running out of memory");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Initialize the structure */
	InitIOPrivate(pCtx->pVm, pStream, pDev);
	/* Open the target directory */
	rc = pStream->xOpenDir(zPath, nArg > 1 ? apArg[1] : 0, &pDev->pHandle);
	if( rc != JX9_OK ){
		/* IO error, return FALSE */
		ReleaseIOPrivate(pCtx, pDev);
		jx9_result_bool(pCtx, 0);
	}else{
		/* Return the handle as a resource */
		jx9_result_resource(pCtx, pDev);
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x5435e
movq %rdx, %r14
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x5438b
leaq 0x13408(%rip), %rdx     # 0x6776d
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r15d
leaq -0x34(%rbp), %r12
movq %r12, %rsi
callq 0x297ed
leaq -0x30(%rbp), %rsi
movq %rax, (%rsi)
movq 0x60(%rbx), %rdi
movl (%r12), %edx
callq 0x47354
testq %rax, %rax
je 0x54416
movq %rax, %r13
cmpq $0x0, 0x18(%rax)
je 0x54433
pushq $0x38
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x2a356
testq %rax, %rax
je 0x54457
movq %rax, %r12
movq 0x60(%rbx), %rax
movq %r13, (%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
movq %rax, 0x10(%r12)
andl $0x0, 0x28(%r12)
movabsq $0xfeac1400000000, %rax # imm = 0xFEAC1400000000
movq %rax, 0x30(%r12)
movq 0x18(%r13), %rax
movq -0x30(%rbp), %rdi
cmpl $0x1, %r15d
jne 0x54465
xorl %esi, %esi
jmp 0x54469
movq -0x30(%rbp), %rcx
leaq 0x13367(%rip), %rdx     # 0x67788
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3be68
jmp 0x54370
movq (%rbx), %rax
movq 0x8(%rax), %rcx
movq (%r13), %r8
leaq 0x132e5(%rip), %rdx     # 0x6772a
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3be68
jmp 0x54370
leaq 0x11e52(%rip), %rdx     # 0x662b0
pushq $0x1
jmp 0x54367
movq 0x8(%r14), %rsi
movq %r12, %rdx
addq $0x8, %rdx
callq *%rax
testl %eax, %eax
je 0x54486
movq %rbx, %rdi
movq %r12, %rsi
callq 0x564ff
jmp 0x54370
movq %rbx, %rdi
movq %r12, %rsi
callq 0x29a04
jmp 0x5437a