// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movl %edx, 0x2c(%rsp)
movl %ecx, 0x28(%rsp)
movl %r8d, 0x24(%rsp)
movl %r9d, 0x20(%rsp)
movl $0x58, %edi
callq 0x2310
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x17044
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729c
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
movl 0x24(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x18(%rax)
movl 0x2c(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0x28(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
movl 0x20(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x30(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movl 0x20(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x170be
movl 0x20(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x170be
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729c
movl 0x24(%rsp), %eax
movl %eax, %edi
movq 0x18(%rsp), %rax
movl 0x4(%rax), %eax
addq $0x10, %rax
movq 0x18(%rsp), %rcx
movl 0x8(%rcx), %ecx
addq %rcx, %rax
imulq %rax, %rdi
callq 0x2310
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x1711f
movq 0x18(%rsp), %rdi
callq 0x22c0
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729c
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x24(%rsp), %eax
jae 0x17185
movq 0x10(%rsp), %rax
movb $0x0, 0x8(%rax)
movq 0x10(%rsp), %rax
movq $0x0, (%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movl 0x4(%rcx), %ecx
addq $0x10, %rcx
movq 0x18(%rsp), %rdx
movl 0x8(%rdx), %edx
addq %rdx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x17135
movl 0x20(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x171d2
movq 0x18(%rsp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2430
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x171d0
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x22c0
movq 0x18(%rsp), %rdi
callq 0x22c0
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729c
jmp 0x171e7
movq 0x18(%rsp), %rdi
addq $0x28, %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2150
movl 0x20(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1727a
movl 0x24(%rsp), %eax
imulq $0x28, %rax, %rdi
callq 0x2310
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x50(%rax)
movq 0x18(%rsp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x1723c
movq 0x18(%rsp), %rdi
callq 0x22c0
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
jmp 0x1729c
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
cmpl 0x24(%rsp), %eax
jae 0x17278
movq 0x18(%rsp), %rax
movq 0x50(%rax), %rdi
movl 0x8(%rsp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2430
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x17244
jmp 0x17287
movq 0x18(%rsp), %rax
movq $0x0, 0x50(%rax)
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
nop