// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rdi, %rbx
xorl %r14d, %r14d
cmpb $0x7e, (%rdi)
jne 0x11879
leaq 0x9696(%rip), %rdi      # 0x1aeaf
callq 0x3040
movq %rax, %r14
testq %rax, %rax
jne 0x11834
leaq 0x9687(%rip), %rdi      # 0x1aeb4
xorl %eax, %eax
callq 0xb8d7
leaq 0x1(%rbx), %r15
leaq 0x2(%rbx), %rax
cmpb $0x2f, 0x1(%rbx)
leaq 0x96aa(%rip), %rcx      # 0x1aef1
leaq 0x96a7(%rip), %rdx      # 0x1aef5
cmoveq %rcx, %rdx
cmoveq %rax, %r15
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0xa2ce
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 0x11899
leaq 0x966a(%rip), %rdi      # 0x1aefc
xorl %eax, %eax
callq 0xb8d7
movslq %r14d, %rax
leaq (%rsp,%rax), %rdi
movq %rbx, %rsi
callq 0x30e0
movq %rsp, %rax
xorl %edx, %edx
movq %rax, %rcx
incq %rcx
movq %rcx, %rdi
movq %rdi, %rcx
movzbl -0x1(%rdi), %esi
cmpl $0x2f, %esi
jne 0x118cd
leaq 0x1(%rcx), %rdi
cmpb $0x2f, %dl
je 0x118b6
jmp 0x118d1
testl %esi, %esi
je 0x118db
movb %sil, (%rax)
incq %rax
movl %esi, %edx
jmp 0x118b0
movb $0x0, (%rax)
leaq 0x9612(%rip), %rsi      # 0x1aef7
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x3760
testq %rax, %rax
sete %cl
cmpq %rbx, %rax
sete %dl
orb %cl, %dl
jne 0x11948
leaq 0x95f0(%rip), %r14      # 0x1aef7
leaq 0x4(%rax), %r15
movq %rbx, %rdi
movq %rax, %rsi
movl $0x2f, %edx
callq 0x8586
leaq 0x1(%rax), %rdi
testq %rax, %rax
cmoveq %rbx, %rdi
movq %r15, %rsi
callq 0x30e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3760
cmpq %rbx, %rax
setne %cl
testq %rax, %rax
je 0x11948
testb %cl, %cl
jne 0x11907
leaq 0x9713(%rip), %rsi      # 0x1b062
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x84b9
testl %eax, %eax
je 0x11994
cmpl $0x2e2e2f, (%rsp)       # imm = 0x2E2E2F
je 0x11994
movq %rbx, %rdi
callq 0x3200
cltq
leaq (%rsp,%rax), %rsi
addq $-0x3, %rsi
movq %rbx, %rdi
movl $0x2f, %edx
callq 0x8586
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %rbx, %rcx
movb $0x0, (%rcx)
movq %rsp, %rdi
callq 0x3200
decl %eax
testl %eax, %eax
jle 0x119ae
movl %eax, %eax
cmpb $0x2f, (%rsp,%rax)
jne 0x119ae
movb $0x0, (%rsp,%rax)
movq %rsp, %rdi
callq 0x647e
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq