// File: /workspace/github_c_makefile_star2_O3/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 0x8076c(%rip), %r15     # 0x102310
movq 0x68(%r15), %rdx
callq 0x41af9
testq %rax, %rax
je 0x81cf3
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
jne 0x81cf3
movslq 0x38(%rbx), %rsi
addq $-0x2, %rsi
movq %rbx, %rdi
callq 0x3d274
cmpl $0x3, 0x38(%rbx)
jl 0x81cf3
movl $0x2, %r13d
leaq 0x8(%rsp), %r12
leaq 0x4dbb4(%rip), %rbp     # 0xcf7b1
movq 0x40(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x51df0
cmpl $-0x1, %eax
je 0x81cd7
movsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x4bdcd(%rip), %xmm0    # 0xcda00
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
movl $0x1a, %esi
leaq 0x20(%rsp), %rdx
callq 0x9db96
testl %eax, %eax
je 0x81cd7
movaps 0x4d964(%rip), %xmm0    # 0xcf5c0
movaps %xmm0, 0x30(%rsp)
movaps 0x4d968(%rip), %xmm0    # 0xcf5d0
movaps %xmm0, 0x40(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x1a, %edx
leaq 0x58(%rsp), %rcx
callq 0x9d68d
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 0x81ca1
movb $0x0, 0x1f(%rsp)
movl $0xb, %edx
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0x3d346
jmp 0x81ce3
movq 0x50(%r15), %rsi
movq %rbx, %rdi
callq 0x3c854
incq %r13
movslq 0x38(%rbx), %rax
cmpq %rax, %r13
jl 0x81bfd
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq