// File: /workspace/github_cpp_makefile_star2_O2/TTLIUJJ[P]acker_redis/command.cpp
// Function: hsetCommand(redisClient*)
void hsetCommand(redisClient *client)
{
	dict *d = client->db->dict;
	robj *o = client->argv[1];
	dictEntry *de = dictFind(d, o);
	//acutally it includes that in hashtable		 			book name  huang
	//it should consider such  situaltions, if we command:  hset book name acker
	//just including right command format					hset x    name acker
	//														hset book weather raining
	if (de != NULL) {
		robj *val = (robj *)de->val;
		if (val->type != REDIS_HASH) {
			explainNotForThat(client, val->type);
			return;
		}
		if (client->argc != 4) {
			EXECUTE_ARGC_ERROR(client);
			return;
		}
		dict *d = (dict *)val->ptr;
		dictEntry *nde = dictFind(d, client->argv[2]);
		robj *nk, *nv;
		if (nde == NULL) {
			nk = createStringObject((char *)(client->argv[2]->ptr));
		}
		else {
			nk = (robj *)nde->key;
			incrRefCount(nk);
			removeHashEntry(d, nde->key, nde->val);
		}
		nv = createStringObject((char *)(client->argv[3]->ptr));
		dictAdd(d, nk, nv);
	}
	else {
		//if argv[1] isn't a dictory, and now we should create a hashObject in db->dict
		//and before process it, it argcs should be checked.
		if ((client->argc % 2) != 0) {
			EXECUTE_ARGC_ERROR(client);
			return;
		}

		robj *noh = createHashObject();
		robj *nks = createStringObject((char *)(client->argv[1])->ptr);
		dict *nd = dictCreate(&dictObjectType, NULL);
		for (int i = 2; i < client->argc; i += 2) {
			char *nk = (char *)(client->argv[i])->ptr;
			char *nv = (char *)(client->argv[i + 1])->ptr;
			robj *nok = createStringObject(nk);
			robj *nov = createStringObject(nv);
			dictAdd(nd, nok, nov);
		}
		noh->ptr = nd;
		dictAdd(d, nks, noh);

	}
	memcpy(client->buf + client->bufpos, "(hset OK)", 9);
	client->bufpos += 9;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x20(%rdi), %rcx
movq (%rax), %r14
movq 0x8(%rcx), %rsi
movq %r14, %rdi
callq 0x28ae
testq %rax, %rax
je 0x1eb9
movq 0x8(%rax), %rax
movl (%rax), %esi
cmpl $0x3, %esi
jne 0x1f57
cmpl $0x4, 0x18(%rbx)
jne 0x1f36
movq 0x8(%rax), %r14
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x28ae
testq %rax, %rax
je 0x1f80
movq %rax, %r12
movq (%rax), %r15
movq %r15, %rdi
callq 0x3c7a
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x3939
jmp 0x1f94
testb $0x1, 0x18(%rbx)
jne 0x1f36
callq 0x3b6b
movq %rax, 0x10(%rsp)
movq 0x20(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3b33
movq %rax, 0x8(%rsp)
leaq 0x728a(%rip), %rdi      # 0x9170
xorl %esi, %esi
callq 0x2863
movq %rax, %r13
pushq $0x2
popq %r15
movslq 0x18(%rbx), %rax
cmpq %rax, %r15
jge 0x1f6d
movq 0x20(%rbx), %rax
movq (%rax,%r15,8), %rcx
movq 0x8(%rax,%r15,8), %rax
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rbp
callq 0x3b33
movq %rax, %r12
movq %rbp, %rdi
callq 0x3b33
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2c6c
addq $0x2, %r15
jmp 0x1ef4
movslq 0x30(%rbx), %rax
movabsq $0x7265206367726128, %rcx # imm = 0x7265206367726128
movq %rcx, 0x34(%rbx,%rax)
movl $0x29726f72, 0x3c(%rbx,%rax) # imm = 0x29726F72
addl $0xc, 0x30(%rbx)
jmp 0x1fcf
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x234d
movq 0x10(%rsp), %rdx
movq %r13, 0x8(%rdx)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
jmp 0x1fae
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3b33
movq %rax, %r15
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3b33
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2c6c
movslq 0x30(%rbx), %rax
movabsq $0x4b4f207465736828, %rcx # imm = 0x4B4F207465736828
movq %rcx, 0x34(%rbx,%rax)
movb $0x29, 0x3c(%rbx,%rax)
addl $0x9, 0x30(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq