// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/counter.c
// Function: setCommand
void setCommand(client *c) {
    counter *cntr;
    long double value;
    unsigned int i;

    if (getLongDoubleFromObjectOrReply(c,c->argv[2],&value,NULL) != C_OK)
        return;

    if (value > COUNTER_MAX) {
        addReplyErrorFormat(c, "Counter value out of allowed range");
        return;
    } else if (value < COUNTER_MIN) {
        addReplyErrorFormat(c, "Counter value out of allowed range");
        return;
    }

    cntr = counterLookup(c->argv[1]->ptr);
    if (cntr == NULL) {
        cntr = counterCreate(c->argv[1]->ptr);
    }

    if (cntr->myshard == NULL) {
        counterAddShard(cntr,myself,myself->name);
    }

    countersUpdateValue(cntr);

    long double newshardvalue = value - (cntr->value - cntr->myshard->value);
    if (newshardvalue > COUNTER_MAX) {
        addReplyErrorFormat(c, "Counter value out of allowed range");
        return;
    } else if (newshardvalue < COUNTER_MIN) {
        addReplyErrorFormat(c, "Counter value out of allowed range");
        return;
    }

    /* myshard->value        = 4
     * cntr->value           = 10
     * value                 = 2
     * value in other shards = 6
     * new myshard->value    = 2 - (10 - 4) = -4
     */
    cntr->myshard->value = newshardvalue;

    /* Force a new prediction to be send. */
    cntr->myshard->predict_time = 0;

    /* Make sure the prediction is 0 so it doesn't change every second. */
    for (i = 0; i < server.history_size; i++) {
        cntr->history[i] = newshardvalue;
    }

    cntr->value = value;
    server.dirty++;
    addReplyCounter(c,cntr);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movq 0x30(%rdi), %rax
movq 0x10(%rax), %rsi
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x265b9
testl %eax, %eax
jne 0x31d58
fldt 0x10(%rsp)
fldl 0x26c5c(%rip)           # 0x588e8
fxch %st(1)
fucomi %st(1), %st
jbe 0x31c99
fstp %st(0)
jmp 0x31d45
fldl 0x26c51(%rip)           # 0x588f0
fucomi %st(1), %st
fstp %st(1)
jbe 0x31cac
fstp %st(1)
jmp 0x31d45
fstpt 0x28(%rsp)
fstpt 0x34(%rsp)
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x3d3c1(%rip), %r15     # 0x6f088
movq 0x618(%r15), %rdi
callq 0x190de
testq %rax, %rax
je 0x31cde
movq 0x8(%rax), %r14
jmp 0x31ce1
xorl %r14d, %r14d
testq %r14, %r14
jne 0x31cfa
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3134d
movq %rax, %r14
cmpq $0x0, 0x10(%r14)
jne 0x31d16
leaq 0x51898(%rip), %rax     # 0x835a0
movq (%rax), %rdx
movq %r14, %rdi
movq %rdx, %rsi
callq 0x313de
movq %r14, %rdi
callq 0x31480
fldt 0x10(%rsp)
fldt 0x20(%r14)
movq 0x10(%r14), %rax
fldt 0x30(%rax)
fsubrp %st, %st(1)
fsubrp %st, %st(1)
fldt 0x34(%rsp)
fxch %st(1)
fucomi %st(1), %st
fstp %st(1)
ja 0x31d45
fldt 0x28(%rsp)
fucompi %st(1), %st
jbe 0x31d62
fstp %st(0)
leaq 0x26c3b(%rip), %rsi     # 0x58989
movq %rbx, %rdi
xorl %eax, %eax
callq 0x22331
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
fld %st(0)
fstpt 0x30(%rax)
movq $0x0, 0x40(%rax)
movl 0x628(%r15), %eax
testq %rax, %rax
je 0x31d93
movq 0x30(%r14), %rcx
shlq $0x4, %rax
xorl %edx, %edx
fld %st(0)
fstpt (%rcx,%rdx)
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x31d85
fstp %st(0)
fldt 0x10(%rsp)
fld %st(0)
fstpt 0x20(%r14)
incq 0x6a0(%r15)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x227d7
jmp 0x31d58