// File: /workspace/github_cpp_makefile_star2_O3/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 0x2a50
testq %rax, %rax
je 0x1fef
movq 0x8(%rax), %rax
movl (%rax), %esi
cmpl $0x3, %esi
jne 0x20a7
cmpl $0x4, 0x18(%rbx)
jne 0x2086
movq 0x8(%rax), %r14
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x2a50
testq %rax, %rax
je 0x20bd
movq %rax, %r12
movq (%rax), %r15
movq %r15, %rdi
callq 0x4083
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x3c8b
jmp 0x20d1
testb $0x1, 0x18(%rbx)
jne 0x2086
callq 0x3f58
movq %rax, 0x10(%rsp)
movq 0x20(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3efc
movq %rax, 0x8(%rsp)
leaq 0x6150(%rip), %rdi      # 0x8170
xorl %esi, %esi
callq 0x2a03
movq %rax, %r13
cmpl $0x3, 0x18(%rbx)
jl 0x2073
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 0x3efc
movq %rax, %r12
movq %rbp, %rdi
callq 0x3efc
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2e6c
addq $0x2, %r15
cmpl %r15d, 0x18(%rbx)
jg 0x2036
movq 0x10(%rsp), %rdx
movq %r13, 0x8(%rdx)
movq %r14, %rdi
movq 0x8(%rsp), %rsi
jmp 0x20eb
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 0x210c
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x24c3
movq 0x20(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3efc
movq %rax, %r15
movq 0x20(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x3efc
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2e6c
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