// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3d40
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x27e4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
je 0x2702
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl (%rax), %esi
callq 0x2d10
jmp 0x2934
movq -0x8(%rbp), %rax
cmpl $0x4, 0x18(%rax)
je 0x2742
jmp 0x270e
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x30(%rcx), %rcx
movq 0x49c1(%rip), %rdx      # 0x70e2
movq %rdx, 0x34(%rax,%rcx)
movl 0x49be(%rip), %edx      # 0x70ea
movl %edx, 0x3c(%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0xc, %ecx
movl %ecx, 0x30(%rax)
jmp 0x2934
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x3d40
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x2789
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x6420
movq %rax, -0x40(%rbp)
jmp 0x27b5
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x66b0
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x6030
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x6420
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4520
jmp 0x2905
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x282e
jmp 0x27fa
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x30(%rcx), %rcx
movq 0x48d5(%rip), %rdx      # 0x70e2
movq %rdx, 0x34(%rax,%rcx)
movl 0x48d2(%rip), %edx      # 0x70ea
movl %edx, 0x3c(%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0xc, %ecx
movl %ecx, 0x30(%rax)
jmp 0x2934
callq 0x64b0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x6420
movq %rax, -0x58(%rbp)
leaq 0x7921(%rip), %rdi      # 0xa178
xorl %eax, %eax
movl %eax, %esi
callq 0x3be0
movq %rax, -0x60(%rbp)
movl $0x2, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x28e8
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x64(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0x6420
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x6420
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x4520
movl -0x64(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x64(%rbp)
jmp 0x286b
movq -0x60(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x4520
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x30(%rcx), %rcx
movq 0x47d7(%rip), %rdx      # 0x70ef
movq %rdx, 0x34(%rax,%rcx)
movb 0x47d4(%rip), %dl       # 0x70f7
movb %dl, 0x3c(%rax,%rcx)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x9, %ecx
movl %ecx, 0x30(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)