// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/t_set.c
// Function: sinterGenericCommand
void sinterGenericCommand(client *c, robj **setkeys,
                          unsigned long setnum, robj *dstkey) {
    robj **sets = zmalloc(sizeof(robj*)*setnum);
    setTypeIterator *si;
    robj *eleobj, *dstset = NULL;
    int64_t intobj;
    void *replylen = NULL;
    unsigned long j, cardinality = 0;
    int encoding;

    for (j = 0; j < setnum; j++) {
        robj *setobj = dstkey ?
            lookupKeyWrite(c->db,setkeys[j]) :
            lookupKeyRead(c->db,setkeys[j]);
        if (!setobj) {
            zfree(sets);
            if (dstkey) {
                if (dbDelete(c->db,dstkey)) {
                    signalModifiedKey(c->db,dstkey);
                    server.dirty++;
                }
                addReply(c,shared.czero);
            } else {
                addReply(c,shared.emptymultibulk);
            }
            return;
        }
        if (checkType(c,setobj,OBJ_SET)) {
            zfree(sets);
            return;
        }
        sets[j] = setobj;
    }
    /* Sort sets from the smallest to largest, this will improve our
     * algorithm's performance */
    qsort(sets,setnum,sizeof(robj*),qsortCompareSetsByCardinality);

    /* The first thing we should output is the total number of elements...
     * since this is a multi-bulk write, but at this stage we don't know
     * the intersection set size, so we use a trick, append an empty object
     * to the output list and save the pointer to later modify it with the
     * right length */
    if (!dstkey) {
        replylen = addDeferredMultiBulkLength(c);
    } else {
        /* If we have a target key where to store the resulting set
         * create this key with an empty set inside */
        dstset = createIntsetObject();
    }

    /* Iterate all the elements of the first (smallest) set, and test
     * the element against all the other sets, if at least one set does
     * not include the element it is discarded */
    si = setTypeInitIterator(sets[0]);
    while((encoding = setTypeNext(si,&eleobj,&intobj)) != -1) {
        for (j = 1; j < setnum; j++) {
            if (sets[j] == sets[0]) continue;
            if (encoding == OBJ_ENCODING_INTSET) {
                /* intset with intset is simple... and fast */
                if (sets[j]->encoding == OBJ_ENCODING_INTSET &&
                    !intsetFind((intset*)sets[j]->ptr,intobj))
                {
                    break;
                /* in order to compare an integer with an object we
                 * have to use the generic function, creating an object
                 * for this */
                } else if (sets[j]->encoding == OBJ_ENCODING_HT) {
                    eleobj = createStringObjectFromLongLong(intobj);
                    if (!setTypeIsMember(sets[j],eleobj)) {
                        decrRefCount(eleobj);
                        break;
                    }
                    decrRefCount(eleobj);
                }
            } else if (encoding == OBJ_ENCODING_HT) {
                /* Optimization... if the source object is integer
                 * encoded AND the target set is an intset, we can get
                 * a much faster path. */
                if (eleobj->encoding == OBJ_ENCODING_INT &&
                    sets[j]->encoding == OBJ_ENCODING_INTSET &&
                    !intsetFind((intset*)sets[j]->ptr,(long)eleobj->ptr))
                {
                    break;
                /* else... object to object check is easy as we use the
                 * type agnostic API here. */
                } else if (!setTypeIsMember(sets[j],eleobj)) {
                    break;
                }
            }
        }

        /* Only take action when all sets contain the member */
        if (j == setnum) {
            if (!dstkey) {
                if (encoding == OBJ_ENCODING_HT)
                    addReplyBulk(c,eleobj);
                else
                    addReplyBulkLongLong(c,intobj);
                cardinality++;
            } else {
                if (encoding == OBJ_ENCODING_INTSET) {
                    eleobj = createStringObjectFromLongLong(intobj);
                    setTypeAdd(dstset,eleobj);
                    decrRefCount(eleobj);
                } else {
                    setTypeAdd(dstset,eleobj);
                }
            }
        }
    }
    setTypeReleaseIterator(si);

    if (dstkey) {
        /* Store the resulting set into the target, if the intersection
         * is not an empty set. */
        int deleted = dbDelete(c->db,dstkey);
        if (setTypeSize(dstset) > 0) {
            dbAdd(c->db,dstkey,dstset);
            addReplyLongLong(c,setTypeSize(dstset));
            notifyKeyspaceEvent(NOTIFY_SET,"sinterstore",
                dstkey,c->db->id);
        } else {
            decrRefCount(dstset);
            addReply(c,shared.czero);
            if (deleted)
                notifyKeyspaceEvent(NOTIFY_GENERIC,"del",
                    dstkey,c->db->id);
        }
        signalModifiedKey(c->db,dstkey);
        server.dirty++;
    } else {
        setDeferredMultiBulkLength(c,replylen,cardinality);
    }
    zfree(sets);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3acd0
movq %rax, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x5d9cc
cmpq $0x0, -0x20(%rbp)
je 0x5d8d0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x4a6f0
movq %rax, -0x80(%rbp)
jmp 0x5d8ed
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x4a6c0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x5d986
movq -0x28(%rbp), %rdi
callq 0x3afa0
cmpq $0x0, -0x20(%rbp)
je 0x5d96d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x4ac10
cmpl $0x0, %eax
je 0x5d957
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x4aa60
leaq 0x11a89a(%rip), %rax    # 0x1781d8
movq 0x720(%rax), %rcx
addq $0x1, %rcx
leaq 0x11a888(%rip), %rax    # 0x1781d8
movq %rcx, 0x720(%rax)
movq -0x8(%rbp), %rdi
leaq 0x11b2de(%rip), %rax    # 0x178c40
movq 0x20(%rax), %rsi
callq 0x42cc0
jmp 0x5d981
movq -0x8(%rbp), %rdi
leaq 0x11b2c8(%rip), %rax    # 0x178c40
movq 0x68(%rax), %rsi
callq 0x42cc0
jmp 0x5dd2e
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl $0x2, %edx
callq 0x490a0
cmpl $0x0, %eax
je 0x5d9ab
movq -0x28(%rbp), %rdi
callq 0x3afa0
jmp 0x5dd2e
movq -0x70(%rbp), %rdx
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5d89c
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x8, %edx
leaq -0x250(%rip), %rcx      # 0x5d790
callq 0x26890
cmpq $0x0, -0x20(%rbp)
jne 0x5d9fb
movq -0x8(%rbp), %rdi
callq 0x432a0
movq %rax, -0x50(%rbp)
jmp 0x5da04
callq 0x48c10
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x5bbf0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x5bce0
movl %eax, -0x64(%rbp)
cmpl $-0x1, %eax
je 0x5dc0b
movq $0x1, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x5db89
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x5da61
jmp 0x5db78
cmpl $0x6, -0x64(%rbp)
jne 0x5db01
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x6, %eax
jne 0x5daa6
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x7b900
cmpb $0x0, %al
jne 0x5daa6
jmp 0x5db89
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x5dafd
movq -0x48(%rbp), %rdi
callq 0x486f0
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x38(%rbp), %rsi
callq 0x5bb30
cmpl $0x0, %eax
jne 0x5daf4
movq -0x38(%rbp), %rdi
callq 0x48f70
jmp 0x5db89
movq -0x38(%rbp), %rdi
callq 0x48f70
jmp 0x5daff
jmp 0x5db76
cmpl $0x2, -0x64(%rbp)
jne 0x5db74
movq -0x38(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x5db54
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x6, %eax
jne 0x5db54
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7b900
cmpb $0x0, %al
jne 0x5db54
jmp 0x5db89
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x38(%rbp), %rsi
callq 0x5bb30
cmpl $0x0, %eax
jne 0x5db70
jmp 0x5db89
jmp 0x5db72
jmp 0x5db74
jmp 0x5db76
jmp 0x5db78
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5da39
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x5dc06
cmpq $0x0, -0x20(%rbp)
jne 0x5dbca
cmpl $0x2, -0x64(%rbp)
jne 0x5dbaf
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x43630
jmp 0x5dbbc
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x439f0
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x5dc04
cmpl $0x6, -0x64(%rbp)
jne 0x5dbf5
movq -0x48(%rbp), %rdi
callq 0x486f0
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x5b750
movq -0x38(%rbp), %rdi
callq 0x48f70
jmp 0x5dc02
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x5b750
jmp 0x5dc04
jmp 0x5dc06
jmp 0x5da14
movq -0x30(%rbp), %rdi
callq 0x5bca0
cmpq $0x0, -0x20(%rbp)
je 0x5dd14
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x4ac10
movl %eax, -0x74(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5bf20
cmpq $0x0, %rax
jbe 0x5dc9c
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4a7d0
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5bf20
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x43780
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x20, %edi
leaq 0xd992c(%rip), %rsi     # 0x1375c1
callq 0x9ce20
jmp 0x5dce1
movq -0x40(%rbp), %rdi
callq 0x48f70
movq -0x8(%rbp), %rdi
leaq 0x11af90(%rip), %rax    # 0x178c40
movq 0x20(%rax), %rsi
callq 0x42cc0
cmpl $0x0, -0x74(%rbp)
je 0x5dcdf
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x30(%rax), %ecx
movl $0x4, %edi
leaq 0xdb7be(%rip), %rsi     # 0x139498
callq 0x9ce20
jmp 0x5dce1
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x4aa60
leaq 0x11a4df(%rip), %rax    # 0x1781d8
movq 0x720(%rax), %rcx
addq $0x1, %rcx
leaq 0x11a4cd(%rip), %rax    # 0x1781d8
movq %rcx, 0x720(%rax)
jmp 0x5dd25
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x43310
movq -0x28(%rbp), %rdi
callq 0x3afa0
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)