// File: /workspace/github_c_makefile_star2_O2/JimKent[P]linearSat/lib/osunix.c
// Function: simplifyPathToDir
char *simplifyPathToDir(char *path)
/* Return path with ~ and .. taken out.  Also any // or trailing /.   
 * freeMem result when done. */
{
/* Expand ~ if any with result in newPath */
char newPath[PATH_LEN];
int newLen = 0;
char *s = path;
if (*s == '~')
    {
    char *homeDir = getenv("HOME");
    if (homeDir == NULL)
        errAbort("No HOME environment var defined after ~ in simplifyPathToDir");
    ++s;
    if (*s == '/')  /*    ~/something      */
        {
	++s;
	safef(newPath, sizeof(newPath), "%s/", homeDir);
	}
    else            /*   ~something        */
	{
	safef(newPath, sizeof(newPath), "%s/../", homeDir);
	}
    newLen = strlen(newPath);
    }
int remainingLen  = strlen(s);
if (newLen + remainingLen >= sizeof(newPath))
    errAbort("path too big in simplifyPathToDir");
strcpy(newPath+newLen, s);

/* Remove //, .. and trailing / */
eatSlashSlashInPath(newPath);
eatExcessDotDotInPath(newPath);
int lastPos = strlen(newPath)-1;
if (lastPos > 0 && newPath[lastPos] == '/')
    newPath[lastPos] = 0;

return cloneString(newPath);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
xorl %r14d, %r14d
cmpb $0x7e, (%rdi)
jne 0xfd59
leaq 0x91c3(%rip), %rdi      # 0x18ebc
callq 0x3040
movq %rax, %r14
testq %rax, %rax
jne 0xfd14
leaq 0x91b4(%rip), %rdi      # 0x18ec1
xorl %eax, %eax
callq 0xa61f
leaq 0x1(%rbx), %r15
leaq 0x2(%rbx), %rax
cmpb $0x2f, 0x1(%rbx)
leaq 0x91d7(%rip), %rcx      # 0x18efe
leaq 0x91d4(%rip), %rdx      # 0x18f02
cmoveq %rcx, %rdx
cmoveq %rax, %r15
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0x939d
movq %rbx, %rdi
callq 0x3200
movq %rax, %r14
movq %r15, %rbx
movq %rbx, %rdi
callq 0x3200
addl %r14d, %eax
cmpl $0x200, %eax            # imm = 0x200
jb 0xfd79
leaq 0x9197(%rip), %rdi      # 0x18f09
xorl %eax, %eax
callq 0xa61f
movslq %r14d, %rax
leaq (%rsp,%rax), %rdi
movq %rbx, %rsi
callq 0x30e0
movq %rsp, %rax
xorl %edx, %edx
movq %rax, %rcx
cmpb $0x2f, %dl
sete %sil
incq %rcx
movq %rcx, %rdi
movq %rdi, %rcx
movzbl -0x1(%rdi), %edx
cmpl $0x2f, %edx
jne 0xfdb8
leaq 0x1(%rcx), %rdi
testb $0x1, %sil
movb $0x1, %sil
jne 0xfd9d
jmp 0xfdbc
testl %edx, %edx
je 0xfdc3
movb %dl, (%rax)
incq %rax
jmp 0xfd90
movb $0x0, (%rax)
leaq 0x9137(%rip), %rbx      # 0x18f04
movq %rsp, %r14
pushq $0x2f
popq %rbp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3760
cmpq %r14, %rax
sete %cl
testq %rax, %rax
je 0xfe16
testb %cl, %cl
jne 0xfe16
movq %rax, %r15
addq $0x4, %r15
movq %r14, %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0x79d1
leaq 0x1(%rax), %rdi
testq %rax, %rax
cmoveq %r14, %rdi
movq %r15, %rsi
callq 0x30e0
jmp 0xfdd3
leaq 0x9252(%rip), %rsi      # 0x1906f
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x7904
testl %eax, %eax
je 0xfe60
cmpl $0x2e2e2f, (%rsp)       # imm = 0x2E2E2F
je 0xfe60
movq %rbx, %rdi
callq 0x3200
cltq
leaq (%rsp,%rax), %rsi
addq $-0x3, %rsi
pushq $0x2f
popq %rdx
movq %rbx, %rdi
callq 0x79d1
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %rbx, %rcx
movb $0x0, (%rcx)
movq %rsp, %rdi
callq 0x3200
decl %eax
testl %eax, %eax
jle 0xfe7a
movl %eax, %eax
cmpb $0x2f, (%rsp,%rax)
jne 0xfe7a
movb $0x0, (%rsp,%rax)
movq %rsp, %rdi
callq 0x5ede
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq