// File: /workspace/github_c_makefile_star2_O3/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 0x261b6
testl %eax, %eax
jne 0x316ef
fldt 0x10(%rsp)
fldl 0x27214(%rip)           # 0x588d8
fxch %st(1)
fucomi %st(1), %st
jbe 0x316ce
fstp %st(0)
jmp 0x316dc
fldl 0x2720c(%rip)           # 0x588e0
fucomi %st(1), %st
fstp %st(1)
jbe 0x316f9
fstp %st(1)
fstp %st(0)
leaq 0x27294(%rip), %rsi     # 0x58979
movq %rbx, %rdi
xorl %eax, %eax
callq 0x22033
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
fstpt 0x28(%rsp)
fstpt 0x34(%rsp)
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x3d974(%rip), %r15     # 0x6f088
movq 0x618(%r15), %rdi
callq 0x18d3e
testq %rax, %rax
je 0x3172e
movq 0x8(%rax), %r14
testq %r14, %r14
jne 0x31742
movq 0x30(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x30d95
movq %rax, %r14
cmpq $0x0, 0x10(%r14)
jne 0x3175e
leaq 0x51e50(%rip), %rax     # 0x835a0
movq (%rax), %rdx
movq %r14, %rdi
movq %rdx, %rsi
callq 0x30e26
movq %r14, %rdi
callq 0x30ec8
fldt 0x10(%rsp)
fldt 0x20(%r14)
movq 0x10(%r14), %rax
fldt 0x30(%rax)
fsubrp %st, %st(1)
fsubr %st(1), %st
fldt 0x34(%rsp)
fxch %st(1)
fucomi %st(1), %st
fstp %st(1)
ja 0x316ca
fldt 0x28(%rsp)
fucompi %st(1), %st
ja 0x316ca
fld %st(0)
fstpt 0x30(%rax)
movq $0x0, 0x40(%rax)
movl 0x628(%r15), %eax
testq %rax, %rax
je 0x317d0
fstp %st(1)
movq 0x30(%r14), %rcx
shlq $0x4, %rax
xorl %edx, %edx
fld %st(0)
fstpt (%rcx,%rdx)
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x317ba
fstp %st(0)
fldt 0x10(%rsp)
fldz
fstp %st(0)
fld %st(0)
fstpt 0x20(%r14)
incq 0x6a0(%r15)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x224d7
jmp 0x316ef