// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq $0x0, -0x38(%rbp)
testq %rsi, %rsi
je 0x3f95e
cmpl $0x0, 0x2c(%r14)
jne 0x3f95e
testb $0x1, 0x8(%r15)
je 0x3f95e
orb $0x1, 0x40(%r14)
testq %r15, %r15
je 0x3f9d8
movl 0x8(%r15), %eax
testl $0x141, %eax            # imm = 0x141
je 0x3f9db
testb $0x1, %al
jne 0x3f97a
movq %r15, %rdi
callq 0x3fb4d
movl 0x28(%r15), %eax
testl %eax, %eax
je 0x3f9d8
movl %eax, -0x3c(%rbp)
movq %rbx, -0x30(%rbp)
movq 0x20(%r15), %r13
movl 0x28(%r15), %ebx
movl %ebx, %eax
cmpl $0x2, %ebx
jl 0x3fa8f
cmpb $0x30, (%r13)
jne 0x3fa8f
movq 0x20(%r15), %rsi
leaq -0x38(%rbp), %rcx
movq %r14, %rdi
movl -0x3c(%rbp), %edx
callq 0x3fba1
testl %eax, %eax
je 0x3fb07
movq 0x20(%r15), %rsi
movl 0x28(%r15), %edx
movq %r14, %rdi
movq -0x30(%rbp), %rcx
callq 0x3fc41
jmp 0x3fa55
xorl %r15d, %r15d
testq %r15, %r15
je 0x3fa3e
testb $0x2, 0x8(%r15)
jne 0x3f9ef
movq %r15, %rdi
callq 0x3fd5f
movq (%r15), %rsi
leaq -0x38(%rbp), %rdx
movq %r14, %rdi
callq 0x3fe39
testl %eax, %eax
je 0x3fa6a
movq (%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3fea3
testl %eax, %eax
jne 0x3fa55
movq (%r15), %rsi
xorl %r12d, %r12d
cmpq 0x48(%r14), %rsi
jl 0x3fa58
incq %rsi
movq %rsi, 0x48(%r14)
xorl %r12d, %r12d
movq %r14, %rdi
xorl %edx, %edx
callq 0x3fe39
testl %eax, %eax
jne 0x3fa58
movq 0x48(%r14), %rsi
jmp 0x3fa20
movq 0x48(%r14), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3fea3
testl %eax, %eax
je 0x3fad5
movl %eax, %r12d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movq -0x38(%rbp), %rcx
movl 0x38(%rcx), %esi
xorl %r12d, %r12d
cmpl %esi, 0x218(%rax)
jbe 0x3faea
imull 0x220(%rax), %esi
addq 0x210(%rax), %rsi
jmp 0x3faec
addq %r13, %rbx
movzbl (%r13), %ecx
cmpl $0x2d, %ecx
je 0x3faa1
cmpl $0x2b, %ecx
jne 0x3faa8
cmpl $0x2, %eax
sbbq $-0x1, %r13
cmpq %rbx, %r13
jae 0x3fae1
movsbq (%r13), %r12
cmpq $-0x41, %r12
ja 0x3f9a7
callq 0xc170
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r12,2)
je 0x3f9a7
incq %r13
jmp 0x3faa8
incq 0x48(%r14)
xorl %r12d, %r12d
jmp 0x3fa58
movq -0x30(%rbp), %rbx
jmp 0x3f9db
xorl %esi, %esi
testq %rsi, %rsi
je 0x3fa58
testq %rbx, %rbx
je 0x3fb40
movq %rbx, %rdi
callq 0x3ebc8
jmp 0x3fa58
movq (%r14), %rax
movq -0x38(%rbp), %rcx
movl 0x38(%rcx), %esi
xorl %r12d, %r12d
cmpl %esi, 0x218(%rax)
movq -0x30(%rbp), %rdi
jbe 0x3fb30
imull 0x220(%rax), %esi
addq 0x210(%rax), %rsi
jmp 0x3fb32
xorl %esi, %esi
testq %rsi, %rsi
je 0x3fa58
testq %rdi, %rdi
jne 0x3fafd
movq %rsi, %rdi
callq 0x309f2
jmp 0x3fa58