// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x8(%rsp)
testl %esi, %esi
je 0x5280e
cmpl $0x2, %ebp
je 0x5284a
cmpl $0x1, %ebp
jne 0x5287b
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x38(%rsp), %rdx
callq 0x52b1b
testl %eax, %eax
je 0x5287b
leaq 0x71124(%rip), %rsi     # 0xc3930
jmp 0x52867
movq 0x10(%rax), %rsi
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x41718
testl %eax, %eax
jne 0x52ac0
movq 0x40(%rbx), %rax
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x41718
testl %eax, %eax
jne 0x52ac0
jmp 0x5287b
movq 0x10(%rax), %rdi
movq 0x18(%rax), %rsi
leaq 0x20(%rsp), %rdx
callq 0x52c43
testl %eax, %eax
je 0x5287b
leaq 0x710e3(%rip), %rsi     # 0xc394a
movq %rbx, %rdi
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
leaq 0xafa8e(%rip), %r12     # 0x102310
movq 0x20(%r12), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41b2b
testq %rax, %rax
je 0x52aa7
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
jne 0x52aa7
testl %ebp, %ebp
je 0x52953
movl (%r15), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
je 0x52918
cmpl $0x5, %eax
jne 0x52af9
movq 0x8(%r15), %rdi
cmpl $0x2, %ebp
je 0x52acd
cmpl $0x1, %ebp
je 0x529d6
testl %ebp, %ebp
jne 0x52ae3
movl 0x18(%rsp), %esi
movl 0x10(%rsp), %eax
subl %esi, %eax
leal 0x1(%rax), %ecx
movq %rcx, 0x8(%rsp)
addl %esi, %esi
leal 0x2(,%rax,2), %edx
callq 0x3b8b4
jmp 0x52adc
movq 0x8(%r15), %r15
cmpl $0x2, %ebp
je 0x529ea
cmpl $0x1, %ebp
je 0x529c3
testl %ebp, %ebp
jne 0x52a00
movq (%r15), %rcx
movq 0x8(%r15), %rdi
movl 0x18(%rsp), %esi
incl %esi
movl 0x10(%rsp), %edx
incl %edx
callq 0x50711
jmp 0x529fb
movq %r15, %rdi
callq 0x51a88
movl %eax, %eax
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
jns 0x5296f
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
jns 0x52981
addq %rax, %rdx
movq %rdx, 0x10(%rsp)
testq %rcx, %rcx
jns 0x52991
movq $0x0, 0x18(%rsp)
xorl %ecx, %ecx
cmpq %rdx, %rcx
jg 0x529b1
cmpq %rax, %rcx
jae 0x529b1
cmpq %rax, %rdx
jb 0x528be
decq %rax
movq %rax, 0x10(%rsp)
jmp 0x528be
movq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x52ac0
movq (%r15), %rdx
movq 0x8(%r15), %rdi
leaq 0x38(%rsp), %rsi
callq 0x504e7
jmp 0x529fb
leaq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x51907
jmp 0x52adc
movq (%r15), %rdx
movq 0x8(%r15), %rdi
leaq 0x20(%rsp), %rsi
callq 0x505db
movq %rax, 0x8(%rsp)
movq (%r15), %rdi
callq 0x30340
testl %eax, %eax
je 0x52a14
movq (%r15), %rdi
callq 0x2e6d1
movq (%r15), %rax
movq 0x28(%rax), %rcx
movb $0x1, %r15b
addq 0x48(%rax), %rcx
jne 0x52a33
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x41e5f
xorl %r15d, %r15d
cmpq $0x0, 0x8(%rsp)
je 0x52a8c
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x41d90
movslq %ebp, %rax
leaq 0x70c6b(%rip), %rcx     # 0xc36bc
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
movl $0x80, %edi
movq %r14, %rdx
callq 0x7c665
testb %r15b, %r15b
jne 0x52a8c
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x6baa9(%rip), %rsi     # 0xbe528
movl $0x4, %edi
movq %r14, %rdx
callq 0x7c665
movq 0x8(%rsp), %rsi
leaq 0xaee10(%rip), %rax     # 0x1018a8
addq %rsi, 0x720(%rax)
movq %rbx, %rdi
callq 0x3d23f
cmpl $0x2, %ebp
jne 0x52ac0
movq 0x20(%rsp), %rdi
callq 0x40c8f
movq 0x28(%rsp), %rdi
callq 0x40c8f
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x519c5
movq %rax, %rdi
movq %rax, 0x8(%r15)
callq 0x3bb78
movb $0x1, %r15b
cmpl $0x2, %eax
jb 0x52a24
jmp 0x52a33
leaq 0x6e1c6(%rip), %rdi     # 0xc0cc6
leaq 0x70bcf(%rip), %rsi     # 0xc36d6
movl $0x615, %edx            # imm = 0x615
callq 0x619b4
movl $0x1, %edi
callq 0x263c0