// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x20(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2a3f0
cmpl $0x0, %eax
je 0x3a3d3
jmp 0x3a58b
fldt -0x20(%rbp)
fldl 0x6eec4(%rip)           # 0xa92a0
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x3a3fd
jmp 0x3a3e6
movq -0x8(%rbp), %rdi
leaq 0x6ef50(%rip), %rsi     # 0xa9341
movb $0x0, %al
callq 0x24360
jmp 0x3a58b
fldt -0x20(%rbp)
fldl 0x6eea2(%rip)           # 0xa92a8
fucompi %st(1), %st
fstp %st(0)
jbe 0x3a425
jmp 0x3a40e
movq -0x8(%rbp), %rdi
leaq 0x6ef28(%rip), %rsi     # 0xa9341
movb $0x0, %al
callq 0x24360
jmp 0x3a58b
jmp 0x3a427
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x396f0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3a460
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x39740
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x3a488
movq -0x10(%rbp), %rdi
leaq 0x9918a(%rip), %rax     # 0xd3600
movq (%rax), %rsi
leaq 0x99180(%rip), %rax     # 0xd3600
movq (%rax), %rdx
callq 0x39810
movq -0x10(%rbp), %rdi
callq 0x398f0
fldt -0x20(%rbp)
movq -0x10(%rbp), %rax
fldt 0x20(%rax)
movq 0x10(%rax), %rax
fldt 0x30(%rax)
fsubrp %st, %st(1)
fsubrp %st, %st(1)
fstpt -0x40(%rbp)
fldt -0x40(%rbp)
fldl 0x6edee(%rip)           # 0xa92a0
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x3a4d3
jmp 0x3a4bc
movq -0x8(%rbp), %rdi
leaq 0x6ee7a(%rip), %rsi     # 0xa9341
movb $0x0, %al
callq 0x24360
jmp 0x3a58b
fldt -0x40(%rbp)
fldl 0x6edcc(%rip)           # 0xa92a8
fucompi %st(1), %st
fstp %st(0)
jbe 0x3a4fb
jmp 0x3a4e4
movq -0x8(%rbp), %rdi
leaq 0x6ee52(%rip), %rsi     # 0xa9341
movb $0x0, %al
callq 0x24360
jmp 0x3a58b
jmp 0x3a4fd
fldt -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
fstpt 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq $0x0, 0x40(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
leaq 0x84bbc(%rip), %rcx     # 0xbf0e8
cmpl 0x628(%rcx), %eax
jae 0x3a554
fldt -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x24(%rbp), %ecx
shlq $0x4, %rcx
fstpt (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a522
fldt -0x20(%rbp)
movq -0x10(%rbp), %rax
fstpt 0x20(%rax)
leaq 0x84b83(%rip), %rax     # 0xbf0e8
movq 0x6a0(%rax), %rcx
addq $0x1, %rcx
leaq 0x84b71(%rip), %rax     # 0xbf0e8
movq %rcx, 0x6a0(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x398c0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)