// File: /workspace/github_c_makefile_star2_O3/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 0x115d1
leaq 0x994b(%rip), %rdi      # 0x1aebc
callq 0x3040
movq %rax, %r14
testq %rax, %rax
jne 0x1158c
leaq 0x993c(%rip), %rdi      # 0x1aec1
xorl %eax, %eax
callq 0xb6c8
leaq 0x1(%rbx), %r15
leaq 0x2(%rbx), %rax
cmpb $0x2f, 0x1(%rbx)
leaq 0x995f(%rip), %rcx      # 0x1aefe
leaq 0x995c(%rip), %rdx      # 0x1af02
cmoveq %rcx, %rdx
cmoveq %rax, %r15
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0xa0ca
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 0x115f1
leaq 0x991f(%rip), %rdi      # 0x1af09
xorl %eax, %eax
callq 0xb6c8
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 0x11630
leaq 0x1(%rcx), %rdi
testb $0x1, %sil
movb $0x1, %sil
jne 0x11615
jmp 0x11634
testl %edx, %edx
je 0x1163b
movb %dl, (%rax)
incq %rax
jmp 0x11608
movb $0x0, (%rax)
leaq 0x98bf(%rip), %rsi      # 0x1af04
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x3760
testq %rax, %rax
sete %cl
cmpq %rbx, %rax
sete %dl
orb %cl, %dl
jne 0x116a8
leaq 0x989d(%rip), %r14      # 0x1af04
leaq 0x4(%rax), %r15
movq %rbx, %rdi
movq %rax, %rsi
movl $0x2f, %edx
callq 0x83ae
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
sete %cl
testq %rax, %rax
je 0x116a8
testb %cl, %cl
je 0x11667
leaq 0x99c0(%rip), %rsi      # 0x1b06f
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x82e1
testl %eax, %eax
je 0x116f4
cmpl $0x2e2e2f, (%rsp)       # imm = 0x2E2E2F
je 0x116f4
movq %rbx, %rdi
callq 0x3200
cltq
leaq (%rsp,%rax), %rsi
addq $-0x3, %rsi
movq %rbx, %rdi
movl $0x2f, %edx
callq 0x83ae
leaq 0x1(%rax), %rcx
testq %rax, %rax
cmoveq %rbx, %rcx
movb $0x0, (%rcx)
movq %rsp, %rdi
callq 0x3200
decl %eax
testl %eax, %eax
jle 0x1170e
movl %eax, %eax
cmpb $0x2f, (%rsp,%rax)
jne 0x1170e
movb $0x0, (%rsp,%rax)
movq %rsp, %rdi
callq 0x6402
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq