// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x2c(%rax)
jae 0x6fc90
cmpq $0x0, -0x18(%rbp)
je 0x6fc90
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6fc90
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x40(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x6fd9b
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x141, %eax            # imm = 0x141
cmpl $0x0, %eax
je 0x6fd9b
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x6fcc8
movq -0x18(%rbp), %rdi
callq 0x6fef0
movq -0x18(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jb 0x6fce4
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
callq 0x6ff60
cmpl $0x0, %eax
je 0x6fcfb
movq -0x18(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jae 0x6fcf6
movq $0x0, -0x18(%rbp)
jmp 0x6fd9d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x18(%rbp), %rax
movl 0x28(%rax), %edx
leaq -0x28(%rbp), %rcx
callq 0x70050
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6fd71
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq $0x208, %rdi            # imm = 0x208
movq -0x28(%rbp), %rax
movl 0x38(%rax), %esi
callq 0x6ea60
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x6fd65
cmpq $0x0, -0x20(%rbp)
je 0x6fd5a
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6e750
jmp 0x6fd63
movq -0x38(%rbp), %rdi
callq 0x70130
jmp 0x6fd65
movl $0x0, -0x4(%rbp)
jmp 0x6feda
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x18(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x20(%rbp), %rcx
callq 0x70150
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6feda
jmp 0x6fd9d
cmpq $0x0, -0x18(%rbp)
je 0x6fea4
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x6fdc0
movq -0x18(%rbp), %rdi
callq 0x70240
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq -0x28(%rbp), %rdx
callq 0x702a0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6fe2e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
addq $0x208, %rdi            # imm = 0x208
movq -0x28(%rbp), %rax
movl 0x38(%rax), %esi
callq 0x6ea60
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x6fe22
cmpq $0x0, -0x20(%rbp)
je 0x6fe17
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x6e750
jmp 0x6fe20
movq -0x40(%rbp), %rdi
callq 0x70130
jmp 0x6fe22
movl $0x0, -0x4(%rbp)
jmp 0x6feda
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x70370
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x6fea2
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jl 0x6fea0
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x702a0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6fe9e
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
jmp 0x6fe6f
jmp 0x6fea0
jmp 0x6fea2
jmp 0x6fed4
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x70370
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x6fed2
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x48(%rax)
jmp 0x6fed4
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)