// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/t_zset.c
// Function: zremrangeGenericCommand
void zremrangeGenericCommand(redisClient *c, int rangetype) {
    robj *key = c->argv[1];
    robj *zobj;
    int keyremoved = 0;
    unsigned long deleted;
    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) != REDIS_OK) ||
            (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != REDIS_OK))
            return;
    } else if (rangetype == ZRANGE_SCORE) {
        if (zslParseRange(c->argv[2],c->argv[3],&range) != REDIS_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) != REDIS_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,REDIS_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 == REDIS_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 == REDIS_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 {
        redisPanic("Unknown sorted set encoding");
    }

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

    server.dirty += deleted;

    // 回复被删除元素的个数
    addReplyLongLong(c,deleted);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x50f1d
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x68(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
jne 0x50f13
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x70(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x50f18
jmp 0x51351
jmp 0x50fa7
cmpl $0x1, -0xc(%rbp)
jne 0x50f60
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x48(%rbp), %rdx
callq 0x51360
cmpl $0x0, %eax
je 0x50f5e
movq -0x8(%rbp), %rdi
leaq 0x92526(%rip), %rsi     # 0xe347a
callq 0x35d40
jmp 0x51351
jmp 0x50fa5
cmpl $0x2, -0xc(%rbp)
jne 0x50fa3
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rsi
leaq -0x60(%rbp), %rdx
callq 0x51560
cmpl $0x0, %eax
je 0x50fa1
movq -0x8(%rbp), %rdi
leaq 0x924fd(%rip), %rsi     # 0xe3494
callq 0x35d40
jmp 0x51351
jmp 0x50fa3
jmp 0x50fa5
jmp 0x50fa7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0xc319a(%rip), %rax     # 0x114150
movq 0x20(%rax), %rdx
callq 0x3c110
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x50fe0
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x3, %edx
callq 0x3abb0
cmpl $0x0, %eax
je 0x50fe5
jmp 0x51342
cmpl $0x0, -0xc(%rbp)
jne 0x51078
movq -0x20(%rbp), %rdi
callq 0x50080
movl %eax, %eax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x68(%rbp)
jge 0x51011
movq -0x78(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x70(%rbp)
jge 0x51024
movq -0x78(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x68(%rbp)
jge 0x51033
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jg 0x51047
movq -0x68(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x51060
movq -0x8(%rbp), %rdi
leaq 0xc30fe(%rip), %rax     # 0x114150
movq 0x20(%rax), %rsi
callq 0x35a70
jmp 0x51342
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x51076
movq -0x78(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x51078
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x5, %eax
jne 0x51159
movl -0xc(%rbp), %eax
movl %eax, -0xa4(%rbp)
testl %eax, %eax
je 0x510b6
jmp 0x5109c
movl -0xa4(%rbp), %eax
subl $0x1, %eax
je 0x510e8
jmp 0x510a9
movl -0xa4(%rbp), %eax
subl $0x2, %eax
je 0x5110a
jmp 0x5112a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x68(%rbp), %rax
addq $0x1, %rax
movl %eax, %esi
movq -0x70(%rbp), %rax
addq $0x1, %rax
movl %eax, %edx
leaq -0x30(%rbp), %rcx
callq 0x50020
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x5112a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x4fe50
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x5112a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x4ff40
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4f0e0
cmpl $0x0, %eax
jne 0x51154
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x3c4f0
movl $0x1, -0x24(%rbp)
jmp 0x51282
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x5125e
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xa8(%rbp)
testl %eax, %eax
je 0x511a3
jmp 0x51189
movl -0xa8(%rbp), %eax
subl $0x1, %eax
je 0x511d1
jmp 0x51196
movl -0xa8(%rbp), %eax
subl $0x2, %eax
je 0x511ef
jmp 0x5120b
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x68(%rbp), %rax
addq $0x1, %rax
movl %eax, %esi
movq -0x70(%rbp), %rax
addq $0x1, %rax
movl %eax, %edx
movq -0x80(%rbp), %rax
movq (%rax), %rcx
callq 0x4e410
movq %rax, -0x30(%rbp)
jmp 0x5120b
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x80(%rbp), %rax
movq (%rax), %rdx
leaq -0x48(%rbp), %rsi
callq 0x4dec0
movq %rax, -0x30(%rbp)
jmp 0x5120b
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x80(%rbp), %rax
movq (%rax), %rdx
leaq -0x60(%rbp), %rsi
callq 0x4e150
movq %rax, -0x30(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rdi
callq 0x25700
cmpl $0x0, %eax
je 0x51228
movq -0x80(%rbp), %rax
movq (%rax), %rdi
callq 0x23250
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rax
movq -0x80(%rbp), %rcx
movq (%rcx), %rcx
addq 0x48(%rcx), %rax
cmpq $0x0, %rax
jne 0x5125c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x3c4f0
movl $0x1, -0x24(%rbp)
jmp 0x51280
leaq 0x90236(%rip), %rdi     # 0xe149b
leaq 0x92022(%rip), %rsi     # 0xe328e
movl $0x82a, %edx            # imm = 0x82A
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x51282
cmpq $0x0, -0x30(%rbp)
je 0x51315
movq 0xbb9cc(%rip), %rax     # 0x10cc60
movq %rax, -0xa0(%rbp)
movq 0xbb9c6(%rip), %rax     # 0x10cc68
movq %rax, -0x98(%rbp)
movq 0xbb9c0(%rip), %rax     # 0x10cc70
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x3c3d0
movslq -0xc(%rbp), %rax
movq -0xa0(%rbp,%rax,8), %rsi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x80, %edi
callq 0x814a0
cmpl $0x0, -0x24(%rbp)
je 0x51313
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x4, %edi
leaq 0x8d1f7(%rip), %rsi     # 0xde505
callq 0x814a0
jmp 0x51315
movq -0x30(%rbp), %rcx
leaq 0xc25d8(%rip), %rax     # 0x1138f8
addq 0x560(%rax), %rcx
leaq 0xc25ca(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x36480
cmpl $0x2, -0xc(%rbp)
jne 0x51351
leaq -0x60(%rbp), %rdi
callq 0x4ea60
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)