// File: 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
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x220(%rbp)
cmpq $0x0, 0x8(%rax)
jne 0xa8d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb065
cmpl $0x0, -0x2c(%rbp)
jg 0xa8e2
movl $0x0, -0x4(%rbp)
jmp 0xb065
movq -0x18(%rbp), %rdx
leaq 0xd8df(%rip), %rsi      # 0x181cc
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0xb510
movq -0x228(%rbp), %rsi
leaq 0xe2c4(%rip), %rdx      # 0x18bd2
leaq -0xb8(%rbp), %rdi
callq 0xb6f0
jmp 0xa91c
movq -0x220(%rbp), %rsi
leaq -0x108(%rbp), %rdi
leaq -0x1c(%rbp), %rdx
callq 0x4560
jmp 0xa935
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0xb620
jmp 0xa951
movq -0x28(%rbp), %rdi
callq 0x3610
movb $0x0, -0x12a(%rbp)
testb $0x1, %al
jne 0xa967
jmp 0xa99f
leaq -0x129(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x3670
movq -0x230(%rbp), %rdx
movb $0x1, -0x12a(%rbp)
leaq 0xd8eb(%rip), %rsi      # 0x1827a
leaq -0x128(%rbp), %rdi
callq 0x3510
jmp 0xa99d
jmp 0xa9ba
movq -0x28(%rbp), %rdx
leaq 0xd743(%rip), %rsi      # 0x180ed
leaq -0x128(%rbp), %rdi
callq 0xb510
jmp 0xa9b8
jmp 0xa9ba
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0xb620
jmp 0xa9d3
movl -0x2c(%rbp), %eax
movb $0x0, -0x152(%rbp)
movb $0x0, -0x179(%rbp)
cmpl $0x0, %eax
jge 0xaa21
leaq -0x151(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x3670
movq -0x238(%rbp), %rdx
movb $0x1, -0x152(%rbp)
leaq 0xd869(%rip), %rsi      # 0x1827a
leaq -0x150(%rbp), %rdi
callq 0x3510
jmp 0xaa1f
jmp 0xaa5f
movq -0x220(%rbp), %rsi
leaq -0x178(%rbp), %rdi
leaq -0x2c(%rbp), %rdx
callq 0x4560
jmp 0xaa3a
movb $0x1, -0x179(%rbp)
leaq 0xd6ad(%rip), %rsi      # 0x180f5
leaq -0x150(%rbp), %rdi
leaq -0x178(%rbp), %rdx
callq 0xb840
jmp 0xaa5d
jmp 0xaa5f
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0xb620
jmp 0xaa75
leaq -0x150(%rbp), %rdi
callq 0x3290
testb $0x1, -0x179(%rbp)
jne 0xaa8c
jmp 0xaa98
leaq -0x178(%rbp), %rdi
callq 0x3290
testb $0x1, -0x152(%rbp)
jne 0xaaa3
jmp 0xaaaf
leaq -0x151(%rbp), %rdi
callq 0x3410
leaq -0x78(%rbp), %rdi
callq 0x3290
leaq -0x128(%rbp), %rdi
callq 0x3290
testb $0x1, -0x12a(%rbp)
jne 0xaacf
jmp 0xaadb
leaq -0x129(%rbp), %rdi
callq 0x3410
leaq -0x98(%rbp), %rdi
callq 0x3290
leaq -0x108(%rbp), %rdi
callq 0x3290
leaq -0xb8(%rbp), %rdi
callq 0x3290
leaq -0xd8(%rbp), %rdi
callq 0x3290
movq -0x220(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x248(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3190
movq -0x248(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x11a60
movq %rax, -0x240(%rbp)
jmp 0xab40
movq -0x220(%rbp), %rdi
movq -0x240(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rsi
callq 0x59f0
testb $0x1, %al
jne 0xab6a
jmp 0xacf3
movq -0x220(%rbp), %rdi
movq -0x188(%rbp), %rsi
callq 0x59c0
jmp 0xab7f
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x18c(%rbp)
jmp 0xb04f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xaccb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xacbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xacb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xac90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xac84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xac64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xac4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3290
testb $0x1, -0x179(%rbp)
jne 0xac56
jmp 0xac62
leaq -0x178(%rbp), %rdi
callq 0x3290
jmp 0xac64
testb $0x1, -0x152(%rbp)
jne 0xac6f
jmp 0xac7b
leaq -0x151(%rbp), %rdi
callq 0x3410
leaq -0x78(%rbp), %rdi
callq 0x3290
leaq -0x128(%rbp), %rdi
callq 0x3290
testb $0x1, -0x12a(%rbp)
jne 0xac9b
jmp 0xaca7
leaq -0x129(%rbp), %rdi
callq 0x3410
leaq -0x98(%rbp), %rdi
callq 0x3290
leaq -0x108(%rbp), %rdi
callq 0x3290
leaq -0xb8(%rbp), %rdi
callq 0x3290
leaq -0xd8(%rbp), %rdi
callq 0x3290
jmp 0xb071
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
jmp 0xb05a
movq -0x188(%rbp), %rax
cmpl $0x2, (%rax)
je 0xad2a
movq -0x220(%rbp), %rdi
movq -0x188(%rbp), %rsi
callq 0x59c0
jmp 0xad14
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
movl $0x1, -0x18c(%rbp)
jmp 0xb04f
movq -0x188(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, -0x19c(%rbp)
movq -0x38(%rbp), %rdi
callq 0xbe70
movl -0x19c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xad7e
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
movl $0x1, -0x18c(%rbp)
jmp 0xb04f
movl $0x0, -0x1a0(%rbp)
movl -0x1a0(%rbp), %eax
cmpl -0x19c(%rbp), %eax
jae 0xaf42
movq -0x198(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x1a0(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x258(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x260(%rbp)
leaq -0x1c1(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3670
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rdx
movq -0x250(%rbp), %rcx
leaq -0x1c0(%rbp), %rdi
callq 0x3450
jmp 0xadfb
leaq -0x1c1(%rbp), %rdi
callq 0x3410
movq -0x198(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x1a0(%rbp), %ecx
incl %ecx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x270(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x278(%rbp)
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x3670
movq -0x278(%rbp), %rsi
movq -0x270(%rbp), %rdx
movq -0x268(%rbp), %rcx
leaq -0x1e8(%rbp), %rdi
callq 0x3450
jmp 0xae6a
leaq -0x1e9(%rbp), %rdi
callq 0x3410
movq -0x38(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0xbe90
movq %rax, -0x280(%rbp)
jmp 0xae8f
movq -0x280(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3050
jmp 0xaea4
leaq -0x1e8(%rbp), %rdi
callq 0x3290
leaq -0x1c0(%rbp), %rdi
callq 0x3290
movl -0x1a0(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1a0(%rbp)
jmp 0xad88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x1c1(%rbp), %rdi
callq 0x3410
jmp 0xb05a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x1e9(%rbp), %rdi
callq 0x3410
jmp 0xaf31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0x3290
leaq -0x1c0(%rbp), %rdi
callq 0x3290
jmp 0xb05a
movl $0xffffffff, -0x1f0(%rbp) # imm = 0xFFFFFFFF
movq -0x188(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x290(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x298(%rbp)
leaq -0x211(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3670
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rdx
movq -0x288(%rbp), %rcx
leaq -0x210(%rbp), %rdi
callq 0x3450
jmp 0xafa6
leaq -0x211(%rbp), %rdi
callq 0x3410
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0xba20
movl %eax, -0x29c(%rbp)
jmp 0xafcd
movq -0x220(%rbp), %rdi
movl -0x29c(%rbp), %eax
movl %eax, -0x1f0(%rbp)
movq -0x188(%rbp), %rsi
callq 0x59c0
jmp 0xafee
movl -0x1f0(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x18c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x3290
jmp 0xb04f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x211(%rbp), %rdi
callq 0x3410
jmp 0xb05a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x3290
jmp 0xb05a
leaq -0x58(%rbp), %rdi
callq 0x3290
jmp 0xb065
leaq -0x58(%rbp), %rdi
callq 0x3290
jmp 0xb071
movl -0x4(%rbp), %eax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq -0xe0(%rbp), %rdi
callq 0x3660
nopl (%rax)