// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
cmpq $0x0, 0xb0(%rdi)
je 0x1abf4
movq %rdi, %r15
cmpl $0x0, 0x4(%rdi)
je 0x1abf4
movq %rsi, 0x10(%rsp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x2220
movq %rax, %r14
movl 0x4(%r15), %eax
addl %eax, %eax
testl %eax, %eax
jle 0x1aa01
xorl %r12d, %r12d
movq 0xb0(%r15), %rax
movq (%rax,%r12,8), %r13
movl 0x8(%r14), %eax
cmpl 0xc(%r14), %eax
jb 0x1a8b9
movl (%r14), %eax
movl 0x4(%r14), %ecx
addl %ecx, %ecx
cmpl %eax, %ecx
movl $0x0, %esi
sbbl %esi, %esi
orl $0x1, %esi
addl %eax, %esi
movq %r14, %rdi
callq 0x1b30f
movl (%r14), %edx
leal -0x1(%rdx), %edi
movq %r13, %r9
shrq $0x21, %r9
movl %r13d, %eax
shll $0xb, %eax
xorl %eax, %r9d
xorl %r13d, %r9d
movl %edi, %esi
andl %r9d, %esi
movq 0x10(%r14), %rax
movl %esi, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r8d
leal (%rsi,%rsi), %ecx
shrl %cl, %r8d
testb $0x2, %r8b
jne 0x1a97c
movl %r9d, %ecx
shrl $0x3, %ecx
shll $0x3, %r9d
xorl %ecx, %r9d
orl $0x1, %r9d
andl %edi, %r9d
movl %edx, %r8d
movl %esi, %r10d
movl %r10d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %r11d
leal (%r10,%r10), %ecx
andl $0x1e, %ecx
movl %r11d, %ebx
shrl %cl, %ebx
testb $0x2, %bl
jne 0x1a953
testb $0x1, %bl
jne 0x1a93b
movq 0x18(%r14), %rbx
movl %r10d, %ebp
cmpq %r13, (%rbx,%rbp,8)
je 0x1a953
btl %ecx, %r11d
cmovbl %r10d, %r8d
addl %r9d, %r10d
andl %edi, %r10d
movl %r8d, %ecx
cmpl %esi, %r10d
jne 0x1a90e
jmp 0x1a955
movl %edx, %ecx
movl %ecx, %esi
cmpl %edx, %ecx
jne 0x1a97c
movl %r10d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %esi
leal (%r10,%r10), %ecx
shrl %cl, %esi
cmpl %edx, %r8d
cmovel %r10d, %r8d
testb $0x2, %sil
cmovel %r10d, %r8d
movl %r8d, %esi
movl %esi, %edx
shrl $0x4, %edx
movl (%rax,%rdx,4), %edi
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %edi, %r8d
shrl %cl, %r8d
movl %esi, %esi
testb $0x2, %r8b
jne 0x1a9be
testb $0x1, %r8b
je 0x1a9ed
movl $0x3, %r8d
shll %cl, %r8d
movq 0x18(%r14), %rcx
movq %r13, (%rcx,%rsi,8)
notl %r8d
andl %r8d, %edi
movl %edi, (%rax,%rdx,4)
incl 0x4(%r14)
jmp 0x1a9e0
movl $0x3, %r8d
shll %cl, %r8d
movq 0x18(%r14), %rcx
movq %r13, (%rcx,%rsi,8)
notl %r8d
andl %r8d, %edi
movl %edi, (%rax,%rdx,4)
incl 0x4(%r14)
incl 0x8(%r14)
movl 0x4(%r14), %eax
decl %eax
movq 0x20(%r14), %rcx
movl %eax, (%rcx,%rsi,4)
incq %r12
movl 0x4(%r15), %eax
addl %eax, %eax
cltq
cmpq %rax, %r12
jl 0x1a885
movslq 0x4(%r14), %rbx
movl $0x18, %esi
movq %rbx, %rdi
callq 0x2220
movq %rax, %r12
movq %rbx, 0x8(%rsp)
testq %rbx, %rbx
jle 0x1aa52
movslq 0x8(%r15), %rbp
movq 0x8(%rsp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %rbx
xorl %r13d, %r13d
movl $0x4, %esi
movq %rbp, %rdi
callq 0x2220
movq %rax, 0x10(%r12,%r13)
addq $0x18, %r13
cmpq %r13, %rbx
jne 0x1aa37
movl (%r14), %eax
testq %rax, %rax
je 0x1aa9c
movq 0x10(%r14), %rdx
xorl %esi, %esi
xorl %edi, %edi
movl %edi, %ecx
shrl $0x4, %ecx
movl (%rdx,%rcx,4), %r8d
movl %esi, %ecx
andb $0x1e, %cl
shrl %cl, %r8d
testb $0x3, %r8b
jne 0x1aa91
movq 0x18(%r14), %rcx
movq 0x20(%r14), %r8
movq (%rcx,%rdi,8), %rcx
movslq (%r8,%rdi,4), %r8
leaq (%r8,%r8,2), %r8
movq %rcx, (%r12,%r8,8)
incq %rdi
addl $0x2, %esi
cmpq %rdi, %rax
jne 0x1aa62
movl 0x4(%r15), %ecx
addl %ecx, %ecx
testl %ecx, %ecx
jle 0x1abb8
movq 0xb0(%r15), %rcx
movq %rcx, 0x18(%rsp)
leal -0x1(%rax), %esi
movq 0x20(%r14), %rcx
movq %rcx, 0x20(%rsp)
xorl %r8d, %r8d
movl $0x0, %r11d
testl %eax, %eax
je 0x1ab58
movq 0x18(%rsp), %rcx
movq (%rcx,%r8,8), %r9
movq %r9, %r10
shrq $0x21, %r10
movl %r9d, %ecx
shll $0xb, %ecx
xorl %ecx, %r10d
xorl %r9d, %r10d
movl %esi, %ebp
andl %r10d, %ebp
movl %r10d, %ecx
shrl $0x3, %ecx
shll $0x3, %r10d
xorl %ecx, %r10d
orl $0x1, %r10d
andl %esi, %r10d
movq 0x10(%r14), %rbx
movl %ebp, %r11d
movl %r11d, %ecx
shrl $0x4, %ecx
movl (%rbx,%rcx,4), %edx
leal (%r11,%r11), %ecx
andl $0x1e, %ecx
movl %edx, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0x1ab4f
testb $0x1, %r13b
jne 0x1ab3f
movq 0x18(%r14), %r13
movl %r11d, %edi
cmpq %r9, (%r13,%rdi,8)
je 0x1ab4f
addl %r10d, %r11d
andl %esi, %r11d
cmpl %ebp, %r11d
jne 0x1ab0f
movl %eax, %r11d
jmp 0x1ab58
shrl %cl, %edx
testb $0x3, %dl
cmovnel %eax, %r11d
movl %r11d, %ecx
movq 0x20(%rsp), %rdx
movslq (%rdx,%rcx,4), %rcx
leaq (%rcx,%rcx,2), %rcx
incl 0x8(%r12,%rcx,8)
cmpl $0x0, 0x8(%r15)
jle 0x1aba3
leaq (%r12,%rcx,8), %rcx
movq 0x20(%r15), %r9
movl %r8d, %r10d
shrl %r10d
xorl %r11d, %r11d
movl (%r9,%r10,4), %edx
btl %r11d, %edx
jae 0x1ab97
movq 0x10(%rcx), %rdx
incl (%rdx,%r11,4)
incq %r11
movslq 0x8(%r15), %rdx
cmpq %rdx, %r11
jl 0x1ab85
incq %r8
movl 0x4(%r15), %ecx
addl %ecx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %r8
jl 0x1aac5
movq 0x18(%r14), %rdi
callq 0x2050
movq 0x10(%r14), %rdi
callq 0x2050
movq 0x20(%r14), %rdi
callq 0x2050
movq %r14, %rdi
callq 0x2050
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1a544
movq 0x10(%rsp), %rax
movl %ebx, (%rax)
jmp 0x1abf7
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq