// File: /workspace/github_cpp_makefile_star2_O1/Sherhang[P]redis-for-cpp/credis.cpp
// Function: Redis::getKeys(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
bool Redis::getKeys(const std::string& yourType, const std::string& pattern, int32_t maxNum, std::vector<std::string>& keys)
{
    if(_context==NULL)
    {
        //DEBUG<<"NULL"<<std::endl;
        return false;
    }
    int32_t cursor = 0;
    int32_t count = 100;
    if(maxNum<0)
    {
        maxNum = 0x7fffffff;
    }
    //DEBUG<<"maxNum "<<maxNum<<std::endl;
    
    keys.clear();
    keys.reserve(maxNum);
    do
    {
        std::string cmd = "SCAN "  + num2str<int32_t>(cursor)
                    + (pattern.empty() ? "" : (" MATCH " + pattern))
                    + (count < 0 ? "" : " COUNT " + num2str<int32_t>(count));
        redisReply* _reply = (redisReply*)::redisCommand(_context, cmd.c_str());
        if(isError(_reply))
        {
            //DEBUG<<"isError"<<std::endl;
            freeReply(_reply);
            return false;
        }
        //DEBUG<<"_reply->type "<<_reply->type<<std::endl;
        if(_reply->type != REDIS_REPLY_ARRAY)
        {
            //DEBUG<<"not array"<<std::endl;
            freeReply(_reply);
            return false;
        }
        redisReply* sub_reply = (_reply->element[1]);
        uint32_t len = sub_reply->elements;
        for(uint32_t i=0;i<len;++i)
        {
            std::string strTemp(sub_reply->element[i]->str, sub_reply->element[i]->len);
            if(yourType.empty())
            {
                keys.push_back(strTemp);
            }
            else if(strcasecmp((type(strTemp)).c_str(), yourType.c_str() ) == 0)
                 {
                    keys.push_back(strTemp);
                 }
            if(keys.size() >= maxNum)
            {
                //DEBUG
                break;
            }
        }
        
        std::string strTemp(_reply->element[0]->str, _reply->element[0]->len);
        cursor = str2num<int32_t>(strTemp);//update cursor
        freeReply(_reply);
        //DEBUG<<keys.size()<<" "<<cursor<<std::endl;

    } while(keys.size() < maxNum && cursor!=0);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, 0xc8(%rsp)
movq %rdi, 0x28(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x5b2b
movq %r8, %rbx
movq %rdx, 0xd0(%rsp)
leaq 0x24(%rsp), %rax
movl $0x0, (%rax)
leaq 0x34(%rsp), %rax
movl $0x64, (%rax)
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
cmpl %r14d, %ecx
cmovbl %ecx, %r14d
movq %r8, %rdi
callq 0xa88a
movq %rbx, 0x78(%rsp)
movq %rbx, %rdi
movq %r14, 0xc0(%rsp)
movq %r14, %rsi
callq 0xa8d0
leaq 0x90(%rsp), %r14
leaq 0xb0(%rsp), %r15
leaq 0x10(%rsp), %rbp
leaq 0xf8(%rsp), %r12
movq %r12, %rdi
movq 0x28(%rsp), %rsi
leaq 0x24(%rsp), %rdx
callq 0x41b0
movl $0x5, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xeba7(%rip), %rcx      # 0x141f5
callq 0x33e0
movq %r14, 0x80(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x567f
movq %rdx, 0x80(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
jmp 0x5686
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0x88(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xd0(%rsp), %rdx
cmpq $0x0, 0x8(%rdx)
leaq 0x68(%rsp), %r13
je 0x56cb
leaq 0xa0(%rsp), %rdi
leaq 0xea51(%rip), %rsi      # 0x14115
callq 0xa756
jmp 0x56ea
movq %r15, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0xebc0(%rip), %rdx      # 0x142a2
movq %rdx, %rsi
callq 0x42a6
movq 0x80(%rsp), %rcx
movl $0xf, %esi
cmpq %r14, %rcx
je 0x5704
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %r8
movq 0xa8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x5739
movl $0xf, %esi
cmpq %r15, 0xa0(%rsp)
je 0x5734
movq 0xb0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x5750
movq 0xa0(%rsp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x3110
jmp 0x5761
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
movq %rbp, (%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x577f
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x5786
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movl 0x34(%rsp), %ebp
testl %ebp, %ebp
setns %r12b
leaq 0xd8(%rsp), %rdi
js 0x580a
movq 0x28(%rsp), %rsi
leaq 0x34(%rsp), %rdx
movq %rdi, %rbx
callq 0x41b0
movl $0x7, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xe940(%rip), %rcx      # 0x1411d
callq 0x33e0
leaq 0x48(%rsp), %rsi
movq %rsi, 0x38(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x582a
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0x5830
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0xea82(%rip), %rdx      # 0x142a2
movq %rdx, %rsi
callq 0x42a6
jmp 0x5848
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x40(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rsp), %rcx
movq 0x8(%rsp), %r8
movq 0x40(%rsp), %rdx
movl $0xf, %esi
leaq 0x10(%rsp), %rax
cmpq %rax, %rcx
je 0x586a
movq 0x10(%rsp), %rsi
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x588e
movl $0xf, %esi
leaq 0x48(%rsp), %rdi
cmpq %rdi, 0x38(%rsp)
je 0x5889
movq 0x48(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x589d
movq 0x38(%rsp), %rsi
movq %rsp, %rdi
callq 0x3110
jmp 0x58ab
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
movq %r13, 0x58(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x58cb
movq %rdx, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0x58d3
movups (%rcx), %xmm0
movups %xmm0, (%r13)
leaq 0x48(%rsp), %r8
movq %rsp, %r12
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x60(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x38(%rsp), %rdi
cmpq %r8, %rdi
je 0x5907
callq 0x3350
testl %ebp, %ebp
leaq 0x10(%rsp), %rbp
js 0x592a
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x592a
callq 0x3350
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x5938
callq 0x3350
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x594a
callq 0x3350
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x595c
callq 0x3350
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x5976
callq 0x3350
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x58(%rsp), %rsi
xorl %eax, %eax
callq 0xe300
movq %rax, %r13
testq %rax, %rax
je 0x5ae8
cmpl $0x2, (%r13)
jne 0x5ae0
movq 0x28(%r13), %rax
movq 0x8(%rax), %r14
movl 0x20(%r14), %r15d
testq %r15, %r15
je 0x5a86
movl $0x1, %ebx
movq 0x28(%r14), %rax
movq -0x8(%rax,%rbx,8), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
movq %rbp, (%rsp)
movq %r12, %rdi
callq 0x42a6
movq 0xc8(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5a3e
leaq 0x80(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x5c4e
movq 0x80(%rsp), %r12
movq 0xc8(%rsp), %rax
movq (%rax), %rsi
movq %r12, %rdi
callq 0x33c0
movl %eax, %ebp
leaq 0x90(%rsp), %rax
cmpq %rax, %r12
je 0x5a32
movq %r12, %rdi
callq 0x3350
testl %ebp, %ebp
leaq 0x10(%rsp), %rbp
movq %rsp, %r12
jne 0x5a4b
movq 0x78(%rsp), %rdi
movq %r12, %rsi
callq 0xa9b0
movq 0x78(%rsp), %rax
movq 0x8(%rax), %r12
subq (%rax), %r12
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x5a65
callq 0x3350
sarq $0x5, %r12
cmpq 0xc0(%rsp), %r12
movq %rsp, %r12
jae 0x5a86
leaq 0x1(%rbx), %rax
cmpq %r15, %rbx
movq %rax, %rbx
jb 0x59bc
movq 0x28(%r13), %rax
movq (%rax), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
movq %rbp, (%rsp)
movq %r12, %rdi
callq 0x42a6
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0xa9ee
leaq 0x90(%rsp), %r14
leaq 0xb0(%rsp), %r15
movl %eax, 0x24(%rsp)
movq %r13, %rdi
callq 0xbc50
movq (%rsp), %rdi
cmpq %rbp, %rdi
je 0x5adb
callq 0x3350
movb $0x1, %r13b
jmp 0x5aeb
movq %r13, %rdi
callq 0xbc50
xorl %r13d, %r13d
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x5aff
callq 0x3350
testb %r13b, %r13b
je 0x5b2e
movq 0x78(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x5, %rax
cmpq 0xc0(%rsp), %rax
jae 0x5b2e
cmpl $0x0, 0x24(%rsp)
jne 0x5620
jmp 0x5b2e
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5c2f
movq %rax, %rbx
jmp 0x5bb0
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %rbp, %rdi
jne 0x5c28
jmp 0x5c32
movq %rax, %rbx
movb $0x1, %r12b
jmp 0x5b8e
movq %rax, %rbx
movb $0x1, %r12b
jmp 0x5bad
movq %rax, %rbx
jmp 0x5be2
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x5b8e
callq 0x3350
testb %r12b, %r12b
je 0x5bad
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x5bad
callq 0x3350
testb %r12b, %r12b
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5bc8
callq 0x3350
jmp 0x5bc8
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x5be2
callq 0x3350
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x5c01
callq 0x3350
jmp 0x5c01
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
jmp 0x5c3c
jmp 0x5c2f
jmp 0x5c17
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5c32
callq 0x3350
jmp 0x5c32
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq 0x58(%rsp), %rdi
cmpq %rax, %rdi
je 0x5c46
callq 0x3350
movq %rbx, %rdi
callq 0x35b0