// File: /workspace/github_c_makefile_star2_O1/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 0x12ba2
movq 0xc8(%r15), %rdi
testq %rdi, %rdi
je 0x12ba2
leaq 0x40(%rdi), %rax
jmp 0x12bad
leaq 0x68(%r15), %rdi
leaq 0xa8(%r15), %rax
movq 0x280(%r15), %r12
movq %r14, %rsi
callq *(%rax)
testq %rax, %rax
je 0x12bfd
movq 0x18(%rax), %r13
testb $0x2, 0x20(%r13)
je 0x12bd1
movq 0x28(%r13), %rax
movq 0x18(%rax), %r13
testq %rbx, %rbx
je 0x12c29
testb $0x1, 0x20(%r13)
jne 0x12c35
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12de1
leaq 0x283a(%rip), %rcx      # 0x1542e
leaq 0x4ab1(%rip), %r8       # 0x176ac
jmp 0x12c1b
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12de1
leaq 0x281a(%rip), %rcx      # 0x1542e
leaq 0x4a80(%rip), %r8       # 0x1769b
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
jmp 0x12ddc
movq %rbx, (%rsp)
movq %r13, %rbx
xorl %r13d, %r13d
jmp 0x12c5e
cmpq $0x0, 0x18(%r13)
je 0x12c47
movq %r15, %rdi
movq %r13, %rsi
callq 0x12a8e
movq 0x28(%r13), %rdi
movq %rbx, %rsi
callq *0x40(%rdi)
testq %rax, %rax
je 0x12cc8
movq %rbx, (%rsp)
movq 0x18(%rax), %rbx
testb $0x30, 0x20(%rbx)
je 0x12c91
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12de1
leaq 0x27b3(%rip), %rcx      # 0x1542e
leaq 0x4a6a(%rip), %r8       # 0x176ec
movq %r15, %rdi
movq %r14, %rsi
movq (%rsp), %rdx
jmp 0x12ddc
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 0x12ceb
movl $0x4, 0x20(%rbx)
movq $0x0, 0x10(%rbx)
jmp 0x12d0d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12de1
leaq 0x274f(%rip), %rcx      # 0x1542e
leaq 0x49db(%rip), %r8       # 0x176c1
jmp 0x12c1b
movq %r15, %rdi
movq %rax, %rsi
callq 0x42f0
leaq 0x47c2(%rip), %rdx      # 0x174bf
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2bb, %ecx            # imm = 0x2BB
callq 0x4280
movl %ebp, %eax
andl $0x1, %eax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x12d75
movq 0x8(%rsp), %rax
leal 0x40(%rax), %r9d
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rcx
movq (%rsp), %r8
callq 0x12455
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x12d81
leaq 0x476f(%rip), %rbx      # 0x174bf
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 0x12d50
jmp 0x12d81
testq %r13, %r13
je 0x12d81
cmpq $0x0, 0x10(%r13)
jne 0x12d1f
testb $0x1, 0x30(%rsp)
je 0x12da0
movq 0x8(%rsp), %rcx
orl $0x40, %ecx
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x12df3
xorl %r12d, %r12d
testb $0x4, 0x30(%rsp)
je 0x12de1
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
btl $0x9, %ebp
jae 0x12de1
movq (%rsp), %rdx
testq %rdx, %rdx
leaq 0x48d7(%rip), %rax      # 0x1769b
leaq 0x48f6(%rip), %r8       # 0x176c1
cmoveq %rax, %r8
leaq 0x2658(%rip), %rcx      # 0x1542e
movq %r15, %rdi
movq %r14, %rsi
callq 0x123d5
movl %r12d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq