// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq -0x28(%rbp), %rcx
xorl %edx, %edx
divl 0x28(%rcx)
movl %edx, -0x34(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2350
movq -0x28(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movl -0x34(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x2ba4
xorl %eax, %eax
movq %rax, -0x40(%rbp)
jmp 0x2bd7
movq -0x28(%rbp), %rax
addq $0x150, %rax            # imm = 0x150
movl -0x34(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
addq $0x150, %rcx            # imm = 0x150
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2e75
movq -0x30(%rbp), %rdi
addq $0x24, %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0x1060
cmpl $0x0, %eax
jne 0x2e2f
jmp 0x2c0a
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
je 0x2c34
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rdx
addq $0x10, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x2c44
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rdx
addq $0x10, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
jmp 0x2c63
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
je 0x2ca0
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rdx
addq $0x10, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x2cb7
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
addq $0x10, %rcx
movq -0x28(%rbp), %rax
addq $0x10, %rax
subq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rsi
addq $0x24, %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
addl 0x4(%rcx), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1070
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rax
addq $0x40, %rax
addq $0xc0, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x400, 0x4(%rax)       # imm = 0x400
jae 0x2db7
movq -0x20(%rbp), %rax
cmpl $0x100, 0x4(%rax)       # imm = 0x100
jae 0x2d92
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x80, %edx
cmovbl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2daf
movq -0x20(%rbp), %rax
movl 0x4(%rax), %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 0x2e06
movq -0x20(%rbp), %rax
cmpl $0x1000, 0x4(%rax)      # imm = 0x1000
jae 0x2de3
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x5, %eax
movl $0x4, %ecx
cmpl $0x800, %edx            # imm = 0x800
cmovbl %ecx, %eax
movl %eax, -0x54(%rbp)
jmp 0x2e00
movq -0x20(%rbp), %rax
movl 0x4(%rax), %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
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2e9c
jmp 0x2e31
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x2e44
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x2e68
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
addq $0x150, %rcx            # imm = 0x150
movl -0x34(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x2bdf
movq -0x28(%rbp), %rax
movq 0x140(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x140(%rax)
movq -0x10(%rbp), %rdi
callq 0x2380
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)