// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/datastruct/kvhash.c
// Function: rehash
static int
rehash(struct kvhash * H)
{
	size_t new_nslots;
	struct kvpair_const * new_pairs;
	uint32_t * new_hashes;
	size_t i, pos;

	/* Sanity check. */
	assert((H->nslots > 0) && (H->nslots <= SIZE_MAX / 2));

	/* Double the table size. */
	new_nslots = H->nslots * 2;

	/* Sanity check; clang can't figure this out by itself. */
	assert(new_nslots > 0);

	/* Allocate new arrays. */
	if (IMALLOC(new_pairs, new_nslots, struct kvpair_const))
		goto err0;
	if (IMALLOC(new_hashes, new_nslots, uint32_t))
		goto err1;

	/* Nothing in the new table yet. */
	memset(new_pairs, 0, new_nslots * sizeof(struct kvpair_const));

	/* Scan the old table and move entries. */
	for (i = 0; i < H->nslots; i++) {
		/* Skip empty slots. */
		if (H->pairs[i].k == NULL)
			continue;

		/* Look for an empty slot in the new table. */
		pos = H->hashes[i] & (new_nslots - 1);
		while (new_pairs[pos].k != NULL)
			pos = (pos + 1) & (new_nslots - 1);

		/* Copy the key, value, and hash across. */
		new_pairs[pos].k = H->pairs[i].k;
		new_pairs[pos].v = H->pairs[i].v;
		new_hashes[pos] = H->hashes[i];
	}

	/* Free the old arrays. */
	free(H->pairs);
	free(H->hashes);

	/* Attach new arrays to the hash table. */
	H->pairs = new_pairs;
	H->hashes = new_hashes;
	H->nslots = new_nslots;

	/* Success! */
	return (0);

err1:
	free(new_pairs);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x18add
movq -0x10(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
cmpq %rcx, 0x18(%rax)
ja 0x18add
jmp 0x18afc
leaq 0x8154(%rip), %rdi      # 0x20c38
leaq 0x817c(%rip), %rsi      # 0x20c67
movl $0x18, %edx
leaq 0x818b(%rip), %rcx      # 0x20c82
callq 0x21d0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shlq %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jbe 0x18b14
jmp 0x18b33
leaq 0x8183(%rip), %rdi      # 0x20c9e
leaq 0x8145(%rip), %rsi      # 0x20c67
movl $0x1e, %edx
leaq 0x8154(%rip), %rcx      # 0x20c82
callq 0x21d0
movq -0x18(%rbp), %rdi
movl $0x10, %esi
callq 0x18870
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x18b57
cmpq $0x0, -0x18(%rbp)
jbe 0x18b57
jmp 0x18cda
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x18870
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x18b7b
cmpq $0x0, -0x18(%rbp)
jbe 0x18b7b
jmp 0x18cd1
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x21e0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x18c8c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x18bc5
jmp 0x18c7b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
andq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x18c11
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
andq %rcx, %rax
movq %rax, -0x38(%rbp)
jmp 0x18be3
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x18b96
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2040
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x18ce1
movq -0x20(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)