// File: /workspace/github_c_makefile_star2_O1/ryo[P]shmqueue/shmqueue.c
// Function: shmqueue_keyvalue_fetch
struct keyvalue *
shmqueue_keyvalue_fetch(struct shmqueue *shmq_header, uint8_t *key, struct keyvalue *keyvalue)
{
	struct shmqueue_header *header;
	struct shmqueue_item *item;
	uint32_t hashidx;

	header = shmq_header->header;
	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) {
			/* found! */

			/*
			 * 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 to caller */
			keyvalue->kv_keysize = item->shi_keyvalue.kv_keysize;
			keyvalue->kv_storagesize = item->shi_keyvalue.kv_storagesize;
			memcpy(keyvalue->kv_data, item->shi_keyvalue.kv_data, keyvalue->kv_keysize + keyvalue->kv_storagesize);
			KEYVALUE_STORAGE(keyvalue)[keyvalue->kv_storagesize] = '\0';

			/* update statistics */
			header->sha_stat.ss_fetch_success[SIZE2BUCKET(keyvalue->kv_storagesize)]++;

			shmqueue_unlock(shmq_header);
			return keyvalue;
		}
	}

	/* update statistics */
	header->sha_stat.ss_fetch_failure++;

	shmqueue_unlock(shmq_header);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, (%rsp)
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %r13
movq %rsi, %rdi
callq *0x8(%r14)
xorl %edx, %edx
divl 0x28(%r13)
movl %edx, %r12d
movl $0x148, %edi            # imm = 0x148
addq (%r14), %rdi
callq 0x2694
shlq $0x4, %r12
leaq (%r12,%r13), %rbx
addq $0x150, %rbx            # imm = 0x150
movq (%rbx), %rbp
testq %rbp, %rbp
sete %al
addq %rbx, %rbp
sete %cl
orb %al, %cl
jne 0x1f94
leaq 0x2c(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x1090
testl %eax, %eax
je 0x1fa2
movq 0x10(%rbp), %rax
leaq (%rax,%rbx), %rbp
testq %rax, %rax
cmoveq %rax, %rbp
testq %rbp, %rbp
jne 0x1f6d
addq $0x140, %r13            # imm = 0x140
xorl %ebx, %ebx
jmp 0x2089
movq (%rbp), %rdx
movq 0x8(%rbp), %rsi
leaq 0x18(%r13), %rax
leaq 0x10(%r13), %rcx
testq %rdx, %rdx
leaq 0x18(%rdx,%r13), %rdx
cmoveq %rax, %rdx
movq %rsi, (%rdx)
movq (%rbp), %rdx
movq 0x8(%rbp), %rsi
movq %rdx, 0x10(%rsi,%r13)
movq 0x10(%r13), %rsi
movq %rsi, (%rbp)
movq %rbp, %rdx
subq %rcx, %rdx
testq %rsi, %rsi
je 0x1feb
movq (%rcx), %rax
addq %rcx, %rax
addq $0x8, %rax
movq %rdx, (%rax)
movq %rdx, 0x10(%r13)
movq $0x0, 0x8(%rbp)
movl 0x24(%rbp), %eax
movq (%rsp), %rbx
movl %eax, (%rbx)
movl 0x28(%rbp), %r15d
movl %r15d, 0x4(%rbx)
leaq 0x8(%rbx), %rdi
leal (%r15,%rax), %edx
movq %rax, %rbp
movq %r12, %rsi
callq 0x10a0
addq $0x100, %r13            # imm = 0x100
leaq (%rbx,%rbp), %rax
addq $0x8, %rax
movb $0x0, (%r15,%rax)
cmpq $0x3ff, %r15            # imm = 0x3FF
ja 0x204f
cmpl $0xff, %r15d
ja 0x2066
xorl %eax, %eax
cmpl $0x7f, %r15d
seta %al
jmp 0x2084
cmpl $0xfff, %r15d           # imm = 0xFFF
ja 0x2074
cmpl $0x800, %r15d           # imm = 0x800
movl $0x5, %eax
jmp 0x2080
cmpl $0x200, %r15d           # imm = 0x200
movl $0x3, %eax
jmp 0x2080
cmpl $0x4000, %r15d          # imm = 0x4000
movl $0x7, %eax
sbbq $0x0, %rax
leaq (%r13,%rax,8), %r13
incq (%r13)
movl $0x148, %edi            # imm = 0x148
addq (%r14), %rdi
callq 0x26b4
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq