// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/geo.c
// Function: geohashCommand
void geohashCommand(client *c) {
    char *geoalphabet= "0123456789bcdefghjkmnpqrstuvwxyz";
    int j;

    /* Look up the requested zset */
    robj *zobj = NULL;
    if ((zobj = lookupKeyReadOrReply(c, c->argv[1], shared.emptymultibulk))
        == NULL || checkType(c, zobj, OBJ_ZSET)) return;

    /* Geohash elements one after the other, using a null bulk reply for
     * missing elements. */
    addReplyMultiBulkLen(c,c->argc-2);
    for (j = 2; j < c->argc; j++) {
        double score;
        if (zsetScore(zobj, c->argv[j], &score) == C_ERR) {
            addReply(c,shared.nullbulk);
        } else {
            /* The internal format we use for geocoding is a bit different
             * than the standard, since we use as initial latitude range
             * -85,85, while the normal geohashing algorithm uses -90,90.
             * So we have to decode our position and re-encode using the
             * standard ranges in order to output a valid geohash string. */

            /* Decode... */
            double xy[2];
            if (!decodeGeohash(score,xy)) {
                addReply(c,shared.nullbulk);
                continue;
            }

            /* Re-encode */
            GeoHashRange r[2];
            GeoHashBits hash;
            r[0].min = -180;
            r[0].max = 180;
            r[1].min = -90;
            r[1].max = 90;
            geohashEncode(&r[0],&r[1],xy[0],xy[1],26,&hash);

            char buf[12];
            int i;
            for (i = 0; i < 11; i++) {
                int idx = (hash.bits >> (52-((i+1)*5))) & 0x1f;
                buf[i] = geoalphabet[idx];
            }
            buf[11] = '\0';
            addReplyBulkCBuffer(c,buf,11);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rsi
leaq 0x81c05(%rip), %r15     # 0x1072b0
movq 0x68(%r15), %rdx
callq 0x44f89
testq %rax, %rax
je 0x8581e
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
jne 0x8581e
movslq 0x38(%rbx), %rsi
addq $-0x2, %rsi
movq %rbx, %rdi
callq 0x4063b
cmpl $0x3, 0x38(%rbx)
jl 0x8581e
movl $0x2, %r13d
leaq 0x8(%rsp), %r12
leaq 0x4cf9a(%rip), %rbp     # 0xd269e
movq 0x40(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x55517
cmpl $-0x1, %eax
je 0x85802
movsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x4b1ae(%rip), %xmm0    # 0xd08e8
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
movl $0x1a, %esi
leaq 0x40(%rsp), %rdx
callq 0xa10ee
testl %eax, %eax
je 0x85802
movabsq $-0x3f99800000000000, %rax # imm = 0xC066800000000000
movq %rax, 0x20(%rsp)
movabsq $0x4066800000000000, %rax # imm = 0x4066800000000000
movq %rax, 0x28(%rsp)
movabsq $-0x3fa9800000000000, %rax # imm = 0xC056800000000000
movq %rax, 0x30(%rsp)
movabsq $0x4056800000000000, %rax # imm = 0x4056800000000000
movq %rax, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x1a, %edx
leaq 0x58(%rsp), %rcx
callq 0xa0b6b
movl $0x2f, %ecx
movq 0x58(%rsp), %rax
leaq 0x14(%rsp), %rdx
movq %rax, %rsi
shrq %cl, %rsi
andl $0x1f, %esi
movb (%rsi,%rbp), %sil
movb %sil, (%rdx)
incq %rdx
addq $-0x5, %rcx
cmpq $-0x8, %rcx
jne 0x857cc
movb $0x0, 0x1f(%rsp)
movl $0xb, %edx
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0x4070f
jmp 0x8580e
movq 0x50(%r15), %rsi
movq %rbx, %rdi
callq 0x3fc19
incq %r13
movslq 0x38(%rbx), %rax
cmpq %rax, %r13
jl 0x85704
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq