// File: /workspace/github_c_makefile_star2_O3/antirez[P]stonky/sds.c
// Function: sdsRemoveFreeSpace
sds sdsRemoveFreeSpace(sds s) {
    void *sh, *newsh;
    char type, oldtype = s[-1] & SDS_TYPE_MASK;
    int hdrlen, oldhdrlen = sdsHdrSize(oldtype);
    size_t len = sdslen(s);
    size_t avail = sdsavail(s);
    sh = (char*)s-oldhdrlen;

    /* Return ASAP if there is no space left. */
    if (avail == 0) return s;

    /* Check what would be the minimum SDS header that is just good enough to
     * fit this string. */
    type = sdsReqType(len);
    hdrlen = sdsHdrSize(type);

    /* If the type is the same, or at least a large enough type is still
     * required, we just realloc(), letting the allocator to do the copy
     * only if really needed. Otherwise if the change is huge, we manually
     * reallocate the string to use the different header type. */
    if (oldtype==type || type > SDS_TYPE_8) {
        newsh = s_realloc(sh, oldhdrlen+len+1);
        if (newsh == NULL) return NULL;
        s = (char*)newsh+oldhdrlen;
    } else {
        newsh = s_malloc(hdrlen+len+1);
        if (newsh == NULL) return NULL;
        memcpy((char*)newsh+hdrlen, s, len+1);
        s_free(sh);
        s = (char*)newsh+hdrlen;
        s[-1] = type;
        sdssetlen(s, len);
    }
    sdssetalloc(s, len);
    return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzbl -0x1(%rdi), %ecx
movl %ecx, %r12d
movl %r12d, %eax
andl $0x7, %eax
cmpb $0x4, %al
ja 0x5a6c
leaq 0x8a0a(%rip), %rdx      # 0xe470
movq (%rdx,%rax,8), %r13
jmp 0x5a6f
xorl %r13d, %r13d
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x5aa7
leaq 0x86e6(%rip), %rdx      # 0xe164
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %r12d
jmp 0x5aaa
movq -0x11(%rbx), %r12
jmp 0x5aaa
movzwl -0x5(%rbx), %r12d
jmp 0x5aaa
movl -0x9(%rbx), %r12d
jmp 0x5aaa
movzbl -0x3(%rbx), %r12d
jmp 0x5aaa
xorl %r12d, %r12d
movzbl %al, %ecx
decl %ecx
cmpl $0x3, %ecx
ja 0x5b06
leaq 0x86bd(%rip), %rdx      # 0xe178
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movzbl -0x2(%rbx), %ecx
movzbl -0x3(%rbx), %edx
jmp 0x5ae8
movl -0x5(%rbx), %ecx
subl -0x9(%rbx), %ecx
jmp 0x5aeb
movq -0x9(%rbx), %rcx
subq -0x11(%rbx), %rcx
jmp 0x5aeb
movzwl -0x3(%rbx), %ecx
movzwl -0x5(%rbx), %edx
subq %rdx, %rcx
testq %rcx, %rcx
je 0x5b06
movq %rbx, %r15
subq %r13, %r15
cmpq $0x20, %r12
jae 0x5b0e
movl $0x1, %r13d
xorl %ebp, %ebp
jmp 0x5b4b
movq %rbx, %r14
jmp 0x5bda
cmpq $0x100, %r12            # imm = 0x100
setb %cl
cmpb $0x1, %al
setne %al
testb %al, %cl
jne 0x5b42
leaq (%r12,%r13), %rsi
incq %rsi
movq %r15, %rdi
callq 0x774b
testq %rax, %rax
je 0x5b9b
movq %rax, %r14
addq %r13, %r14
movb -0x1(%rax,%r13), %bpl
jmp 0x5ba4
movb $0x1, %bpl
movl $0x3, %r13d
leaq (%r12,%r13), %rdi
incq %rdi
callq 0x7720
testq %rax, %rax
je 0x5b9b
movq %rax, %r14
leaq 0x1(%r12), %rdx
movq %rax, (%rsp)
addq %r13, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %r15, %rdi
callq 0x7776
movq (%rsp), %rax
movb %bpl, -0x1(%rax,%r13)
cmpq $0x1f, %r12
ja 0x5ba0
leal (,%r12,8), %ebp
movb %bpl, -0x1(%r14)
jmp 0x5ba4
xorl %r14d, %r14d
jmp 0x5bda
movb %r12b, -0x3(%r14)
andb $0x7, %bpl
movzbl %bpl, %eax
decl %eax
cmpl $0x3, %eax
ja 0x5bda
leaq 0x85ce(%rip), %rcx      # 0xe188
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb %r12b, -0x2(%r14)
jmp 0x5bda
movl %r12d, -0x5(%r14)
jmp 0x5bda
movq %r12, -0x9(%r14)
jmp 0x5bda
movw %r12w, -0x3(%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq