// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0x362b0
leaq 0x806a5(%rip), %rsi     # 0xc0ab1
movq %rax, %rdi
callq 0x376a4
movq %rax, %rbx
cmpb $0x2f, (%rax)
je 0x40609
movq %rsp, %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x26910
testq %rax, %rax
je 0x40466
movq %rsp, %rdi
callq 0x362b0
movq %rax, %r14
movzbl -0x1(%rax), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x404d4
leaq 0x805d2(%rip), %rdx     # 0xc0a28
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
movl %eax, %edx
shrl $0x3, %edx
jmp 0x40486
xorl %r14d, %r14d
jmp 0x405fe
movq -0x11(%r14), %rdx
jmp 0x40486
movzwl -0x5(%r14), %edx
jmp 0x40486
movl -0x9(%r14), %edx
jmp 0x40486
movzbl -0x3(%r14), %edx
testq %rdx, %rdx
je 0x404d4
movl %ecx, %ecx
leaq 0x805a8(%rip), %rdx     # 0xc0a3c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x404ba
movq -0x11(%r14), %rax
jmp 0x404ba
movzwl -0x5(%r14), %eax
jmp 0x404ba
movl -0x9(%r14), %eax
jmp 0x404ba
movzbl -0x3(%r14), %eax
cmpb $0x2f, -0x1(%r14,%rax)
je 0x404d4
leaq 0x91449(%rip), %rsi     # 0xd1912
movq %r14, %rdi
callq 0x36b9c
movq %rax, %r14
leaq -0x3(%r14), %r15
leaq 0x80571(%rip), %r12     # 0xc0a50
leaq 0x8057e(%rip), %r13     # 0xc0a64
leaq 0x8058b(%rip), %rbp     # 0xc0a78
movzbl -0x1(%rbx), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x405f0
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x40522
movq -0x11(%rbx), %rax
jmp 0x40522
movzwl -0x5(%rbx), %eax
jmp 0x40522
movl -0x9(%rbx), %eax
jmp 0x40522
movzbl -0x3(%rbx), %eax
cmpq $0x3, %rax
jb 0x405f0
cmpb $0x2e, (%rbx)
jne 0x405f0
cmpb $0x2e, 0x1(%rbx)
jne 0x405f0
cmpb $0x2f, 0x2(%rbx)
jne 0x405f0
movq %rbx, %rdi
movl $0x3, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x377b2
movzbl -0x1(%r14), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x404ed
movslq (%r13,%rcx,4), %rdx
addq %r13, %rdx
jmpq *%rdx
movl %eax, %edx
shrl $0x3, %edx
jmp 0x40593
movq -0x11(%r14), %rdx
jmp 0x40593
movzwl -0x5(%r14), %edx
jmp 0x40593
movl -0x9(%r14), %edx
jmp 0x40593
movzbl -0x3(%r14), %edx
cmpq $0x2, %rdx
jb 0x404ed
movl %ecx, %ecx
movslq (%rbp,%rcx,4), %rcx
addq %rbp, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x405c6
movq -0x11(%r14), %rax
jmp 0x405c6
movzwl -0x5(%r14), %eax
jmp 0x405c6
movl -0x9(%r14), %eax
jmp 0x405c6
movzbl -0x3(%r14), %eax
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
cmpb $0x2f, -0x2(%r14,%rax)
je 0x405e1
addq %r15, %rax
decl %edx
cmpb $0x2f, (%rax)
leaq -0x1(%rax), %rax
jne 0x405d6
movq %r14, %rdi
xorl %esi, %esi
callq 0x377b2
jmp 0x404ed
movq %r14, %rdi
movq %rbx, %rsi
callq 0x36bc3
movq %rax, %r14
movq %rbx, %rdi
callq 0x36330
movq %r14, %rbx
movq %rbx, %rax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq