// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0x18614
leaq 0x221a6(%rip), %rdi     # 0x3a788
movslq (%rdi,%rdx,4), %rdx
addq %rdi, %rdx
jmpq *%rdx
movzbl -0x2(%rbx), %edx
movzbl -0x3(%rbx), %edi
jmp 0x1860f
movl -0x5(%rbx), %edx
subl -0x9(%rbx), %edx
jmp 0x18616
movq -0x9(%rbx), %rdx
subq -0x11(%rbx), %rdx
jmp 0x18616
movzwl -0x3(%rbx), %edx
movzwl -0x5(%rbx), %edi
subq %rdi, %rdx
jmp 0x18616
xorl %edx, %edx
cmpq %rsi, %rdx
jae 0x18639
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x1865b
leaq 0x2216e(%rip), %rdx     # 0x3a798
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %r8d
jmp 0x1865e
movq %rbx, %r14
jmp 0x187a6
movq -0x11(%rbx), %r8
jmp 0x1865e
movzwl -0x5(%rbx), %r8d
jmp 0x1865e
movl -0x9(%rbx), %r8d
jmp 0x1865e
movzbl -0x3(%rbx), %r8d
jmp 0x1865e
xorl %r8d, %r8d
cmpb $0x4, %al
ja 0x1866f
leaq 0x22497(%rip), %rcx     # 0x3ab00
movq (%rcx,%rax,8), %r15
jmp 0x18672
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 0x18693
xorl %ecx, %ecx
jmp 0x186b6
movb $0x1, %cl
cmpq $0xff, %r13
jb 0x186b6
movb $0x2, %cl
cmpq $0xffff, %r13           # imm = 0xFFFF
jb 0x186b6
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 0x2260c(%rip), %rdx     # 0x3ace0
movq -0x8(%rdx,%rcx,8), %rbp
leaq 0x1(,%rbp), %rsi
addq %r13, %rsi
cmpb %r12b, %al
jne 0x18729
movq %r15, %rdi
callq 0xb3d0
testq %rax, %rax
je 0x18790
movq %rax, %r14
addq %rbp, %r14
movzbl -0x1(%r14), %eax
andl $0x7, %eax
decl %eax
cmpl $0x3, %eax
ja 0x187a6
leaq 0x220a2(%rip), %rcx     # 0x3a7bc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb %r13b, -0x2(%r14)
jmp 0x187a6
movq %r8, 0x8(%rsp)
movq %rsi, %rdi
callq 0xb390
testq %rax, %rax
je 0x18790
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 0xb340
movq %r15, %rdi
callq 0xb050
movq 0x10(%rsp), %rax
movb %r12b, -0x1(%rax,%rbp)
movzbl %r12b, %eax
decl %eax
leaq 0x22033(%rip), %rcx     # 0x3a7ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
movb %al, -0x3(%r14)
jmp 0x18700
xorl %r14d, %r14d
jmp 0x187a6
movl %r13d, -0x5(%r14)
jmp 0x187a6
movq %r13, -0x9(%r14)
jmp 0x187a6
movw %r13w, -0x3(%r14)
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movl %eax, -0x9(%r14)
jmp 0x18700
movq 0x8(%rsp), %rax
movq %rax, -0x11(%r14)
jmp 0x18700
movq 0x8(%rsp), %rax
movw %ax, -0x5(%r14)
jmp 0x18700