// File: /workspace/github_cpp_makefile_star2_O2/Sherhang[P]redis-for-cpp/credis.cpp
// Function: Redis::hscan(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<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>>>>>&)
int32_t Redis::hscan(const std::string& key, int32_t cursor, const std::string& pattern, int32_t count, std::map<std::string, std::string>& key_value)
{
    
     if(_context==NULL)
    {
        //DEBUG<<"NULL"<<std::endl;
        return -1;
    }
    
    if (count <= 0)
    {
        // DEBUG
        return 0;
    }
    std::string cmd = "HSCAN " + key + " " + 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 -2;
    }
    //DEBUG<<"_reply->type "<<_reply->type<<std::endl;
    if(_reply->type != REDIS_REPLY_ARRAY)
    {
        //DEBUG<<"not array"<<std::endl;
        freeReply(_reply);
        return -3;
    }
    redisReply* sub_reply = (_reply->element[1]);
    uint32_t len = sub_reply->elements;
    key_value.clear();
    if(len & 0x01)
    {
        //DEBUG<<"return not match"<<std::endl;
        return -4;
    }
    for(uint32_t i=0;i<len;i=i+2)
    {
        std::string key(sub_reply->element[i]->str, sub_reply->element[i]->len);
        std::string val(sub_reply->element[i+1]->str, sub_reply->element[i+1]->len);
        key_value[key] = val;
    }
    int32_t ret = -1;
    std::string strTemp(_reply->element[0]->str, _reply->element[0]->len);
    ret = str2num<int32_t>(strTemp);
    freeReply(_reply);
    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, 0x30(%rsp)
movl %edx, 0xc(%rsp)
movl %r8d, 0x8(%rsp)
cmpq $0x0, 0x8(%rdi)
je 0x728c
testl %r8d, %r8d
jle 0x7294
movq %rcx, %r15
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x9fbb(%rip), %rsi      # 0x111cc
leaq 0x128(%rsp), %r12
movq %r12, %rdi
movq %rax, %rdx
callq 0x7822
leaq 0xa9c7(%rip), %rdx      # 0x11bf2
leaq 0xe8(%rsp), %rdi
movq %r12, %rsi
callq 0x78ff
leaq 0xc8(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %rbx, %rsi
callq 0x3de4
leaq 0x48(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x7898
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x729b
leaq 0x9e73(%rip), %rsi      # 0x110ed
leaq 0xa8(%rsp), %rdi
movq %r15, %rdx
callq 0x7822
jmp 0x72b4
pushq $-0x1
popq %rbx
jmp 0x74ae
xorl %ebx, %ebx
jmp 0x74ae
leaq 0xa002(%rip), %rsi      # 0x112a4
leaq 0xa8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x3140
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x7898
movl 0x8(%rsp), %ebp
testl %ebp, %ebp
js 0x7300
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %rbx, %rsi
callq 0x3de4
leaq 0x9e09(%rip), %rsi      # 0x110f5
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x7994
jmp 0x7319
leaq 0x9f9d(%rip), %rsi      # 0x112a4
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x3140
leaq 0x108(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x7898
leaq 0x88(%rsp), %rdi
callq 0x3180
testl %ebp, %ebp
js 0x734e
leaq 0x68(%rsp), %rdi
callq 0x3180
leaq 0x10(%rsp), %rdi
callq 0x3180
leaq 0xa8(%rsp), %rdi
callq 0x3180
testq %r12, %r12
leaq 0x48(%rsp), %rdi
callq 0x3180
leaq 0xc8(%rsp), %rdi
callq 0x3180
leaq 0xe8(%rsp), %rdi
callq 0x3180
leaq 0x128(%rsp), %rdi
callq 0x3180
movq 0x8(%rbx), %rdi
movq 0x108(%rsp), %rsi
xorl %eax, %eax
callq 0xb190
movq %rax, %r14
testq %rax, %rax
je 0x7487
cmpl $0x2, (%r14)
jne 0x7492
movq 0x28(%r14), %rax
movq 0x8(%rax), %rbp
movq 0x20(%rbp), %r15
movq 0x30(%rsp), %rdi
callq 0x7f24
testb $0x1, %r15b
jne 0x749e
movq %r14, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
pushq $0x1
popq %r14
leaq 0x58(%rsp), %rbx
leaq 0x10(%rsp), %r12
leaq 0x48(%rsp), %r13
leal -0x1(%r14), %eax
cmpl %r15d, %eax
jae 0x74c2
movq 0x28(%rbp), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x7cd0
movq 0x28(%rbp), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
movq %rbx, 0x48(%rsp)
movq %r13, %rdi
callq 0x7cd0
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x7c32
movq %rax, %rdi
movq %r13, %rsi
callq 0x31e0
movq %r13, %rdi
callq 0x3180
movq %r12, %rdi
callq 0x3180
addl $0x2, %r14d
jmp 0x73ff
xorl %esi, %esi
callq 0x43f8
pushq $-0x2
jmp 0x74a0
movq %r14, %rdi
callq 0x8ae0
pushq $-0x3
jmp 0x74a0
pushq $-0x4
popq %rbx
leaq 0x108(%rsp), %rdi
callq 0x3180
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rsp), %r14
movq 0x28(%r14), %rax
movq (%rax), %rax
movq 0x18(%rax), %rsi
movq 0x10(%rax), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
movq %rax, (%rdi)
callq 0x7cd0
leaq 0x10(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x7a78
movl %eax, %ebx
movq %r14, %rdi
callq 0x8ae0
leaq 0x10(%rsp), %rdi
callq 0x3180
jmp 0x74a1
jmp 0x75a7
jmp 0x75ac
jmp 0x7521
movq %rax, %rbx
jmp 0x753a
movq %rax, %rbx
jmp 0x7544
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3180
testl %ebp, %ebp
js 0x7544
leaq 0x68(%rsp), %rdi
callq 0x3180
leaq 0x10(%rsp), %rdi
callq 0x3180
jmp 0x7553
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3180
jmp 0x7565
movq %rax, %rbx
testq %r12, %r12
leaq 0x48(%rsp), %rdi
callq 0x3180
leaq 0xc8(%rsp), %rdi
callq 0x3180
leaq 0xe8(%rsp), %rdi
callq 0x3180
leaq 0x128(%rsp), %rdi
jmp 0x75d0
movq %rax, %rbx
jmp 0x7572
movq %rax, %rbx
jmp 0x757f
movq %rax, %rbx
jmp 0x758c
jmp 0x75a7
movq %rax, %rbx
jmp 0x75c8
movq %rax, %rbx
jmp 0x75be
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3180
leaq 0x10(%rsp), %rdi
callq 0x3180
leaq 0x108(%rsp), %rdi
callq 0x3180
movq %rbx, %rdi
callq 0x35a0
nop