// File: /workspace/github_c_makefile_star2_O0/ryo[P]shmqueue/shmqueue.c
// Function: shmqueue_keyvalue_store
int
shmqueue_keyvalue_store(struct shmqueue *shmq_header, uint8_t *key, uint8_t *storage, uint32_t storage_size)
{
	struct shmqueue_header *header;
	struct shmqueue_item *item;
	uint32_t hashidx;
	int keylen;

	header = shmq_header->header;

	keylen = strlen((char *)key) + 1;
	if (storage_size + keylen >= SHMQUEUE_KEYVALUE_DATASIZE) {
		/* update statistics */
		shmqueue_lock(shmq_header);
		header->sha_stat.ss_store_failure[SIZE2BUCKET(storage_size)]++;
		shmqueue_unlock(shmq_header);

		return -1;
	}

	hashidx = shmq_header->hash_callback(key) % header->sha_hashnum;

	shmqueue_lock(shmq_header);
	for (item = RTAILQ_FIRST(&header->sha_hashlist[hashidx], shmqueue_item);
	    item != NULL;
	    item = RTAILQ_NEXT(item, &header->sha_hashlist[hashidx], shmqueue_item, shi_hashlist)) {

		if (SHMQUEUE_STRCMP(KEYVALUE_KEY(&item->shi_keyvalue), key) == 0) {
			/* already exists! */

			/*
			 * move to top of LRU.
			 * delete from LRU, and insert to top
			 */
			RTAILQ_REMOVE(&header->sha_lrulist,
			    item, shmqueue_item, shi_list);
			RTAILQ_INSERT_HEAD(&header->sha_lrulist,
			    item, shmqueue_item, shi_list);

			/* copy from caller */
			item->shi_keyvalue.kv_storagesize = storage_size;
			memcpy(KEYVALUE_STORAGE(&item->shi_keyvalue), storage, storage_size);
			KEYVALUE_STORAGE(&item->shi_keyvalue)[storage_size] = '\0';

			/* update statistics */
			header->sha_stat.ss_store_reuse_success[SIZE2BUCKET(storage_size)]++;

			shmqueue_unlock(shmq_header);
			return 0;
		}
	}
	/* not found */
	shmqueue_unlock(shmq_header);


	/* allocate pool */
	item = shmqueue_remove_from_freelist(shmq_header);
	if (item == NULL) {
		/* update statistics */
		shmqueue_lock(shmq_header);
		header->sha_stat.ss_store_failure[SIZE2BUCKET(storage_size)]++;
		shmqueue_unlock(shmq_header);

		return -1;
	}

	/* update data, and store */
	SHMQUEUE_STRCPY(KEYVALUE_KEY(&item->shi_keyvalue), key);
	item->shi_keyvalue.kv_keysize = keylen;
	item->shi_keyvalue.kv_storagesize = storage_size;
	memcpy(KEYVALUE_STORAGE(&item->shi_keyvalue), storage, storage_size);
	KEYVALUE_STORAGE(&item->shi_keyvalue)[storage_size] = '\0';

	shmqueue_add_to_lru(shmq_header, item, hashidx);

	/* update statistics */
	shmqueue_lock(shmq_header);
	header->sha_stat.ss_store_new_success[SIZE2BUCKET(storage_size)]++;
	shmqueue_unlock(shmq_header);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1040
addq $0x1, %rax
movl %eax, -0x40(%rbp)
movl -0x24(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, %eax
cmpq $0x7d0, %rax            # imm = 0x7D0
jb 0x2fcd
movq -0x10(%rbp), %rdi
callq 0x2350
movq -0x30(%rbp), %rax
addq $0x40, %rax
addq $0x80, %rax
movq %rax, -0x48(%rbp)
cmpl $0x400, -0x24(%rbp)     # imm = 0x400
jae 0x2f5f
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jae 0x2f3e
movl -0x24(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x80, %edx
cmovbl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2f57
movl -0x24(%rbp), %edx
movl $0x3, %eax
movl $0x2, %ecx
cmpl $0x200, %edx            # imm = 0x200
cmovbl %ecx, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x2fa2
cmpl $0x1000, -0x24(%rbp)    # imm = 0x1000
jae 0x2f83
movl -0x24(%rbp), %edx
movl $0x5, %eax
movl $0x4, %ecx
cmpl $0x800, %edx            # imm = 0x800
cmovbl %ecx, %eax
movl %eax, -0x54(%rbp)
jmp 0x2f9c
movl -0x24(%rbp), %edx
movl $0x7, %eax
movl $0x6, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
cmovbl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl -0x50(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rdi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x352b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq -0x30(%rbp), %rcx
xorl %edx, %edx
divl 0x28(%rcx)
movl %edx, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2350
movq -0x30(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movl -0x3c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x3012
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x3045
movq -0x30(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movl -0x3c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
addq $0x150, %rcx            # imm = 0x150
movl -0x3c(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x32b1
movq -0x38(%rbp), %rdi
addq $0x24, %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0x1060
cmpl $0x0, %eax
jne 0x326b
jmp 0x3078
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
je 0x30a2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rdx
addq $0x10, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x30b2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rdx
addq $0x10, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
jmp 0x30d1
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
je 0x310e
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rdx
addq $0x10, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x3125
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rcx
addq $0x10, %rcx
movq -0x30(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x38(%rbp), %rdi
addq $0x24, %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rax
movl 0x24(%rax), %eax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %eax
movl %eax, %edx
callq 0x1070
movq -0x38(%rbp), %rax
addq $0x24, %rax
addq $0x8, %rax
movq -0x38(%rbp), %rcx
movl 0x24(%rcx), %ecx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x40, %rax
addq $0x40, %rax
movq %rax, -0x68(%rbp)
cmpl $0x400, -0x24(%rbp)     # imm = 0x400
jae 0x31fd
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jae 0x31dc
movl -0x24(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x80, %edx
cmovbl %ecx, %eax
movl %eax, -0x6c(%rbp)
jmp 0x31f5
movl -0x24(%rbp), %edx
movl $0x3, %eax
movl $0x2, %ecx
cmpl $0x200, %edx            # imm = 0x200
cmovbl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x70(%rbp)
jmp 0x3240
cmpl $0x1000, -0x24(%rbp)    # imm = 0x1000
jae 0x3221
movl -0x24(%rbp), %edx
movl $0x5, %eax
movl $0x4, %ecx
cmpl $0x800, %edx            # imm = 0x800
cmovbl %ecx, %eax
movl %eax, -0x74(%rbp)
jmp 0x323a
movl -0x24(%rbp), %edx
movl $0x7, %eax
movl $0x6, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
cmovbl %ecx, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movl -0x70(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rdi
callq 0x2380
movl $0x0, -0x4(%rbp)
jmp 0x352b
jmp 0x326d
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x3280
xorl %eax, %eax
movq %rax, -0x80(%rbp)
jmp 0x32a4
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
addq $0x150, %rcx            # imm = 0x150
movl -0x3c(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x304d
movq -0x10(%rbp), %rdi
callq 0x2380
movq -0x10(%rbp), %rdi
callq 0x2250
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x33c7
movq -0x10(%rbp), %rdi
callq 0x2350
movq -0x30(%rbp), %rax
addq $0x40, %rax
addq $0x80, %rax
movq %rax, -0x88(%rbp)
cmpl $0x400, -0x24(%rbp)     # imm = 0x400
jae 0x3347
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jae 0x331d
movl -0x24(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x80, %edx
cmovbl %ecx, %eax
movl %eax, -0x8c(%rbp)
jmp 0x3339
movl -0x24(%rbp), %edx
movl $0x3, %eax
movl $0x2, %ecx
cmpl $0x200, %edx            # imm = 0x200
cmovbl %ecx, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x90(%rbp)
jmp 0x3396
cmpl $0x1000, -0x24(%rbp)    # imm = 0x1000
jae 0x336e
movl -0x24(%rbp), %edx
movl $0x5, %eax
movl $0x4, %ecx
cmpl $0x800, %edx            # imm = 0x800
cmovbl %ecx, %eax
movl %eax, -0x94(%rbp)
jmp 0x338a
movl -0x24(%rbp), %edx
movl $0x7, %eax
movl $0x6, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
cmovbl %ecx, %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movl -0x90(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rdi
callq 0x2380
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x352b
movq -0x38(%rbp), %rdi
addq $0x24, %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0x1030
movl -0x40(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x38(%rbp), %rdi
addq $0x24, %rdi
addq $0x8, %rdi
movq -0x38(%rbp), %rax
movl 0x24(%rax), %eax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %eax
movl %eax, %edx
callq 0x1070
movq -0x38(%rbp), %rax
addq $0x24, %rax
addq $0x8, %rax
movq -0x38(%rbp), %rcx
movl 0x24(%rcx), %ecx
addq %rcx, %rax
movl -0x24(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0x23b0
movq -0x10(%rbp), %rdi
callq 0x2350
movq -0x30(%rbp), %rax
addq $0x40, %rax
movq %rax, -0xa0(%rbp)
cmpl $0x400, -0x24(%rbp)     # imm = 0x400
jae 0x34b0
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jae 0x3486
movl -0x24(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x80, %edx
cmovbl %ecx, %eax
movl %eax, -0xa4(%rbp)
jmp 0x34a2
movl -0x24(%rbp), %edx
movl $0x3, %eax
movl $0x2, %ecx
cmpl $0x200, %edx            # imm = 0x200
cmovbl %ecx, %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xa8(%rbp)
jmp 0x34ff
cmpl $0x1000, -0x24(%rbp)    # imm = 0x1000
jae 0x34d7
movl -0x24(%rbp), %edx
movl $0x5, %eax
movl $0x4, %ecx
cmpl $0x800, %edx            # imm = 0x800
cmovbl %ecx, %eax
movl %eax, -0xac(%rbp)
jmp 0x34f3
movl -0x24(%rbp), %edx
movl $0x7, %eax
movl $0x6, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
cmovbl %ecx, %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movl -0xa8(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rdi
callq 0x2380
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)