// File: /workspace/github_c_makefile_star2_O1/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 0x43d0
testq %rax, %rax
je 0x14276
movq %rax, %rbp
leaq 0x3358(%rip), %r12      # 0x174bf
movq 0x18(%rbp), %r13
movl 0x20(%r13), %r14d
testb $0x2, %r14b
jne 0x14225
xorl %ebx, %ebx
cmpq $0x0, 0x10(%r13)
je 0x141d1
leaq 0x20(%rbp), %rcx
movq 0x18(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x14194
movq (%rcx), %rcx
movl %ebx, %r9d
orl 0xc(%rsp), %r9d
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %rbp, %rdx
xorl %r8d, %r8d
callq 0x12455
movq 0x10(%r13), %rsi
testq %rsi, %rsi
je 0x141d1
movq 0x18(%rsi), %rax
movq %rax, 0x10(%r13)
movq %r15, %rdi
movq %r12, %rdx
movl $0x771, %ecx            # imm = 0x771
callq 0x4280
jmp 0x141ae
testb $0x1, 0x20(%r13)
je 0x141fd
leaq 0x20(%rbp), %rsi
movq 0x18(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x141ea
movq (%rsi), %rsi
orl 0xc(%rsp), %ebx
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movl %ebx, %ecx
callq 0x12df3
testb $0x2, %r14b
je 0x14210
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x42f0
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl $0x77b, %ecx            # imm = 0x77B
callq 0x4280
jmp 0x14254
movq 0x28(%r13), %rbp
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl $0x758, %ecx            # imm = 0x758
callq 0x4280
movq 0x18(%rbp), %r13
decl 0x8(%r13)
jne 0x14254
testb $0x4, 0x20(%r13)
je 0x14254
cmpq $0x0, 0x10(%r13)
je 0x1426c
leaq 0x20(%rsp), %rdi
callq 0x4380
movq %rax, %rbp
testq %rax, %rax
jne 0x14167
jmp 0x14276
movl $0x1, %ebx
jmp 0x1417b
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