// File: /workspace/github_c_makefile_star2_O3/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 0x2648
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
je 0x1f51
addq $0x140, %r13            # imm = 0x140
xorl %ebx, %ebx
jmp 0x2054
leaq 0x2c(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x1090
testl %eax, %eax
je 0x1f74
movq 0x10(%rbp), %rbp
testq %rbp, %rbp
je 0x1f43
addq %rbx, %rbp
jne 0x1f51
jmp 0x1f43
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
leaq 0x18(%r13), %rdx
leaq 0x10(%r13), %rsi
testq %rax, %rax
leaq 0x18(%rax,%r13), %rax
cmoveq %rdx, %rax
movq %rcx, (%rax)
movq (%rbp), %rax
movq %rax, 0x10(%rcx,%r13)
movq 0x10(%r13), %rax
movq %rax, (%rbp)
movq %rbp, %rcx
subq %rsi, %rcx
testq %rax, %rax
leaq 0x18(%rax,%r13), %rax
cmoveq %rdx, %rax
movq %rcx, (%rax)
movq %rcx, 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 0x201a
cmpl $0xff, %r15d
ja 0x2031
xorl %eax, %eax
cmpl $0x7f, %r15d
seta %al
jmp 0x204f
cmpl $0xfff, %r15d           # imm = 0xFFF
ja 0x203f
cmpl $0x800, %r15d           # imm = 0x800
movl $0x5, %eax
jmp 0x204b
cmpl $0x200, %r15d           # imm = 0x200
movl $0x3, %eax
jmp 0x204b
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 0x2668
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq