// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/sort.c
// Function: lookupKeyByPattern
robj *lookupKeyByPattern(redisDb *db, robj *pattern, robj *subst) {
    char *p, *f, *k;
    sds spat, ssub;
    robj *keyobj, *fieldobj = NULL, *o;
    int prefixlen, sublen, postfixlen, fieldlen;

    /* If the pattern is "#" return the substitution object itself in order
     * to implement the "SORT ... GET #" feature. */
    spat = pattern->ptr;
    if (spat[0] == '#' && spat[1] == '\0') {
        incrRefCount(subst);
        return subst;
    }

    /* The substitution object may be specially encoded. If so we create
     * a decoded object on the fly. Otherwise getDecodedObject will just
     * increment the ref count, that we'll decrement later. */
    subst = getDecodedObject(subst);
    ssub = subst->ptr;

    /* If we can't find '*' in the pattern we return NULL as to GET a
     * fixed key does not make sense. */
    p = strchr(spat,'*');
    if (!p) {
        decrRefCount(subst);
        return NULL;
    }

    /* Find out if we're dealing with a hash dereference. */
    if ((f = strstr(p+1, "->")) != NULL && *(f+2) != '\0') {
        fieldlen = sdslen(spat)-(f-spat)-2;
        fieldobj = createStringObject(f+2,fieldlen);
    } else {
        fieldlen = 0;
    }

    /* Perform the '*' substitution. */
    prefixlen = p-spat;
    sublen = sdslen(ssub);
    postfixlen = sdslen(spat)-(prefixlen+1)-(fieldlen ? fieldlen+2 : 0);
    keyobj = createStringObject(NULL,prefixlen+sublen+postfixlen);
    k = keyobj->ptr;
    memcpy(k,spat,prefixlen);
    memcpy(k+prefixlen,ssub,sublen);
    memcpy(k+prefixlen+sublen,p+1,postfixlen);
    decrRefCount(subst); /* Incremented by decodeObject() */

    /* Lookup substituted key */
    o = lookupKeyRead(db,keyobj);
    if (o == NULL) goto noobj;

    if (fieldobj) {
        if (o->type != OBJ_HASH) goto noobj;

        /* Retrieve value from hash by the field name. This operation
         * already increases the refcount of the returned object. */
        o = hashTypeGetObject(o, fieldobj);
    } else {
        if (o->type != OBJ_STRING) goto noobj;

        /* Every object that this function returns needs to have its refcount
         * increased. sortCommand decreases it again. */
        incrRefCount(o);
    }
    decrRefCount(keyobj);
    if (fieldobj) decrRefCount(fieldobj);
    return o;

noobj:
    decrRefCount(keyobj);
    if (fieldlen) decrRefCount(fieldobj);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq 0x8(%rsi), %r15
cmpb $0x23, (%r15)
jne 0x63898
cmpb $0x0, 0x1(%r15)
je 0x6391c
movq %r14, %rdi
callq 0x41026
movq %rax, %r13
movq 0x8(%rax), %rbp
movq %r15, %rdi
movl $0x2a, %esi
callq 0x267f0
testq %rax, %rax
je 0x63914
movq %rax, %r12
leaq 0x1(%rax), %rdi
leaq 0x639e9(%rip), %rsi     # 0xc72b0
movq %rdi, 0x18(%rsp)
callq 0x266b0
testq %rax, %rax
je 0x63907
cmpb $0x0, 0x2(%rax)
je 0x63907
movq %rax, %rdi
addq $0x2, %rdi
movzbl -0x1(%r15), %ecx
movl %ecx, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x63943
leaq 0x6397b(%rip), %rsi     # 0xc7274
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
shrl $0x3, %ecx
jmp 0x63945
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
jmp 0x63962
movq %r13, %rdi
jmp 0x63ac5
movq %r14, %rdi
callq 0x407a8
jmp 0x63acd
movq -0x11(%r15), %rcx
jmp 0x63945
movzwl -0x5(%r15), %ecx
jmp 0x63945
movl -0x9(%r15), %ecx
jmp 0x63945
movzbl -0x3(%r15), %ecx
jmp 0x63945
xorl %ecx, %ecx
movl %r15d, %edx
subl %eax, %edx
leal (%rdx,%rcx), %r14d
addl $-0x2, %r14d
movslq %r14d, %rsi
callq 0x40744
movq %r14, %rsi
movq %rax, 0x8(%rsp)
movzbl -0x1(%rbp), %r14d
movl %r14d, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x639a2
leaq 0x6390f(%rip), %rcx     # 0xc7288
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %r14d
jmp 0x639a5
movq -0x11(%rbp), %r14
jmp 0x639a5
movzwl -0x5(%rbp), %r14d
jmp 0x639a5
movl -0x9(%rbp), %r14d
jmp 0x639a5
movzbl -0x3(%rbp), %r14d
jmp 0x639a5
xorl %r14d, %r14d
subq %r15, %r12
movzbl -0x1(%r15), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
movq %rbx, 0x30(%rsp)
movq %r13, 0x28(%rsp)
movq %rbp, 0x20(%rsp)
ja 0x639f5
leaq 0x638cf(%rip), %rdx     # 0xc729c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x639f7
movq -0x11(%r15), %rax
jmp 0x639f7
movzwl -0x5(%r15), %eax
jmp 0x639f7
movl -0x9(%r15), %eax
jmp 0x639f7
movzbl -0x3(%r15), %eax
jmp 0x639f7
xorl %eax, %eax
leal 0x2(%rsi), %ecx
testl %esi, %esi
movq %rsi, 0x10(%rsp)
cmovel %esi, %ecx
movq %r12, %rbp
notq %rbp
subq %rcx, %rbp
addq %rax, %rbp
leal (%r14,%r12), %eax
addl %ebp, %eax
movslq %eax, %rsi
xorl %edi, %edi
callq 0x40744
movq %rax, %rbx
movq 0x8(%rax), %r13
movslq %r12d, %r12
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x26c50
addq %r12, %r13
movslq %r14d, %r15
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x26c50
addq %r15, %r13
movslq %ebp, %rdx
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x26c50
movq 0x28(%rsp), %rdi
callq 0x40c8f
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x41acf
testq %rax, %rax
movq 0x8(%rsp), %r15
je 0x63ab3
movq %rax, %r14
movl (%rax), %eax
andl $0xf, %eax
testq %r15, %r15
je 0x63aaf
cmpl $0x4, %eax
jne 0x63ab3
movq %r14, %rdi
movq %r15, %rsi
callq 0x5569d
movq %rax, %r14
movq %rbx, %rdi
callq 0x40c8f
movq %r15, %rdi
jmp 0x63aea
testl %eax, %eax
je 0x63adf
movq %rbx, %rdi
callq 0x40c8f
cmpl $0x0, 0x10(%rsp)
je 0x63aca
movq %r15, %rdi
callq 0x40c8f
xorl %r14d, %r14d
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x407a8
movq %rbx, %rdi
callq 0x40c8f
jmp 0x63acd