// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/geo.c
// Function: georadiusGeneric
void georadiusGeneric(client *c, int flags) {
    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 (flags & RADIUS_COORDS) {
        base_args = 6;
        if (extractLongLatOrReply(c, c->argv + 2, xy) == C_ERR)
            return;
    } else if (flags & 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 &&
                       !(flags & RADIUS_NOSTORE))
            {
                storekey = c->argv[base_args+i+1];
                storedist = 0;
                i++;
            } else if (!strcasecmp(arg, "storedist") &&
                       (i+1) < remaining &&
                       !(flags & RADIUS_NOSTORE))
            {
                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 $0x208, %rsp            # imm = 0x208
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rsi
leaq 0x8612f(%rip), %r14     # 0xfa310
movq 0x68(%r14), %rdx
callq 0x3aee5
testq %rax, %rax
je 0x74204
movq %rax, %r15
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a311
testl %eax, %eax
je 0x74216
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
movapd %xmm0, 0x120(%rsp)
testb $0x1, %bpl
jne 0x7423b
testb $0x2, %bpl
jne 0x7425c
leaq 0x4c085(%rip), %rsi     # 0xc02bb
jmp 0x745ed
movq 0x40(%rbx), %rsi
addq $0x10, %rsi
leaq 0x120(%rsp), %rdx
movq %rbx, %rdi
callq 0x73989
cmpl $-0x1, %eax
je 0x74204
pushq $0x6
jmp 0x7427f
movq 0x40(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x120(%rsp), %rdx
movq %r15, %rdi
callq 0x73a2a
cmpl $-0x1, %eax
je 0x745e6
pushq $0x5
popq %r12
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
leaq 0x140(%rsp), %rdx
movq %rax, (%rdx)
movq 0x40(%rbx), %rax
movl %r12d, %ecx
leaq (%rax,%rcx,8), %rsi
addq $-0x10, %rsi
movq %rbx, %rdi
callq 0x73ae5
xorpd %xmm1, %xmm1
movsd %xmm0, 0x100(%rsp)
ucomisd %xmm0, %xmm1
ja 0x74204
andq $0x0, 0x118(%rsp)
movl 0x38(%rbx), %ecx
movb $0x1, %al
movq %rax, 0x138(%rsp)
subl %r12d, %ecx
movl %ecx, 0xc0(%rsp)
jle 0x7452f
movq %r12, 0xe0(%rsp)
movl %ebp, 0xfc(%rsp)
movq %r15, 0x130(%rsp)
movq $0x0, 0x110(%rsp)
xorl %r13d, %r13d
movl $0x0, 0xe8(%rsp)
movl $0x0, 0xd0(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xf0(%rsp)
movl $0x0, 0xcc(%rsp)
movq $0x0, 0x108(%rsp)
cmpl 0xc0(%rsp), %r13d
jge 0x7457b
movq 0x40(%rbx), %r12
movq 0xe0(%rsp), %rax
addl %r13d, %eax
movslq %eax, %rbp
movq (%r12,%rbp,8), %rax
movq 0x8(%rax), %r14
movq %r14, %rdi
leaq 0x4bf54(%rip), %rsi     # 0xc02d9
callq 0x262f0
testl %eax, %eax
je 0x74450
movq %r14, %rdi
leaq 0x4bf46(%rip), %rsi     # 0xc02e2
callq 0x262f0
testl %eax, %eax
je 0x74462
movq %r14, %rdi
leaq 0x4bf38(%rip), %rsi     # 0xc02eb
callq 0x262f0
testl %eax, %eax
je 0x74474
movq %r14, %rdi
leaq 0x44101(%rip), %rsi     # 0xb84cb
callq 0x262f0
testl %eax, %eax
je 0x74483
movq %r14, %rdi
leaq 0x440ee(%rip), %rsi     # 0xb84cf
callq 0x262f0
testl %eax, %eax
je 0x744ef
movq %r14, %rdi
leaq 0x49581(%rip), %rsi     # 0xbd979
callq 0x262f0
testl %eax, %eax
jne 0x7448a
leal 0x1(%r13), %r15d
cmpl 0xc0(%rsp), %r15d
jge 0x7448a
movq 0x8(%r12,%rbp,8), %rsi
movq %rbx, %rdi
leaq 0x118(%rsp), %rdx
xorl %ecx, %ecx
callq 0x3ab03
testl %eax, %eax
jne 0x74204
movq 0x118(%rsp), %rcx
movq %rcx, 0x110(%rsp)
testq %rcx, %rcx
jg 0x744fc
jmp 0x74a4c
movl %r13d, %r15d
pushq $0x1
popq %rax
movl %eax, 0xf0(%rsp)
jmp 0x744fc
movl %r13d, %r15d
pushq $0x1
popq %rax
movl %eax, 0xd8(%rsp)
jmp 0x744fc
movl %r13d, %r15d
pushq $0x1
popq %rax
movl %eax, 0xd0(%rsp)
jmp 0x744fc
movl %r13d, %r15d
pushq $0x1
jmp 0x744f4
movq %r14, %rdi
leaq 0x3a35a(%rip), %rsi     # 0xae7ee
callq 0x262f0
testl %eax, %eax
je 0x74507
movq %r14, %rdi
leaq 0x3e452(%rip), %rsi     # 0xb28f9
callq 0x262f0
testl %eax, %eax
jne 0x74a31
testb $0x4, 0xfc(%rsp)
jne 0x74a31
incl %r13d
movl %r13d, %r15d
pushq $0x1
popq %rax
movl %eax, 0xcc(%rsp)
cmpl 0xc0(%rsp), %r13d
jge 0x74a31
movq 0x8(%r12,%rbp,8), %rax
movq %rax, 0x108(%rsp)
jmp 0x744fc
movl %r13d, %r15d
pushq $0x2
popq %rax
movl %eax, 0xe8(%rsp)
incl %r15d
movl %r15d, %r13d
jmp 0x74353
testb $0x4, 0xfc(%rsp)
jne 0x7449d
leal 0x1(%r13), %r15d
movl $0x0, 0xcc(%rsp)
cmpl 0xc0(%rsp), %r15d
jl 0x744e0
jmp 0x7449d
movq $0x0, 0x110(%rsp)
xorl %r12d, %r12d
movl $0x0, 0xcc(%rsp)
movq $0x0, 0xe0(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xd0(%rsp)
movl $0x0, 0xe8(%rsp)
jmp 0x7461b
movq $0x0, 0xe0(%rsp)
movq 0x108(%rsp), %r12
testq %r12, %r12
je 0x745fa
movl 0xf0(%rsp), %eax
orl 0xd8(%rsp), %eax
orl 0xd0(%rsp), %eax
movl $0x0, %eax
movq %rax, 0x138(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xd0(%rsp)
leaq 0x85d3d(%rip), %r14     # 0xfa310
movq 0x130(%rsp), %r15
je 0x7461b
leaq 0x4bd23(%rip), %rsi     # 0xc0307
jmp 0x745ed
leaq 0x4bca7(%rip), %rsi     # 0xc0294
movq %rbx, %rdi
callq 0x36b6f
jmp 0x74204
xorl %r12d, %r12d
movl 0xf0(%rsp), %eax
movq %rax, 0xe0(%rsp)
leaq 0x85cfd(%rip), %r14     # 0xfa310
movq 0x130(%rsp), %r15
movsd 0x120(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
leaq 0x148(%rsp), %rbp
movq %rbp, %rdi
movsd 0x100(%rsp), %xmm2
callq 0x8e991
callq 0x738c4
movq %rax, %r13
movsd 0x120(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
pushq $0x18
popq %rcx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
movsd 0x100(%rsp), %xmm2
movq %rax, %rsi
callq 0x73f47
movq %r13, 0xc0(%rsp)
movq 0x10(%r13), %rsi
testq %rsi, %rsi
setne %al
movq 0x138(%rsp), %r15
movl %r15d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x746b5
movq 0x68(%r14), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x74a1f
movl 0xe8(%rsp), %eax
testl %eax, %eax
pushq $0x1
popq %rcx
cmovnel %eax, %ecx
cmpq $0x0, 0x110(%rsp)
cmovel %eax, %ecx
movq 0x118(%rsp), %rax
cmpq %rax, %rsi
movq %rax, %r14
cmovlq %rsi, %r14
testq %rax, %rax
cmoveq %rsi, %r14
cmpl $0x1, %ecx
je 0x746fc
cmpl $0x2, %ecx
jne 0x74716
leaq 0x39d(%rip), %rcx       # 0x74a97
jmp 0x74703
leaq 0x375(%rip), %rcx       # 0x74a78
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
pushq $0x28
popq %rdx
callq 0x26890
testb %r15b, %r15b
je 0x74826
xorl %eax, %eax
cmpl $0x0, 0xe0(%rsp)
setne %al
movq %r14, %r15
leaq 0x1(%rax), %r14
cmpl $0x0, 0xd0(%rsp)
cmoveq %rax, %r14
cmpl $0x1, 0xd8(%rsp)
sbbq $-0x1, %r14
movq %rbx, %rdi
movq %r15, %rsi
callq 0x370d9
leaq 0x1(%r14), %r12
xorl %ebp, %ebp
testq %r15, %r15
cmovgq %r15, %rbp
pushq $0x20
popq %r15
subq $0x1, %rbp
jb 0x74a1f
movq 0xc0(%rsp), %rax
movq (%rax), %r13
movsd -0x10(%r13,%r15), %xmm0
divsd 0x140(%rsp), %xmm0
movsd %xmm0, -0x10(%r13,%r15)
testq %r14, %r14
je 0x747a3
movq %rbx, %rdi
movq %r12, %rsi
callq 0x370d9
movq (%r13,%r15), %rsi
movq %rbx, %rdi
callq 0x371aa
andq $0x0, (%r13,%r15)
cmpl $0x0, 0xe0(%rsp)
je 0x747cf
movsd -0x10(%r13,%r15), %xmm0
movq %rbx, %rdi
callq 0x73b7b
cmpl $0x0, 0xd8(%rsp)
je 0x747e8
cvttsd2si -0x8(%r13,%r15), %rsi
movq %rbx, %rdi
callq 0x370a6
cmpl $0x0, 0xd0(%rsp)
je 0x7481d
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x370d9
fldl -0x20(%r13,%r15)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x36fa3
fldl -0x18(%r13,%r15)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x36fa3
addq $0x28, %r15
jmp 0x74767
testq %r14, %r14
je 0x74846
callq 0x3a0df
movq %rax, 0xe8(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0xf0(%rsp)
jmp 0x74846
xorl %ecx, %ecx
testq %r14, %r14
movl $0x0, %r15d
movq %r14, 0x100(%rsp)
cmovgq %r14, %r15
pushq $0x20
popq %r14
movq %rbx, 0xd0(%rsp)
movq %r12, 0x108(%rsp)
subq $0x1, %r15
jb 0x74979
movq 0xc0(%rsp), %rax
movq (%rax), %r12
movsd -0x10(%r12,%r14), %xmm0
divsd 0x140(%rsp), %xmm0
movsd %xmm0, -0x10(%r12,%r14)
cmpl $0x0, 0xcc(%rsp)
jne 0x748ae
movsd -0x8(%r12,%r14), %xmm0
movq (%r12,%r14), %rsi
movzbl -0x1(%rsi), %r13d
movl %r13d, %eax
andl $0x7, %eax
cmpl $0x4, %eax
movq %rcx, 0xd8(%rsp)
movsd %xmm0, 0xe0(%rsp)
ja 0x74903
leaq 0x4b8c6(%rip), %rdx     # 0xc01a0
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
shrl $0x3, %r13d
jmp 0x74906
movq -0x11(%rsi), %r13
jmp 0x74906
movzwl -0x5(%rsi), %r13d
jmp 0x74906
movl -0x9(%rsi), %r13d
jmp 0x74906
movzbl -0x3(%rsi), %r13d
jmp 0x74906
xorl %r13d, %r13d
xorl %edi, %edi
callq 0x39d58
movq %rax, %rbp
movq %rax, %rdi
callq 0x39e74
movq 0xf0(%rsp), %rbx
movq 0x8(%rbx), %rdi
movsd 0xe0(%rsp), %xmm0
movq %rbp, %rsi
callq 0x479ab
movq (%rbx), %rdi
leaq 0x8(%rax), %rdx
movq %rbp, %rsi
callq 0x2a3ed
testl %eax, %eax
jne 0x74a58
movq 0xd8(%rsp), %rcx
cmpq %r13, %rcx
cmovbeq %r13, %rcx
andq $0x0, (%r12,%r14)
addq $0x28, %r14
movq 0x108(%rsp), %r12
movq 0xd0(%rsp), %rbx
jmp 0x74871
movq 0x100(%rsp), %r14
testq %r14, %r14
je 0x749ce
movq 0xe8(%rsp), %r15
movq %r15, %rdi
movq %rcx, %rsi
callq 0x4940d
movq 0x10(%rbx), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3b076
movq %r15, %rdi
callq 0x3a265
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x4b9a4(%rip), %rsi     # 0xc0362
pushq $0x10
popq %rdi
movq %r12, %rdx
callq 0x6fb58
movq %r14, %rax
jmp 0x74a06
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x3b1df
testl %eax, %eax
je 0x74a14
movq 0x10(%rbx), %rdi
movq %r12, %rsi
callq 0x3b125
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x3ba20(%rip), %rsi     # 0xb0418
pushq $0x4
popq %rdi
movq %r12, %rdx
callq 0x6fb58
pushq $0x1
popq %rax
leaq 0x84e9b(%rip), %rcx     # 0xf98a8
addq %rax, 0x720(%rcx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x370a6
movq 0xc0(%rsp), %rdi
callq 0x73923
jmp 0x74204
leaq 0x858d8(%rip), %rax     # 0xfa310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x36987
jmp 0x74204
leaq 0x4b8a2(%rip), %rsi     # 0xc02f5
jmp 0x745ed
leaq 0x402f4(%rip), %rdi     # 0xb4d53
leaq 0x4b7e2(%rip), %rsi     # 0xc0248
movl $0x293, %edx            # imm = 0x293
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0