// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38510
movq %rax, -0x420(%rbp)
movq -0x420(%rbp), %rdi
leaq 0xf34b1(%rip), %rsi     # 0x13b60e
callq 0x39c80
movq %rax, -0x420(%rbp)
movq -0x420(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x48188
movq -0x420(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x48387
leaq -0x410(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x26910
cmpq $0x0, %rax
jne 0x481b8
movq -0x420(%rbp), %rdi
callq 0x38620
movq $0x0, -0x8(%rbp)
jmp 0x48387
leaq -0x410(%rbp), %rdi
callq 0x38510
movq %rax, -0x418(%rbp)
movq -0x418(%rbp), %rdi
callq 0x483a0
cmpq $0x0, %rax
je 0x48228
movq -0x418(%rbp), %rax
movq %rax, -0x438(%rbp)
movq -0x418(%rbp), %rdi
callq 0x483a0
movq %rax, %rcx
movq -0x438(%rbp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0x48228
movq -0x418(%rbp), %rdi
leaq 0xf1e25(%rip), %rsi     # 0x13a041
callq 0x390d0
movq %rax, -0x418(%rbp)
jmp 0x4822a
movq -0x420(%rbp), %rdi
callq 0x483a0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x3, %rcx
movb %al, -0x439(%rbp)
jb 0x4828d
movq -0x420(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, -0x439(%rbp)
jne 0x4828d
movq -0x420(%rbp), %rax
movsbl 0x1(%rax), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, -0x439(%rbp)
jne 0x4828d
movq -0x420(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2f, %eax
sete %al
movb %al, -0x439(%rbp)
movb -0x439(%rbp), %al
testb $0x1, %al
jne 0x4829c
jmp 0x48356
movq -0x420(%rbp), %rdi
movl $0x3, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x39db0
movq -0x418(%rbp), %rdi
callq 0x483a0
cmpq $0x1, %rax
jbe 0x48351
movq -0x418(%rbp), %rax
movq %rax, -0x448(%rbp)
movq -0x418(%rbp), %rdi
callq 0x483a0
movq %rax, %rcx
movq -0x448(%rbp), %rax
addq %rcx, %rax
addq $-0x2, %rax
movq %rax, -0x428(%rbp)
movl $0x1, -0x42c(%rbp)
movq -0x428(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x48336
movq -0x428(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x428(%rbp)
movl -0x42c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x42c(%rbp)
jmp 0x48304
movq -0x418(%rbp), %rdi
movl -0x42c(%rbp), %eax
addl $0x1, %eax
xorl %edx, %edx
subl %eax, %edx
xorl %esi, %esi
callq 0x39db0
jmp 0x4822a
movq -0x418(%rbp), %rdi
movq -0x420(%rbp), %rsi
callq 0x39110
movq %rax, -0x418(%rbp)
movq -0x420(%rbp), %rdi
callq 0x38620
movq -0x418(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopw %cs:(%rax,%rax)