// File: /workspace/github_c_makefile_star2_O1/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 0x31082
testl %eax, %eax
je 0x4300b
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 0x42b94
testq %rax, %rax
je 0x42ffe
movq %rax, %r14
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x42479
testq %rax, %rax
je 0x43060
movq %rax, %r15
leaq 0x5662d(%rip), %rcx     # 0x9966f
movq %rsp, %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x31082
movl %eax, %ebp
movq %r15, %rdi
callq 0x30834
testl %ebp, %ebp
jne 0x42ffe
jmp 0x43068
movq $0x0, (%rsp)
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq (%rsp), %rax
movq 0x8(%rsp), %rdi
subq %rax, %rcx
testq %rdi, %rdi
jns 0x43091
testq %rax, %rax
jns 0x43091
leaq 0x1(%rcx), %rdx
cmpq %rdx, %rdi
jl 0x430af
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 0x430c3
leaq 0x55e35(%rip), %rsi     # 0x98eeb
movq %rbx, %rdi
callq 0x2d9d7
jmp 0x42ffe
addq %rax, %rdi
movq %rdi, (%rsp)
callq 0x303c6
movq %rax, %r15
movl $0xf0, %eax
andl (%r14), %eax
cmpl $0x20, %eax
jne 0x430f2
movq 0x38(%rbx), %r12
movq 0x10(%r12), %rdi
callq 0x30971
movq %rax, 0x10(%r12)
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x425b0
movq %r15, %rdi
callq 0x30834
movq (%rsp), %rsi
movq %rbx, %rdi
callq 0x2dea3
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x316b7
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq 0x8(%rcx), %rdx
movl 0x30(%rax), %ecx
leaq 0x51337(%rip), %rsi     # 0x94477
movl $0x40, %edi
callq 0x608b5
leaq 0x86e57(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
jmp 0x42ffe