// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxGlob.c
// Function: Hax_TildeSubst
char *
Hax_TildeSubst(
    Hax_Interp *interp,		/* Interpreter in which to store error
				 * message (if necessary). */
    ClientData clientData,	/* Unix Client Data */
    char *name			/* File name, which may begin with "~/"
				 * (to indicate current user's home directory)
				 * or "~<user>/" (to indicate any user's
				 * home directory). */)
{
    Hax_Memoryp *memoryp;
    UnixClientData *clientDataPtr = (UnixClientData *) clientData;
    char *dir;
    int length;
    int fromPw = 0;
    char *p;

    if (name[0] != '~') {
	return name;
    }

    memoryp = Hax_GetMemoryp (interp);

    /*
     * First, find the directory name corresponding to the tilde entry.
     */

    if ((name[1] == '/') || (name[1] == '\0')) {
	dir = getenv("HOME");
	if (dir == NULL) {
	    Hax_ResetResult(interp);
	    Hax_AppendResult(interp, "couldn't find HOME environment ",
		    "variable to expand \"", name, "\"", (char *) NULL);
	    return NULL;
	}
	p = name+1;
    } else {
	struct passwd *pwPtr;

	for (p = &name[1]; (*p != 0) && (*p != '/'); p++) {
	    /* Null body;  just find end of name. */
	}
	length = p-&name[1];
	if (length >= clientDataPtr->curSize) {
	    length = clientDataPtr->curSize-1;
	}
	memcpy(clientDataPtr->curBuf, (name+1), length);
	clientDataPtr->curBuf[length] = '\0';
	pwPtr = getpwnam(clientDataPtr->curBuf);
	if (pwPtr == NULL) {
	    endpwent();
	    Hax_ResetResult(interp);
	    Hax_AppendResult(interp, "user \"", clientDataPtr->curBuf,
		    "\" doesn't exist", (char *) NULL);
	    return NULL;
	}
	dir = pwPtr->pw_dir;
	fromPw = 1;
    }

    /*
     * Grow the buffer if necessary to make enough space for the
     * full file name.
     */

    length = strlen(dir) + strlen(p);
    if (length >= clientDataPtr->curSize) {
	if (clientDataPtr->curBuf != clientDataPtr->staticBuf) {
	    ckfree(memoryp, clientDataPtr->curBuf);
	}
	clientDataPtr->curSize = length + 1;
	clientDataPtr->curBuf = (char *) ckalloc(memoryp,
		clientDataPtr->curSize);
    }

    /*
     * Finally, concatenate the directory name with the remainder
     * of the path in the buffer.
     */

    strcpy(clientDataPtr->curBuf, dir);
    strcat(clientDataPtr->curBuf, p);
    if (fromPw) {
	endpwent();
    }
    return clientDataPtr->curBuf;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbp
cmpb $0x7e, (%rdx)
jne 0x3fcc
movq %rsi, %rbx
movq %rdi, %r12
callq 0x3540
movq %rax, (%rsp)
leaq 0x1(%rbp), %r15
movzbl 0x1(%rbp), %ecx
testl %ecx, %ecx
je 0x3e63
cmpl $0x2f, %ecx
jne 0x3e80
leaq 0x427e(%rip), %rdi      # 0x80e8
callq 0x3050
testq %rax, %rax
je 0x3f6d
movq %rax, %r13
movb $0x1, %r14b
jmp 0x3edd
xorl %eax, %eax
movq %r15, %rbp
testb %cl, %cl
je 0x3e9b
movzbl %cl, %ecx
cmpl $0x2f, %ecx
je 0x3e9b
movb 0x1(%rbp), %cl
incq %rbp
incl %eax
jmp 0x3e85
movl 0x54(%rbx), %ecx
leal -0x1(%rcx), %edx
cmpl %eax, %ecx
cmovgl %eax, %edx
movq 0x58(%rbx), %rdi
movslq %edx, %r13
movq %r15, %rsi
movq %r13, %rdx
callq 0x33c0
movq 0x58(%rbx), %rax
movb $0x0, (%rax,%r13)
movq 0x58(%rbx), %rdi
callq 0x3350
testq %rax, %rax
je 0x3f9e
movq 0x20(%rax), %r13
xorl %r14d, %r14d
movq %rbp, %r15
movq %r13, %rdi
callq 0x3190
movq %rax, %rbp
movq %r15, %rdi
callq 0x3190
movq %rax, %r12
addl %ebp, %r12d
movq 0x58(%rbx), %rax
cmpl %r12d, 0x54(%rbx)
jg 0x3f46
leaq 0x20(%rbx), %rcx
cmpq %rcx, %rax
movq (%rsp), %rbp
je 0x3f24
leaq 0x4225(%rip), %rdx      # 0x8139
movq %rbp, %rdi
movq %rax, %rsi
movl $0x1da, %ecx            # imm = 0x1DA
callq 0x31f0
incl %r12d
movl %r12d, 0x54(%rbx)
movslq %r12d, %rsi
leaq 0x4204(%rip), %rdx      # 0x8139
movq %rbp, %rdi
movl $0x1de, %ecx            # imm = 0x1DE
callq 0x34c0
movq %rax, 0x58(%rbx)
movq %rax, %rdi
movq %r13, %rsi
callq 0x30e0
movq 0x58(%rbx), %rdi
movq %r15, %rsi
callq 0x3580
testb %r14b, %r14b
jne 0x3f67
callq 0x3450
movq 0x58(%rbx), %rbp
jmp 0x3fcc
movq %r12, %rdi
callq 0x3270
leaq 0x4171(%rip), %rsi      # 0x80ed
leaq 0x418a(%rip), %rdx      # 0x810d
leaq 0x4196(%rip), %r8       # 0x8120
movq %r12, %rdi
movq %rbp, %rcx
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3510
xorl %ebp, %ebp
jmp 0x3fcc
callq 0x3450
movq %r12, %rdi
callq 0x3270
movq 0x58(%rbx), %rdx
leaq 0x416c(%rip), %rsi      # 0x8122
leaq 0x416c(%rip), %rcx      # 0x8129
xorl %ebp, %ebp
movq %r12, %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3510
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq