// File: /workspace/github_cpp_makefile_star2_O3/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, 0xa8(%rsp)
movq %rdi, 0x28(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x5afd
movq %r8, %rbx
movq %rdx, 0xd0(%rsp)
leaq 0x4(%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 0xa780
movq %rbx, 0x58(%rsp)
movq %rbx, %rdi
movq %r14, 0xa0(%rsp)
movq %r14, %rsi
callq 0xa7c6
leaq 0x70(%rsp), %r12
leaq 0xc0(%rsp), %r14
leaq 0x18(%rsp), %rbp
leaq 0x48(%rsp), %r15
leaq 0xf8(%rsp), %r13
movq %r13, %rdi
movq 0x28(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x41be
movl $0x5, %r8d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xebc5(%rip), %rcx      # 0x141f5
callq 0x33e0
movq %r12, 0x60(%rsp)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
movq 0xd0(%rsp), %rdx
je 0x5660
movq %rsi, 0x60(%rsp)
movq (%rcx), %rsi
movq %rsi, 0x70(%rsp)
jmp 0x5668
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rsi
movq %rsi, 0x68(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
cmpq $0x0, 0x8(%rdx)
leaq 0x90(%rsp), %r13
je 0x56a5
leaq 0xb0(%rsp), %rdi
leaq 0xea77(%rip), %rsi      # 0x14115
callq 0xa64c
jmp 0x56c4
movq %r14, 0xb0(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xebe6(%rip), %rdx      # 0x142a2
movq %rdx, %rsi
callq 0x42ba
movq 0x60(%rsp), %rcx
movl $0xf, %edi
cmpq %r12, %rcx
je 0x56d8
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %r8
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x570d
movl $0xf, %edi
cmpq %r14, %rsi
je 0x5708
movq 0xc0(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x5719
leaq 0x60(%rsp), %rdi
callq 0x3110
jmp 0x572a
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
movq %rbp, 0x8(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x574a
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x5751
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movl 0x34(%rsp), %ebp
testl %ebp, %ebp
leaq 0xd8(%rsp), %rdi
js 0x57d5
movq 0x28(%rsp), %rsi
leaq 0x34(%rsp), %rdx
movq %rdi, %rbx
callq 0x41be
movl $0x7, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xe979(%rip), %rcx      # 0x1411d
callq 0x33e0
movq %r13, 0x80(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x57f6
movq %rdx, 0x80(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
jmp 0x57fe
movq %r13, 0x80(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0xeab6(%rip), %rdx      # 0x142a2
movq %rdx, %rsi
callq 0x42ba
jmp 0x5819
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x88(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movl $0xf, %edi
leaq 0x18(%rsp), %rax
cmpq %rax, %rcx
je 0x5847
movq 0x18(%rsp), %rdi
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x5867
movl $0xf, %edi
cmpq %r13, %rsi
je 0x5862
movq 0x90(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x5873
leaq 0x8(%rsp), %rdi
callq 0x3110
jmp 0x5884
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
movq %r15, 0x38(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x58a4
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0x58ab
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x40(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0x58da
callq 0x3350
testl %ebp, %ebp
leaq 0x18(%rsp), %rbp
js 0x58fd
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x58fd
callq 0x3350
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x590c
callq 0x3350
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x591e
callq 0x3350
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x592d
callq 0x3350
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0x5947
callq 0x3350
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x38(%rsp), %rsi
xorl %eax, %eax
callq 0xe1b0
movq %rax, %r13
testq %rax, %rax
je 0x5abf
cmpl $0x2, (%r13)
jne 0x5ab7
movq 0x28(%r13), %rax
movq 0x8(%rax), %r14
movl 0x20(%r14), %r15d
testq %r15, %r15
je 0x5a5d
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, 0x8(%rsp)
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x42ba
movq 0xa8(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5a0e
leaq 0x60(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x5c16
movq 0x60(%rsp), %r12
movq 0xa8(%rsp), %rax
movq (%rax), %rsi
movq %r12, %rdi
callq 0x33c0
movl %eax, %ebp
leaq 0x70(%rsp), %rax
cmpq %rax, %r12
je 0x5a00
movq %r12, %rdi
callq 0x3350
testl %ebp, %ebp
leaq 0x18(%rsp), %rbp
leaq 0x8(%rsp), %r12
jne 0x5a1b
movq 0x58(%rsp), %rdi
movq %r12, %rsi
callq 0xa8a6
movq 0x58(%rsp), %rax
movq 0x8(%rax), %r12
subq (%rax), %r12
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5a36
callq 0x3350
sarq $0x5, %r12
cmpq 0xa0(%rsp), %r12
jae 0x5a54
leaq 0x1(%rbx), %rax
cmpq %r15, %rbx
movq %rax, %rbx
jb 0x598d
movq 0x28(%r13), %rax
leaq 0x70(%rsp), %r12
movq (%rax), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
movq %rbp, 0x8(%rsp)
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x42ba
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
leaq 0x48(%rsp), %r15
callq 0xa8e4
leaq 0xc0(%rsp), %r14
movl %eax, 0x4(%rsp)
movq %r13, %rdi
callq 0xbb00
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5ab2
callq 0x3350
movb $0x1, %r13b
jmp 0x5ac2
movq %r13, %rdi
callq 0xbb00
xorl %r13d, %r13d
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ad1
callq 0x3350
testb %r13b, %r13b
je 0x5b00
movq 0x58(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x5, %rax
cmpq 0xa0(%rsp), %rax
jae 0x5b00
cmpl $0x0, 0x4(%rsp)
jne 0x5602
jmp 0x5b00
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 0x5bf7
jmp 0x5b37
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x5bf0
jmp 0x5bfa
movq %rax, %rbx
jmp 0x5b5a
movq %rax, %rbx
jmp 0x5b74
movq %rax, %rbx
jmp 0x5ba7
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r13, %rdi
je 0x5b56
callq 0x3350
testl %ebp, %ebp
js 0x5b74
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x5b74
callq 0x3350
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5b8d
callq 0x3350
jmp 0x5b8d
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x5ba7
callq 0x3350
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x5bc0
callq 0x3350
jmp 0x5bc0
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
jne 0x5c09
jmp 0x5c0e
movq %rax, %rbx
jmp 0x5bff
jmp 0x5bde
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5bfa
callq 0x3350
jmp 0x5bfa
movq %rax, %rbx
leaq 0x48(%rsp), %r15
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x5c0e
callq 0x3350
movq %rbx, %rdi
callq 0x35b0