// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxVar.c
// Function: Hax_UnsetVar2
int
Hax_UnsetVar2(
    Hax_Interp *interp,		/* Command interpreter in which varName is
				 * to be looked up. */
    char *part1,		/* Name of variable or array. */
    char *part2,		/* Name of element within array or NULL. */
    int flags			/* OR-ed combination of any of
				 * HAX_GLOBAL_ONLY or HAX_LEAVE_ERR_MSG. */)
{
    Hax_HashEntry *hPtr, dummyEntry;
    Var *varPtr, dummyVar;
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    Var *arrayPtr = NULL;

    if ((flags & HAX_GLOBAL_ONLY) || (iPtr->varFramePtr == NULL)) {
	hPtr = Hax_FindHashEntry(&iPtr->globalTable, part1);
    } else {
	hPtr = Hax_FindHashEntry(&iPtr->varFramePtr->varTable, part1);
    }
    if (hPtr == NULL) {
	if (flags & HAX_LEAVE_ERR_MSG) {
	    VarErrMsg(interp, part1, part2, (char *) "unset",
		(char *) noSuchVar);
	}
	return -1;
    }
    varPtr = (Var *) Hax_GetHashValue(hPtr);

    /*
     * For global variables referenced in procedures, leave the procedure's
     * reference variable in place, but unset the global variable.  Can't
     * decrement the actual variable's use count, since we didn't delete
     * the reference variable.
     */

    if (varPtr->flags & VAR_UPVAR) {
	hPtr = varPtr->value.upvarPtr;
	varPtr = (Var *) Hax_GetHashValue(hPtr);
    }

    /*
     * If the variable being deleted is an element of an array, then
     * remember trace procedures on the overall array and find the
     * element to delete.
     */

    if (part2 != NULL) {
	if (!(varPtr->flags & VAR_ARRAY)) {
	    if (flags & HAX_LEAVE_ERR_MSG) {
		VarErrMsg(interp, part1, part2, (char *) "unset",
		    (char *) needArray);
	    }
	    return -1;
	}
	if (varPtr->searchPtr != NULL) {
	    DeleteSearches(interp, varPtr);
	}
	arrayPtr = varPtr;
	hPtr = Hax_FindHashEntry(varPtr->value.tablePtr, part2);
	if (hPtr == NULL) {
	    if (flags & HAX_LEAVE_ERR_MSG) {
		VarErrMsg(interp, part1, part2, (char *) "unset",
		    (char *) noSuchElement);
	    }
	    return -1;
	}
	varPtr = (Var *) Hax_GetHashValue(hPtr);
    }

    /*
     * If there is a trace active on this variable or if the variable
     * is already being deleted then don't delete the variable:  it
     * isn't safe, since there are procedures higher up on the stack
     * that will use pointers to the variable.  Also don't delete an
     * array if there are traces active on any of its elements.
     */

    if (varPtr->flags &
	    (VAR_TRACE_ACTIVE|VAR_ELEMENT_ACTIVE)) {
	if (flags & HAX_LEAVE_ERR_MSG) {
	    VarErrMsg(interp, part1, part2, (char *) "unset",
		(char *) traceActive);
	}
	return -1;
    }

    /*
     * The code below is tricky, because of the possibility that
     * a trace procedure might try to access a variable being
     * deleted.  To handle this situation gracefully, copy the
     * contents of the variable and its hash table entry to
     * dummy variables, then clean up the actual variable so that
     * it's been completely deleted before the traces are called.
     * Then call the traces, and finally clean up the variable's
     * storage using the dummy copies.
     */

    dummyVar = *varPtr;
    Hax_SetHashValue(&dummyEntry, &dummyVar);
    if (varPtr->upvarUses == 0) {
	Hax_DeleteHashEntry(interp, hPtr);
	ckfree(memoryp, (char *) varPtr);
    } else {
	varPtr->flags = VAR_UNDEFINED;
	varPtr->tracePtr = NULL;
    }

    /*
     * Call trace procedures for the variable being deleted and delete
     * its traces.
     */

    if ((dummyVar.tracePtr != NULL)
	    || ((arrayPtr != NULL) && (arrayPtr->tracePtr != NULL))) {
	(void) CallTraces(iPtr, arrayPtr, &dummyEntry, part1, part2,
		(flags & HAX_GLOBAL_ONLY) | HAX_TRACE_UNSETS);
	while (dummyVar.tracePtr != NULL) {
	    VarTrace *tracePtr = dummyVar.tracePtr;
	    dummyVar.tracePtr = tracePtr->nextPtr;
	    ckfree(memoryp, (char *) tracePtr);
	}
    }

    /*
     * If the variable is an array, delete all of its elements.  This
     * must be done after calling the traces on the array, above (that's
     * the way traces are defined).
     */

    if (dummyVar.flags & VAR_ARRAY) {
	DeleteArray(iPtr, part1, &dummyVar,
	    (flags & HAX_GLOBAL_ONLY) | HAX_TRACE_UNSETS);
    }
    if (dummyVar.flags & VAR_UNDEFINED) {
	if (flags & HAX_LEAVE_ERR_MSG) {
	    VarErrMsg(interp, part1, part2, (char *) "unset",
		(part2 == NULL) ? (char *) noSuchVar : (char *) noSuchElement);
	}
	return -1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
testb $0x1, %bpl
jne 0x123d3
movq 0xc8(%r15), %rdi
testq %rdi, %rdi
je 0x123d3
leaq 0x40(%rdi), %rax
jmp 0x123de
leaq 0x68(%r15), %rdi
leaq 0xa8(%r15), %rax
movq 0x280(%r15), %r12
movq %r14, %rsi
callq *(%rax)
testq %rax, %rax
je 0x1242e
movq 0x18(%rax), %r13
testb $0x2, 0x20(%r13)
je 0x12402
movq 0x28(%r13), %rax
movq 0x18(%rax), %r13
testq %rbx, %rbx
je 0x1245a
testb $0x1, 0x20(%r13)
jne 0x12466
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12632
leaq 0x2009(%rip), %rcx      # 0x1442e
leaq 0x3f84(%rip), %r8       # 0x163b0
jmp 0x1244c
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12632
leaq 0x1fe9(%rip), %rcx      # 0x1442e
leaq 0x3f53(%rip), %r8       # 0x1639f
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
jmp 0x1262d
movq %rbx, (%rsp)
movq %r13, %rbx
xorl %r13d, %r13d
jmp 0x12493
cmpq $0x0, 0x18(%r13)
je 0x1247c
movq 0x280(%r15), %rdi
movq %r13, %rsi
callq 0x12301
movq 0x28(%r13), %rdi
movq %rbx, %rsi
callq *0x40(%rdi)
testq %rax, %rax
je 0x124fd
movq %rbx, (%rsp)
movq 0x18(%rax), %rbx
testb $0x30, 0x20(%rbx)
je 0x124c6
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12632
leaq 0x1f7e(%rip), %rcx      # 0x1442e
leaq 0x3f39(%rip), %r8       # 0x163f0
movq %r15, %rdi
movq %r14, %rsi
movq (%rsp), %rdx
jmp 0x1262d
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
leaq 0x10(%rsp), %rcx
movaps %xmm2, 0x20(%rcx)
movaps %xmm1, 0x10(%rcx)
movaps %xmm0, (%rcx)
movq %rcx, 0x58(%rsp)
cmpl $0x0, 0x8(%rbx)
je 0x12520
movl $0x4, 0x20(%rbx)
movq $0x0, 0x10(%rbx)
jmp 0x12542
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12632
leaq 0x1f1a(%rip), %rcx      # 0x1442e
leaq 0x3eaa(%rip), %r8       # 0x163c5
jmp 0x1244c
movq %r15, %rdi
movq %rax, %rsi
callq 0x42f0
leaq 0x3c91(%rip), %rdx      # 0x161c3
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2bb, %ecx            # imm = 0x2BB
callq 0x4280
movl %ebp, %eax
andl $0x1, %eax
cmpq $0x0, 0x20(%rsp)
movq (%rsp), %r8
movq %rax, 0x8(%rsp)
je 0x125a5
leal 0x40(%rax), %r9d
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rcx
callq 0x11d13
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x125ce
leaq 0x3c43(%rip), %rbx      # 0x161c3
movq 0x18(%rsi), %rax
movq %rax, 0x20(%rsp)
movq %r12, %rdi
movq %rbx, %rdx
movl $0x2cd, %ecx            # imm = 0x2CD
callq 0x4280
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
jne 0x12580
jmp 0x125ce
testq %r13, %r13
je 0x125ce
cmpq $0x0, 0x10(%r13)
je 0x125ce
movq 0x8(%rsp), %rax
leal 0x40(%rax), %r9d
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rcx
movq (%rsp), %r8
jmp 0x1256a
movl 0x30(%rsp), %eax
testb $0x1, %al
je 0x125f4
movq 0x8(%rsp), %rcx
orl $0x40, %ecx
leaq 0x10(%rsp), %rbx
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x12644
movl 0x20(%rbx), %eax
xorl %r12d, %r12d
testb $0x4, %al
je 0x12632
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12632
movq (%rsp), %rdx
testq %rdx, %rdx
leaq 0x3d8a(%rip), %rax      # 0x1639f
leaq 0x3da9(%rip), %r8       # 0x163c5
cmoveq %rax, %r8
leaq 0x1e07(%rip), %rcx      # 0x1442e
movq %r15, %rdi
movq %r14, %rsi
callq 0x11c93
movl %r12d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq