// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/geo.c
// Function: georadiusGeneric
void georadiusGeneric(client *c, int type) {
    robj *key = c->argv[1];
    robj *storekey = NULL;
    int storedist = 0; /* 0 for STORE, 1 for STOREDIST. */

    /* Look up the requested zset */
    robj *zobj = NULL;
    if ((zobj = lookupKeyReadOrReply(c, key, shared.emptymultibulk)) == NULL ||
        checkType(c, zobj, OBJ_ZSET)) {
        return;
    }

    /* Find long/lat to use for radius search based on inquiry type */
    int base_args;
    double xy[2] = { 0 };
    if (type == RADIUS_COORDS) {
        base_args = 6;
        if (extractLongLatOrReply(c, c->argv + 2, xy) == C_ERR)
            return;
    } else if (type == RADIUS_MEMBER) {
        base_args = 5;
        robj *member = c->argv[2];
        if (longLatFromMember(zobj, member, xy) == C_ERR) {
            addReplyError(c, "could not decode requested zset member");
            return;
        }
    } else {
        addReplyError(c, "unknown georadius search type");
        return;
    }

    /* Extract radius and units from arguments */
    double radius_meters = 0, conversion = 1;
    if ((radius_meters = extractDistanceOrReply(c, c->argv + base_args - 2,
                                                &conversion)) < 0) {
        return;
    }

    /* Discover and populate all optional parameters. */
    int withdist = 0, withhash = 0, withcoords = 0;
    int sort = SORT_NONE;
    long long count = 0;
    if (c->argc > base_args) {
        int remaining = c->argc - base_args;
        for (int i = 0; i < remaining; i++) {
            char *arg = c->argv[base_args + i]->ptr;
            if (!strcasecmp(arg, "withdist")) {
                withdist = 1;
            } else if (!strcasecmp(arg, "withhash")) {
                withhash = 1;
            } else if (!strcasecmp(arg, "withcoord")) {
                withcoords = 1;
            } else if (!strcasecmp(arg, "asc")) {
                sort = SORT_ASC;
            } else if (!strcasecmp(arg, "desc")) {
                sort = SORT_DESC;
            } else if (!strcasecmp(arg, "count") && (i+1) < remaining) {
                if (getLongLongFromObjectOrReply(c, c->argv[base_args+i+1],
                    &count, NULL) != C_OK) return;
                if (count <= 0) {
                    addReplyError(c,"COUNT must be > 0");
                    return;
                }
                i++;
            } else if (!strcasecmp(arg, "store") && (i+1) < remaining) {
                storekey = c->argv[base_args+i+1];
                storedist = 0;
                i++;
            } else if (!strcasecmp(arg, "storedist") && (i+1) < remaining) {
                storekey = c->argv[base_args+i+1];
                storedist = 1;
                i++;
            } else {
                addReply(c, shared.syntaxerr);
                return;
            }
        }
    }

    /* Trap options not compatible with STORE and STOREDIST. */
    if (storekey && (withdist || withhash || withcoords)) {
        addReplyError(c,
            "STORE option in GEORADIUS is not compatible with "
            "WITHDIST, WITHHASH and WITHCOORDS options");
        return;
    }

    /* COUNT without ordering does not make much sense, force ASC
     * ordering if COUNT was specified but no sorting was requested. */
    if (count != 0 && sort == SORT_NONE) sort = SORT_ASC;

    /* Get all neighbor geohash boxes for our radius search */
    GeoHashRadius georadius =
        geohashGetAreasByRadiusWGS84(xy[0], xy[1], radius_meters);

    /* Search the zset for all matching points */
    geoArray *ga = geoArrayCreate();
    membersOfAllNeighbors(zobj, georadius, xy[0], xy[1], radius_meters, ga);

    /* If no matching results, the user gets an empty reply. */
    if (ga->used == 0 && storekey == NULL) {
        addReply(c, shared.emptymultibulk);
        geoArrayFree(ga);
        return;
    }

    long result_length = ga->used;
    long returned_items = (count == 0 || result_length < count) ?
                          result_length : count;
    long option_length = 0;

    /* Process [optional] requested sorting */
    if (sort == SORT_ASC) {
        qsort(ga->array, result_length, sizeof(geoPoint), sort_gp_asc);
    } else if (sort == SORT_DESC) {
        qsort(ga->array, result_length, sizeof(geoPoint), sort_gp_desc);
    }

    if (storekey == NULL) {
        /* No target key, return results to user. */

        /* Our options are self-contained nested multibulk replies, so we
         * only need to track how many of those nested replies we return. */
        if (withdist)
            option_length++;

        if (withcoords)
            option_length++;

        if (withhash)
            option_length++;

        /* The multibulk len we send is exactly result_length. The result is
         * either all strings of just zset members  *or* a nested multi-bulk
         * reply containing the zset member string _and_ all the additional
         * options the user enabled for this request. */
        addReplyMultiBulkLen(c, returned_items);

        /* Finally send results back to the caller */
        int i;
        for (i = 0; i < returned_items; i++) {
            geoPoint *gp = ga->array+i;
            gp->dist /= conversion; /* Fix according to unit. */

            /* If we have options in option_length, return each sub-result
             * as a nested multi-bulk.  Add 1 to account for result value
             * itself. */
            if (option_length)
                addReplyMultiBulkLen(c, option_length + 1);

            addReplyBulkSds(c,gp->member);
            gp->member = NULL;

            if (withdist)
                addReplyDoubleDistance(c, gp->dist);

            if (withhash)
                addReplyLongLong(c, gp->score);

            if (withcoords) {
                addReplyMultiBulkLen(c, 2);
                addReplyHumanLongDouble(c, gp->longitude);
                addReplyHumanLongDouble(c, gp->latitude);
            }
        }
    } else {
        /* Target key, create a sorted set with the results. */
        robj *zobj;
        zset *zs;
        int i;
        size_t maxelelen = 0;

        if (returned_items) {
            zobj = createZsetObject();
            zs = zobj->ptr;
        }

        for (i = 0; i < returned_items; i++) {
            zskiplistNode *znode;
            geoPoint *gp = ga->array+i;
            gp->dist /= conversion; /* Fix according to unit. */
            double score = storedist ? gp->dist : gp->score;
            size_t elelen = sdslen(gp->member);
            robj *ele = createObject(OBJ_STRING,gp->member);

            if (maxelelen < elelen) maxelelen = elelen;
            incrRefCount(ele); /* Set refcount to 2 since we reference the
                                  object both in the skiplist and dict. */
            znode = zslInsert(zs->zsl,score,ele);
            serverAssert(dictAdd(zs->dict,ele,&znode->score) == DICT_OK);
            gp->member = NULL;
        }

        if (returned_items) {
            zsetConvertToZiplistIfNeeded(zobj,maxelelen);
            setKey(c->db,storekey,zobj);
            decrRefCount(zobj);
            notifyKeyspaceEvent(NOTIFY_LIST,"georadiusstore",storekey,
                                c->db->id);
            server.dirty += returned_items;
        } else if (dbDelete(c->db,storekey)) {
            signalModifiedKey(c->db,storekey);
            notifyKeyspaceEvent(NOTIFY_GENERIC,"del",storekey,c->db->id);
            server.dirty++;
        }
        addReplyLongLong(c, returned_items);
    }
    geoArrayFree(ga);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rsi
leaq 0x825ba(%rip), %r14     # 0x1072b0
movq 0x68(%r14), %rdx
callq 0x44f89
testq %rax, %rax
je 0x85174
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x441ab
testl %eax, %eax
jne 0x85174
xorpd %xmm0, %xmm0
movapd %xmm0, 0x120(%rsp)
cmpl $0x2, %ebp
je 0x84d66
cmpl $0x1, %ebp
jne 0x85090
movq 0x40(%rbx), %rsi
addq $0x10, %rsi
leaq 0x120(%rsp), %rdx
movq %rbx, %rdi
callq 0x843a2
movl $0x6, %r12d
cmpl $-0x1, %eax
jne 0x84d8d
jmp 0x85174
movq 0x40(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x120(%rsp), %rdx
movq %r15, %rdi
callq 0x8444b
movl $0x5, %r12d
cmpl $-0x1, %eax
je 0x8509c
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
leaq 0x138(%rsp), %rdx
movq %rax, (%rdx)
movq 0x40(%rbx), %rax
movl %r12d, %ecx
leaq (%rax,%rcx,8), %rsi
addq $-0x10, %rsi
movq %rbx, %rdi
callq 0x8454f
xorpd %xmm1, %xmm1
movsd %xmm0, 0x110(%rsp)
ucomisd %xmm0, %xmm1
ja 0x85174
movq $0x0, 0x118(%rsp)
movl 0x38(%rbx), %ebp
movl %ebp, %eax
subl %r12d, %eax
jle 0x850a8
testl %eax, %eax
setg 0x100(%rsp)
subl %r12d, %ebp
jle 0x850e4
movq $0x0, 0xe0(%rsp)
movl $0x0, 0xdc(%rsp)
movl $0x0, 0xf0(%rsp)
movl $0x0, 0xe8(%rsp)
movl $0x0, 0xd8(%rsp)
movq $0x0, 0x108(%rsp)
xorl %r13d, %r13d
movq %r12, 0xc8(%rsp)
movl %ebp, 0xd0(%rsp)
movq 0x40(%rbx), %r14
leal (%r12,%r13), %eax
movslq %eax, %r12
movq (%r14,%r12,8), %rax
movq 0x8(%rax), %rbp
movq %rbp, %rdi
leaq 0x4d78c(%rip), %rsi     # 0xd25fc
callq 0x26300
movb $0x1, %cl
testl %eax, %eax
je 0x84f29
movq %rbp, %rdi
leaq 0x4d77c(%rip), %rsi     # 0xd2605
callq 0x26300
testl %eax, %eax
je 0x84f48
movq %rbp, %rdi
leaq 0x4d76e(%rip), %rsi     # 0xd260e
callq 0x26300
testl %eax, %eax
je 0x84f58
movq %rbp, %rdi
leaq 0x4539c(%rip), %rsi     # 0xca253
callq 0x26300
testl %eax, %eax
je 0x84f68
movq %rbp, %rdi
leaq 0x45389(%rip), %rsi     # 0xca257
callq 0x26300
testl %eax, %eax
je 0x84ff6
movq %rbp, %rdi
leaq 0x4ad48(%rip), %rsi     # 0xcfc2d
callq 0x26300
testl %eax, %eax
jne 0x84f72
leal 0x1(%r13), %eax
cmpl 0xd0(%rsp), %eax
jge 0x84f72
movl %eax, 0xf8(%rsp)
movq 0x8(%r14,%r12,8), %rsi
movq %rbx, %rdi
leaq 0x118(%rsp), %rdx
xorl %ecx, %ecx
callq 0x44b44
testl %eax, %eax
je 0x85057
xorl %ecx, %ecx
jmp 0x84f34
movl $0x1, 0xf0(%rsp)
movq 0xc8(%rsp), %r12
movl 0xd0(%rsp), %ebp
jmp 0x85014
movl $0x1, 0xe8(%rsp)
jmp 0x85003
movl $0x1, 0xd8(%rsp)
jmp 0x85003
movl $0x1, %eax
jmp 0x84ffb
movq %rbp, %rdi
leaq 0x3a932(%rip), %rsi     # 0xbf8ae
callq 0x26300
testl %eax, %eax
jne 0x84faf
leal 0x1(%r13), %eax
cmpl 0xd0(%rsp), %eax
jge 0x84faf
movq 0x8(%r14,%r12,8), %rcx
movq %rcx, 0xe0(%rsp)
movl $0x0, 0xdc(%rsp)
movl %eax, %r13d
jmp 0x85003
movq %rbp, %rdi
leaq 0x4d671(%rip), %rsi     # 0xd262a
callq 0x26300
testl %eax, %eax
movl 0xd0(%rsp), %ebp
jne 0x85035
leal 0x1(%r13), %eax
cmpl %ebp, %eax
jge 0x85035
movq 0x8(%r14,%r12,8), %rcx
movq %rcx, 0xe0(%rsp)
movl $0x1, 0xdc(%rsp)
movl %eax, %r13d
movq 0xc8(%rsp), %r12
jmp 0x85012
movl $0x2, %eax
movq %rax, 0x108(%rsp)
movq 0xc8(%rsp), %r12
movl 0xd0(%rsp), %ebp
movb $0x1, %cl
testb %cl, %cl
je 0x85128
incl %r13d
cmpl %ebp, %r13d
setl 0x100(%rsp)
jl 0x84e53
jmp 0x85128
leaq 0x82274(%rip), %rax     # 0x1072b0
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x3fc19
xorl %ecx, %ecx
movq 0xc8(%rsp), %r12
jmp 0x85014
cmpq $0x0, 0x118(%rsp)
movq 0xc8(%rsp), %r12
movl 0xd0(%rsp), %ebp
jle 0x8507d
movl 0xf8(%rsp), %eax
movl %eax, %r13d
jmp 0x85012
movq %rbx, %rdi
leaq 0x4d591(%rip), %rsi     # 0xd2618
callq 0x3ffcb
xorl %ecx, %ecx
jmp 0x85014
leaq 0x4d547(%rip), %rsi     # 0xd25de
jmp 0x8516c
leaq 0x4d514(%rip), %rsi     # 0xd25b7
jmp 0x8516c
movq $0x0, 0x108(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xe8(%rsp)
movl $0x0, 0xf0(%rsp)
movl $0x0, 0xdc(%rsp)
xorl %eax, %eax
jmp 0x85141
movq $0x0, 0x108(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xe8(%rsp)
movl $0x0, 0xf0(%rsp)
movl $0x0, 0xdc(%rsp)
movq $0x0, 0xe0(%rsp)
testb $0x1, 0x100(%rsp)
movq 0xe0(%rsp), %rax
leaq 0x82171(%rip), %r14     # 0x1072b0
jne 0x85174
movq %rax, 0xe0(%rsp)
testq %rax, %rax
je 0x85186
movl 0xf0(%rsp), %eax
orl 0xe8(%rsp), %eax
orl 0xd8(%rsp), %eax
je 0x85186
leaq 0x4d4c8(%rip), %rsi     # 0xd2634
movq %rbx, %rdi
callq 0x3ffcb
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %r12
movq %rbx, 0xf8(%rsp)
movq 0x118(%rsp), %rbx
movsd 0x120(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
leaq 0x1c8(%rsp), %r13
movq %r13, %rdi
movsd 0x110(%rsp), %xmm2
callq 0xa1997
movl $0x18, %edi
callq 0x3b29d
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movsd 0x120(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
movl $0x18, %ecx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
movsd 0x110(%rsp), %xmm2
movq %rax, %rsi
callq 0x84a10
movq %r14, 0xc8(%rsp)
movq 0x10(%r14), %rsi
movq 0xe0(%rsp), %r14
movq %r14, %rax
orq %rsi, %rax
jne 0x85246
movq 0x68(%r12), %rsi
movq 0xf8(%rsp), %rdi
callq 0x3fc19
jmp 0x855fa
movq 0x108(%rsp), %rcx
testl %ecx, %ecx
movl $0x1, %eax
cmovnel %ecx, %eax
testq %rbx, %rbx
cmovel %ecx, %eax
movq 0x118(%rsp), %rcx
cmpq %rcx, %rsi
movq %rcx, %r13
cmovlq %rsi, %r13
testq %rcx, %rcx
cmoveq %rsi, %r13
cmpl $0x1, %eax
je 0x85292
cmpl $0x2, %eax
movq 0xf8(%rsp), %rbx
jne 0x852b6
leaq 0x3bf(%rip), %rcx       # 0x8564f
jmp 0x852a1
leaq 0x395(%rip), %rcx       # 0x8562e
movq 0xf8(%rsp), %rbx
movq 0xc8(%rsp), %rax
movq (%rax), %rdi
movl $0x28, %edx
callq 0x268a0
testq %r14, %r14
je 0x852e2
testq %r13, %r13
je 0x85420
callq 0x43f3a
movq %rax, 0xe8(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0xf0(%rsp)
jmp 0x85420
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4063b
testq %r13, %r13
jle 0x855fa
movq %r13, %r15
xorl %eax, %eax
cmpl $0x0, 0xf0(%rsp)
setne %al
leaq 0x1(%rax), %rbp
cmpl $0x0, 0xd8(%rsp)
cmoveq %rax, %rbp
cmpl $0x1, 0xe8(%rsp)
sbbq $-0x1, %rbp
leaq 0x1(%rbp), %rax
movq %rax, 0x100(%rsp)
movl $0x20, %r12d
movq 0xc8(%rsp), %rax
movq (%rax), %r13
movsd -0x10(%r13,%r12), %xmm0
divsd 0x138(%rsp), %xmm0
movsd %xmm0, -0x10(%r13,%r12)
testq %rbp, %rbp
je 0x8536b
movq %rbx, %rdi
movq 0x100(%rsp), %rsi
callq 0x4063b
movq (%r13,%r12), %rsi
movq %rbx, %rdi
callq 0x4074f
movq $0x0, (%r13,%r12)
cmpl $0x0, 0xf0(%rsp)
je 0x853be
movsd -0x10(%r13,%r12), %xmm0
movl $0x80, %esi
leaq 0x140(%rsp), %r14
movq %r14, %rdi
leaq 0x4d1bd(%rip), %rdx     # 0xd2566
movb $0x1, %al
callq 0x26120
movslq %eax, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4070f
cmpl $0x0, 0xe8(%rsp)
je 0x853d7
cvttsd2si -0x8(%r13,%r12), %rsi
movq %rbx, %rdi
callq 0x40606
cmpl $0x0, 0xd8(%rsp)
je 0x8540e
movl $0x2, %esi
movq %rbx, %rdi
callq 0x4063b
fldl -0x20(%r13,%r12)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x404ff
fldl -0x18(%r13,%r12)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x404ff
addq $0x28, %r12
decq %r15
jne 0x85334
jmp 0x855fa
testq %r13, %r13
movq %r13, 0x110(%rsp)
jle 0x8552c
movl $0x20, %r12d
xorl %ebp, %ebp
movq %r13, %r15
movq 0xc8(%rsp), %rax
movq (%rax), %r14
movsd -0x10(%r14,%r12), %xmm0
divsd 0x138(%rsp), %xmm0
movsd %xmm0, -0x10(%r14,%r12)
cmpl $0x0, 0xdc(%rsp)
jne 0x8546f
movsd -0x8(%r14,%r12), %xmm0
movq (%r14,%r12), %rsi
movzbl -0x1(%rsi), %ebx
movl %ebx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
movq %r15, 0x100(%rsp)
movsd %xmm0, 0xd0(%rsp)
ja 0x854be
leaq 0x4d027(%rip), %rcx     # 0xd24c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %ebx
jmp 0x854c0
movq -0x11(%rsi), %rbx
jmp 0x854c0
movzwl -0x5(%rsi), %ebx
jmp 0x854c0
movl -0x9(%rsi), %ebx
jmp 0x854c0
movzbl -0x3(%rsi), %ebx
jmp 0x854c0
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x43ab4
movq %rax, %r13
movq %rax, %rdi
callq 0x43c0c
movq 0xf0(%rsp), %r15
movq 0x8(%r15), %rdi
movsd 0xd0(%rsp), %xmm0
movq %r13, %rsi
callq 0x5361a
movq (%r15), %rdi
leaq 0x8(%rax), %rdx
movq %r13, %rsi
callq 0x31a95
testl %eax, %eax
movq 0x100(%rsp), %r15
jne 0x8560c
cmpq %rbx, %rbp
cmovbeq %rbx, %rbp
movq $0x0, (%r14,%r12)
addq $0x28, %r12
decq %r15
jne 0x8543c
jmp 0x8552e
xorl %ebp, %ebp
movq 0x110(%rsp), %r15
testq %r15, %r15
je 0x85595
movq 0xe8(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x554db
movq 0xf8(%rsp), %rbx
movq 0x10(%rbx), %rdi
movq 0xe0(%rsp), %r14
movq %r14, %rsi
movq %r12, %rdx
callq 0x45162
movq %r12, %rdi
callq 0x440f3
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x4d10c(%rip), %rsi     # 0xd268f
movl $0x10, %edi
movq %r14, %rdx
callq 0x800c9
movq %r15, %rax
jmp 0x855e1
movq 0xf8(%rsp), %rbx
movq 0x10(%rbx), %rdi
movq 0xe0(%rsp), %r14
movq %r14, %rsi
callq 0x452f3
testl %eax, %eax
je 0x855ef
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x45220
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x3bee7(%rip), %rsi     # 0xc14b6
movl $0x4, %edi
movq %r14, %rdx
callq 0x800c9
movl $0x1, %eax
leaq 0x81270(%rip), %rcx     # 0x106858
addq %rax, 0x710(%rcx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x40606
movq 0xc8(%rsp), %rdi
callq 0x84330
jmp 0x85174
leaq 0x41244(%rip), %rdi     # 0xc6857
leaq 0x4cf51(%rip), %rsi     # 0xd256b
movl $0x28c, %edx            # imm = 0x28C
callq 0x654e1
movl $0x1, %edi
callq 0x263d0