// File: chhylp123[P]hifiasm/htab.cpp
// Function: ha_ct_insert_list(ha_ct_t*, int, int, unsigned long const*)
static int ha_ct_insert_list(ha_ct_t *h, int create_new, int n, const uint64_t *a)
{
	int j, mask = (1<<h->pre) - 1, n_ins = 0;
	ha_ct1_t *g;
	if (n == 0) return 0;
	///corresponding small hash index
	g = &h->h[a[0]&mask];
	for (j = 0; j < n; ++j) {
		int ins = 1, absent;
		///x is a 64-bit word, h->pre=12
		///all elements at a have the same low 12 bits
		///so low 12 bits are not useful
		uint64_t x = a[j] >> h->pre;
		khint_t k;
		assert((a[j]&mask) == (a[0]&mask));
		if (create_new) {
			if (g->b)
				ins = (yak_bf_insert(g->b, x) == h->n_hash);
			///x = the high 52 bits of a[j] + low 12 bits 0
			///the low 12 bits are used for counting
			if (ins) {
				k = yak_ct_put(g->h, x << YAK_COUNTER_BITS | (g->b? 1 : 0), &absent);
				if (absent) ++n_ins;
				if ((kh_key(g->h, k)&YAK_MAX_COUNT) < YAK_MAX_COUNT)
					++kh_key(g->h, k);
			}
		} else {
			k = yak_ct_get(g->h, x<<YAK_COUNTER_BITS);
			if (k != kh_end(g->h) && (kh_key(g->h, k)&YAK_MAX_COUNT) < YAK_MAX_COUNT)
				++kh_key(g->h, k);
		}
	}
	return n_ins;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x18f723
movl $0x0, -0x4(%rbp)
jmp 0x18f92a
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x28(%rbp), %rdx
andq %rdx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x18f924
movl $0x1, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
shrq %cl, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
andq %rcx, %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x28(%rbp), %rdx
andq %rdx, %rcx
cmpq %rcx, %rax
jne 0x18f7a0
jmp 0x18f7bf
leaq 0x1fb1ab(%rip), %rdi    # 0x38a952
leaq 0x1fb151(%rip), %rsi    # 0x38a8ff
movl $0xc3, %edx
leaq 0x1fb9ac(%rip), %rcx    # 0x38b166
callq 0x2130
cmpl $0x0, -0x14(%rbp)
je 0x18f887
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x18f7f7
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x186570
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x18f882
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rsi
shlq $0xc, %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
cltq
orq %rax, %rsi
leaq -0x40(%rbp), %rdx
callq 0x18f940
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x18f846
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq $0xfff, %rax            # imm = 0xFFF
cmpq $0xfff, %rax            # imm = 0xFFF
jae 0x18f880
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x18f882
jmp 0x18f914
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rsi
shlq $0xc, %rsi
callq 0x18a740
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x18f8c7
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x54(%rbp)
jmp 0x18f8ce
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x18f8ce
movl -0x50(%rbp), %eax
movl -0x54(%rbp), %ecx
cmpl %ecx, %eax
je 0x18f912
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq $0xfff, %rax            # imm = 0xFFF
cmpq $0xfff, %rax            # imm = 0xFFF
jae 0x18f912
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x18f914
jmp 0x18f916
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x18f74b
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)