// File: /workspace/github_c_makefile_star2_O1/sharpyfox[P]citrusleaf-client/tests/loop_c/src/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, uint flags)
{
	shash *h;

	h = 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 = h->table;
	for (uint 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( &h->biglock, 0, sizeof( h->biglock ) );
	
	if (flags & SHASH_CR_MT_MANYLOCK) {
		h->lock_table = malloc( sizeof(pthread_mutex_t) * sz);
		if (! h->lock_table) {
			free(h);
			*h_r = 0;
			return(SHASH_ERR);
		}
		for (uint 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 0x22e0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x3ba2
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 0x3a91
movq (%rsp), %rax
movq $0x0, (%rax)
jmp 0x3ba2
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 0x22e0
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x3b8a
testl %r12d, %r12d
je 0x3ae7
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 0x3ad5
addq $0x28, %r15
movl %r13d, %ecx
testb $0x4, %cl
jne 0x3b0a
xorl %eax, %eax
movq %rax, 0x20(%r15)
movq %rax, 0x18(%r15)
movq %rax, 0x10(%r15)
movq %rax, 0x8(%r15)
movq %rax, (%r15)
jmp 0x3b2e
movq %r15, %rdi
xorl %esi, %esi
callq 0x2400
movl %r13d, %ecx
testl %eax, %eax
je 0x3b2e
movq 0x20(%r14), %rdi
callq 0x22c0
movq %r14, %rdi
callq 0x22c0
jmp 0x3b9d
testb $0x8, %cl
jne 0x3b3d
movq $0x0, 0x50(%r14)
jmp 0x3b7f
leaq (,%rbp,8), %rax
leaq (%rax,%rax,4), %rdi
callq 0x22e0
movq %rax, 0x50(%r14)
testq %rax, %rax
je 0x3b8a
testl %r12d, %r12d
je 0x3b7f
shlq $0x3, %rbp
leaq (%rbp,%rbp,4), %rbx
xorl %r15d, %r15d
movq 0x50(%r14), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x2400
addq $0x28, %r15
cmpq %r15, %rbx
jne 0x3b68
movq (%rsp), %rax
movq %r14, (%rax)
xorl %ecx, %ecx
jmp 0x3ba2
movq %r14, %rdi
callq 0x22c0
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