// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxVar.c
// Function: HaxDeleteVars
void
HaxDeleteVars(
    Interp *iPtr,		/* Interpreter to which variables belong. */
    Hax_HashTable *tablePtr	/* Hash table containing variables to
				 * delete. */)
{
    Hax_Memoryp *memoryp = iPtr->memoryp;
    Hax_HashSearch search;
    Hax_HashEntry *hPtr;
    Var *varPtr;
    int flags, globalFlag;

    flags = HAX_TRACE_UNSETS;
    if (tablePtr == &iPtr->globalTable) {
	flags |= HAX_INTERP_DESTROYED | HAX_GLOBAL_ONLY;
    }
    for (hPtr = Hax_FirstHashEntry(tablePtr, &search); hPtr != NULL;
	    hPtr = Hax_NextHashEntry(&search)) {
	varPtr = (Var *) Hax_GetHashValue(hPtr);

	/*
	 * For global/upvar variables referenced in procedures, free up the
	 * local space and then decrement the reference count on the
	 * variable referred to.  If there are no more references to the
	 * global/upvar and it is undefined and has no traces set, then
	 * follow on and delete the referenced variable too.
	 */

	globalFlag = 0;
	if (varPtr->flags & VAR_UPVAR) {
	    hPtr = varPtr->value.upvarPtr;
	    ckfree(memoryp, (char *) varPtr);
	    varPtr = (Var *) Hax_GetHashValue(hPtr);
	    varPtr->upvarUses--;
	    if ((varPtr->upvarUses != 0) || !(varPtr->flags & VAR_UNDEFINED)
		    || (varPtr->tracePtr != NULL)) {
		continue;
	    }
	    globalFlag = HAX_GLOBAL_ONLY;
	}

	/*
	 * Invoke traces on the variable that is being deleted, then
	 * free up the variable's space (no need to free the hash entry
	 * here, unless we're dealing with a global variable:  the
	 * hash entries will be deleted automatically when the whole
	 * table is deleted).
	 */

	if (varPtr->tracePtr != NULL) {
	    (void) CallTraces(iPtr, (Var *) NULL, hPtr,
		    Hax_GetHashKey(tablePtr, hPtr), (char *) NULL,
		    flags | globalFlag);
	    while (varPtr->tracePtr != NULL) {
		VarTrace *tracePtr = varPtr->tracePtr;
		varPtr->tracePtr = tracePtr->nextPtr;
		ckfree(memoryp, (char *) tracePtr);
	    }
	}
	if (varPtr->flags & VAR_ARRAY) {
	    DeleteArray(iPtr, Hax_GetHashKey(tablePtr, hPtr), varPtr,
		    flags | globalFlag);
	}
	if (globalFlag) {
	    Hax_DeleteHashEntry((Hax_Interp *) iPtr, hPtr);
	}
	ckfree(memoryp, (char *) varPtr);
    }
    Hax_DeleteHashTable((Hax_Interp *) iPtr, tablePtr);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rcx
movq 0x280(%rdi), %r15
movq %rdi, 0x10(%rsp)
leaq 0x68(%rdi), %rax
cmpq %rsi, %rax
movl $0x141, %eax            # imm = 0x141
movl $0x40, %edx
cmovel %eax, %edx
movl %edx, 0xc(%rsp)
leaq 0x20(%rsp), %rsi
movq %rcx, 0x18(%rsp)
movq %rcx, %rdi
callq 0x43e0
testq %rax, %rax
je 0x1396d
movq %rax, %r13
leaq 0x295a(%rip), %r12      # 0x161c3
movq 0x18(%r13), %rbp
movl 0x20(%rbp), %r14d
testb $0x2, %r14b
jne 0x138d0
cmpq $0x0, 0x10(%rbp)
je 0x13904
leaq 0x20(%r13), %rcx
movq 0x18(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x13894
movq (%rcx), %rcx
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
xorl %r8d, %r8d
movl 0xc(%rsp), %r9d
callq 0x11d13
movq 0x10(%rbp), %rsi
testq %rsi, %rsi
je 0x13906
movq 0x18(%rsi), %rax
movq %rax, 0x10(%rbp)
movq %r15, %rdi
movq %r12, %rdx
movl $0x771, %ecx            # imm = 0x771
callq 0x4280
jmp 0x138ad
movq 0x28(%rbp), %r13
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl $0x758, %ecx            # imm = 0x758
callq 0x4280
movq 0x18(%r13), %rbp
decl 0x8(%rbp)
jne 0x13957
testb $0x4, 0x20(%rbp)
je 0x13957
cmpq $0x0, 0x10(%rbp)
jne 0x13957
movl $0x1, %ebx
jmp 0x13906
xorl %ebx, %ebx
testb $0x1, 0x20(%rbp)
je 0x13931
leaq 0x20(%r13), %rsi
movq 0x18(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x1391e
movq (%rsi), %rsi
orl 0xc(%rsp), %ebx
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
movl %ebx, %ecx
callq 0x12644
testb $0x2, %r14b
je 0x13944
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x42f0
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl $0x77b, %ecx            # imm = 0x77B
callq 0x4280
leaq 0x20(%rsp), %rdi
callq 0x4390
movq %rax, %r13
testq %rax, %rax
jne 0x13869
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4210
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop