// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/geo.c
// Function: geoaddCommand
void geoaddCommand(client *c) {
    /* Check arguments number for sanity. */
    if ((c->argc - 2) % 3 != 0) {
        /* Need an odd number of arguments if we got this far... */
        addReplyError(c, "syntax error. Try GEOADD key [x1] [y1] [name1] "
                         "[x2] [y2] [name2] ... ");
        return;
    }

    int elements = (c->argc - 2) / 3;
    int argc = 2+elements*2; /* ZADD key score ele ... */
    robj **argv = zcalloc(argc*sizeof(robj*));
    argv[0] = createRawStringObject("zadd",4);
    argv[1] = c->argv[1]; /* key */
    incrRefCount(argv[1]);

    /* Create the argument vector to call ZADD in order to add all
     * the score,value pairs to the requested zset, where score is actually
     * an encoded version of lat,long. */
    int i;
    for (i = 0; i < elements; i++) {
        double xy[2];

        if (extractLongLatOrReply(c, (c->argv+2)+(i*3),xy) == C_ERR) {
            for (i = 0; i < argc; i++)
                if (argv[i]) decrRefCount(argv[i]);
            zfree(argv);
            return;
        }

        /* Turn the coordinates into the score of the element. */
        GeoHashBits hash;
        geohashEncodeWGS84(xy[0], xy[1], GEO_STEP_MAX, &hash);
        GeoHashFix52Bits bits = geohashAlign52Bits(hash);
        robj *score = createObject(OBJ_STRING, sdsfromlonglong(bits));
        robj *val = c->argv[2 + i * 3 + 2];
        argv[2+i*2] = score;
        argv[3+i*2] = val;
        incrRefCount(val);
    }

    /* Finally call ZADD that will do the work for us. */
    replaceClientCommandVector(c,argc,argv);
    zaddCommand(c);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl 0x38(%rdi), %r15d
imull $0xaaaaaaab, %r15d, %eax # imm = 0xAAAAAAAB
addl $0xd5555554, %eax       # imm = 0xD5555554
cmpl $0x55555555, %eax       # imm = 0x55555555
jb 0x8107e
leaq 0x4e626(%rip), %rsi     # 0xcf68e
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3cc06
leal -0x2(%r15), %eax
cltq
imulq $0x55555556, %rax, %r12 # imm = 0x55555556
movq %r12, %rax
shrq $0x3f, %rax
shrq $0x20, %r12
addl %eax, %r12d
leal (%r12,%r12), %eax
leal 0x2(,%r12,2), %ecx
movl %ecx, 0xc(%rsp)
cltq
leaq 0x10(,%rax,8), %rdi
callq 0x38323
movq %rax, %r14
leaq 0x3b5ce(%rip), %rdi     # 0xbc690
movl $0x4, %esi
callq 0x4068b
movq %rax, (%r14)
movq 0x40(%rbx), %rax
movq 0x8(%rax), %rdi
movq %rdi, 0x8(%r14)
callq 0x407a8
cmpl $0x5, %r15d
jl 0x81180
cmpl $0x2, %r12d
movl $0x1, %r13d
cmovgel %r12d, %r13d
shlq $0x4, %r13
movl $0x10, %ebp
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
movq 0x40(%rbx), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x808f2
cmpl $-0x1, %eax
je 0x81199
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movl $0x1a, %edi
leaq 0x28(%rsp), %rsi
callq 0x9d888
movq 0x28(%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x9e44f
movq %rax, %rdi
callq 0x36e1a
xorl %edi, %edi
movq %rax, %rsi
callq 0x40650
movq 0x40(%rbx), %rcx
movq 0x10(%rcx,%rbp), %rdi
movq %rax, 0x10(%r14,%r12)
movq %rdi, 0x18(%r14,%r12)
callq 0x407a8
addq $0x10, %r12
addq $0x18, %rbp
cmpq %r12, %r13
jne 0x81109
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movq %r14, %rdx
callq 0x3f779
movq %rbx, %rdi
callq 0x52567
jmp 0x811c9
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
testq %rdi, %rdi
je 0x811b9
callq 0x40c8f
incq %r15
cmpq %r15, %rbx
jne 0x811ab
movq %r14, %rdi
callq 0x38413
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq