// File: /workspace/github_c_makefile_star2_O3/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 $0x298, %rsp            # imm = 0x298
movl %esi, %ebp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rsi
leaq 0x81113(%rip), %r12     # 0x102310
movq 0x68(%r12), %rdx
callq 0x41af9
testq %rax, %rax
je 0x81223
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
movl $0x3, %edx
callq 0x40d47
testl %eax, %eax
je 0x81235
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
movapd %xmm0, 0x120(%rsp)
testb $0x1, %bpl
jne 0x8125a
testb $0x2, %bpl
jne 0x8127f
leaq 0x4e4a6(%rip), %rsi     # 0xcf6fb
jmp 0x81629
movq 0x40(%rbx), %rsi
addq $0x10, %rsi
leaq 0x120(%rsp), %rdx
movq %rbx, %rdi
callq 0x808f2
movl $0x6, %r14d
cmpl $-0x1, %eax
jne 0x812a6
jmp 0x81223
movq 0x40(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x120(%rsp), %rdx
movq %r13, %rdi
callq 0x809a1
movl $0x5, %r14d
cmpl $-0x1, %eax
je 0x81622
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
leaq 0x148(%rsp), %rdx
movq %rax, (%rdx)
movq 0x40(%rbx), %rax
movl %r14d, %ecx
leaq (%rax,%rcx,8), %rsi
addq $-0x10, %rsi
movq %rbx, %rdi
callq 0x80a85
movapd %xmm0, %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
ja 0x81223
movq $0x0, 0x118(%rsp)
movl 0x38(%rbx), %ecx
movq $0x0, 0x110(%rsp)
movb $0x1, %al
movq %rax, 0x140(%rsp)
subl %r14d, %ecx
movl %ecx, 0xc0(%rsp)
movsd %xmm2, 0xf8(%rsp)
jle 0x8156e
movl %ebp, 0x104(%rsp)
movq %r13, 0x138(%rsp)
movq $0x0, 0x110(%rsp)
movq $0x0, 0x108(%rsp)
movl $0x0, 0xcc(%rsp)
movl $0x0, 0xe8(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xd0(%rsp)
movl $0x0, 0xf0(%rsp)
xorl %r12d, %r12d
movq %r14, 0xe0(%rsp)
movq 0x40(%rbx), %r13
leal (%r12,%r14), %eax
movslq %eax, %rbp
movq (%r13,%rbp,8), %rax
movq 0x8(%rax), %r14
movq %r14, %rdi
leaq 0x4e370(%rip), %rsi     # 0xcf719
callq 0x262f0
testl %eax, %eax
je 0x81475
movq %r14, %rdi
leaq 0x4e362(%rip), %rsi     # 0xcf722
callq 0x262f0
testl %eax, %eax
je 0x81485
movq %r14, %rdi
leaq 0x4e354(%rip), %rsi     # 0xcf72b
callq 0x262f0
testl %eax, %eax
je 0x81495
movq %r14, %rdi
leaq 0x45ec5(%rip), %rsi     # 0xc72b3
callq 0x262f0
testl %eax, %eax
je 0x814a2
movq %r14, %rdi
leaq 0x45eb2(%rip), %rsi     # 0xc72b7
callq 0x262f0
testl %eax, %eax
je 0x81515
movq %r14, %rdi
leaq 0x4b911(%rip), %rsi     # 0xccd2d
callq 0x262f0
testl %eax, %eax
jne 0x814af
leal 0x1(%r12), %r15d
cmpl 0xc0(%rsp), %r15d
jge 0x814af
movq 0x8(%r13,%rbp,8), %rsi
movq %rbx, %rdi
leaq 0x118(%rsp), %rdx
xorl %ecx, %ecx
callq 0x416bb
testl %eax, %eax
jne 0x81223
movq 0x118(%rsp), %rcx
movq %rcx, 0x110(%rsp)
testq %rcx, %rcx
jg 0x81523
jmp 0x81ae5
movl $0x1, 0xe8(%rsp)
jmp 0x81520
movl $0x1, 0xd8(%rsp)
jmp 0x81520
movl $0x1, 0xd0(%rsp)
jmp 0x81520
movl $0x1, 0xf0(%rsp)
jmp 0x81520
movq %r14, %rdi
leaq 0x3b445(%rip), %rsi     # 0xbc8fe
callq 0x262f0
testl %eax, %eax
je 0x81541
movq %r14, %rdi
leaq 0x3fc31(%rip), %rsi     # 0xc10fd
callq 0x262f0
testl %eax, %eax
jne 0x81a44
testb $0x4, 0x104(%rsp)
jne 0x81a44
incl %r12d
movl $0x1, 0xcc(%rsp)
movl %r12d, %r15d
cmpl 0xc0(%rsp), %r12d
jge 0x81a44
movq 0x8(%r13,%rbp,8), %rax
movq %rax, 0x108(%rsp)
jmp 0x81523
movl $0x2, 0xf0(%rsp)
movl %r12d, %r15d
incl %r15d
movl %r15d, %r12d
cmpl 0xc0(%rsp), %r15d
movq 0xe0(%rsp), %r14
jl 0x8138b
jmp 0x815ae
testb $0x4, 0x104(%rsp)
jne 0x814c2
leal 0x1(%r12), %r15d
movl $0x0, 0xcc(%rsp)
cmpl 0xc0(%rsp), %r15d
jl 0x81506
jmp 0x814c2
xorl %r15d, %r15d
movl $0x0, 0xcc(%rsp)
movq $0x0, 0xe0(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xd0(%rsp)
movl $0x0, 0xf0(%rsp)
jmp 0x81660
movq $0x0, 0xe0(%rsp)
movq 0x108(%rsp), %r15
testq %r15, %r15
je 0x81636
movl 0xe8(%rsp), %eax
orl 0xd8(%rsp), %eax
orl 0xd0(%rsp), %eax
movl $0x0, %eax
movq %rax, 0x140(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0x0, 0xd0(%rsp)
leaq 0x80d0a(%rip), %r12     # 0x102310
movq 0x138(%rsp), %r13
movsd 0xf8(%rsp), %xmm2
je 0x81660
leaq 0x4e127(%rip), %rsi     # 0xcf747
jmp 0x81629
leaq 0x4e0ab(%rip), %rsi     # 0xcf6d4
movq %rbx, %rdi
callq 0x3cc06
jmp 0x81223
xorl %r15d, %r15d
movl 0xe8(%rsp), %eax
movq %rax, 0xe0(%rsp)
leaq 0x80cc1(%rip), %r12     # 0x102310
movq 0x138(%rsp), %r13
movsd 0xf8(%rsp), %xmm2
movsd 0x120(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
leaq 0x1d8(%rsp), %r14
movq %r14, %rdi
callq 0x9e441
movl $0x18, %edi
callq 0x382d1
movq %rax, %rbp
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 %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r13, %rdi
movsd 0xf8(%rsp), %xmm2
movq %rax, %rsi
callq 0x80f1e
movq %rbp, 0xc0(%rsp)
movq 0x10(%rbp), %rsi
testq %rsi, %rsi
setne %al
movq 0x140(%rsp), %r14
movl %r14d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x81707
movq 0x68(%r12), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x81ad3
movl 0xf0(%rsp), %ecx
testl %ecx, %ecx
movl $0x1, %eax
cmovnel %ecx, %eax
cmpq $0x0, 0x110(%rsp)
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 0x81750
cmpl $0x2, %eax
jne 0x8176c
leaq 0x3e6(%rip), %rcx       # 0x81b34
jmp 0x81757
leaq 0x3bc(%rip), %rcx       # 0x81b13
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
movl $0x28, %edx
callq 0x26890
testb %r14b, %r14b
je 0x818b1
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3d274
testq %r13, %r13
jle 0x81ad3
movq %r13, %r12
xorl %eax, %eax
cmpl $0x0, 0xe0(%rsp)
setne %al
leaq 0x1(%rax), %rbp
cmpl $0x0, 0xd0(%rsp)
cmoveq %rax, %rbp
cmpl $0x1, 0xd8(%rsp)
sbbq $-0x1, %rbp
leaq 0x1(%rbp), %rax
movq %rax, 0xe8(%rsp)
movl $0x20, %r13d
movq 0xc0(%rsp), %rax
movq (%rax), %r14
movsd -0x10(%r14,%r13), %xmm0
divsd 0x148(%rsp), %xmm0
movsd %xmm0, -0x10(%r14,%r13)
testq %rbp, %rbp
je 0x817fe
movq %rbx, %rdi
movq 0xe8(%rsp), %rsi
callq 0x3d274
movq (%r14,%r13), %rsi
movq %rbx, %rdi
callq 0x3d386
movq $0x0, (%r14,%r13)
cmpl $0x0, 0xe0(%rsp)
je 0x8184f
movsd -0x10(%r14,%r13), %xmm0
movl $0x80, %esi
leaq 0x150(%rsp), %r15
movq %r15, %rdi
leaq 0x4de49(%rip), %rdx     # 0xcf683
movb $0x1, %al
callq 0x26120
movslq %eax, %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3d346
cmpl $0x0, 0xd8(%rsp)
je 0x81868
cvttsd2si -0x8(%r14,%r13), %rsi
movq %rbx, %rdi
callq 0x3d23f
cmpl $0x0, 0xd0(%rsp)
je 0x8189f
movl $0x2, %esi
movq %rbx, %rdi
callq 0x3d274
fldl -0x20(%r14,%r13)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x3d138
fldl -0x18(%r14,%r13)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x3d138
addq $0x28, %r13
decq %r12
jne 0x817c7
jmp 0x81ad3
testq %r13, %r13
je 0x81a02
movq %r15, 0x108(%rsp)
callq 0x40ad6
testq %r13, %r13
movq %r13, 0xf0(%rsp)
movq %rax, 0xf8(%rsp)
jle 0x81a5f
movq %r13, %rcx
movq 0x8(%rax), %rax
movq %rax, 0xe8(%rsp)
movl $0x20, %r12d
xorl %r13d, %r13d
movq %rcx, %rdx
movq 0xe8(%rsp), %r14
movq 0xc0(%rsp), %rax
movq (%rax), %rdi
movsd -0x10(%rdi,%r12), %xmm0
divsd 0x148(%rsp), %xmm0
movsd %xmm0, -0x10(%rdi,%r12)
cmpl $0x0, 0xcc(%rsp)
jne 0x81936
movsd -0x8(%rdi,%r12), %xmm0
movq (%rdi,%r12), %rsi
movzbl -0x1(%rsi), %r15d
movl %r15d, %eax
andl $0x7, %eax
cmpl $0x4, %eax
movq %rdx, 0xe0(%rsp)
movq %rdi, 0xd0(%rsp)
movsd %xmm0, 0xd8(%rsp)
ja 0x81993
leaq 0x4dc76(%rip), %rcx     # 0xcf5e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %r15d
jmp 0x81996
movq -0x11(%rsi), %r15
jmp 0x81996
movzwl -0x5(%rsi), %r15d
jmp 0x81996
movl -0x9(%rsi), %r15d
jmp 0x81996
movzbl -0x3(%rsi), %r15d
jmp 0x81996
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x40650
movq %rax, %rbp
movq %rax, %rdi
callq 0x407a8
movq 0x8(%r14), %rdi
movsd 0xd8(%rsp), %xmm0
movq %rbp, %rsi
callq 0x4feda
movq (%r14), %rdi
leaq 0x8(%rax), %rdx
movq %rbp, %rsi
callq 0x2e9b8
testl %eax, %eax
movq 0xe0(%rsp), %rdx
jne 0x81af1
cmpq %r15, %r13
cmovbeq %r15, %r13
movq 0xd0(%rsp), %rax
movq $0x0, (%rax,%r12)
addq $0x28, %r12
decq %rdx
jne 0x81903
jmp 0x81a62
movq 0x10(%rbx), %rdi
movq %r15, %rsi
callq 0x41e5f
testl %eax, %eax
je 0x81ac8
movq 0x10(%rbx), %rdi
movq %r15, %rsi
callq 0x41d90
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x3caf8(%rip), %rsi     # 0xbe528
movl $0x4, %edi
movq %r15, %rdx
callq 0x7c665
movl $0x1, %eax
jmp 0x81aba
leaq 0x808c5(%rip), %rax     # 0x102310
movq 0x80(%rax), %rsi
movq %rbx, %rdi
callq 0x3c854
jmp 0x81223
xorl %r13d, %r13d
movq 0xf8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x51db4
movq 0x10(%rbx), %rdi
movq 0x108(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x41cd2
movq %r15, %rdi
callq 0x40c8f
movq 0x10(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x4dd00(%rip), %rsi     # 0xcf7a2
movl $0x10, %edi
movq %r14, %rdx
callq 0x7c665
movq 0xf0(%rsp), %r13
movq %r13, %rax
leaq 0x7fde7(%rip), %rcx     # 0x1018a8
addq %rax, 0x720(%rcx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3d23f
movq 0xc0(%rsp), %rdi
callq 0x80880
jmp 0x81223
leaq 0x4dc49(%rip), %rsi     # 0xcf735
jmp 0x81629
leaq 0x41ddf(%rip), %rdi     # 0xc38d7
leaq 0x4db89(%rip), %rsi     # 0xcf688
movl $0x293, %edx            # imm = 0x293
callq 0x61908
movl $0x1, %edi
callq 0x263c0