// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 %r12
pushq %rbx
subq $0x50, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %r14
andq $0x0, 0x8(%rsp)
testl %esi, %esi
je 0x49d99
cmpl $0x2, %ebp
je 0x49dd5
cmpl $0x1, %ebp
jne 0x49e06
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x38(%rsp), %rdx
callq 0x4a088
testl %eax, %eax
je 0x49e06
leaq 0x6b015(%rip), %rsi     # 0xb4dac
jmp 0x49df2
movq 0x10(%rax), %rsi
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x3ab5e
testl %eax, %eax
jne 0x4a030
movq 0x40(%rbx), %rax
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x3ab5e
testl %eax, %eax
jne 0x4a030
jmp 0x49e06
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x20(%rsp), %rdx
callq 0x4a19e
testl %eax, %eax
je 0x49e06
leaq 0x6afd4(%rip), %rsi     # 0xb4dc6
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x36b6f
leaq 0xb0503(%rip), %r12     # 0xfa310
movq 0x20(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3af15
testq %rax, %rax
je 0x4a021
movq %rax, %r15
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
jne 0x4a021
testl %ebp, %ebp
je 0x49ed2
movl (%r15), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x49e97
cmpl $0x5, %eax
jne 0x4a068
movq 0x8(%r15), %rdi
cmpl $0x2, %ebp
je 0x4a03d
cmpl $0x1, %ebp
je 0x49f52
testl %ebp, %ebp
jne 0x4a053
movl 0x18(%rsp), %esi
incl %esi
movl 0x10(%rsp), %edx
incl %edx
leaq 0x8(%rsp), %rcx
callq 0x490d9
jmp 0x4a04c
movq 0x8(%r15), %r15
cmpl $0x2, %ebp
je 0x49f66
cmpl $0x1, %ebp
je 0x49f3f
testl %ebp, %ebp
jne 0x49f7c
movq (%r15), %rcx
movq 0x8(%r15), %rdi
movl 0x18(%rsp), %esi
incl %esi
movl 0x10(%rsp), %edx
incl %edx
callq 0x480b3
jmp 0x49f77
movq %r15, %rdi
callq 0x490f5
movl %eax, %eax
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
jns 0x49eee
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
jns 0x49f00
addq %rax, %rdx
movq %rdx, 0x10(%rsp)
testq %rcx, %rcx
jns 0x49f0d
andq $0x0, 0x18(%rsp)
xorl %ecx, %ecx
cmpq %rdx, %rcx
jg 0x49f2d
cmpq %rax, %rcx
jae 0x49f2d
cmpq %rax, %rdx
jb 0x49e47
decq %rax
movq %rax, 0x10(%rsp)
jmp 0x49e47
movq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x4a030
movq (%r15), %rdx
movq 0x8(%r15), %rdi
leaq 0x38(%rsp), %rsi
callq 0x47ee3
jmp 0x49f77
leaq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x48f90
jmp 0x4a04c
movq (%r15), %rdx
movq 0x8(%r15), %rdi
leaq 0x20(%rsp), %rsi
callq 0x47fb7
movq %rax, 0x8(%rsp)
movq (%r15), %rdi
callq 0x2bac1
testl %eax, %eax
je 0x49f90
movq (%r15), %rdi
callq 0x2a192
movq (%r15), %rax
movq 0x28(%rax), %rcx
movb $0x1, %r15b
addq 0x48(%rax), %rcx
jne 0x49faf
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x3b1df
xorl %r15d, %r15d
cmpq $0x0, 0x8(%rsp)
je 0x4a006
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x3b125
movslq %ebp, %rax
leaq 0x6ab6b(%rip), %rcx     # 0xb4b38
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
movl $0x80, %edi
movq %r14, %rdx
callq 0x6fb58
testb %r15b, %r15b
jne 0x4a006
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x6641d(%rip), %rsi     # 0xb0418
pushq $0x4
popq %rdi
movq %r14, %rdx
callq 0x6fb58
movq 0x8(%rsp), %rsi
leaq 0xaf896(%rip), %rax     # 0xf98a8
addq %rsi, 0x720(%rax)
movq %rbx, %rdi
callq 0x370a6
cmpl $0x2, %ebp
jne 0x4a030
leaq 0x20(%rsp), %rdi
callq 0x4832a
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x49040
movq %rax, %rdi
movq %rax, 0x8(%r15)
callq 0x486e9
movb $0x1, %r15b
testl %eax, %eax
jne 0x49faf
jmp 0x49fa0
leaq 0x6852f(%rip), %rdi     # 0xb259e
leaq 0x6aadc(%rip), %rsi     # 0xb4b52
movl $0x615, %edx            # imm = 0x615
callq 0x57b45
pushq $0x1
popq %rdi
callq 0x263c0