// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/src/cf_shash.c
// Function: shash_create
int
shash_create(shash **h_r, shash_hash_fn h_fn, uint32_t key_len, uint32_t value_len, uint32_t sz, unsigned int flags)
{
	shash *h;

	h = (shash*)malloc(sizeof(shash));
	if (!h)	return(SHASH_ERR);

	h->elements = 0;
	h->table_len = sz;
	h->key_len = key_len;
	h->value_len = value_len;
	h->flags = flags;
	h->h_fn = h_fn;

	if ((flags & SHASH_CR_MT_BIGLOCK) && (flags & SHASH_CR_MT_MANYLOCK)) {
		*h_r = 0;
		return(SHASH_ERR);
	}
	
	h->table = malloc(sz * SHASH_ELEM_SZ(h));
	if (!h->table) {
		free(h);
		*h_r = 0;
		return(SHASH_ERR);
	}
	
	shash_elem *table = (shash_elem*)h->table;
	for (unsigned int i=0;i<sz;i++) {
		table->in_use = false;
		table->next = 0;
		// next element in head table
		table = (shash_elem *) (((uint8_t *)table) + SHASH_ELEM_SZ(h));
	}
	
	if (flags & SHASH_CR_MT_BIGLOCK) {
		if (0 != pthread_mutex_init ( &h->biglock, 0) ) {
			free(h->table); free(h);
			return(SHASH_ERR);
		}
	}
	else
		memset( (void*)&h->biglock, 0, sizeof( h->biglock ) );
	
	if (flags & SHASH_CR_MT_MANYLOCK) {
		h->lock_table = (pthread_mutex_t*)malloc( sizeof(pthread_mutex_t) * sz);
		if (! h->lock_table) {
			free(h);
			*h_r = 0;
			return(SHASH_ERR);
		}
		for (unsigned int i=0;i<sz;i++) {
			pthread_mutex_init( &(h->lock_table[i]), 0 );
		}
	}
	else
		h->lock_table = 0;
	

	*h_r = h;

	return(SHASH_OK);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movl $0x58, %edi
movl %r9d, %ebx
movl %r8d, %r12d
movl %ecx, %r13d
movl %edx, %ebp
movq %rsi, %r15
callq 0x22f0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xece0
movl %ebx, %edx
movl $0x0, (%rax)
movl %r12d, 0x18(%rax)
movl %ebp, 0x4(%rax)
movl %r13d, 0x8(%rax)
movl %ebx, 0xc(%rax)
movq %r14, 0x8(%rsp)
movq %r15, 0x10(%rax)
notl %edx
testb $0xc, %dl
jne 0xebd3
movq 0x8(%rsp), %rax
jmp 0xecd9
movq %rax, %r14
movq %rax, 0x10(%rsp)
movl %ebp, %eax
movl %r13d, %ecx
movl %ebx, 0x4(%rsp)
movl %r12d, %r15d
leaq 0x10(%rax,%rcx), %rbx
movq %rbx, %rdi
imulq %r15, %rdi
callq 0x22f0
testq %rax, %rax
movq %rax, 0x20(%r14)
je 0xecc7
testl %r12d, %r12d
je 0xec23
addq $0x8, %rax
movl %r12d, %ecx
movb $0x0, (%rax)
movq $0x0, -0x8(%rax)
addq %rbx, %rax
decl %ecx
jne 0xec11
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %ecx
movl %r12d, %ebx
addq $0x28, %rdi
testb $0x4, %cl
jne 0xec4f
xorl %eax, %eax
movq %rax, 0x20(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x10(%rdi)
movq %rax, 0x8(%rdi)
movq %rax, (%rdi)
jmp 0xec76
xorl %esi, %esi
callq 0x2410
movl 0x4(%rsp), %ecx
testl %eax, %eax
je 0xec76
movq 0x20(%r14), %rdi
callq 0x22a0
movq %r14, %rdi
callq 0x22a0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0xece0
testb $0x8, %cl
jne 0xec85
movq $0x0, 0x50(%r14)
jmp 0xecbb
shlq $0x3, %r15
leaq (%r15,%r15,4), %r12
movq %r12, %rdi
callq 0x22f0
testq %rax, %rax
movq %rax, 0x50(%r14)
je 0xecc7
testl %ebx, %ebx
je 0xecbb
xorl %ebx, %ebx
movq 0x50(%r14), %rdi
xorl %esi, %esi
addq %rbx, %rdi
callq 0x2410
addq $0x28, %rbx
cmpq %rbx, %r12
jne 0xeca4
movq 0x8(%rsp), %rax
xorl %ecx, %ecx
movq %r14, (%rax)
jmp 0xece0
movq %r14, %rdi
callq 0x22a0
movq 0x8(%rsp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq $0x0, (%rax)
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq