// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movq %rcx, 0x18(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
cmpl $0x0, 0x60(%rsi)
jne 0x3a8b
leaq 0x559f(%rip), %rdi      # 0x9023
xorl %eax, %eax
callq 0x3130
movq %r15, 0x20(%rsp)
movq %r15, %rdi
callq 0x3540
movq %rax, 0x10(%rsp)
leaq 0xc(%rsp), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3330
cmpl $-0x1, %eax
je 0x3b08
movl %eax, %ebp
movq 0x68(%r12), %rax
movslq %ebp, %rcx
movq (%rax,%rcx,8), %r13
movslq 0xc(%rsp), %r15
leaq (%r15,%r13), %rsi
incq %rsi
movq 0x18(%rsp), %rdi
callq 0x3320
testl %r14d, %r14d
je 0x3c15
testl %eax, %eax
je 0x3c15
leaq 0x5556(%rip), %rdx      # 0x9044
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movl $0xf1, %ecx
callq 0x31f0
jmp 0x3b9c
movl 0xc(%rsp), %ebp
movslq %ebp, %r13
leal 0x2(%r13), %eax
cmpl 0x60(%r12), %eax
jle 0x3b7e
leal 0x28(,%r13,8), %esi
leaq 0x551b(%rip), %rdx      # 0x9044
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0xd2, %ecx
callq 0x34c0
movq %rax, %r15
movq 0x948b(%rip), %rax      # 0xcfd0
movq (%rax), %rsi
movq %r13, %rdx
shlq $0x3, %rdx
movq %r15, %rdi
callq 0x33c0
movq 0x68(%r12), %rsi
movq %r14, %rdi
leaq 0x54de(%rip), %rdx      # 0x9044
movl $0xd5, %ecx
callq 0x31f0
movq %r15, 0x68(%r12)
leal 0x5(%r13), %eax
movl %eax, 0x60(%r12)
movq 0x68(%r12), %rax
movq $0x0, 0x8(%rax,%r13,8)
movq %rbx, %rdi
callq 0x3190
movq %rax, %r15
movq 0x10(%rsp), %r14
movslq %r15d, %r15
movq 0x18(%rsp), %r13
movq %r13, %rdi
callq 0x3190
leaq (%r15,%rax), %rsi
addq $0x2, %rsi
leaq 0x5489(%rip), %rdx      # 0x9044
movq %r14, %rdi
movl $0xf9, %ecx
callq 0x34c0
movq %rax, %r14
movq 0x68(%r12), %rax
movslq %ebp, %rcx
movq %r14, (%rax,%rcx,8)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x30e0
addq %r15, %r14
incq %r14
movb $0x3d, -0x1(%r14)
movq %r14, %rdi
movq %r13, %rsi
callq 0x30e0
leaq 0x5420(%rip), %rsi      # 0x901f
movq 0x20(%rsp), %rdi
movq %rbx, %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