// File: /workspace/github_c_makefile_star2_O2/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 0x551b2
movq %rdx, %r14
movq (%rdx), %rdi
testb $0x1, 0x8(%rdi)
jne 0x551df
leaq 0x126b2(%rip), %rdx     # 0x6786b
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2a0db
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %r15d
leaq -0x4c(%rbp), %rsi
callq 0x297ed
movq %rax, -0x48(%rbp)
cmpl $0x1, %r15d
jne 0x55205
movl $0x1, -0x2c(%rbp)
leaq 0x14132(%rip), %r13     # 0x69335
jmp 0x55215
movq 0x8(%r14), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x297ed
movq %rax, %r13
movq 0x60(%rbx), %rdi
movl -0x4c(%rbp), %edx
leaq -0x48(%rbp), %rsi
callq 0x47354
testq %rax, %rax
je 0x55257
movq %rax, -0x38(%rbp)
pushq $0x38
popq %rsi
pushq $0x1
popq %r12
movq %rbx, %rdi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x2a356
testq %rax, %rax
je 0x55274
cmpl $0x4, %r15d
jb 0x55282
leaq 0x18(%r14), %rdx
movq -0x38(%rbp), %rsi
jmp 0x5529a
movq -0x48(%rbp), %rcx
leaq 0x12626(%rip), %rdx     # 0x67888
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3be68
jmp 0x551c4
leaq 0x11035(%rip), %rdx     # 0x662b0
pushq $0x1
jmp 0x551bb
leaq 0x30157(%rip), %rcx     # 0x853e0
movq %r14, %rdx
movq -0x38(%rbp), %rsi
cmpq %rcx, %rsi
je 0x5529a
xorl %r9d, %r9d
jmp 0x5529d
movq (%rdx), %r9
movq 0x60(%rbx), %rcx
movq %rsi, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movq %rcx, 0x10(%rax)
andl $0x0, 0x28(%rax)
movabsq $0xfeac1400000000, %rcx # imm = 0xFEAC1400000000
movq %rcx, 0x30(%rax)
movslq -0x2c(%rbp), %rdi
testq %rdi, %rdi
movq %rax, -0x58(%rbp)
jle 0x553f8
movzbl (%r13), %ecx
andl $-0x21, %ecx
cmpl $0x41, %ecx
je 0x553ac
cmpl $0x43, %ecx
je 0x55325
cmpl $0x58, %ecx
je 0x5535c
cmpl $0x57, %ecx
je 0x55339
cmpl $0x52, %ecx
jne 0x5537f
leaq 0x1(%r13), %rdx
cmpl $0x1, %edi
je 0x553bd
movzbl (%rdx), %ecx
cmpl $0x2b, %ecx
je 0x5531e
cmpl $0x77, %ecx
je 0x5531e
cmpl $0x57, %ecx
jne 0x553bd
pushq $0x4
jmp 0x553bb
leaq 0x1(%r13), %rdx
cmpl $0x1, %edi
jne 0x55489
pushq $0xa
jmp 0x553bb
leaq 0x1(%r13), %rdx
pushq $0x1a
popq %r12
cmpl $0x1, %edi
je 0x553bd
movzbl (%rdx), %ecx
cmpl $0x2b, %ecx
je 0x55358
cmpl $0x72, %ecx
je 0x55358
cmpl $0x52, %ecx
jne 0x553bd
pushq $0x1c
jmp 0x553bb
leaq 0x1(%r13), %rdx
pushq $0x42
popq %r12
cmpl $0x1, %edi
je 0x553bd
movzbl (%rdx), %ecx
cmpl $0x2b, %ecx
je 0x5537b
cmpl $0x72, %ecx
je 0x5537b
cmpl $0x52, %ecx
jne 0x553bd
pushq $0x44
jmp 0x553bb
leaq 0x12538(%rip), %rdx     # 0x678be
pushq $0x3
popq %rsi
movq %rdi, -0x40(%rbp)
movq %rbx, %rdi
movq %r9, %r12
callq 0x2a0db
movq -0x40(%rbp), %rdi
movq %r12, %r9
movq -0x38(%rbp), %rsi
pushq $0x1
popq %r12
movq %r13, %rdx
jmp 0x553bd
leaq 0x1(%r13), %rdx
cmpl $0x1, %edi
jne 0x5549e
pushq $0x2a
popq %r12
addq %rdi, %r13
cmpq %r13, %rdx
jae 0x553f8
movzbl (%rdx), %ecx
andl $-0x21, %ecx
cmpl $0x54, %ecx
je 0x553e5
cmpl $0x42, %ecx
jne 0x553f3
andl $0xfffffd7f, %r12d      # imm = 0xFFFFFD7F
orl $0x80, %r12d
jmp 0x553f3
andl $0xfffffd7f, %r12d      # imm = 0xFFFFFD7F
orl $0x200, %r12d           # imm = 0x200
incq %rdx
jmp 0x553c0
movq 0x60(%rbx), %r13
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
xorl %r8d, %r8d
cmpl $0x3, %r15d
jl 0x55423
movq 0x10(%r14), %rdi
movq %r9, %r14
callq 0x29790
movq %r14, %r9
movq -0x38(%rbp), %rsi
movl %eax, %r8d
movq %r13, %rdi
movq -0x40(%rbp), %r15
movq %r15, %rdx
movl %r12d, %ecx
pushq $0x0
pushq $0x0
callq 0x474a5
popq %rcx
popq %rdx
movq -0x58(%rbp), %rsi
movq %rax, 0x8(%rsi)
testq %rax, %rax
je 0x55455
movq %rbx, %rdi
callq 0x29a04
jmp 0x551ce
leaq 0x121d1(%rip), %rdx     # 0x6762d
movq %rsi, %r14
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3be68
movq %rbx, %rdi
xorl %esi, %esi
callq 0x298b2
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a404
jmp 0x551ce
xorl %ecx, %ecx
cmpb $0x2b, (%rdx)
sete %cl
leal 0xa(,%rcx,2), %r12d
jmp 0x553bd
xorl %ecx, %ecx
cmpb $0x2b, (%rdx)
sete %cl
leal 0x2a(,%rcx,2), %r12d
jmp 0x553bd