// File: /workspace/github_c_makefile_star2_O3/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_fopen
static int jx9Builtin_fopen(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const jx9_io_stream *pStream;
	const char *zUri, *zMode;
	jx9_value *pResource;
	io_private *pDev;
	int iLen, imLen;
	int iOpenFlags;
	if( nArg < 1 || !jx9_value_is_string(apArg[0]) ){
		/* Missing/Invalid arguments, return FALSE */
		jx9_context_throw_error(pCtx, JX9_CTX_WARNING, "Expecting a file path or URL");
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the URI and the desired access mode */
	zUri  = jx9_value_to_string(apArg[0], &iLen);
	if( nArg > 1 ){
		zMode = jx9_value_to_string(apArg[1], &imLen);
	}else{
		/* Set a default read-only mode */
		zMode = "r";
		imLen = (int)sizeof(char);
	}
	/* Try to extract a stream */
	pStream = jx9VmGetStreamDevice(pCtx->pVm, &zUri, iLen);
	if( pStream == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING, 
			"No stream device is associated with the given URI(%s)", zUri);
		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;
	}
	pResource = 0;
	if( nArg > 3 ){
		pResource = apArg[3];
	}else if( is_jx9_stream(pStream) ){
		/* TICKET 1433-80: The jx9:// stream need a jx9_value to access the underlying
		 * virtual machine.
		 */
		pResource = apArg[0];
	}
	/* Initialize the structure */
	InitIOPrivate(pCtx->pVm, pStream, pDev);
	/* Convert open mode to JX9 flags */
	iOpenFlags = StrModeToFlags(pCtx, zMode, imLen);
	/* Try to get a handle */
	pDev->pHandle = jx9StreamOpenHandle(pCtx->pVm, pStream, zUri, iOpenFlags, 
		nArg > 2 ? jx9_value_to_bool(apArg[2]) : FALSE, pResource, FALSE, 0);
	if( pDev->pHandle == 0 ){
		jx9_context_throw_error_format(pCtx, JX9_CTX_ERR, "IO error while opening '%s'", zUri);
		jx9_result_bool(pCtx, 0);
		jx9_context_free_chunk(pCtx, pDev);
		return JX9_OK;
	}
	/* All done, return the io_private instance 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 $0x38, %rsp
movq %rdi, %rbx
testl %esi, %esi
jle 0x63625
movq %rdx, %r15
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x63673
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14254(%rip), %rcx     # 0x7788b
movl $0x2, %edx
callq 0x40afa
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq $0x0, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x8, %eax
movl %eax, 0x8(%rbx)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r12d
leaq -0x3c(%rbp), %rsi
callq 0x30577
movq %rax, -0x38(%rbp)
cmpl $0x1, %r12d
jne 0x63699
movl $0x1, -0x2c(%rbp)
leaq 0x15cbe(%rip), %r13     # 0x79355
jmp 0x636a9
movq 0x8(%r15), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x30577
movq %rax, %r13
movq 0x60(%rbx), %rdi
movl -0x3c(%rbp), %edx
leaq -0x38(%rbp), %rsi
callq 0x51bfb
testq %rax, %rax
je 0x636e6
movq %rax, %r14
movq %rbx, %rdi
movl $0x38, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x312d8
testq %rax, %rax
je 0x63705
cmpl $0x4, %r12d
jb 0x63721
leaq 0x18(%r15), %rdx
jmp 0x63735
movq -0x38(%rbp), %rcx
leaq 0x141b7(%rip), %rdx     # 0x778a8
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x44ed3
jmp 0x63641
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x12bb9(%rip), %rcx     # 0x762d0
movl $0x1, %edx
jmp 0x6363c
leaq 0x2eca8(%rip), %rcx     # 0x923d0
movq %r15, %rdx
cmpq %rcx, %r14
je 0x63735
xorl %r9d, %r9d
jmp 0x63738
movq (%rdx), %r9
movq 0x60(%rbx), %rcx
movq %r14, -0x58(%rbp)
movq %r14, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movq %rcx, 0x10(%rax)
movl $0x0, 0x28(%rax)
movabsq $0xfeac1400000000, %rcx # imm = 0xFEAC1400000000
movq %rax, -0x60(%rbp)
movq %rcx, 0x30(%rax)
movslq -0x2c(%rbp), %rax
testq %rax, %rax
movq %r15, -0x50(%rbp)
jle 0x637d7
movq %rax, %r14
addq %r13, %r14
movzbl (%r13), %ecx
andl $-0x21, %ecx
cmpl $0x51, %ecx
jle 0x637e2
cmpl $0x58, %ecx
je 0x6381d
cmpl $0x57, %ecx
je 0x63852
cmpl $0x52, %ecx
jne 0x638a6
incq %r13
movl $0x1, %r15d
cmpl $0x1, %eax
je 0x63903
movzbl (%r13), %eax
cmpl $0x2b, %eax
je 0x637cc
cmpl $0x77, %eax
je 0x637cc
cmpl $0x57, %eax
jne 0x63903
movl $0x4, %r15d
jmp 0x63903
movl $0x1, %r15d
jmp 0x63908
cmpl $0x41, %ecx
je 0x63884
cmpl $0x43, %ecx
jne 0x638a6
incq %r13
movl $0xa, %r15d
cmpl $0x1, %eax
je 0x63903
xorl %eax, %eax
cmpb $0x2b, (%r13)
sete %al
leal 0xa(,%rax,2), %r15d
jmp 0x63903
incq %r13
movl $0x42, %r15d
cmpl $0x1, %eax
je 0x63903
movzbl (%r13), %eax
cmpl $0x2b, %eax
je 0x63847
cmpl $0x72, %eax
je 0x63847
cmpl $0x52, %eax
jne 0x63903
movl $0x44, %r15d
jmp 0x63903
incq %r13
movl $0x1a, %r15d
cmpl $0x1, %eax
je 0x63903
movzbl (%r13), %eax
cmpl $0x2b, %eax
je 0x6387c
cmpl $0x72, %eax
je 0x6387c
cmpl $0x52, %eax
jne 0x63903
movl $0x1c, %r15d
jmp 0x63903
incq %r13
movl $0x2a, %r15d
cmpl $0x1, %eax
je 0x63903
xorl %eax, %eax
cmpb $0x2b, (%r13)
sete %al
leal 0x2a(,%rax,2), %r15d
jmp 0x63903
movq (%rbx), %rsi
movq 0x60(%rbx), %rdi
addq $0x8, %rsi
leaq 0x14026(%rip), %rcx     # 0x778de
movl $0x3, %edx
movq %r9, %r15
callq 0x40afa
movq %r15, %r9
movl $0x1, %r15d
jmp 0x63903
movzbl (%r13), %eax
andl $-0x21, %eax
cmpl $0x54, %eax
je 0x638f2
cmpl $0x42, %eax
jne 0x63900
andl $0xfffffd7f, %r15d      # imm = 0xFFFFFD7F
orl $0x80, %r15d
jmp 0x63900
andl $0xfffffd7f, %r15d      # imm = 0xFFFFFD7F
orl $0x200, %r15d           # imm = 0x200
incq %r13
cmpq %r14, %r13
jb 0x638d0
movq 0x60(%rbx), %r13
movq -0x38(%rbp), %r14
xorl %r8d, %r8d
cmpl $0x3, %r12d
jl 0x6393a
movq -0x50(%rbp), %rax
movq %r14, -0x48(%rbp)
movq 0x10(%rax), %r14
movq %r14, %rdi
movq %r9, %r12
callq 0x438dd
movq %r12, %r9
movl (%r14), %r8d
movq -0x48(%rbp), %r14
movq %r13, %rdi
movq -0x58(%rbp), %rsi
movq %r14, %rdx
movl %r15d, %ecx
pushq $0x0
pushq $0x0
callq 0x51dad
addq $0x10, %rsp
movq -0x60(%rbp), %r15
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x63982
movq 0x8(%rbx), %rbx
movq %rbx, %rdi
callq 0x30465
movq %r15, (%rbx)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%rbx), %eax
orl $0x100, %eax            # imm = 0x100
jmp 0x6365f
leaq 0x13cc4(%rip), %rdx     # 0x7764d
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x44ed3
movq 0x8(%rbx), %r14
movq %r14, %rdi
callq 0x30465
movq $0x0, (%r14)
movl $0xfffffe90, %eax       # imm = 0xFFFFFE90
andl 0x8(%r14), %eax
orl $0x8, %eax
movl %eax, 0x8(%r14)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x313b9
jmp 0x63662