// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: HashmapInsert
static sxi32 HashmapInsert(
	jx9_hashmap *pMap, /* Target hashmap */
	jx9_value *pKey,   /* Lookup key  */
	jx9_value *pVal    /* Node value */
	)
{
	jx9_hashmap_node *pNode = 0;
	sxi32 rc = SXRET_OK;
	if( pMap->nEntry < 1 && pKey && (pKey->iFlags & MEMOBJ_STRING) ){
		pMap->iFlags |= HASHMAP_JSON_OBJECT;
	}
	if( pKey && (pKey->iFlags & (MEMOBJ_STRING|MEMOBJ_HASHMAP|MEMOBJ_RES)) ){
		if( (pKey->iFlags & MEMOBJ_STRING) == 0 ){
			/* Force a string cast */
			jx9MemObjToString(&(*pKey));
		}
		if( SyBlobLength(&pKey->sBlob) < 1 || HashmapIsIntKey(&pKey->sBlob) ){
			if(SyBlobLength(&pKey->sBlob) < 1){
				/* Automatic index assign */
				pKey = 0;
			}
			goto IntKey;
		}
		if( SXRET_OK == HashmapLookupBlobKey(&(*pMap), SyBlobData(&pKey->sBlob), 
			SyBlobLength(&pKey->sBlob), &pNode) ){
				/* Overwrite the old value */
				jx9_value *pElem;
				pElem = (jx9_value *)SySetAt(&pMap->pVm->aMemObj, pNode->nValIdx);
				if( pElem ){
					if( pVal ){
						jx9MemObjStore(pVal, pElem);
					}else{
						/* Nullify the entry */
						jx9MemObjToNull(pElem);
					}
				}
				return SXRET_OK;
		}
		/* Perform a blob-key insertion */
		rc = HashmapInsertBlobKey(&(*pMap),SyBlobData(&pKey->sBlob),SyBlobLength(&pKey->sBlob),&(*pVal));
		return rc;
	}
IntKey:
	if( pKey ){
		if((pKey->iFlags & MEMOBJ_INT) == 0 ){
			/* Force an integer cast */
			jx9MemObjToInteger(pKey);
		}
		if( SXRET_OK == HashmapLookupIntKey(&(*pMap), pKey->x.iVal, &pNode) ){
			/* Overwrite the old value */
			jx9_value *pElem;
			pElem = (jx9_value *)SySetAt(&pMap->pVm->aMemObj, pNode->nValIdx);
			if( pElem ){
				if( pVal ){
					jx9MemObjStore(pVal, pElem);
				}else{
					/* Nullify the entry */
					jx9MemObjToNull(pElem);
				}
			}
			return SXRET_OK;
		}
		/* Perform a 64-bit-int-key insertion */
		rc = HashmapInsertIntKey(&(*pMap), pKey->x.iVal, &(*pVal));
		if( rc == SXRET_OK ){
			if( pKey->x.iVal >= pMap->iNextIdx ){
				/* Increment the automatic index */ 
				pMap->iNextIdx = pKey->x.iVal + 1;
				/* Make sure the automatic index is not reserved */
				while( SXRET_OK == HashmapLookupIntKey(&(*pMap), pMap->iNextIdx, 0) ){
					pMap->iNextIdx++;
				}
			}
		}
	}else{
		/* Assign an automatic index */
		rc = HashmapInsertIntKey(&(*pMap),pMap->iNextIdx,&(*pVal));
		if( rc == SXRET_OK ){
			++pMap->iNextIdx;
		}
	}
	/* Insertion result */
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
andq $0x0, -0x30(%rbp)
testq %rsi, %rsi
je 0x369d3
cmpl $0x0, 0x2c(%r14)
jne 0x369d3
movl 0x8(%r15), %eax
testb $0x1, %al
je 0x369e0
orb $0x1, 0x40(%r14)
jmp 0x369e0
testq %r15, %r15
je 0x36b59
movl 0x8(%r15), %eax
testw $0x141, %ax             # imm = 0x141
je 0x36afa
testb $0x1, %al
jne 0x369f6
movq %r15, %rdi
callq 0x36bcf
movl 0x28(%r15), %eax
testq %rax, %rax
je 0x36b59
movq %rbx, -0x38(%rbp)
movq 0x20(%r15), %rdx
movq %rax, -0x48(%rbp)
cmpl $0x2, %eax
setge %cl
movq %rdx, -0x40(%rbp)
movb (%rdx), %al
cmpb $0x30, %al
sete %dl
testb %dl, %cl
jne 0x36a74
movzbl %al, %eax
cmpl $0x2d, %eax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rdx
je 0x36a3c
movq %rdx, %r13
cmpl $0x2b, %eax
jne 0x36a49
xorl %r13d, %r13d
cmpl $0x1, %ecx
setne %r13b
addq %rdx, %r13
leaq (%rdx,%rcx), %rbx
cmpq %rbx, %r13
jae 0x36aed
movsbq (%r13), %r12
cmpq $-0x41, %r12
ja 0x36a74
callq 0xc190
movq (%rax), %rax
incq %r13
testb $0x8, 0x1(%rax,%r12,2)
jne 0x36a4d
leaq -0x30(%rbp), %rcx
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x36c0a
testl %eax, %eax
je 0x36aa8
movq 0x20(%r15), %rsi
movl 0x28(%r15), %edx
movq %r14, %rdi
movq -0x38(%rbp), %rcx
callq 0x36cac
movl %eax, %r15d
jmp 0x36bbd
movq (%r14), %rcx
movq -0x30(%rbp), %rax
movl 0x38(%rax), %eax
xorl %r15d, %r15d
cmpl %eax, 0x218(%rcx)
movq -0x38(%rbp), %rdi
jbe 0x36bbd
movq 0x210(%rcx), %rsi
testq %rsi, %rsi
je 0x36bbd
imull 0x220(%rcx), %eax
addq %rax, %rsi
testq %rdi, %rdi
jne 0x36bae
jmp 0x36bb5
testq %r15, %r15
movq -0x38(%rbp), %rbx
je 0x36b59
movl 0x8(%r15), %eax
testb $0x2, %al
jne 0x36b06
movq %r15, %rdi
callq 0x36daa
movq (%r15), %rsi
leaq -0x30(%rbp), %rdx
movq %r14, %rdi
callq 0x36e57
testl %eax, %eax
je 0x36b7b
movq (%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x36ec2
testl %eax, %eax
jne 0x36b6c
movq (%r15), %rsi
xorl %r15d, %r15d
cmpq 0x48(%r14), %rsi
jl 0x36bbd
incq %rsi
movq %rsi, 0x48(%r14)
xorl %r15d, %r15d
movq %r14, %rdi
xorl %edx, %edx
callq 0x36e57
testl %eax, %eax
jne 0x36bbd
movq 0x48(%r14), %rsi
jmp 0x36b3b
movq 0x48(%r14), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x36ec2
testl %eax, %eax
je 0x36b72
pushq $-0x1
popq %r15
jmp 0x36bbd
incq 0x48(%r14)
xorl %r15d, %r15d
jmp 0x36bbd
movq (%r14), %rcx
movq -0x30(%rbp), %rax
movl 0x38(%rax), %eax
xorl %r15d, %r15d
cmpl %eax, 0x218(%rcx)
jbe 0x36bbd
movq 0x210(%rcx), %rsi
testq %rsi, %rsi
je 0x36bbd
imull 0x220(%rcx), %eax
addq %rax, %rsi
testq %rbx, %rbx
je 0x36bb5
movq %rbx, %rdi
callq 0x35ceb
jmp 0x36bbd
movq %rsi, %rdi
callq 0x296af
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq