// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x18(%rax), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x31355
testl %eax, %eax
je 0x42ebc
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x42a45
testq %rax, %rax
je 0x42eaf
movq %rax, %r14
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x42357
testq %rax, %rax
je 0x42f15
movq %rax, %r15
leaq 0x567c4(%rip), %rcx     # 0x996b7
movq %rsp, %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x31355
movl %eax, %ebp
movq %r15, %rdi
callq 0x30b0c
testl %ebp, %ebp
jne 0x42eaf
movq (%rsp), %rax
jmp 0x42f1f
movq $0x0, (%rsp)
xorl %eax, %eax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq 0x8(%rsp), %rdi
subq %rax, %rcx
testq %rdi, %rdi
jns 0x42f44
testq %rax, %rax
jns 0x42f44
leaq 0x1(%rcx), %rdx
cmpq %rdx, %rdi
jl 0x42f62
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 0x42f76
leaq 0x55fcb(%rip), %rsi     # 0x98f34
movq %rbx, %rdi
callq 0x2dc63
jmp 0x42eaf
addq %rax, %rdi
movq %rdi, (%rsp)
callq 0x3069e
movq %rax, %r15
movl $0xf0, %eax
andl (%r14), %eax
cmpl $0x20, %eax
jne 0x42fa5
movq 0x38(%rbx), %r12
movq 0x10(%r12), %rdi
callq 0x30c49
movq %rax, 0x10(%r12)
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x4248e
movq %r15, %rdi
callq 0x30b0c
movq (%rsp), %rsi
movq %rbx, %rdi
callq 0x2e133
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x319b8
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x514d4(%rip), %rsi     # 0x944c7
movl $0x40, %edi
callq 0x60371
leaq 0x86fa4(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
jmp 0x42eaf