// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 0x85813(%rip), %rax     # 0xfa310
movq 0x68(%rax), %rdx
callq 0x3aee5
testq %rax, %rax
je 0x74b20
movq %rax, %r14
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
je 0x74b2f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0x38(%rbx), %rsi
addq $-0x2, %rsi
movq %rbx, %rdi
callq 0x370d9
pushq $0x2
popq %r13
leaq 0x8(%rsp), %r12
leaq 0x24(%rsp), %r15
leaq 0x4b81d(%rip), %rbp     # 0xc0371
movslq 0x38(%rbx), %rax
cmpq %rax, %r13
jge 0x74b20
movq 0x40(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x49447
cmpl $-0x1, %eax
je 0x74bee
movsd 0x8(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
callq 0x7395f
testl %eax, %eax
je 0x74bee
movaps 0x4b5f0(%rip), %xmm0    # 0xc0180
movaps %xmm0, 0x30(%rsp)
movaps 0x4b5f4(%rip), %xmm0    # 0xc0190
movaps %xmm0, 0x40(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x1a
popq %rdx
leaq 0x58(%rsp), %rcx
callq 0x8dd25
movq 0x58(%rsp), %rax
movq %r15, %rdx
pushq $0x2f
popq %rcx
cmpq $-0x8, %rcx
je 0x74c03
movq %rax, %rsi
shrq %cl, %rsi
andl $0x1f, %esi
movb (%rsi,%rbp), %sil
movb %sil, (%rdx)
addq $-0x5, %rcx
incq %rdx
jmp 0x74bcf
leaq 0x8571b(%rip), %rax     # 0xfa310
movq 0x50(%rax), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x74c16
movb $0x0, 0x2f(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
pushq $0xb
popq %rdx
callq 0x3716c
incq %r13
jmp 0x74b54