// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movl %r9d, %r13d
movl %r8d, %r12d
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movl $0x58, %edi
callq 0x22f0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xf196
movq %r14, (%rsp)
movl $0x0, (%rax)
movl %r12d, 0x18(%rax)
movl %ebp, 0x4(%rax)
movl %ebx, 0x8(%rax)
movl %r13d, 0xc(%rax)
movq %r15, 0x10(%rax)
movl %r13d, %edx
notl %edx
testb $0xc, %dl
jne 0xf085
movq (%rsp), %rax
movq $0x0, (%rax)
jmp 0xf196
movq %rax, %r14
movq %rax, %r15
movl %r12d, %ecx
movl %ebp, %eax
movq %rcx, %rbp
movl %ebx, %ecx
leaq 0x10(%rax,%rcx), %rdi
imulq %rbp, %rdi
callq 0x22f0
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0xf17e
testl %r12d, %r12d
je 0xf0db
movl 0x4(%r14), %ecx
movl 0x8(%r14), %edx
leaq 0x10(%rcx,%rdx), %rcx
addq $0x8, %rax
movl %r12d, %edx
movb $0x0, (%rax)
movq $0x0, -0x8(%rax)
addq %rcx, %rax
decl %edx
jne 0xf0c9
addq $0x28, %r15
movl %r13d, %ecx
testb $0x4, %cl
jne 0xf0fe
xorl %eax, %eax
movq %rax, 0x20(%r15)
movq %rax, 0x18(%r15)
movq %rax, 0x10(%r15)
movq %rax, 0x8(%r15)
movq %rax, (%r15)
jmp 0xf122
movq %r15, %rdi
xorl %esi, %esi
callq 0x2410
movl %r13d, %ecx
testl %eax, %eax
je 0xf122
movq 0x20(%r14), %rdi
callq 0x22a0
movq %r14, %rdi
callq 0x22a0
jmp 0xf191
testb $0x8, %cl
jne 0xf131
movq $0x0, 0x50(%r14)
jmp 0xf173
leaq (,%rbp,8), %rax
leaq (%rax,%rax,4), %rdi
callq 0x22f0
movq %rax, 0x50(%r14)
testq %rax, %rax
je 0xf17e
testl %r12d, %r12d
je 0xf173
shlq $0x3, %rbp
leaq (%rbp,%rbp,4), %rbx
xorl %r15d, %r15d
movq 0x50(%r14), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x2410
addq $0x28, %r15
cmpq %r15, %rbx
jne 0xf15c
movq (%rsp), %rax
movq %r14, (%rax)
xorl %ecx, %ecx
jmp 0xf196
movq %r14, %rdi
callq 0x22a0
movq (%rsp), %rax
movq $0x0, (%rax)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq