// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/util.c
// Function: getAbsolutePath
sds getAbsolutePath(char *filename) {
    char cwd[1024];
    sds abspath;
    sds relpath = sdsnew(filename);

    relpath = sdstrim(relpath," \r\n\t");
    if (relpath[0] == '/') return relpath; /* Path is already absolute. */

    /* If path is relative, join cwd and relative path. */
    if (getcwd(cwd,sizeof(cwd)) == NULL) {
        sdsfree(relpath);
        return NULL;
    }
    abspath = sdsnew(cwd);
    if (sdslen(abspath) && abspath[sdslen(abspath)-1] != '/')
        abspath = sdscat(abspath,"/");

    /* At this point we have the current path always ending with "/", and
     * the trimmed relative path. Try to normalize the obvious case of
     * trailing ../ elements at the start of the path.
     *
     * For every "../" we find in the filename, we remove it and also remove
     * the last element of the cwd, unless the current cwd is "/". */
    while (sdslen(relpath) >= 3 &&
           relpath[0] == '.' && relpath[1] == '.' && relpath[2] == '/')
    {
        sdsrange(relpath,3,-1);
        if (sdslen(abspath) > 1) {
            char *p = abspath + sdslen(abspath)-2;
            int trimlen = 1;

            while(*p != '/') {
                p--;
                trimlen++;
            }
            sdsrange(abspath,0,-(trimlen+1));
        }
    }

    /* Finally glue the two parts together. */
    abspath = sdscatsds(abspath,relpath);
    sdsfree(relpath);
    return abspath;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
callq 0x1de62
leaq 0x2fa2f(%rip), %rsi     # 0x55201
movq %rax, %rdi
callq 0x1f248
movq %rax, %rbx
cmpb $0x2f, (%rax)
je 0x259e5
movq %rsp, %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x123a0
testq %rax, %rax
je 0x25828
movq %rsp, %rdi
callq 0x1de62
movq %rax, %r14
movzbl -0x1(%rax), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x2584a
leaq 0x2f960(%rip), %rdx     # 0x55178
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movl %eax, %edx
shrl $0x3, %edx
jmp 0x2584c
xorl %r14d, %r14d
jmp 0x259da
movq -0x11(%r14), %rdx
jmp 0x2584c
movzwl -0x5(%r14), %edx
jmp 0x2584c
movl -0x9(%r14), %edx
jmp 0x2584c
movzbl -0x3(%r14), %edx
jmp 0x2584c
xorl %edx, %edx
testq %rdx, %rdx
je 0x258a3
cmpl $0x4, %ecx
ja 0x25887
movl %ecx, %ecx
leaq 0x2f92d(%rip), %rdx     # 0x5518c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x25889
movq -0x11(%r14), %rax
jmp 0x25889
movzwl -0x5(%r14), %eax
jmp 0x25889
movl -0x9(%r14), %eax
jmp 0x25889
movzbl -0x3(%r14), %eax
jmp 0x25889
xorl %eax, %eax
cmpb $0x2f, -0x1(%r14,%rax)
je 0x258a3
leaq 0x2e690(%rip), %rsi     # 0x53f28
movq %r14, %rdi
callq 0x1e73d
movq %rax, %r14
leaq -0x3(%r14), %r15
leaq 0x2f91a(%rip), %r12     # 0x551c8
leaq 0x2f8ff(%rip), %r13     # 0x551b4
leaq 0x2f8e4(%rip), %rbp     # 0x551a0
movzbl -0x1(%rbx), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x258f0
movslq (%rbp,%rcx,4), %rcx
addq %rbp, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x258f2
movq -0x11(%rbx), %rax
jmp 0x258f2
movzwl -0x5(%rbx), %eax
jmp 0x258f2
movl -0x9(%rbx), %eax
jmp 0x258f2
movzbl -0x3(%rbx), %eax
jmp 0x258f2
xorl %eax, %eax
cmpq $0x3, %rax
jb 0x259cc
cmpb $0x2e, (%rbx)
jne 0x259cc
cmpb $0x2e, 0x1(%rbx)
jne 0x259cc
cmpb $0x2f, 0x2(%rbx)
jne 0x259cc
movq %rbx, %rdi
movl $0x3, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1f352
movzbl -0x1(%r14), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x25965
movslq (%r13,%rcx,4), %rdx
addq %r13, %rdx
jmpq *%rdx
movl %eax, %edx
shrl $0x3, %edx
jmp 0x25967
movq -0x11(%r14), %rdx
jmp 0x25967
movzwl -0x5(%r14), %edx
jmp 0x25967
movl -0x9(%r14), %edx
jmp 0x25967
movzbl -0x3(%r14), %edx
jmp 0x25967
xorl %edx, %edx
cmpq $0x2, %rdx
jb 0x258bc
cmpl $0x4, %ecx
ja 0x259a0
movl %ecx, %ecx
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x259a2
movq -0x11(%r14), %rax
jmp 0x259a2
movzwl -0x5(%r14), %eax
jmp 0x259a2
movl -0x9(%r14), %eax
jmp 0x259a2
movzbl -0x3(%r14), %eax
jmp 0x259a2
xorl %eax, %eax
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
cmpb $0x2f, -0x2(%r14,%rax)
je 0x259bd
addq %r15, %rax
decl %edx
cmpb $0x2f, (%rax)
leaq -0x1(%rax), %rax
jne 0x259b2
movq %r14, %rdi
xorl %esi, %esi
callq 0x1f352
jmp 0x258bc
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1e764
movq %rax, %r14
movq %rbx, %rdi
callq 0x1ded3
movq %r14, %rbx
movq %rbx, %rax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq