// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/t_hash.c
// Function: hincrbyCommand
void hincrbyCommand(redisClient *c) {
    long long value, incr, oldvalue;
    robj *o, *current, *new;

    // 取出 incr 参数的值，并创建对象
    if (getLongLongFromObjectOrReply(c,c->argv[3],&incr,NULL) != REDIS_OK) return;

    // 取出或新创建哈希对象
    if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;

    // 取出 field 的当前值
    if ((current = hashTypeGetObject(o,c->argv[2])) != NULL) {
        // 取出值的整数表示
        if (getLongLongFromObjectOrReply(c,current,&value,
            "hash value is not an integer") != REDIS_OK) {
            decrRefCount(current);
            return;
        }
        decrRefCount(current);
    } else {
        // 如果值当前不存在，那么默认为 0
        value = 0;
    }

    // 检查计算是否会造成溢出
    oldvalue = value;
    if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN-oldvalue)) ||
        (incr > 0 && oldvalue > 0 && incr > (LLONG_MAX-oldvalue))) {
        addReplyError(c,"increment or decrement would overflow");
        return;
    }

    // 计算结果
    value += incr;
    // 为结果创建新的值对象
    new = createStringObjectFromLongLong(value);
    // 编码值对象
    hashTypeTryObjectEncoding(o,&c->argv[2],NULL);
    // 关联键和新的值对象，如果已经有对象存在，那么用新对象替换它
    hashTypeSet(o,c->argv[2],new);
    decrRefCount(new);

    // 将计算结果用作回复
    addReplyLongLong(c,value);

    // 发送键修改信号
    signalModifiedKey(c->db,c->argv[1]);

    // 发送事件通知
    notifyKeyspaceEvent(REDIS_NOTIFY_HASH,"hincrby",c->argv[1],c->db->id);

    // 将数据库设为脏
    server.dirty++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2f617
testl %eax, %eax
je 0x3fcf8
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x3f894
testq %rax, %rax
je 0x3fced
movq %rax, %r14
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x3f1db
testq %rax, %rax
je 0x3fd54
movq %rax, %r15
leaq 0x4f94c(%rip), %rcx     # 0x8f67b
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2f617
movl %eax, %ebp
movq %r15, %rdi
callq 0x2ee1f
testl %ebp, %ebp
jne 0x3fced
movq 0x8(%rsp), %rax
jmp 0x3fd5c
andq $0x0, 0x8(%rsp)
xorl %eax, %eax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq 0x10(%rsp), %rdi
subq %rax, %rcx
testq %rdi, %rdi
jns 0x3fd81
testq %rax, %rax
jns 0x3fd81
leaq 0x1(%rcx), %rdx
cmpq %rdx, %rdi
jl 0x3fd9f
testq %rdi, %rdi
setg %dl
testq %rax, %rax
setg %sil
andb %dl, %sil
cmpq %rcx, %rdi
setg %cl
andb %sil, %cl
cmpb $0x1, %cl
jne 0x3fdb3
leaq 0x4f152(%rip), %rsi     # 0x8eef8
movq %rbx, %rdi
callq 0x2c2da
jmp 0x3fced
addq %rax, %rdi
movq %rdi, 0x8(%rsp)
callq 0x2ea90
movq %rax, %r15
movq 0x38(%rbx), %rsi
addq $0x10, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x3f05f
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x3f300
movq %r15, %rdi
callq 0x2ee1f
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x2c794
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x2fbc0
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x4a663(%rip), %rsi     # 0x8a487
pushq $0x40
popq %rdi
callq 0x5b488
leaq 0x87175(%rip), %rax     # 0xc6fa8
incq 0x560(%rax)
jmp 0x3fced