// File: chhylp123[P]hifiasm/htab.cpp
// Function: ha_pt_insert_list(ha_pt_s*, int, ha_mz1_t const*)
int ha_pt_insert_list(ha_pt_t *h, int n, const ha_mz1_t *a)
{
	int j, mask = (1<<h->pre) - 1, n_ins = 0;
	ha_pt1_t *g;
	if (n == 0) return 0;
	g = &h->h[a[0].x&mask];
	for (j = 0; j < n; ++j) {
		uint64_t x = a[j].x >> h->pre;
		khint_t k;
		int n;
		ha_idxpos_t *p;
		assert((a[j].x&mask) == (a[0].x&mask));
		k = yak_pt_get(g->h, x<<YAK_COUNTER_BITS);
		if (k == kh_end(g->h)) continue; // TODO: understand why we sometimes come here
		n = kh_key(g->h, k) & YAK_MAX_COUNT;
		assert(n < YAK_MAX_COUNT);
		p = &g->a[kh_val(g->h, k) + n];
		p->rid = a[j].rid, p->rev = a[j].rev, p->pos = a[j].pos, p->span = a[j].span;
		//(uint64_t)a[j].rid<<36 | (uint64_t)a[j].rev<<35 | (uint64_t)a[j].pos<<8 | (uint64_t)a[j].span;
		++kh_key(g->h, k);
		++n_ins;
	}
	return n_ins;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -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, -0x14(%rbp)
jne 0x187210
movl $0x0, -0x4(%rbp)
jmp 0x1874b2
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x28(%rbp), %rdx
andq %rdx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1874ac
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
shrq %cl, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %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 0x187292
jmp 0x1872b1
leaq 0x203647(%rip), %rdi    # 0x38a8e0
leaq 0x20365f(%rip), %rsi    # 0x38a8ff
movl $0x1c0, %edx            # imm = 0x1C0
leaq 0x20365c(%rip), %rcx    # 0x38a908
callq 0x2130
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
shlq $0xc, %rsi
callq 0x1874c0
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x1872f1
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl (%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x58(%rbp)
jmp 0x1872f8
xorl %eax, %eax
movl %eax, -0x58(%rbp)
jmp 0x1872f8
movl -0x54(%rbp), %eax
movl -0x58(%rbp), %ecx
cmpl %ecx, %eax
jne 0x187307
jmp 0x18749e
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x44(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
andq $0xfff, %rax            # imm = 0xFFF
movl %eax, -0x48(%rbp)
cmpl $0xfff, -0x48(%rbp)     # imm = 0xFFF
jge 0x187333
jmp 0x187352
leaq 0x203606(%rip), %rdi    # 0x38a940
leaq 0x2035be(%rip), %rsi    # 0x38a8ff
movl $0x1c4, %edx            # imm = 0x1C4
leaq 0x2035bb(%rip), %rcx    # 0x38a908
callq 0x2130
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movl -0x44(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
movslq -0x48(%rbp), %rdx
addq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
andq $0xfffffff, %rdx        # imm = 0xFFFFFFF
movq -0x50(%rbp), %rax
movq (%rax), %rcx
andq $0xfffffff, %rdx        # imm = 0xFFFFFFF
andq $-0x10000000, %rcx      # imm = 0xF0000000
orq %rdx, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
shrq $0x37, %rdx
andq $0x1, %rdx
movq -0x50(%rbp), %rax
movq (%rax), %rcx
andq $0x1, %rdx
shlq $0x37, %rdx
movabsq $-0x80000000000001, %rsi # imm = 0xFF7FFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
shrq $0x1c, %rdx
andq $0x7ffffff, %rdx        # imm = 0x7FFFFFF
movq -0x50(%rbp), %rax
movq (%rax), %rcx
andq $0x7ffffff, %rdx        # imm = 0x7FFFFFF
shlq $0x1c, %rdx
movabsq $-0x7ffffff0000001, %rsi # imm = 0xFF8000000FFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
shrq $0x38, %rdx
movq -0x50(%rbp), %rax
movq (%rax), %rcx
andq $0xff, %rdx
shlq $0x38, %rdx
movabsq $0xffffffffffffff, %rsi # imm = 0xFFFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x44(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x187238
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)