// File: /workspace/github_c_makefile_star2_O0/sharpyfox[P]citrusleaf-client/tests/loop_c/src/shash.c
// Function: shash_put_unique
int
shash_put_unique(shash *h, void *key, void *value)
{
	// Calculate hash
	uint hash = h->h_fn(key);
	hash %= h->table_len;

	pthread_mutex_t		*l = 0;
	if (h->flags & SHASH_CR_MT_BIGLOCK) {
		l = &h->biglock;
	}
	else if (h->flags & SHASH_CR_MT_MANYLOCK) {
		l = & (h->lock_table[hash]);
	}
	if (l)     pthread_mutex_lock( l );
		
	shash_elem *e = (shash_elem *) ( ((uint8_t *)h->table) + (SHASH_ELEM_SZ(h) * hash));	

	// most common case should be insert into empty bucket, special case
	if ( e->in_use == false ) {
		goto Copy;
	}

	shash_elem *e_head = e;

	while (e) {
		if ( memcmp(SHASH_ELEM_KEY_PTR(h, e), key, h->key_len) == 0) {
			if (h->flags & SHASH_CR_MT_BIGLOCK)
				pthread_mutex_unlock(&h->biglock);
			return(SHASH_ERR_FOUND);
		}
		e = e->next;
	}

	e = (shash_elem *) malloc( SHASH_ELEM_SZ(h) );
	e->next = e_head->next;
	e_head->next = e;
	
Copy:
	memcpy(SHASH_ELEM_KEY_PTR(h, e), key, h->key_len);
	memcpy(SHASH_ELEM_VALUE_PTR(h, e), value, h->value_len);
	e->in_use = true;
	h->elements++;
	if (l)	pthread_mutex_unlock( l );
	return(SHASH_OK);	

}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rsp), %rdi
callq *%rax
movl %eax, 0x24(%rsp)
movq 0x38(%rsp), %rax
movl 0x18(%rax), %ecx
movl 0x24(%rsp), %eax
xorl %edx, %edx
divl %ecx
movl %edx, 0x24(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4494
movq 0x38(%rsp), %rax
addq $0x28, %rax
movq %rax, 0x18(%rsp)
jmp 0x44bf
movq 0x38(%rsp), %rax
movl 0xc(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x44bd
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rax
movl 0x24(%rsp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
jmp 0x44bf
cmpq $0x0, 0x18(%rsp)
je 0x44d1
movq 0x18(%rsp), %rdi
callq 0x23e0
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x38(%rsp), %rcx
movl 0x4(%rcx), %ecx
addq $0x10, %rcx
movq 0x38(%rsp), %rdx
movl 0x8(%rdx), %edx
addq %rdx, %rcx
movl 0x24(%rsp), %edx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movb 0x8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4518
jmp 0x45c6
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x4586
movq 0x10(%rsp), %rdi
addq $0x9, %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
callq 0x2110
cmpl $0x0, %eax
jne 0x4577
movq 0x38(%rsp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x456a
movq 0x38(%rsp), %rdi
addq $0x28, %rdi
callq 0x21c0
movl $0xfffffffc, 0x44(%rsp) # imm = 0xFFFFFFFC
jmp 0x463a
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x4522
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edi
addq $0x10, %rdi
movq 0x38(%rsp), %rax
movl 0x8(%rax), %eax
addq %rax, %rdi
callq 0x2310
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x10(%rsp), %rdi
addq $0x9, %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, %edx
callq 0x21e0
movq 0x10(%rsp), %rdi
addq $0x9, %rdi
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
addq %rax, %rdi
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, %edx
callq 0x21e0
movq 0x10(%rsp), %rax
movb $0x1, 0x8(%rax)
movq 0x38(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
cmpq $0x0, 0x18(%rsp)
je 0x4632
movq 0x18(%rsp), %rdi
callq 0x21c0
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)