// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x60(%rax)
jne 0x3c6c
leaq 0x73be(%rip), %rdi      # 0xb023
movb $0x0, %al
callq 0x3130
movq -0x10(%rbp), %rdi
callq 0x3540
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x3330
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x3d4d
movl -0x48(%rbp), %eax
addl $0x2, %eax
movq -0x38(%rbp), %rcx
cmpl 0x60(%rcx), %eax
jle 0x3d20
movq -0x40(%rbp), %rdi
movl -0x48(%rbp), %eax
addl $0x5, %eax
cltq
shlq $0x3, %rax
movl %eax, %eax
movl %eax, %esi
leaq 0x7383(%rip), %rdx      # 0xb044
movl $0xd2, %ecx
callq 0x34c0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq 0xa2fe(%rip), %rax      # 0xdfd8
movq (%rax), %rsi
movslq -0x48(%rbp), %rdx
shlq $0x3, %rdx
callq 0x33c0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rsi
leaq 0x7347(%rip), %rdx      # 0xb044
movl $0xd5, %ecx
callq 0x31f0
movq -0x60(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x68(%rax)
movl -0x48(%rbp), %ecx
addl $0x5, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x60(%rax)
movl -0x48(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x20(%rbp), %rdi
callq 0x3190
movl %eax, -0x4c(%rbp)
jmp 0x3dbf
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movslq -0x48(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
callq 0x3320
cmpl $0x0, %eax
jne 0x3d82
movl $0x0, -0x4(%rbp)
jmp 0x3e6f
cmpl $0x0, -0x2c(%rbp)
jne 0x3d94
movl $0x0, -0x4(%rbp)
jmp 0x3e6f
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x7295(%rip), %rdx      # 0xb044
movl $0xf1, %ecx
callq 0x31f0
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movslq -0x4c(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rdi
callq 0x3190
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdi
addq %rax, %rsi
addq $0x2, %rsi
leaq 0x7256(%rip), %rdx      # 0xb044
movl $0xf9, %ecx
callq 0x34c0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x44(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x30e0
movl -0x4c(%rbp), %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movb $0x3d, (%rax)
movq -0x58(%rbp), %rdi
addq $0x1, %rdi
movq -0x28(%rbp), %rsi
callq 0x30e0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x58(%rbp), %rcx
addq $0x1, %rcx
leaq 0x71c2(%rip), %rsi      # 0xb01f
movl $0x1, %r8d
callq 0x30c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)