// File: /workspace/github_c_makefile_star2_O2/lh3[P]bgt/bgt.c
// Function: bgtm_hapcnt
bgt_hapcnt_t *bgtm_hapcnt(const bgtm_t *bm, int *n_hap)
{
	int i, j, absent, n;
	khint_t k;
	khash_t(hc) *h;
	bgt_hapcnt_t *hc;
	if (bm->hap == 0 || bm->n_out == 0) return 0;
	h = kh_init(hc);
	for (i = 0; i < bm->n_out<<1; ++i) {
		k = kh_put(hc, h, bm->hap[i], &absent);
		if (absent) kh_val(h, k) = kh_size(h) - 1;
	}
	n = kh_size(h);
	hc = (bgt_hapcnt_t*)calloc(n, sizeof(bgt_hapcnt_t));
	for (i = 0; i < n; ++i)
		hc[i].cnt = (int*)calloc(bm->n_groups, sizeof(int));
	for (k = 0; k < kh_end(h); ++k)
		if (kh_exist(h, k))
			hc[kh_val(h, k)].hap = kh_key(h, k);
	for (i = 0; i < bm->n_out<<1; ++i) {
		int t;
		k = kh_get(hc, h, bm->hap[i]);
		t = kh_val(h, k);
		++hc[t].tot;
		for (j = 0; j < bm->n_groups; ++j)
			if (bm->group[i>>1] & 1U<<j)
				++hc[t].cnt[j];
	}
	kh_destroy(hc, h);
	ks_introsort(hc, n, hc);
	*n_hap = n;
	return hc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
cmpq $0x0, 0xb0(%rdi)
je 0x14cb1
movq %rdi, %rax
movl 0x4(%rdi), %r15d
testl %r15d, %r15d
je 0x14cb1
movq %rsi, 0x58(%rsp)
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
movq %rax, 0x18(%rsp)
callq 0x2220
movq 0x18(%rsp), %r11
xorl %r9d, %r9d
movq %rax, %r14
movsd 0x4603(%rip), %xmm1     # 0x18e38
movsd 0x4603(%rip), %xmm2     # 0x18e40
pushq $0x2
popq %rbx
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r8d, %r8d
xorl %ecx, %ecx
xorl %eax, %eax
xorl %r10d, %r10d
xorl %edi, %edi
movq %r14, 0x50(%rsp)
leal (%r15,%r15), %esi
movslq %esi, %rsi
movq %r9, %rbp
movl %r9d, %edx
movq %rdx, 0x20(%rsp)
cmpq %rsi, %rdi
jge 0x14cb9
movq 0xb0(%r11), %rsi
movq %rdi, 0x48(%rsp)
movq (%rsi,%rdi,8), %rdx
movq %rdx, 0x28(%rsp)
cmpl %ecx, %eax
movq %r8, 0x40(%rsp)
jae 0x148a7
leal -0x1(%rbp), %r15d
movq %rcx, 0x10(%rsp)
jmp 0x14b2f
leal (%r8,%r8), %edx
movq %rbp, %r9
cmpl %r9d, %edx
movl $0x0, %edx
sbbl %edx, %edx
orl $0x1, %edx
addl %ebp, %edx
decl %edx
movl %edx, %esi
shrl %esi
orl %edx, %esi
movl %esi, %edx
shrl $0x2, %edx
orl %esi, %edx
movl %edx, %esi
shrl $0x4, %esi
orl %edx, %esi
movl %esi, %edi
shrl $0x8, %edi
orl %esi, %edi
movl %edi, %edx
shrl $0x10, %edx
orl %edi, %edx
incl %edx
cmpl $0x5, %edx
pushq $0x4
popq %rsi
movl %esi, %r15d
cmovael %edx, %r15d
cvtsi2sd %r15, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %rdi
cmpl %edi, %r8d
jae 0x14a97
movq %rdi, 0x10(%rsp)
movl %r15d, %edi
shrl $0x2, %edi
andl $-0x4, %edi
cmpl $0x10, %edx
cmovbl %esi, %edi
movq %rdi, 0x30(%rsp)
movq %r9, 0x60(%rsp)
callq 0x22e0
movq %rax, %r13
movq %rax, %rdi
movl $0xaa, %esi
movq 0x30(%rsp), %rdx
callq 0x21e0
movl %r15d, %eax
movq %r15, 0x38(%rsp)
cmpl %r15d, 0x60(%rsp)
movq %rax, 0x30(%rsp)
jae 0x1498b
leaq (,%rax,8), %rsi
movq %r12, %rdi
movq %rax, %r15
callq 0x2340
movq %rax, %r12
movq %rax, 0x18(%r14)
movq 0x20(%r14), %rdi
leaq (,%r15,4), %rsi
callq 0x2340
movq %rax, 0x8(%rsp)
movq %rax, 0x20(%r14)
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rax
leal -0x1(%rax), %r15d
xorl %eax, %eax
cmpq %rdi, %rax
je 0x14aab
movq 0x10(%r14), %rdx
movl %eax, %r8d
shrl $0x4, %r8d
movl (%rdx,%r8,4), %r9d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r9d, %esi
shrl %cl, %esi
testb $0x3, %sil
jne 0x14a8f
movq (%r12,%rax,8), %rdi
movq 0x8(%rsp), %rsi
movl (%rsi,%rax,4), %esi
btsl %ecx, %r9d
movl %r9d, (%rdx,%r8,4)
movq %rdi, %r9
shrq $0x21, %r9
movl %edi, %ecx
shll $0xb, %ecx
xorl %ecx, %r9d
xorl %edi, %r9d
movl %r15d, %r10d
andl %r9d, %r10d
movl %r9d, %ecx
shrl $0x3, %ecx
shll $0x3, %r9d
xorl %ecx, %r9d
orl $0x1, %r9d
andl %r15d, %r9d
movl %r10d, %r8d
shrl $0x4, %r8d
movl (%r13,%r8,4), %r11d
leal (%r10,%r10), %ecx
andl $0x1e, %ecx
movl %ebx, %r14d
shll %cl, %r14d
testl %r11d, %r14d
jne 0x14a2e
addl %r9d, %r10d
andl %r15d, %r10d
jmp 0x14a08
notl %r14d
andl %r14d, %r11d
movl %r11d, (%r13,%r8,4)
movl %r10d, %r9d
cmpl %ebp, %r10d
jae 0x14a78
movl (%rdx,%r8,4), %r10d
shrl %cl, %r10d
testb $0x3, %r10b
jne 0x14a78
movq (%r12,%r9,8), %r10
movq %rdi, (%r12,%r9,8)
movq 0x8(%rsp), %r14
movl (%r14,%r9,4), %edi
pushq $0x1
popq %r11
shll %cl, %r11d
movl %esi, (%r14,%r9,4)
orl %r11d, (%rdx,%r8,4)
movl %edi, %esi
movq %r10, %rdi
jmp 0x149dc
movq %rdi, (%r12,%r9,8)
movq 0x8(%rsp), %rcx
movl %esi, (%rcx,%r9,4)
movq 0x50(%rsp), %r14
movq 0x20(%rsp), %rdi
incq %rax
jmp 0x1499b
leal -0x1(%r9), %r15d
movl %r9d, %ebp
movq %rcx, 0x10(%rsp)
movl %r8d, %r10d
jmp 0x14b2f
movq 0x38(%rsp), %rax
cmpl %eax, %ebp
jbe 0x14af0
movq 0x30(%rsp), %rbp
leaq (,%rbp,8), %rsi
movq %r12, %rdi
callq 0x2340
movq %rax, %r12
movq %rax, 0x18(%r14)
movq 0x20(%r14), %rdi
shlq $0x2, %rbp
movq %rbp, %rsi
movq 0x38(%rsp), %rbp
callq 0x2340
movq %rax, 0x8(%rsp)
movq %rax, 0x20(%r14)
jmp 0x14af3
movq %rax, %rbp
movq 0x10(%r14), %rdi
callq 0x2050
movq %r13, 0x10(%r14)
movl %ebp, (%r14)
movq 0x40(%rsp), %rcx
movl %ecx, 0x8(%r14)
movq 0x10(%rsp), %rax
movl %eax, 0xc(%r14)
movl %ecx, %eax
movl %ecx, %r10d
movq 0x18(%rsp), %r11
movsd 0x4311(%rip), %xmm1     # 0x18e38
movsd 0x4311(%rip), %xmm2     # 0x18e40
movl %r10d, 0x20(%rsp)
movq 0x28(%rsp), %rsi
movq %rsi, %r8
shrq $0x21, %r8
movl %esi, %ecx
shll $0xb, %ecx
xorl %ecx, %r8d
xorl %esi, %r8d
movl %r15d, %esi
andl %r8d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %edi
leal (%rsi,%rsi), %ecx
shrl %cl, %edi
testb $0x2, %dil
je 0x14b6d
movl %esi, %edi
jmp 0x14c00
movl %r8d, %ecx
shrl $0x3, %ecx
shll $0x3, %r8d
xorl %ecx, %r8d
orl $0x1, %r8d
andl %r15d, %r8d
movl %ebp, %edi
movl %esi, %r9d
movl %r9d, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %r10d
leal (%r9,%r9), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x14bdb
testb $0x1, %r11b
jne 0x14bb8
movl %r9d, %r11d
movq 0x28(%rsp), %rdx
cmpq %rdx, (%r12,%r11,8)
je 0x14bdb
btl %ecx, %r10d
cmovbl %r9d, %edi
addl %r8d, %r9d
andl %r15d, %r9d
cmpl %esi, %r9d
jne 0x14b86
movb $0x1, %cl
movl %ebp, %r8d
cmpl %ebp, %edi
movq 0x18(%rsp), %r11
je 0x14bf0
jmp 0x14c00
shrl %cl, %r10d
testb $0x2, %r10b
sete %cl
movl %r9d, %esi
movl %edi, %r8d
movq 0x18(%rsp), %r11
cmpl %ebp, %r8d
cmovel %esi, %r8d
testb %cl, %cl
cmovnel %esi, %r8d
movl %r8d, %edi
movl %edi, %r8d
shrl $0x4, %r8d
movl (%r13,%r8,4), %r9d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r9d, %r10d
shrl %cl, %r10d
movl %edi, %esi
testb $0x2, %r10b
jne 0x14c37
testb $0x1, %r10b
movq 0x48(%rsp), %rdi
jne 0x14c6b
movq 0x40(%rsp), %r8
movl 0x20(%rsp), %r10d
jmp 0x14c9d
movq 0x28(%rsp), %rax
movq %rax, (%r12,%rsi,8)
pushq $0x3
popq %rax
shll %cl, %eax
notl %eax
andl %eax, %r9d
movl %r9d, (%r13,%r8,4)
movl 0x4(%r14), %r8d
movl 0x8(%r14), %eax
incl %r8d
movl %r8d, 0x4(%r14)
incl %eax
movl %eax, 0x8(%r14)
movq 0x48(%rsp), %rdi
jmp 0x14c8e
pushq $0x3
popq %rdx
shll %cl, %edx
movq 0x28(%rsp), %rcx
movq %rcx, (%r12,%rsi,8)
notl %edx
andl %edx, %r9d
movl %r9d, (%r13,%r8,4)
movl 0x4(%r14), %r8d
incl %r8d
movl %r8d, 0x4(%r14)
leal -0x1(%r8), %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx,%rsi,4)
movl %r8d, %r10d
incq %rdi
movl 0x4(%r11), %r15d
movl %ebp, %r9d
movq 0x10(%rsp), %rcx
jmp 0x14860
xorl %r14d, %r14d
jmp 0x14e87
movslq %r10d, %rdi
movq %rdi, 0x10(%rsp)
pushq $0x18
popq %rsi
callq 0x2220
movq %rax, %rbx
xorl %r14d, %r14d
movq 0x10(%rsp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x28(%rsp)
cmpq %r14, 0x28(%rsp)
movq 0x18(%rsp), %r9
je 0x14d0a
movslq 0x8(%r9), %rdi
pushq $0x4
popq %rsi
callq 0x2220
movq %rax, 0x10(%rbx,%r14)
addq $0x18, %r14
jmp 0x14ce7
xorl %eax, %eax
xorl %edx, %edx
movq 0x50(%rsp), %r8
movq 0x20(%rsp), %rdi
movq %rbx, %r14
cmpq %rdx, %rdi
je 0x14d54
movl %edx, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %esi
movl %eax, %ecx
andb $0x1e, %cl
shrl %cl, %esi
testb $0x3, %sil
jne 0x14d4c
movq (%r12,%rdx,8), %rcx
movq 0x8(%rsp), %rsi
movslq (%rsi,%rdx,4), %rsi
imulq $0x18, %rsi, %rsi
movq %rcx, (%r14,%rsi)
incq %rdx
addl $0x2, %eax
jmp 0x14d1b
leal -0x1(%rbp), %eax
xorl %edx, %edx
movq %r8, %rbx
addl %r15d, %r15d
movslq %r15d, %rcx
cmpq %rcx, %rdx
jge 0x14e49
testl %ebp, %ebp
je 0x14dfa
movq 0xb0(%r9), %rcx
movq (%rcx,%rdx,8), %rdi
movq %rdi, %r8
shrq $0x21, %r8
movl %edi, %ecx
shll $0xb, %ecx
xorl %ecx, %r8d
xorl %edi, %r8d
movl %eax, %r9d
andl %r8d, %r9d
movl %r8d, %ecx
shrl $0x3, %ecx
shll $0x3, %r8d
xorl %ecx, %r8d
orl $0x1, %r8d
andl %eax, %r8d
movl %r9d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r13,%rcx,4), %r10d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x14de9
testb $0x1, %r11b
jne 0x14dd8
movl %esi, %r11d
cmpq %rdi, (%r12,%r11,8)
je 0x14de9
addl %r8d, %esi
andl %eax, %esi
cmpl %r9d, %esi
jne 0x14dad
movq 0x20(%rsp), %rsi
jmp 0x14df3
shrl %cl, %r10d
testb $0x3, %r10b
cmovnel %ebp, %esi
movq 0x18(%rsp), %r9
jmp 0x14dfc
xorl %esi, %esi
movl %esi, %ecx
movq 0x8(%rsp), %rsi
movslq (%rsi,%rcx,4), %rcx
imulq $0x18, %rcx, %rcx
incl 0x8(%r14,%rcx)
addq %r14, %rcx
movl %edx, %esi
shrl %esi
xorl %edi, %edi
movslq 0x8(%r9), %r8
cmpq %r8, %rdi
jge 0x14e3d
movq 0x20(%r9), %r8
movl (%r8,%rsi,4), %r8d
btl %edi, %r8d
jae 0x14e38
movq 0x10(%rcx), %r8
incl (%r8,%rdi,4)
incq %rdi
jmp 0x14e19
incq %rdx
movl 0x4(%r9), %r15d
jmp 0x14d5c
testq %rbx, %rbx
je 0x14e70
movq %r12, %rdi
callq 0x2050
movq 0x10(%rbx), %rdi
callq 0x2050
movq 0x20(%rbx), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x14530
movq 0x58(%rsp), %rax
movl %ebx, (%rax)
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq