// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %r14
movq 0x8(%rdi), %rdi
movl 0x48(%r14), %esi
callq 0xd800
movq %rax, %rbx
testq %rax, %rax
je 0xb7d4
cmpl $0x0, (%rbx)
je 0xb7d4
movq %rbx, %rdi
callq 0xd540
xorl %ebx, %ebx
jmp 0xb928
cmpb $0x1, 0x90(%r14)
jne 0xb928
movq 0x30(%r14), %rdx
leaq 0x30(%rsp), %rax
testq %rdx, %rdx
je 0xb807
movq %rax, -0x10(%rax)
movq 0x28(%r14), %rsi
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0xacf4
jmp 0xb824
movq %rax, -0x10(%rax)
movl $0x35343231, (%rax)     # imm = 0x35343231
movl $0x38373635, 0x3(%rax)  # imm = 0x38373635
movq $0x7, -0x8(%rax)
movb $0x0, 0x7(%rax)
leaq 0x89f8(%rip), %rcx      # 0x14223
leaq 0x20(%rsp), %rdi
movl $0x5, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x33e0
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xb866
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0xb86e
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb899
callq 0x3350
movq (%rsp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe300
movq %rax, %r15
testq %rax, %rax
je 0xb913
movl (%r15), %ebp
cmpl $0x6, %ebp
je 0xb8d5
cmpl $0x5, %ebp
jne 0xb909
movq 0x18(%r15), %rdi
leaq 0x8875(%rip), %rsi      # 0x1413c
callq 0x33c0
testl %eax, %eax
jne 0xb918
cmpl $0x6, %ebp
jne 0xb909
movq 0x18(%r15), %rdi
leaq 0x897b(%rip), %rsi      # 0x1425b
callq 0x33c0
testl %eax, %eax
jne 0xb918
movb $0x0, 0x90(%r14)
testq %rbx, %rbx
je 0xb8fe
movq %rbx, %rdi
callq 0xd540
movq %r14, %rdi
callq 0xb79c
movq %rax, %rbx
movq %r15, %rdi
callq 0xbc50
jmp 0xb91a
cmpl $0x0, (%rbx)
je 0xb8af
xorl %ebx, %ebx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xb928
callq 0x3350
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0xb961
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0xb95c
jmp 0xb961
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xb961
callq 0x3350
movq %rbx, %rdi
callq 0x35b0
nop