// File: /workspace/github_c_makefile_star2_O1/haxlang[P]hax/haxVar.c
// Function: Hax_SetVar2
char *
Hax_SetVar2(
    Hax_Interp *interp,		/* Command interpreter in which variable is
				 * to be looked up. */
    char *part1,		/* If part2 is NULL, this is name of scalar
				 * variable.  Otherwise it is name of array. */
    char *part2,		/* Name of an element within array, or NULL. */
    char *newValue,		/* New value for variable. */
    int flags			/* Various flags that tell how to set value:
				 * any of HAX_GLOBAL_ONLY, HAX_APPEND_VALUE,
				 * HAX_LIST_ELEMENT, and HAX_NO_SPACE, or
				 * HAX_LEAVE_ERR_MSG . */)
{
    Hax_HashEntry *hPtr;
    Var *varPtr = NULL;
				/* Initial value only used to stop compiler
				 * from complaining; not really needed. */
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    int length, newPtr, listFlags;
    Var *arrayPtr = NULL;

    /*
     * Lookup the first name.
     */

    if ((flags & HAX_GLOBAL_ONLY) || (iPtr->varFramePtr == NULL)) {
	hPtr = Hax_CreateHashEntry(interp, &iPtr->globalTable, part1, &newPtr);
    } else {
	hPtr = Hax_CreateHashEntry(interp, &iPtr->varFramePtr->varTable,
		part1, &newPtr);
    }
    if (!newPtr) {
	varPtr = (Var *) Hax_GetHashValue(hPtr);
	if (varPtr->flags & VAR_UPVAR) {
	    hPtr = varPtr->value.upvarPtr;
	    varPtr = (Var *) Hax_GetHashValue(hPtr);
	}
    }

    /*
     * If this is an array reference, then create a new array (if
     * needed), remember any traces on the array, and lookup the
     * element within the array.
     */

    if (part2 != NULL) {
	if (newPtr) {
	    varPtr = NewVar(interp, 0);
	    Hax_SetHashValue(hPtr, varPtr);
	    varPtr->flags = VAR_ARRAY;
	    varPtr->value.tablePtr = (Hax_HashTable *)
		    ckalloc(memoryp, sizeof(Hax_HashTable));
	    Hax_InitHashTable(varPtr->value.tablePtr, HAX_STRING_KEYS);
	} else {
	    if (varPtr->flags & VAR_UNDEFINED) {
		varPtr->flags = VAR_ARRAY;
		varPtr->value.tablePtr = (Hax_HashTable *)
			ckalloc(memoryp, sizeof(Hax_HashTable));
		Hax_InitHashTable(varPtr->value.tablePtr, HAX_STRING_KEYS);
	    } else if (!(varPtr->flags & VAR_ARRAY)) {
		if (flags & HAX_LEAVE_ERR_MSG) {
		    VarErrMsg(interp, part1, part2, (char *) "set",
			(char *) needArray);
		}
		return NULL;
	    }
	    arrayPtr = varPtr;
	}
	hPtr = Hax_CreateHashEntry(interp, varPtr->value.tablePtr, part2,
	                           &newPtr);
    }

    /*
     * Compute how many bytes will be needed for newValue (leave space
     * for a separating space between list elements).
     */

    if (flags & HAX_LIST_ELEMENT) {
	length = Hax_ScanElement(newValue, &listFlags) + 1;
    } else {
	length = strlen(newValue);
    }

    /*
     * If the variable doesn't exist then create a new one.  If it
     * does exist then clear its current value unless this is an
     * append operation.
     */

    if (newPtr) {
	varPtr = NewVar(interp, length);
	Hax_SetHashValue(hPtr, varPtr);
	if ((arrayPtr != NULL) && (arrayPtr->searchPtr != NULL)) {
	    DeleteSearches(interp, arrayPtr);
	}
    } else {
	varPtr = (Var *) Hax_GetHashValue(hPtr);
	if (varPtr->flags & VAR_ARRAY) {
	    if (flags & HAX_LEAVE_ERR_MSG) {
		VarErrMsg(interp, part1, part2, (char *) "set",
		    (char *) isArray);
	    }
	    return NULL;
	}
	if (!(flags & HAX_APPEND_VALUE) || (varPtr->flags & VAR_UNDEFINED)) {
	    varPtr->valueLength = 0;
	}
    }

    /*
     * Make sure there's enough space to hold the variable's
     * new value.  If not, enlarge the variable's space.
     */

    if ((length + varPtr->valueLength) >= varPtr->valueSpace) {
	Var *newVarPtr;
	int newSize;

	newSize = 2*varPtr->valueSpace;
	if (newSize <= (length + varPtr->valueLength)) {
	    newSize += length;
	}
	newVarPtr = NewVar(interp, newSize);
	newVarPtr->valueLength = varPtr->valueLength;
	newVarPtr->upvarUses = varPtr->upvarUses;
	newVarPtr->tracePtr = varPtr->tracePtr;
	newVarPtr->searchPtr = varPtr->searchPtr;
	newVarPtr->flags = varPtr->flags;
	strcpy(newVarPtr->value.string, varPtr->value.string);
	Hax_SetHashValue(hPtr, newVarPtr);
	ckfree(memoryp, (char *) varPtr);
	varPtr = newVarPtr;
    }

    /*
     * Append the new value to the variable, either as a list
     * element or as a string.
     */

    if (flags & HAX_LIST_ELEMENT) {
	if ((varPtr->valueLength > 0) && !(flags & HAX_NO_SPACE)) {
	    ((char *)varPtr->value.string)[varPtr->valueLength] = ' ';
	    varPtr->valueLength++;
	}
	varPtr->valueLength += Hax_ConvertElement(newValue,
		(char *)varPtr->value.string + varPtr->valueLength, listFlags);
	((char *)varPtr->value.string)[varPtr->valueLength] = 0;
    } else {
	strcpy(((char *)varPtr->value.string) + varPtr->valueLength, newValue);
	varPtr->valueLength += length;
    }
    varPtr->flags &= ~VAR_UNDEFINED;

    /*
     * Invoke any write traces for the variable.
     */

    if ((varPtr->tracePtr != NULL)
	    || ((arrayPtr != NULL) && (arrayPtr->tracePtr != NULL))) {
	char *msg;

	msg = CallTraces(iPtr, arrayPtr, hPtr, part1, part2,
		(flags & HAX_GLOBAL_ONLY) | HAX_TRACE_WRITES);
	if (msg != NULL) {
	    VarErrMsg(interp, part1, part2, (char *) "set", (char *) msg);
	    return NULL;
	}

	/*
	 * Watch out!  The variable could have gotten re-allocated to
	 * a larger size.  Fortunately the hash table entry will still
	 * be around.
	 */

	varPtr = (Var *) Hax_GetHashValue(hPtr);
    }
    return varPtr->value.string;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %r15d
movq %rcx, %r13
movq %rdx, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
testb $0x1, %r15b
jne 0x1265d
movq 0xc8(%r12), %rsi
testq %rsi, %rsi
je 0x1265d
leaq 0x48(%rsi), %rax
jmp 0x1266a
leaq 0x68(%r12), %rsi
leaq 0xb0(%r12), %rax
movq 0x280(%r12), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x24(%rsp), %rbx
movq %r12, %rdi
movq 0x18(%rsp), %rdx
movq %rbx, %rcx
callq *(%rax)
movq %rax, %rbp
movl (%rbx), %eax
testl %eax, %eax
je 0x12696
xorl %ebx, %ebx
jmp 0x126a8
movq 0x18(%rbp), %rbx
testb $0x2, 0x20(%rbx)
je 0x126a8
movq 0x28(%rbx), %rbp
movq 0x18(%rbp), %rbx
cmpq $0x0, 0x8(%rsp)
je 0x1272d
testl %eax, %eax
je 0x12738
movq 0x280(%r12), %rdi
leaq 0x4df8(%rip), %r14      # 0x174bf
movl $0x30, %esi
movq %r14, %rdx
movl $0x825, %ecx            # imm = 0x825
callq 0x44c0
movq %rax, %rbx
movabsq $0x800000000, %rax      # imm = 0x800000000
movq %rax, (%rbx)
xorl %eax, %eax
movl %eax, 0x8(%rbx)
movb $0x0, 0x28(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movq $0x0, 0x10(%rsp)
movl %eax, 0x20(%rbx)
movq %rbx, 0x18(%rbp)
movl $0x1, 0x20(%rbx)
movl $0x50, %esi
movq 0x30(%rsp), %rdi
movq %r14, %rdx
movl $0x182, %ecx            # imm = 0x182
callq 0x44c0
movq %rax, 0x28(%rbx)
jmp 0x12791
movq $0x0, 0x10(%rsp)
jmp 0x127b2
movl 0x20(%rbx), %eax
testb $0x4, %al
jne 0x12766
movq %rbx, 0x10(%rsp)
testb $0x1, %al
jne 0x1279b
btl $0x9, %r15d
jae 0x12a79
leaq 0x2cd6(%rip), %rcx      # 0x15430
leaq 0x4f4b(%rip), %r8       # 0x176ac
jmp 0x12a67
movl $0x1, 0x20(%rbx)
leaq 0x4d4b(%rip), %rdx      # 0x174bf
movl $0x50, %esi
movq 0x30(%rsp), %rdi
movl $0x188, %ecx            # imm = 0x188
callq 0x44c0
movq %rax, 0x28(%rbx)
movq %rbx, 0x10(%rsp)
movq %rax, %rdi
xorl %esi, %esi
callq 0x4590
movq 0x28(%rbx), %rsi
leaq 0x24(%rsp), %rcx
movq %r12, %rdi
movq 0x8(%rsp), %rdx
callq *0x48(%rsi)
movq %rax, %rbp
testb $0x4, %r15b
jne 0x127c5
movq %r13, %rdi
callq 0x41d0
movq %rax, %rbx
jmp 0x127d6
leaq 0x3c(%rsp), %rsi
movq %r13, %rdi
callq 0x4110
movl %eax, %ebx
incl %ebx
cmpl $0x0, 0x24(%rsp)
movq %r13, 0x28(%rsp)
movl %r15d, 0x4(%rsp)
je 0x12a0b
movq %r12, %r15
movq 0x280(%r12), %rdi
leal -0x8(%rbx), %esi
xorl %r12d, %r12d
testl %esi, %esi
cmovlel %r12d, %esi
movl $0x8, %r13d
cmovnsl %ebx, %r13d
addl $0x30, %esi
leaq 0x4ca9(%rip), %rdx      # 0x174bf
movl $0x825, %ecx            # imm = 0x825
callq 0x44c0
movq %rax, %r14
movl %r12d, (%rax)
movl %r13d, 0x4(%rax)
movl %r12d, 0x8(%rax)
movb $0x0, 0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl %r12d, 0x20(%rax)
movq %rbp, %r13
movq %rax, 0x18(%rbp)
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x12862
cmpq $0x0, 0x18(%rsi)
je 0x12862
movq %r15, %r12
movq %r15, %rdi
callq 0x12a8e
jmp 0x12865
movq %r15, %r12
movl 0x4(%rsp), %r15d
movq 0x28(%rsp), %rsi
movq %r13, %rbp
movl (%r14), %ecx
addl %ebx, %ecx
movl 0x4(%r14), %eax
cmpl %eax, %ecx
jge 0x12887
movq %rsi, %r13
jmp 0x12956
leal (%rax,%rax), %edx
xorl %r13d, %r13d
cmpl %ecx, %edx
movl %ebx, %ecx
cmovgl %r13d, %ecx
leal (%rcx,%rax,2), %edx
movq 0x280(%r12), %rdi
leal (%rcx,%rax,2), %esi
addl $-0x8, %esi
testl %esi, %esi
cmovlel %r13d, %esi
movq %rbp, %r15
movl $0x8, %ebp
cmovnsl %edx, %ebp
addl $0x30, %esi
leaq 0x4bfe(%rip), %rdx      # 0x174bf
movl $0x825, %ecx            # imm = 0x825
callq 0x44c0
movq %r12, 0x40(%rsp)
movq %rax, %r12
movl %r13d, (%rax)
movl %ebp, 0x4(%rax)
movq %r15, %rbp
movl 0x4(%rsp), %r15d
movl %r13d, 0x8(%rax)
leaq 0x28(%rax), %rdi
movb $0x0, 0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl %r13d, 0x20(%rax)
movq 0x28(%rsp), %r13
movl (%r14), %eax
movl %eax, (%r12)
movl 0x8(%r14), %eax
movl %eax, 0x8(%r12)
movq 0x10(%r14), %rax
movq %rax, 0x10(%r12)
movq 0x18(%r14), %rax
movq %rax, 0x18(%r12)
movl 0x20(%r14), %eax
movl %eax, 0x20(%r12)
leaq 0x28(%r14), %rsi
callq 0x40f0
movq %r12, 0x18(%rbp)
movq 0x30(%rsp), %rdi
movq %r14, %rsi
leaq 0x4b7b(%rip), %rdx      # 0x174bf
movl $0x1d1, %ecx            # imm = 0x1D1
callq 0x4280
movq %r12, %r14
movq 0x40(%rsp), %r12
testb $0x4, %r15b
jne 0x12974
movslq (%r14), %rax
leaq (%r14,%rax), %rdi
addq $0x28, %rdi
movq %r13, %rsi
callq 0x40f0
addl %ebx, (%r14)
jmp 0x129b4
testb $0x8, %r15b
jne 0x1298c
movl (%r14), %eax
testl %eax, %eax
jle 0x1298c
movb $0x20, 0x28(%r14,%rax)
incl %eax
movl %eax, (%r14)
movslq (%r14), %rax
leaq (%r14,%rax), %rsi
addq $0x28, %rsi
movl 0x3c(%rsp), %edx
movq %r13, %rdi
callq 0x4170
movslq (%r14), %rcx
cltq
addq %rcx, %rax
movl %eax, (%r14)
movb $0x0, 0x28(%r14,%rax)
andb $-0x5, 0x20(%r14)
cmpq $0x0, 0x10(%r14)
movq 0x10(%rsp), %rsi
je 0x12a35
andl $0x1, %r15d
orl $0x20, %r15d
movq %r12, %rdi
movq %rbp, %rdx
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r8
movl %r15d, %r9d
callq 0x12455
movq %rax, %rbx
testq %rax, %rax
je 0x12a43
leaq 0x2a3c(%rip), %rcx      # 0x15430
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %r8
callq 0x123d5
jmp 0x12a47
movq 0x18(%rbp), %r14
movl 0x20(%r14), %eax
testb $0x1, %al
jne 0x12a52
movq %r13, %rsi
testb $0x2, %r15b
je 0x12a29
andl $0x4, %eax
je 0x12872
movl $0x0, (%r14)
jmp 0x12872
testq %rsi, %rsi
je 0x12a4c
cmpq $0x0, 0x10(%rsi)
jne 0x129c5
jmp 0x12a4c
movq 0x18(%rbp), %r14
testq %rbx, %rbx
jne 0x12a79
addq $0x28, %r14
jmp 0x12a7c
btl $0x9, %r15d
jae 0x12a79
leaq 0x29d0(%rip), %rcx      # 0x15430
leaq 0x4c73(%rip), %r8       # 0x176da
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x123d5
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq