// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/db.c
// Function: scanGenericCommand
void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
    int i, j;
    list *keys = listCreate();
    listNode *node, *nextnode;
    long count = 10;
    sds pat = NULL;
    int patlen = 0, use_pattern = 0;
    dict *ht;

    /* Object must be NULL (to iterate keys names), or the type of the object
     * must be Set, Sorted Set, or Hash. */
    serverAssert(o == NULL || o->type == OBJ_SET || o->type == OBJ_HASH ||
                o->type == OBJ_ZSET);

    /* Set i to the first option argument. The previous one is the cursor. */
    i = (o == NULL) ? 2 : 3; /* Skip the key argument if needed. */

    /* Step 1: Parse options. */
    while (i < c->argc) {
        j = c->argc - i;
        if (!strcasecmp(c->argv[i]->ptr, "count") && j >= 2) {
            if (getLongFromObjectOrReply(c, c->argv[i+1], &count, NULL)
                != C_OK)
            {
                goto cleanup;
            }

            if (count < 1) {
                addReply(c,shared.syntaxerr);
                goto cleanup;
            }

            i += 2;
        } else if (!strcasecmp(c->argv[i]->ptr, "match") && j >= 2) {
            pat = c->argv[i+1]->ptr;
            patlen = sdslen(pat);

            /* The pattern always matches if it is exactly "*", so it is
             * equivalent to disabling it. */
            use_pattern = !(pat[0] == '*' && patlen == 1);

            i += 2;
        } else {
            addReply(c,shared.syntaxerr);
            goto cleanup;
        }
    }

    /* Step 2: Iterate the collection.
     *
     * Note that if the object is encoded with a ziplist, intset, or any other
     * representation that is not a hash table, we are sure that it is also
     * composed of a small number of elements. So to avoid taking state we
     * just return everything inside the object in a single call, setting the
     * cursor to zero to signal the end of the iteration. */

    /* Handle the case of a hash table. */
    ht = NULL;
    if (o == NULL) {
        ht = c->db->dict;
    } else if (o->type == OBJ_SET && o->encoding == OBJ_ENCODING_HT) {
        ht = o->ptr;
    } else if (o->type == OBJ_HASH && o->encoding == OBJ_ENCODING_HT) {
        ht = o->ptr;
        count *= 2; /* We return key / value for this type. */
    } else if (o->type == OBJ_ZSET && o->encoding == OBJ_ENCODING_SKIPLIST) {
        zset *zs = o->ptr;
        ht = zs->dict;
        count *= 2; /* We return key / value for this type. */
    }

    if (ht) {
        void *privdata[2];
        /* We set the max number of iterations to ten times the specified
         * COUNT, so if the hash table is in a pathological state (very
         * sparsely populated) we avoid to block too much time at the cost
         * of returning no or very few elements. */
        long maxiterations = count*10;

        /* We pass two pointers to the callback: the list to which it will
         * add new elements, and the object containing the dictionary so that
         * it is possible to fetch more data in a type-dependent way. */
        privdata[0] = keys;
        privdata[1] = o;
        do {
            cursor = dictScan(ht, cursor, scanCallback, privdata);
        } while (cursor &&
              maxiterations-- &&
              listLength(keys) < (unsigned long)count);
    } else if (o->type == OBJ_SET) {
        int pos = 0;
        int64_t ll;

        while(intsetGet(o->ptr,pos++,&ll))
            listAddNodeTail(keys,createStringObjectFromLongLong(ll));
        cursor = 0;
    } else if (o->type == OBJ_HASH || o->type == OBJ_ZSET) {
        unsigned char *p = ziplistIndex(o->ptr,0);
        unsigned char *vstr;
        unsigned int vlen;
        long long vll;

        while(p) {
            ziplistGet(p,&vstr,&vlen,&vll);
            listAddNodeTail(keys,
                (vstr != NULL) ? createStringObject((char*)vstr,vlen) :
                                 createStringObjectFromLongLong(vll));
            p = ziplistNext(o->ptr,p);
        }
        cursor = 0;
    } else {
        serverPanic("Not handled encoding in SCAN.");
    }

    /* Step 3: Filter elements. */
    node = listFirst(keys);
    while (node) {
        robj *kobj = listNodeValue(node);
        nextnode = listNextNode(node);
        int filter = 0;

        /* Filter element if it does not match the pattern. */
        if (!filter && use_pattern) {
            if (sdsEncodedObject(kobj)) {
                if (!stringmatchlen(pat, patlen, kobj->ptr, sdslen(kobj->ptr), 0))
                    filter = 1;
            } else {
                char buf[LONG_STR_SIZE];
                int len;

                serverAssert(kobj->encoding == OBJ_ENCODING_INT);
                len = ll2string(buf,sizeof(buf),(long)kobj->ptr);
                if (!stringmatchlen(pat, patlen, buf, len, 0)) filter = 1;
            }
        }

        /* Filter element if it is an expired key. */
        if (!filter && o == NULL && expireIfNeeded(c->db, kobj)) filter = 1;

        /* Remove the element and its associted value if needed. */
        if (filter) {
            decrRefCount(kobj);
            listDelNode(keys, node);
        }

        /* If this is a hash or a sorted set, we have a flat list of
         * key-value elements, so if this element was filtered, remove the
         * value, or skip it if it was not filtered: we only match keys. */
        if (o && (o->type == OBJ_ZSET || o->type == OBJ_HASH)) {
            node = nextnode;
            nextnode = listNextNode(node);
            if (filter) {
                kobj = listNodeValue(node);
                decrRefCount(kobj);
                listDelNode(keys, node);
            }
        }
        node = nextnode;
    }

    /* Step 4: Reply to the client. */
    addReplyMultiBulkLen(c, 2);
    addReplyBulkLongLong(c,cursor);

    addReplyMultiBulkLen(c, listLength(keys));
    while ((node = listFirst(keys)) != NULL) {
        robj *kobj = listNodeValue(node);
        addReplyBulk(c, kobj);
        decrRefCount(kobj);
        listDelNode(keys, node);
    }

cleanup:
    listSetFreeMethod(keys,decrRefCountVoid);
    listRelease(keys);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x26e20
movq %rax, -0x28(%rbp)
movq $0xa, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x4b7af
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x2, %eax
je 0x4b7af
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
je 0x4b7af
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x3, %eax
jne 0x4b7b1
jmp 0x4b7d3
leaq 0xf0151(%rip), %rdi     # 0x13b909
leaq 0xf19e3(%rip), %rsi     # 0x13d1a2
movl $0x1f7, %edx            # imm = 0x1F7
callq 0x76ce0
movl $0x1, %edi
callq 0x263c0
movq -0x10(%rbp), %rdx
movl $0x3, %eax
movl $0x2, %ecx
cmpq $0x0, %rdx
cmovel %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jge 0x4b947
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0xfb216(%rip), %rsi     # 0x146a39
callq 0x26300
cmpl $0x0, %eax
jne 0x4b894
cmpl $0x2, -0x20(%rbp)
jl 0x4b894
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x49f20
cmpl $0x0, %eax
je 0x4b863
jmp 0x4bed0
cmpq $0x1, -0x40(%rbp)
jge 0x4b886
movq -0x8(%rbp), %rdi
leaq 0x12d3cb(%rip), %rax    # 0x178c40
movq 0x80(%rax), %rsi
callq 0x42cc0
jmp 0x4bed0
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4b942
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0xffb62(%rip), %rsi     # 0x14b411
callq 0x26300
cmpl $0x0, %eax
jne 0x4b924
cmpl $0x2, -0x20(%rbp)
jl 0x4b924
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x4ab80
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2a, %ecx
movb %al, -0xe1(%rbp)
jne 0x4b909
cmpl $0x1, -0x4c(%rbp)
sete %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4b940
movq -0x8(%rbp), %rdi
leaq 0x12d311(%rip), %rax    # 0x178c40
movq 0x80(%rax), %rsi
callq 0x42cc0
jmp 0x4bed0
jmp 0x4b942
jmp 0x4b7eb
movq $0x0, -0x58(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4b96a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x4ba16
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x4b997
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x4b997
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x4ba14
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x4b9cf
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x4b9cf
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
jmp 0x4ba12
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x3, %eax
jne 0x4ba10
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
jne 0x4ba10
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
jmp 0x4ba12
jmp 0x4ba14
jmp 0x4ba16
cmpq $0x0, -0x58(%rbp)
je 0x4baa6
imulq $0xa, -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rcx
leaq -0x51d(%rip), %rdx      # 0x4b530
callq 0x2eac0
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0xe2(%rbp)
je 0x4ba97
movq -0x78(%rbp), %rcx
movq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0xe2(%rbp)
je 0x4ba97
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0xe2(%rbp)
movb -0xe2(%rbp), %al
testb $0x1, %al
jne 0x4ba3a
jmp 0x4bc20
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x4bb13
movl $0x0, -0x7c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x7c(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
leaq -0x88(%rbp), %rdx
callq 0x7b9d0
cmpb $0x0, %al
je 0x4bb06
movq -0x28(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x88(%rbp), %rdi
callq 0x486f0
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x27000
jmp 0x4babb
movq $0x0, -0x18(%rbp)
jmp 0x4bc1e
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
je 0x4bb33
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x3, %eax
jne 0x4bbfa
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x41120
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x4bbf0
movq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x9c(%rbp), %rdx
leaq -0xa8(%rbp), %rcx
callq 0x41470
movq -0x28(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x4bbaa
movq -0x98(%rbp), %rdi
movl -0x9c(%rbp), %eax
movl %eax, %esi
callq 0x486a0
movq %rax, -0x100(%rbp)
jmp 0x4bbbd
movq -0xa8(%rbp), %rdi
callq 0x486f0
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x27000
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x90(%rbp), %rsi
callq 0x412e0
movq %rax, -0x90(%rbp)
jmp 0x4bb49
movq $0x0, -0x18(%rbp)
jmp 0x4bc1c
leaq 0xefd56(%rip), %rdi     # 0x13b957
leaq 0xf159a(%rip), %rsi     # 0x13d1a2
movl $0x25a, %edx            # imm = 0x25A
callq 0x76d80
movl $0x1, %edi
callq 0x263c0
jmp 0x4bc1e
jmp 0x4bc20
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4be57
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jne 0x4bd8b
cmpl $0x0, -0x50(%rbp)
je 0x4bd8b
movq -0xb0(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x4bc9a
movq -0xb0(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0x4bd02
movq -0x48(%rbp), %rax
movq %rax, -0x118(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x10c(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x108(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4ab80
movq -0x118(%rbp), %rdi
movl -0x10c(%rbp), %esi
movq -0x108(%rbp), %rdx
movl %eax, %ecx
xorl %r8d, %r8d
callq 0x46ef0
cmpl $0x0, %eax
jne 0x4bcfd
movl $0x1, -0xb4(%rbp)
jmp 0x4bd89
movq -0xb0(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x4bd18
jmp 0x4bd3a
leaq 0xefc58(%rip), %rdi     # 0x13b977
leaq 0xf147c(%rip), %rsi     # 0x13d1a2
movl $0x26d, %edx            # imm = 0x26D
callq 0x76ce0
movl $0x1, %edi
callq 0x263c0
leaq -0xd0(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x15, %esi
callq 0x477e0
movl %eax, -0xd4(%rbp)
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %esi
leaq -0xd0(%rbp), %rdx
movl -0xd4(%rbp), %ecx
xorl %r8d, %r8d
callq 0x46ef0
cmpl $0x0, %eax
jne 0x4bd87
movl $0x1, -0xb4(%rbp)
jmp 0x4bd89
jmp 0x4bd8b
cmpl $0x0, -0xb4(%rbp)
jne 0x4bdbe
cmpq $0x0, -0x10(%rbp)
jne 0x4bdbe
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xb0(%rbp), %rsi
callq 0x4a590
cmpl $0x0, %eax
je 0x4bdbe
movl $0x1, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
je 0x4bde0
movq -0xb0(%rbp), %rdi
callq 0x48f70
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x271e0
cmpq $0x0, -0x10(%rbp)
je 0x4be4a
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x3, %eax
je 0x4be03
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x4be4a
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0xb4(%rbp)
je 0x4be48
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x48f70
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x271e0
jmp 0x4be4a
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x4bc2b
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x437f0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x439f0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x437f0
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x4bece
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x43630
movq -0xe0(%rbp), %rdi
callq 0x48f70
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x271e0
jmp 0x4be83
jmp 0x4bed0
movq -0x28(%rbp), %rax
leaq -0x2e7b(%rip), %rcx     # 0x49060
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rdi
callq 0x26ea0
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)