// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
subl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xa4958
movq -0x8(%rbp), %rdi
leaq 0xa4ba2(%rip), %rsi     # 0x1494f0
callq 0x42f90
jmp 0xa4b08
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
subl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
shll %eax
addl $0x2, %eax
movl %eax, -0x10(%rbp)
movslq -0x10(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3ad80
movq %rax, -0x18(%rbp)
leaq 0x92c70(%rip), %rdi     # 0x137600
movl $0x4, %esi
callq 0x48540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x487b0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xa4aef
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
addq $0x10, %rsi
imull $0x3, -0x1c(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rsi
leaq -0x30(%rbp), %rdx
callq 0xa3980
cmpl $-0x1, %eax
jne 0xa4a4d
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0xa4a3f
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0xa4a32
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x48f70
jmp 0xa4a34
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa4a0a
movq -0x18(%rbp), %rdi
callq 0x3afa0
jmp 0xa4b08
movsd -0x30(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movl $0x1a, %edi
leaq -0x40(%rbp), %rsi
callq 0xd39c0
movq -0x40(%rbp), %rdi
movzbl -0x38(%rbp), %esi
callq 0xd4bc0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x393f0
movq %rax, %rsi
xorl %edi, %edi
callq 0x48480
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
imull $0x3, -0x1c(%rbp), %ecx
addl $0x2, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdx
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdi
callq 0x487b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa49cc
movq -0x8(%rbp), %rdi
movl -0x10(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x46a30
movq -0x8(%rbp), %rdi
callq 0x61f00
addq $0x60, %rsp
popq %rbp
retq
nop