// File: /workspace/github_cpp_makefile_star2_O3/Sherhang[P]redis-for-cpp/redis_connect_pool.cpp
// Function: RedisConnectPool::connect()
redisContext * RedisConnectPool::connect()
{
    redisContext *redisConn = NULL;
    redisConn = redisConnect(_redisIP.c_str(), _redisProt);
    if(redisConn != NULL && redisConn->err)
    {
        if (redisConn->errstr != NULL)
        {
        }
        
        if (NULL != redisConn)
        {
            redisFree(redisConn);
        }
        redisConn = NULL;
        return NULL;
    }
    if (!_needPasswd ) 
    {
        //debug 
        return redisConn;
    }
    std::string cmd = "AUTH " + (_passwd.empty()? "1245678" : _passwd);
    redisReply *reply = (redisReply*)::redisCommand(redisConn, cmd.c_str());
    if (reply == NULL && redisConn->err != 0)
    {
        return NULL;
    }

    if (reply->type == REDIS_REPLY_STATUS && strcasecmp(reply->str, "OK") != 0)
    {
        return NULL;
    }
    if (reply->type == REDIS_REPLY_ERROR) 
    {
        if (strcasecmp(reply->str, "ERR Client sent AUTH, but no password is set") == 0) 
        {
            _needPasswd = false;
            reConnect(redisConn);
        } 
        else 
        {
            return NULL;
        }
    }
    if(reply)
    {
        freeReplyObject(reply);
        reply = NULL;
    }
    
    return redisConn;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
movq 0x8(%rdi), %rdi
movl 0x48(%r14), %esi
callq 0xd6b0
movq %rax, %rbx
testq %rax, %rax
je 0xb693
cmpl $0x0, (%rbx)
je 0xb693
movq %rbx, %rdi
callq 0xd3f0
xorl %ebx, %ebx
jmp 0xb7ec
cmpb $0x1, 0x90(%r14)
jne 0xb7ec
movq 0x30(%r14), %rdx
leaq 0x38(%rsp), %rax
testq %rdx, %rdx
je 0xb6c6
movq %rax, -0x10(%rax)
movq 0x28(%r14), %rsi
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0xabea
jmp 0xb6e3
movq %rax, -0x10(%rax)
movl $0x35343231, (%rax)     # imm = 0x35343231
movl $0x38373635, 0x3(%rax)  # imm = 0x38373635
movq $0x7, -0x8(%rax)
movb $0x0, 0x7(%rax)
leaq 0x8b39(%rip), %rcx      # 0x14223
leaq 0x28(%rsp), %rdi
movl $0x5, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0xb726
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0xb731
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq %r12, %rsi
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb761
callq 0x3350
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe1b0
movq %rax, %r15
testq %rax, %rax
je 0xb796
movl (%r15), %eax
cmpl $0x6, %eax
je 0xb79d
cmpl $0x5, %eax
jne 0xb7d5
movq 0x18(%r15), %rdi
leaq 0x89b1(%rip), %rsi      # 0x1413c
callq 0x33c0
testl %eax, %eax
jne 0xb7b1
jmp 0xb7d5
cmpl $0x0, (%rbx)
jne 0xb7b1
jmp 0xb773
movq 0x18(%r15), %rdi
leaq 0x8ab3(%rip), %rsi      # 0x1425b
callq 0x33c0
testl %eax, %eax
je 0xb7b5
xorl %ebx, %ebx
jmp 0xb7dd
movb $0x0, 0x90(%r14)
testq %rbx, %rbx
je 0xb7ca
movq %rbx, %rdi
callq 0xd3f0
movq %r14, %rdi
callq 0xb65c
movq %rax, %rbx
movq %r15, %rdi
callq 0xbb00
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0xb7ec
callq 0x3350
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
jmp 0xb825
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0xb820
jmp 0xb825
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0xb825
callq 0x3350
movq %rbx, %rdi
callq 0x35b0
nop