// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/deps/hiredis/sds.c
// Function: sdsMakeRoomFor
sds sdsMakeRoomFor(sds s, size_t addlen) {
    void *sh, *newsh;
    size_t avail = sdsavail(s);
    size_t len, newlen;
    char type, oldtype = s[-1] & SDS_TYPE_MASK;
    int hdrlen;

    /* Return ASAP if there is enough space left. */
    if (avail >= addlen) return s;

    len = sdslen(s);
    sh = (char*)s-sdsHdrSize(oldtype);
    newlen = (len+addlen);
    if (newlen < SDS_MAX_PREALLOC)
        newlen *= 2;
    else
        newlen += SDS_MAX_PREALLOC;

    type = sdsReqType(newlen);

    /* Don't use type 5: the user is appending to the string and type 5 is
     * not able to remember empty space, so sdsMakeRoomFor() must be called
     * at every appending operation. */
    if (type == SDS_TYPE_5) type = SDS_TYPE_8;

    hdrlen = sdsHdrSize(type);
    if (oldtype==type) {
        newsh = s_realloc(sh, hdrlen+newlen+1);
        if (newsh == NULL) return NULL;
        s = (char*)newsh+hdrlen;
    } else {
        /* Since the header size changes, need to move the string forward,
         * and can't use realloc */
        newsh = s_malloc(hdrlen+newlen+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, newlen);
    return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f180
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movsbl -0x1(%rax), %eax
andl $0x7, %eax
movb %al, -0x42(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0x1f012
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1f16b
movq -0x10(%rbp), %rdi
callq 0x1edf0
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movsbl -0x42(%rbp), %edi
callq 0x1ece0
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x100000, -0x40(%rbp)  # imm = 0x100000
jae 0x1f068
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
jmp 0x1f076
movq -0x40(%rbp), %rax
addq $0x100000, %rax         # imm = 0x100000
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1ec90
movb %al, -0x41(%rbp)
movsbl -0x41(%rbp), %eax
cmpl $0x0, %eax
jne 0x1f08f
movb $0x1, -0x41(%rbp)
movsbl -0x41(%rbp), %edi
callq 0x1ece0
movl %eax, -0x48(%rbp)
movsbl -0x42(%rbp), %eax
movsbl -0x41(%rbp), %ecx
cmpl %ecx, %eax
jne 0x1f0e5
movq -0x20(%rbp), %rdi
movslq -0x48(%rbp), %rsi
addq -0x40(%rbp), %rsi
addq $0x1, %rsi
callq 0x10460
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1f0d4
movq $0x0, -0x8(%rbp)
jmp 0x1f16b
movq -0x28(%rbp), %rax
movslq -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x1f156
movslq -0x48(%rbp), %rdi
addq -0x40(%rbp), %rdi
addq $0x1, %rdi
callq 0x10410
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1f10b
movq $0x0, -0x8(%rbp)
jmp 0x1f16b
movq -0x28(%rbp), %rdi
movslq -0x48(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0x1, %rdx
callq 0x103b0
movq -0x20(%rbp), %rdi
callq 0x10050
movq -0x28(%rbp), %rax
movslq -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movb -0x41(%rbp), %cl
movq -0x10(%rbp), %rax
movb %cl, -0x1(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1ef00
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x1f270
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)