// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq $0x0, -0x38(%rbp)
testq %rsi, %rsi
je 0x3ef58
cmpl $0x0, 0x2c(%rbx)
jne 0x3ef58
movl 0x8(%r15), %eax
testb $0x1, %al
je 0x3ef65
orb $0x1, 0x40(%rbx)
jmp 0x3ef65
testq %r15, %r15
je 0x3f0b3
movl 0x8(%r15), %eax
testl $0x141, %eax            # imm = 0x141
je 0x3f043
testb $0x1, %al
jne 0x3ef7c
movq %r15, %rdi
callq 0x3f163
movl 0x28(%r15), %r12d
testq %r12, %r12
je 0x3f0b3
movq %r14, -0x30(%rbp)
movq 0x20(%r15), %rax
cmpl $0x2, %r12d
setge %cl
movq %rax, -0x40(%rbp)
movb (%rax), %al
cmpb $0x30, %al
sete %dl
testb %dl, %cl
je 0x3efde
leaq -0x38(%rbp), %rcx
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movl %r12d, %edx
callq 0x3f1b7
testl %eax, %eax
je 0x3f10e
movq 0x20(%r15), %rsi
movl 0x28(%r15), %edx
movq %rbx, %rdi
movq -0x30(%rbp), %rcx
callq 0x3f257
movl %eax, %r12d
jmp 0x3f151
movq -0x40(%rbp), %rcx
leaq (%rcx,%r12), %rdx
movq %rdx, -0x48(%rbp)
movzbl %al, %eax
cmpl $0x2d, %eax
je 0x3effa
movq %rcx, %r13
cmpl $0x2b, %eax
jne 0x3f008
xorl %r13d, %r13d
cmpl $0x1, %r12d
setne %r13b
addq %rcx, %r13
cmpq -0x48(%rbp), %r13
movq -0x30(%rbp), %r14
jae 0x3f043
movsbq (%r13), %r14
cmpq $-0x41, %r14
ja 0x3efa7
callq 0xc170
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r14,2)
je 0x3efa7
incq %r13
cmpq -0x48(%rbp), %r13
jb 0x3f012
testq %r15, %r15
movq -0x30(%rbp), %r14
je 0x3f0b3
testb $0x2, 0x8(%r15)
jne 0x3f052
movq %r15, %rdi
callq 0x3f362
movq (%r15), %rsi
leaq -0x38(%rbp), %rdx
movq %rbx, %rdi
callq 0x3f43c
testl %eax, %eax
je 0x3f0d9
movq (%r15), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3f4a6
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x3f151
movq (%r15), %rsi
xorl %r12d, %r12d
cmpq 0x48(%rbx), %rsi
jl 0x3f151
incq %rsi
movq %rsi, 0x48(%rbx)
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3f43c
testl %eax, %eax
jne 0x3f151
movq 0x48(%rbx), %rsi
jmp 0x3f091
movq 0x48(%rbx), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3f4a6
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x3f151
incq 0x48(%rbx)
xorl %r12d, %r12d
jmp 0x3f151
movq (%rbx), %rcx
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
xorl %r12d, %r12d
cmpl %eax, 0x218(%rcx)
jbe 0x3f151
movq 0x210(%rcx), %rsi
testq %rsi, %rsi
je 0x3f151
imull 0x220(%rcx), %eax
addq %rax, %rsi
testq %r14, %r14
je 0x3f149
movq %r14, %rdi
jmp 0x3f142
movq (%rbx), %rcx
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
xorl %r12d, %r12d
cmpl %eax, 0x218(%rcx)
movq -0x30(%rbp), %rdi
jbe 0x3f151
movq 0x210(%rcx), %rsi
testq %rsi, %rsi
je 0x3f151
imull 0x220(%rcx), %eax
addq %rax, %rsi
testq %rdi, %rdi
je 0x3f149
callq 0x3e19f
jmp 0x3f151
movq %rsi, %rdi
callq 0x30465
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq