// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdx, %rbp
cmpb $0x7e, (%rdx)
jne 0x3ffd
movq %rsi, %rbx
movq %rdi, %r12
callq 0x3540
movq %rax, %r15
leaq 0x1(%rbp), %r14
movzbl 0x1(%rbp), %eax
testl %eax, %eax
je 0x3e71
cmpl $0x2f, %eax
jne 0x3e93
leaq 0x5270(%rip), %rdi      # 0x90e8
callq 0x3050
testq %rax, %rax
je 0x3ef7
movq %rax, %r13
movq $0x0, 0x8(%rsp)
jmp 0x3f6f
movq %r15, 0x10(%rsp)
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0x3eae
cmpl $0x2f, %eax
je 0x3eae
incq %r15
jmp 0x3e9b
movl 0x54(%rbx), %eax
leal -0x1(%rax), %ecx
cmpl %r15d, %eax
cmovgl %r15d, %ecx
movq 0x58(%rbx), %rdi
movslq %ecx, %r13
movq %r14, %rsi
movq %r13, %rdx
callq 0x33c0
movq 0x58(%rbx), %rax
movb $0x0, (%rax,%r13)
movq 0x58(%rbx), %rdi
callq 0x3350
movq %rax, %rbp
testq %rax, %rax
je 0x3f29
movq 0x20(%rbp), %r13
movl $0x1, %eax
movq %rax, 0x8(%rsp)
jmp 0x3f5e
movq %r12, %rdi
callq 0x3270
leaq 0x51e7(%rip), %rsi      # 0x90ed
leaq 0x5200(%rip), %rdx      # 0x910d
leaq 0x520c(%rip), %r8       # 0x9120
movq %r12, %rdi
movq %rbp, %rcx
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3510
jmp 0x3ffb
callq 0x3450
movq %r12, %rdi
callq 0x3270
movq 0x58(%rbx), %rdx
leaq 0x51e1(%rip), %rsi      # 0x9122
leaq 0x51e1(%rip), %rcx      # 0x9129
movq $0x0, 0x8(%rsp)
movq %r12, %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3510
testq %rbp, %rbp
je 0x3ffb
addq %r15, %r14
movq 0x10(%rsp), %r15
movq %r13, %rdi
callq 0x3190
movq %rax, %rbp
movq %r14, %rdi
callq 0x3190
movq %rax, %r12
addl %ebp, %r12d
cmpl %r12d, 0x54(%rbx)
jg 0x3fd1
movq 0x58(%rbx), %rsi
leaq 0x20(%rbx), %rax
cmpq %rax, %rsi
je 0x3faf
leaq 0x5197(%rip), %rdx      # 0x9139
movq %r15, %rdi
movl $0x1da, %ecx            # imm = 0x1DA
callq 0x31f0
incl %r12d
movl %r12d, 0x54(%rbx)
movslq %r12d, %rsi
leaq 0x5179(%rip), %rdx      # 0x9139
movq %r15, %rdi
movl $0x1de, %ecx            # imm = 0x1DE
callq 0x34c0
movq %rax, 0x58(%rbx)
movq 0x58(%rbx), %rdi
movq %r13, %rsi
callq 0x30e0
movq 0x58(%rbx), %rdi
movq %r14, %rsi
callq 0x3580
cmpl $0x0, 0x8(%rsp)
je 0x3ff5
callq 0x3450
movq 0x58(%rbx), %rbp
jmp 0x3ffd
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq