// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/t_zset.c
// Function: zremrangeGenericCommand
void zremrangeGenericCommand(client *c, int rangetype) {
    robj *key = c->argv[1];
    robj *zobj;
    int keyremoved = 0;
    unsigned long deleted = 0;
    zrangespec range;
    zlexrangespec lexrange;
    long start, end, llen;

    /* Step 1: Parse the range. */
    if (rangetype == ZRANGE_RANK) {
        if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) ||
            (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK))
            return;
    } else if (rangetype == ZRANGE_SCORE) {
        if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
            addReplyError(c,"min or max is not a float");
            return;
        }
    } else if (rangetype == ZRANGE_LEX) {
        if (zslParseLexRange(c->argv[2],c->argv[3],&lexrange) != C_OK) {
            addReplyError(c,"min or max not valid string range item");
            return;
        }
    }

    /* Step 2: Lookup & range sanity checks if needed. */
    if ((zobj = lookupKeyWriteOrReply(c,key,shared.czero)) == NULL ||
        checkType(c,zobj,OBJ_ZSET)) goto cleanup;

    if (rangetype == ZRANGE_RANK) {
        /* Sanitize indexes. */
        llen = zsetLength(zobj);
        if (start < 0) start = llen+start;
        if (end < 0) end = llen+end;
        if (start < 0) start = 0;

        /* Invariant: start >= 0, so this test will be true when end < 0.
         * The range is empty when start > end or start >= length. */
        if (start > end || start >= llen) {
            addReply(c,shared.czero);
            goto cleanup;
        }
        if (end >= llen) end = llen-1;
    }

    /* Step 3: Perform the range deletion operation. */
    if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
        switch(rangetype) {
        case ZRANGE_RANK:
            zobj->ptr = zzlDeleteRangeByRank(zobj->ptr,start+1,end+1,&deleted);
            break;
        case ZRANGE_SCORE:
            zobj->ptr = zzlDeleteRangeByScore(zobj->ptr,&range,&deleted);
            break;
        case ZRANGE_LEX:
            zobj->ptr = zzlDeleteRangeByLex(zobj->ptr,&lexrange,&deleted);
            break;
        }
        if (zzlLength(zobj->ptr) == 0) {
            dbDelete(c->db,key);
            keyremoved = 1;
        }
    } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
        zset *zs = zobj->ptr;
        switch(rangetype) {
        case ZRANGE_RANK:
            deleted = zslDeleteRangeByRank(zs->zsl,start+1,end+1,zs->dict);
            break;
        case ZRANGE_SCORE:
            deleted = zslDeleteRangeByScore(zs->zsl,&range,zs->dict);
            break;
        case ZRANGE_LEX:
            deleted = zslDeleteRangeByLex(zs->zsl,&lexrange,zs->dict);
            break;
        }
        if (htNeedsResize(zs->dict)) dictResize(zs->dict);
        if (dictSize(zs->dict) == 0) {
            dbDelete(c->db,key);
            keyremoved = 1;
        }
    } else {
        serverPanic("Unknown sorted set encoding");
    }

    /* Step 4: Notifications and reply. */
    if (deleted) {
        char *event[3] = {"zremrangebyrank","zremrangebyscore","zremrangebylex"};
        signalModifiedKey(c->db,key);
        notifyKeyspaceEvent(NOTIFY_ZSET,event[rangetype],key,c->db->id);
        if (keyremoved)
            notifyKeyspaceEvent(NOTIFY_GENERIC,"del",key,c->db->id);
    }
    server.dirty += deleted;
    addReplyLongLong(c,deleted);

cleanup:
    if (rangetype == ZRANGE_LEX) zslFreeLexRange(&lexrange);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebx
movq %rdi, %r14
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r15
movq $0x0, (%rsp)
testl %esi, %esi
je 0x5601b
cmpl $0x2, %ebx
je 0x56057
cmpl $0x1, %ebx
jne 0x5608a
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x30(%rsp), %rdx
callq 0x56346
testl %eax, %eax
je 0x5608a
leaq 0x70897(%rip), %rsi     # 0xc68b0
jmp 0x56074
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
jne 0x562e3
movq 0x40(%r14), %rax
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x44ba1
testl %eax, %eax
jne 0x562e3
jmp 0x5608a
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x18(%rsp), %rdx
callq 0x5646e
testl %eax, %eax
je 0x5608a
leaq 0x70856(%rip), %rsi     # 0xc68ca
movq %r14, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ffcb
leaq 0xb121f(%rip), %r13     # 0x1072b0
movq 0x20(%r13), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x44fbb
testq %rax, %rax
je 0x562ca
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
jne 0x562ca
testl %ebx, %ebx
je 0x56165
movl (%r12), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x56127
cmpl $0x5, %eax
jne 0x56324
cmpl $0x2, %ebx
je 0x562f2
cmpl $0x1, %ebx
je 0x561f4
testl %ebx, %ebx
jne 0x56309
movq 0x8(%r12), %rdi
movl 0x8(%rsp), %esi
movl 0x10(%rsp), %eax
subl %esi, %eax
leal 0x1(%rax), %ecx
movq %rcx, (%rsp)
addl %esi, %esi
leal 0x2(,%rax,2), %edx
callq 0x3ec1d
jmp 0x56304
movq 0x8(%r12), %r12
cmpl $0x2, %ebx
je 0x5620b
cmpl $0x1, %ebx
je 0x561df
testl %ebx, %ebx
jne 0x56222
movq (%r12), %rcx
movq 0x8(%r12), %rdi
movl 0x8(%rsp), %esi
incl %esi
movl 0x10(%rsp), %edx
incl %edx
callq 0x53e4a
jmp 0x5621e
movq %r12, %rdi
callq 0x551a5
movl %eax, %eax
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
jns 0x56181
addq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
jns 0x56193
addq %rax, %rcx
movq %rcx, 0x10(%rsp)
cmpq $0x0, 0x8(%rsp)
jns 0x561a4
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
cmpq %rcx, %rdx
jg 0x561ce
cmpq %rax, %rdx
jge 0x561ce
cmpq %rax, %rcx
jl 0x560cc
decq %rax
movq %rax, 0x10(%rsp)
jmp 0x560cc
movq 0x20(%r13), %rsi
movq %r14, %rdi
callq 0x3fc19
jmp 0x562ca
movq (%r12), %rdx
movq 0x8(%r12), %rdi
leaq 0x30(%rsp), %rsi
callq 0x53c16
jmp 0x5621e
movq 0x8(%r12), %rdi
leaq 0x30(%rsp), %rsi
movq %rsp, %rdx
callq 0x54ff9
jmp 0x56304
movq (%r12), %rdx
movq 0x8(%r12), %rdi
leaq 0x18(%rsp), %rsi
callq 0x53d10
movq %rax, (%rsp)
movq (%r12), %rdi
callq 0x3343a
testl %eax, %eax
je 0x56238
movq (%r12), %rdi
callq 0x317b9
movq (%r12), %rax
movq 0x28(%rax), %rcx
addq 0x48(%rax), %rcx
setne %bpl
jne 0x56258
movq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0x452f3
xorl %ebp, %ebp
cmpq $0x0, (%rsp)
je 0x562b0
movq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0x45220
movslq %ebx, %rax
leaq 0x703c7(%rip), %rcx     # 0xc663c
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq 0x10(%r14), %rax
movl 0x30(%rax), %ecx
movl $0x80, %edi
movq %r15, %rdx
callq 0x800c9
testb %bpl, %bpl
jne 0x562b0
movq 0x10(%r14), %rax
movl 0x30(%rax), %ecx
leaq 0x6b213(%rip), %rsi     # 0xc14b6
movl $0x4, %edi
movq %r15, %rdx
callq 0x800c9
movq (%rsp), %rsi
leaq 0xb059d(%rip), %rax     # 0x106858
addq %rsi, 0x710(%rax)
movq %r14, %rdi
callq 0x40606
cmpl $0x2, %ebx
jne 0x562e3
movq 0x18(%rsp), %rdi
callq 0x440f3
movq 0x20(%rsp), %rdi
callq 0x440f3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r12), %rdi
leaq 0x18(%rsp), %rsi
movq %rsp, %rdx
callq 0x550c0
movq %rax, 0x8(%r12)
movq 0x8(%r12), %rdi
callq 0x3ef20
movb $0x1, %bpl
cmpl $0x2, %eax
jb 0x5624a
jmp 0x56258
leaq 0x6d94b(%rip), %rdi     # 0xc3c76
leaq 0x70324(%rip), %rsi     # 0xc6656
movl $0x615, %edx            # imm = 0x615
callq 0x6558d
movl $0x1, %edi
callq 0x263d0