// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxEnv.c
// Function: Hax_SetEnv
int
Hax_SetEnv(
    Hax_Interp *interp,
    ClientData clientData,	/* Unix Client Data */
    char *name,			/* Name of variable whose value is to be
				 * set. */
    char *value,		/* New value for variable. */
    int overwrite)
{
    UnixClientData *unixClientData = (UnixClientData *) clientData;
    Hax_Memoryp *memoryp;
    int index, length, nameLength;
    char *p;

    if (unixClientData->environSize == 0) {
	Hax_Panic ((char *) "Unexpected uninitialized environ");
    }

    memoryp = Hax_GetMemoryp(interp);

    /*
     * Figure out where the entry is going to go.  If the name doesn't
     * already exist, enlarge the array if necessary to make room.  If
     * the name exists, free its old entry.
     */

    index = Hax_FindVariable((ClientData) unixClientData, name, &length);
    if (index == -1) {
	if ((length+2) > unixClientData->environSize) {
	    char **newEnviron;

	    newEnviron = (char **) ckalloc(memoryp, (unsigned)
		    ((length+5) * sizeof(char *)));
	    memcpy(newEnviron, environ,
		    length*sizeof(char *));
	    ckfree(memoryp, unixClientData->haxEnviron);
	    unixClientData->haxEnviron = newEnviron;
	    unixClientData->environSize = length+5;
	}
	index = length;
	unixClientData->haxEnviron[index+1] = NULL;
	nameLength = strlen(name);
    } else {
	/*
	 * Compare the new value to the existing value.  If they're
	 * the same then quit immediately (e.g. don't rewrite the
	 * value or propagate it to other interpeters).  Otherwise,
	 * when there are N interpreters there will be N! propagations
	 * of the same value among the interpreters.
	 */

	if (strcmp(value, unixClientData->haxEnviron[index]+length+1) == 0) {
	    return HAX_OK;
	}

	/*
	 * If the variable does exist, the argument overwrite is tested;
	 * if overwrite is zero, the variable is not reset, otherwise it is
	 * reset to the given value.
	 */
	if (!overwrite) {
	    return HAX_OK;
	}
	ckfree(memoryp, unixClientData->haxEnviron[index]);
	nameLength = length;
    }

    /*
     * Create a new entry and enter it into the table.
     */

    p = (char *) ckalloc(memoryp, nameLength + strlen(value) + 2);
    unixClientData->haxEnviron[index] = p;
    strcpy(p, name);
    p += nameLength;
    *p = '=';
    strcpy(p+1, value);

    Hax_SetVar2(interp, (char *) "env", (char *) name,
	p+1, HAX_GLOBAL_ONLY);

    return HAX_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebp
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
cmpl $0x0, 0x60(%rsi)
jne 0x3a7d
leaq 0x45ad(%rip), %rdi      # 0x8023
xorl %eax, %eax
callq 0x3130
movq %r14, %rdi
callq 0x3540
movq %rax, %r13
leaq 0xc(%rsp), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x3330
cmpl $-0x1, %eax
movq %r14, 0x20(%rsp)
je 0x3af7
movq %r13, %rbx
movq 0x68(%r12), %rcx
cltq
movq %rax, 0x10(%rsp)
movq (%rcx,%rax,8), %r14
movslq 0xc(%rsp), %r13
leaq (%r14,%r13), %rsi
incq %rsi
movq 0x18(%rsp), %rdi
callq 0x3320
testl %ebp, %ebp
je 0x3c09
testl %eax, %eax
je 0x3c09
leaq 0x4562(%rip), %rdx      # 0x8044
movq %rbx, %rdi
movq %r14, %rsi
movl $0xf1, %ecx
callq 0x31f0
jmp 0x3b91
movslq 0xc(%rsp), %rcx
leal 0x2(%rcx), %eax
cmpl 0x60(%r12), %eax
jle 0x3b70
leal 0x28(,%rcx,8), %esi
leaq 0x4530(%rip), %rdx      # 0x8044
movq %r13, %rdi
movq %rcx, %r14
movl $0xd2, %ecx
callq 0x34c0
movq %rax, %rbp
movq 0x84a2(%rip), %rax      # 0xbfd0
movq (%rax), %rsi
leaq (,%r14,8), %rdx
movq %rbp, %rdi
callq 0x33c0
movq 0x68(%r12), %rsi
movq %r13, %rbx
movq %r13, %rdi
leaq 0x44f1(%rip), %rdx      # 0x8044
movl $0xd5, %ecx
callq 0x31f0
movq %r14, %rcx
movq %rbp, 0x68(%r12)
leal 0x5(%r14), %eax
movl %eax, 0x60(%r12)
jmp 0x3b78
movq %r13, %rbx
movq 0x68(%r12), %rbp
movq %rcx, 0x10(%rsp)
movq $0x0, 0x8(%rbp,%rcx,8)
movq %r15, %rdi
callq 0x3190
movslq %eax, %r13
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
callq 0x3190
leaq (%rax,%r13), %rsi
addq $0x2, %rsi
leaq 0x4497(%rip), %rdx      # 0x8044
movq %rbx, %rdi
movl $0xf9, %ecx
callq 0x34c0
movq %rax, %r14
movq 0x68(%r12), %rax
movq 0x10(%rsp), %rcx
movq %r14, (%rax,%rcx,8)
movq %r14, %rdi
movq %r15, %rsi
callq 0x30e0
addq %r13, %r14
incq %r14
movb $0x3d, -0x1(%r14)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x30e0
leaq 0x442c(%rip), %rsi      # 0x801f
movq 0x20(%rsp), %rdi
movq %r15, %rdx
movq %r14, %rcx
movl $0x1, %r8d
callq 0x30c0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq