// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/intset.c
// Function: intsetAdd
intset *intsetAdd(intset *is, int64_t value, uint8_t *success) {
    uint8_t valenc = _intsetValueEncoding(value);
    uint32_t pos;
    if (success) *success = 1;

    /* Upgrade encoding if necessary. If we need to upgrade, we know that
     * this value should be either appended (if > 0) or prepended (if < 0),
     * because it lies outside the range of existing values. */
    if (valenc > intrev32ifbe(is->encoding)) {
        /* This always succeeds, so we don't need to curry *success. */
        return intsetUpgradeAndAdd(is,value);
    } else {
        /* Abort if the value is already present in the set.
         * This call will populate "pos" with the right position to insert
         * the value when it cannot be found. */
        if (intsetSearch(is,value,&pos)) {
            if (success) *success = 0;
            return is;
        }

        is = intsetResize(is,intrev32ifbe(is->length)+1);
        if (pos < intrev32ifbe(is->length)) intsetMoveTail(is,pos,pos+1);
    }

    _intsetSet(is,pos,value);
    is->length = intrev32ifbe(intrev32ifbe(is->length)+1);
    return is;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x80000000(%rsi), %rax
movswq %r14w, %rcx
xorl %edx, %edx
cmpq %rsi, %rcx
setne %dl
leal 0x2(,%rdx,2), %esi
testq %r15, %r15
je 0x68667
movb $0x1, (%r15)
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rax
movl $0x8, %ecx
cmovbl %ecx, %esi
movl (%rbx), %ebp
cmpl %esi, %ebp
jae 0x68736
leaq -0x8000(%r14), %rsi
xorl %edi, %edi
cmpq $-0x10000, %rsi         # imm = 0xFFFF0000
setb %dil
movslq 0x4(%rbx), %r15
leal 0x1(%r15), %esi
leal 0x1(%rdi), %r8d
cmpq %rdx, %rax
leal 0x2(%rdi,%rdi), %eax
cmovbl %ecx, %eax
movl %eax, (%rbx)
movzbl %r8b, %eax
movl $0x3, %ecx
cmovael %eax, %ecx
shll %cl, %esi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x3b349
movq %rax, %rbx
testq %r15, %r15
je 0x68728
movq %r14, %rax
shrq $0x3f, %rax
addq %r15, %rax
movzbl %bpl, %ecx
cmpb $0x4, %bpl
je 0x686f3
cmpl $0x8, %ecx
jne 0x686fa
movq (%rbx,%r15,8), %rdx
jmp 0x68700
movslq 0x4(%rbx,%r15,4), %rdx
jmp 0x68700
movswq 0x6(%rbx,%r15,2), %rdx
movl (%rbx), %esi
cmpl $0x4, %esi
je 0x68712
cmpl $0x8, %esi
jne 0x68718
movq %rdx, (%rbx,%rax,8)
jmp 0x6871d
movl %edx, 0x4(%rbx,%rax,4)
jmp 0x6871d
movw %dx, 0x6(%rbx,%rax,2)
decq %r15
decq %rax
testq %r15, %r15
jne 0x686e2
testq %r14, %r14
js 0x6875c
movslq 0x4(%rbx), %rax
jmp 0x687ef
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x68820
testb %al, %al
je 0x68771
testq %r15, %r15
je 0x68812
movb $0x0, (%r15)
jmp 0x68812
movl (%rbx), %eax
cmpl $0x4, %eax
je 0x687ba
cmpl $0x8, %eax
jne 0x687c0
movq %r14, 0x8(%rbx)
jmp 0x6880f
movl 0x4(%rbx), %esi
incl %esi
imull %ebp, %esi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x3b349
movq %rax, %rbx
movl 0x4(%rsp), %eax
movl 0x4(%rbx), %edx
cmpl %eax, %edx
jbe 0x687ea
subl %eax, %edx
leal 0x1(%rax), %ecx
movl (%rbx), %esi
movq %rbx, %rdi
addq $0x8, %rdi
cmpl $0x4, %esi
je 0x687c7
cmpl $0x8, %esi
jne 0x687d6
leaq (%rdi,%rax,8), %rsi
leaq (%rdi,%rcx,8), %rdi
movl $0x3, %ecx
jmp 0x687e3
movl %r14d, 0x8(%rbx)
jmp 0x6880f
movw %r14w, 0x8(%rbx)
jmp 0x6880f
leaq (%rdi,%rax,4), %rsi
leaq (%rdi,%rcx,4), %rdi
movl $0x2, %ecx
jmp 0x687e3
leaq (%rdi,%rax,2), %rsi
leaq (%rdi,%rcx,2), %rdi
movl $0x1, %ecx
shll %cl, %edx
callq 0x267f0
movslq 0x4(%rsp), %rax
movl (%rbx), %ecx
cmpl $0x4, %ecx
je 0x68802
cmpl $0x8, %ecx
jne 0x68809
movq %r14, 0x8(%rbx,%rax,8)
jmp 0x6880f
movl %r14d, 0x8(%rbx,%rax,4)
jmp 0x6880f
movw %r14w, 0x8(%rbx,%rax,2)
incl 0x4(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq