// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x1, -0x14(%rbp)
jl 0xa6e3a
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x57480
cmpl $0x0, %eax
jne 0xa6e66
movq -0x10(%rbp), %rdi
movl $0x2, %esi
leaq 0x1ee1c(%rip), %rdx     # 0xc5c66
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa6ffd
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x56e20
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movl -0x3c(%rbp), %edx
leaq -0x30(%rbp), %rsi
callq 0x8e570
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xa6ecb
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl $0x2, %esi
leaq 0x1edd4(%rip), %rdx     # 0xc5c81
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa6ffd
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xa6f1f
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x584d0
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq (%rax), %r8
movl $0x2, %esi
leaq 0x1ed22(%rip), %rdx     # 0xc5c23
movb $0x0, %al
callq 0x79580
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa6ffd
movq -0x10(%rbp), %rdi
movl $0x38, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x58640
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xa6f6b
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x1d862(%rip), %rdx     # 0xc47b1
callq 0x580b0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0xa6ffd
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x90730
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x1, -0x14(%rbp)
jle 0xa6fa8
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0xa6fb0
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0xa6fb0
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0x8, %rdx
callq *%rax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0xa6fe9
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xab080
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
jmp 0xa6ff6
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x57340
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)