// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a6a
testq %rax, %rax
je 0x2011
movq 0x8(%rax), %rax
movl (%rax), %esi
cmpl $0x3, %esi
jne 0x20c9
cmpl $0x4, 0x18(%rbx)
jne 0x20a8
movq 0x8(%rax), %r14
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x2a6a
testq %rax, %rax
je 0x20df
movq %rax, %r12
movq (%rax), %r15
movq %r15, %rdi
callq 0x4047
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x3c7b
jmp 0x20f3
testb $0x1, 0x18(%rbx)
jne 0x20a8
callq 0x3f1c
movq %rax, 0x10(%rsp)
movq 0x20(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3ec0
movq %rax, 0x8(%rsp)
leaq 0x612e(%rip), %rdi      # 0x8170
xorl %esi, %esi
callq 0x2a1d
movq %rax, %r13
cmpl $0x3, 0x18(%rbx)
jl 0x2095
movl $0x2, %r15d
movq 0x20(%rbx), %rax
movq (%rax,%r15,8), %rcx
movq 0x8(%rax,%r15,8), %rax
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rbp
callq 0x3ec0
movq %rax, %r12
movq %rbp, %rdi
callq 0x3ec0
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2ea7
addq $0x2, %r15
cmpl %r15d, 0x18(%rbx)
jg 0x2058
movq 0x10(%rsp), %rdx
movq %r13, 0x8(%rdx)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
jmp 0x210d
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 0x212e
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x24eb
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3ec0
movq %rax, %r15
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3ec0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2ea7
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