// File: /workspace/github_c_makefile_star2_O2/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, %rdx
movq 0x280(%rdi), %r15
movq %rdi, 0x10(%rsp)
leaq 0x68(%rdi), %rax
cmpq %rsi, %rax
movl $0x141, %eax            # imm = 0x141
pushq $0x40
popq %rcx
cmovel %eax, %ecx
movl %ecx, 0xc(%rsp)
leaq 0x20(%rsp), %rsi
movq %rdx, 0x18(%rsp)
movq %rdx, %rdi
callq 0x43f0
movq %rax, %r12
leaq 0x2a74(%rip), %r13      # 0x15193
testq %r12, %r12
je 0x1282f
movq 0x18(%r12), %rbp
movl 0x20(%rbp), %r14d
testb $0x2, %r14b
jne 0x12791
xorl %ebx, %ebx
cmpq $0x0, 0x10(%rbp)
je 0x127ca
leaq 0x20(%r12), %rcx
movq 0x18(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x12757
movq (%rcx), %rcx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %r8d, %r8d
movl 0xc(%rsp), %r9d
callq 0x10e7b
movq 0x10(%rbp), %rsi
testq %rsi, %rsi
je 0x127c5
movq 0x18(%rsi), %rax
movq %rax, 0x10(%rbp)
movq %r15, %rdi
movq %r13, %rdx
movl $0x771, %ecx            # imm = 0x771
callq 0x4280
jmp 0x1276e
movq 0x28(%rbp), %r12
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl $0x758, %ecx            # imm = 0x758
callq 0x4280
movq 0x18(%r12), %rbp
decl 0x8(%rbp)
jne 0x1281d
movl 0x20(%rbp), %eax
testb $0x4, %al
je 0x1281d
cmpq $0x0, 0x10(%rbp)
pushq $0x1
popq %rbx
jne 0x1281d
jmp 0x127cd
movl 0x20(%rbp), %eax
jmp 0x127cd
movl %r14d, %eax
testb $0x1, %al
je 0x127f7
leaq 0x20(%r12), %rsi
movq 0x18(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0x127e4
movq (%rsi), %rsi
orl 0xc(%rsp), %ebx
movq 0x10(%rsp), %rdi
movq %rbp, %rdx
movl %ebx, %ecx
callq 0x116c8
testb $0x2, %r14b
je 0x1280a
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x42f0
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl $0x77b, %ecx            # imm = 0x77B
callq 0x4280
leaq 0x20(%rsp), %rdi
callq 0x43a0
movq %rax, %r12
jmp 0x1271f
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
nopl (%rax)