// File: /workspace/github_c_makefile_star2_O3/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
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 0x22e0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x3b3c
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 0x3a2f
movq 0x8(%rsp), %rax
jmp 0x3b35
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 0x22e0
testq %rax, %rax
movq %rax, 0x20(%r14)
je 0x3b23
testl %r12d, %r12d
je 0x3a7f
addq $0x8, %rax
movl %r12d, %ecx
movb $0x0, (%rax)
movq $0x0, -0x8(%rax)
addq %rbx, %rax
decl %ecx
jne 0x3a6d
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %ecx
movl %r12d, %ebx
addq $0x28, %rdi
testb $0x4, %cl
jne 0x3aab
xorl %eax, %eax
movq %rax, 0x20(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x10(%rdi)
movq %rax, 0x8(%rdi)
movq %rax, (%rdi)
jmp 0x3ad2
xorl %esi, %esi
callq 0x2400
movl 0x4(%rsp), %ecx
testl %eax, %eax
je 0x3ad2
movq 0x20(%r14), %rdi
callq 0x22c0
movq %r14, %rdi
callq 0x22c0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x3b3c
testb $0x8, %cl
jne 0x3ae1
movq $0x0, 0x50(%r14)
jmp 0x3b17
shlq $0x3, %r15
leaq (%r15,%r15,4), %r12
movq %r12, %rdi
callq 0x22e0
testq %rax, %rax
movq %rax, 0x50(%r14)
je 0x3b23
testl %ebx, %ebx
je 0x3b17
xorl %ebx, %ebx
movq 0x50(%r14), %rdi
xorl %esi, %esi
addq %rbx, %rdi
callq 0x2400
addq $0x28, %rbx
cmpq %rbx, %r12
jne 0x3b00
movq 0x8(%rsp), %rax
xorl %ecx, %ecx
movq %r14, (%rax)
jmp 0x3b3c
movq %r14, %rdi
callq 0x22c0
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