// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %rbx
movzbl -0x1(%rdi), %edx
movl %edx, %r12d
movl %r12d, %ecx
andl $0x7, %ecx
leaq 0x885d(%rip), %rax      # 0xe480
cmpb $0x4, %cl
ja 0x5c2e
movq (%rax,%rcx,8), %r13
jmp 0x5c31
xorl %r13d, %r13d
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x5c69
leaq 0x8524(%rip), %rsi      # 0xe164
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
shrl $0x3, %r12d
jmp 0x5c6c
movq -0x11(%rbx), %r12
jmp 0x5c6c
movzwl -0x5(%rbx), %r12d
jmp 0x5c6c
movl -0x9(%rbx), %r12d
jmp 0x5c6c
movzbl -0x3(%rbx), %r12d
jmp 0x5c6c
xorl %r12d, %r12d
movzbl %cl, %edx
decl %edx
cmpl $0x3, %edx
ja 0x5caf
leaq 0x84fb(%rip), %rsi      # 0xe178
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movzbl -0x2(%rbx), %edx
movzbl -0x3(%rbx), %esi
jmp 0x5caa
movl -0x5(%rbx), %edx
subl -0x9(%rbx), %edx
jmp 0x5cb1
movq -0x9(%rbx), %rdx
subq -0x11(%rbx), %rdx
jmp 0x5cb1
movzwl -0x3(%rbx), %edx
movzwl -0x5(%rbx), %esi
subq %rsi, %rdx
jmp 0x5cb1
xorl %edx, %edx
testq %rdx, %rdx
je 0x5cc0
cmpq $0x20, %r12
jae 0x5cc8
xorl %ebp, %ebp
jmp 0x5cf2
movq %rbx, %r14
jmp 0x5dca
movb $0x1, %bpl
cmpq $0x100, %r12            # imm = 0x100
jb 0x5cf2
movb $0x2, %bpl
cmpq $0x10000, %r12          # imm = 0x10000
jb 0x5cf2
movq %r12, %rdx
shrq $0x20, %rdx
cmpq $0x1, %rdx
movb $0x4, %bpl
sbbb $0x0, %bpl
movq %rbx, %r15
subq %r13, %r15
cmpb %bpl, %cl
je 0x5d75
cmpb $0x2, %bpl
jae 0x5d75
movzbl %bpl, %ecx
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %r13
leaq (%r12,%r13), %rdi
incq %rdi
callq 0x7970
testq %rax, %rax
je 0x5db4
movq %rax, %r14
movq %rax, 0x8(%rsp)
addq %r13, %r14
leaq 0x1(%r12), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21d0
movq %r15, %rdi
callq 0x79c6
movq 0x8(%rsp), %rax
movb %bpl, -0x1(%rax,%r13)
leaq 0x842f(%rip), %rax      # 0xe188
movq 0x10(%rsp), %rcx
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leal (,%r12,8), %eax
movb %al, -0x1(%r14)
jmp 0x5d8f
leaq (%r12,%r13), %rsi
incq %rsi
movq %r15, %rdi
callq 0x799b
testq %rax, %rax
je 0x5db4
movq %rax, %r14
addq %r13, %r14
movzbl -0x1(%r14), %eax
andl $0x7, %eax
decl %eax
cmpl $0x3, %eax
ja 0x5dca
leaq 0x83f7(%rip), %rcx      # 0xe19c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb %r12b, -0x2(%r14)
jmp 0x5dca
xorl %r14d, %r14d
jmp 0x5dca
movl %r12d, -0x5(%r14)
jmp 0x5dca
movq %r12, -0x9(%r14)
jmp 0x5dca
movw %r12w, -0x3(%r14)
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, -0x11(%r14)
jmp 0x5d8f
movw %r12w, -0x5(%r14)
jmp 0x5d8f
movl %r12d, -0x9(%r14)
jmp 0x5d8f
movb %r12b, -0x3(%r14)
jmp 0x5d8f