// File: /workspace/github_c_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x30(%rdi), %rax
movq 0x10(%rax), %rsi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x20298
testl %eax, %eax
jne 0x2a726
fldt (%rsp)
fldl 0x27919(%rip)           # 0x51f90
fxch %st(1)
fucomi %st(1), %st
jbe 0x2a684
fstp %st(0)
jmp 0x2a713
fldl 0x2790e(%rip)           # 0x51f98
fucomi %st(1), %st
fstp %st(1)
jbe 0x2a694
fstp %st(1)
jmp 0x2a713
fstpt 0x10(%rsp)
fstpt 0x1c(%rsp)
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x29e0b
movq %rax, %r14
testq %rax, %rax
jne 0x2a6c9
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x29e31
movq %rax, %r14
cmpq $0x0, 0x10(%r14)
jne 0x2a6e5
leaq 0x53ec9(%rip), %rax     # 0x7e5a0
movq (%rax), %rdx
movq %r14, %rdi
movq %rdx, %rsi
callq 0x29ec0
movq %r14, %rdi
callq 0x29f5e
fldt (%rsp)
fldt 0x20(%r14)
movq 0x10(%r14), %rax
fldt 0x30(%rax)
fsubrp %st, %st(1)
fsubrp %st, %st(1)
fldt 0x1c(%rsp)
fxch %st(1)
fucomi %st(1), %st
fstp %st(1)
ja 0x2a713
fldt 0x10(%rsp)
fucompi %st(1), %st
jbe 0x2a72e
fstp %st(0)
leaq 0x27915(%rip), %rsi     # 0x52031
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1caf6
addq $0x28, %rsp
popq %rbx
popq %r14
retq
fld %st(0)
fstpt 0x30(%rax)
andq $0x0, 0x40(%rax)
leaq 0x3f949(%rip), %rax     # 0x6a088
movl 0x628(%rax), %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rcx, %rsi
jae 0x2a760
movq 0x30(%r14), %rdi
fld %st(0)
fstpt (%rdi,%rdx)
incq %rsi
addq $0x10, %rdx
jmp 0x2a749
fstp %st(0)
fldt (%rsp)
fstpt 0x20(%r14)
incq 0x6a0(%rax)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29f4a
jmp 0x2a726