// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movzbl -0x1(%rdi), %ecx
movl %ecx, %r8d
movl %r8d, %eax
andl $0x7, %eax
leal -0x1(%rax), %edx
cmpl $0x3, %edx
ja 0x1db1a
leaq 0x292f8(%rip), %rdi     # 0x46de0
movslq (%rdi,%rdx,4), %rdx
addq %rdi, %rdx
jmpq *%rdx
movzbl -0x2(%rbx), %edx
movzbl -0x3(%rbx), %edi
jmp 0x1db15
movl -0x5(%rbx), %edx
subl -0x9(%rbx), %edx
jmp 0x1db1c
movq -0x9(%rbx), %rdx
subq -0x11(%rbx), %rdx
jmp 0x1db1c
movzwl -0x3(%rbx), %edx
movzwl -0x5(%rbx), %edi
subq %rdi, %rdx
jmp 0x1db1c
xorl %edx, %edx
cmpq %rsi, %rdx
jae 0x1dcc1
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1db5d
leaq 0x292bc(%rip), %rdx     # 0x46df0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %r8d
jmp 0x1db60
movq -0x11(%rbx), %r8
jmp 0x1db60
movzwl -0x5(%rbx), %r8d
jmp 0x1db60
movl -0x9(%rbx), %r8d
jmp 0x1db60
movzbl -0x3(%rbx), %r8d
jmp 0x1db60
xorl %r8d, %r8d
cmpb $0x4, %al
ja 0x1db71
leaq 0x295ed(%rip), %rcx     # 0x47158
movq (%rcx,%rax,8), %r15
jmp 0x1db74
xorl %r15d, %r15d
addq %r8, %rsi
leaq (%rsi,%rsi), %rcx
movl $0x100000, %edx         # imm = 0x100000
leaq (%rsi,%rdx), %r13
cmpq %rdx, %rsi
cmovbq %rcx, %r13
cmpq $0x20, %r13
jae 0x1db95
xorl %ecx, %ecx
jmp 0x1dbb8
movb $0x1, %cl
cmpq $0xff, %r13
jb 0x1dbb8
movb $0x2, %cl
cmpq $0xffff, %r13           # imm = 0xFFFF
jb 0x1dbb8
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %r13
movb $0x4, %cl
sbbb $0x0, %cl
addq %rbx, %r15
movzbl %cl, %ecx
cmpb $0x2, %cl
movl $0x1, %r12d
cmovael %ecx, %r12d
movsbq %r12b, %rcx
leaq 0x29762(%rip), %rdx     # 0x47338
movq -0x8(%rdx,%rcx,8), %rbp
leaq 0x1(,%rbp), %rsi
addq %r13, %rsi
cmpb %r12b, %al
jne 0x1dc25
movq %r15, %rdi
callq 0x104b0
testq %rax, %rax
je 0x1dc8d
movq %rax, %r14
addq %rbp, %r14
movzbl -0x1(%rax,%rbp), %eax
andl $0x7, %eax
decl %eax
cmpl $0x3, %eax
ja 0x1dcbe
leaq 0x291f8(%rip), %rcx     # 0x46e14
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r8, 0x8(%rsp)
movq %rsi, %rdi
callq 0x10450
testq %rax, %rax
je 0x1dc8d
movq %rax, %r14
movq %rax, 0x10(%rsp)
addq %rbp, %r14
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x10400
movq %r15, %rdi
callq 0x10060
movq 0x10(%rsp), %rax
movb %r12b, -0x1(%rax,%rbp)
movzbl %r12b, %eax
decl %eax
leaq 0x2918f(%rip), %rcx     # 0x46e04
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
movb %al, -0x3(%r14)
movb %r13b, -0x2(%r14)
jmp 0x1dcbe
xorl %ebx, %ebx
jmp 0x1dcc1
movq 0x8(%rsp), %rax
movl %eax, -0x9(%r14)
movl %r13d, -0x5(%r14)
jmp 0x1dcbe
movq 0x8(%rsp), %rax
movq %rax, -0x11(%r14)
movq %r13, -0x9(%r14)
jmp 0x1dcbe
movq 0x8(%rsp), %rax
movw %ax, -0x5(%r14)
movw %r13w, -0x3(%r14)
movq %r14, %rbx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq