// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: gen_mmhap_t(ma_ug_t*, asg_t*, ma_hit_t_alloc*)
mmhap_t* gen_mmhap_t(ma_ug_t *ug, asg_t *rg, ma_hit_t_alloc *src)
{
    uint64_t k, z, hom_cov, het_cov, s, *bs = NULL; uint8_t *ff; mmhap_t *p; 
    if(asm_opt.hom_global_coverage_set) {
        hom_cov = asm_opt.hom_global_coverage;
    } else {
        hom_cov = ((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE);
    }
    het_cov = hom_cov/asm_opt.polyploidy;
    CALLOC(ff, rg->n_seq); CALLOC(p, 1); CALLOC(bs, asm_opt.polyploidy+1);
    p->h.n = p->h.m = ug->u.n; CALLOC(p->h.a, p->h.n);
    for (k = p->a.n = s = 0; k < ug->u.n; k++) {
        p->h.a[k].a = p->a.n;
        p->h.a[k].n = 0;
        p->h.a[k].m = infer_mmhap_copy(ug, rg, src, ff, k, het_cov, asm_opt.polyploidy);
        if(p->h.a[k].m == (uint64_t)asm_opt.polyploidy) {
            p->h.a[k].n = p->h.a[k].m; s = 1;
        }
        p->a.n += p->h.a[k].m; bs[p->h.a[k].m] += ug->g->seq[k].len;
    }
    free(ff);
    p->a.m = p->a.n; MALLOC(p->a.a, p->a.n); memset(p->a.a, -1, sizeof((*(p->a.a)))*p->a.n);
    if(s) {
        for (k = p->a.n = 0; k < ug->u.n; k++) {
            if(p->h.a[k].n == p->h.a[k].m) {
                for (z = 0; z < p->h.a[k].m; z++) p->a.a[p->h.a[k].a+z] = z;
            }
        }
    }

    for (k = 1; k <= (uint64_t)asm_opt.polyploidy; k++) {
        fprintf(stderr, "[M::stat] # %lu-copy bases: %lu\n", k, bs[k]);
    }
    free(bs);
    return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x40(%rsp)
movq %rdi, %rbx
leaq 0x133123(%rip), %r8     # 0x295758
movslq 0x144(%r8), %rcx
cvtsi2sd %ecx, %xmm0
divsd 0xd3718(%rip), %xmm0    # 0x235d60
cvttsd2si %xmm0, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
subsd 0xcecac(%rip), %xmm0    # 0x231308
cvttsd2si %xmm0, %rax
andq %rdi, %rax
orq %rdx, %rax
cmpl $0x0, 0x148(%r8)
cmovneq %rcx, %rax
movslq 0x1bc(%r8), %rbp
xorl %r12d, %r12d
xorl %edx, %edx
divq %rbp
movq %rax, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movl 0x14(%rsi), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, 0x20(%rsp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %r14
movq %rbp, %rdi
incq %rdi
movl $0x8, %esi
callq 0x2120
movq %rax, 0x8(%rsp)
movq (%rbx), %r13
movq %r13, 0x8(%r14)
movq %r13, (%r14)
movl $0xc, %esi
movq %r13, %rdi
callq 0x2120
movq %r14, 0x10(%rsp)
movq %rax, 0x10(%r14)
testq %r13, %r13
movq %rax, 0x28(%rsp)
je 0x1627aa
xorl %r12d, %r12d
movq %rax, %r14
xorl %r13d, %r13d
movq $0x0, 0x18(%rsp)
movl %r12d, 0x8(%r14)
movl $0x0, (%r14)
movslq %ebp, %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %r13, %r8
movq 0x30(%rsp), %r9
callq 0xc6ccb
movl %eax, 0x4(%r14)
movl %eax, %ecx
leaq 0x13300f(%rip), %rdx    # 0x295758
movslq 0x1bc(%rdx), %rbp
cmpq %rbp, %rcx
jne 0x162762
movl %eax, (%r14)
movl $0x1, %ecx
movq %rcx, 0x18(%rsp)
movl %eax, %eax
addq %rax, %r12
movq 0x18(%rbx), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%r13,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x8(%rsp), %rdx
addq %rcx, (%rdx,%rax,8)
incq %r13
movq (%rbx), %r15
addq $0xc, %r14
cmpq %r15, %r13
jb 0x16270b
movq 0x10(%rsp), %r13
movq %r12, 0x18(%r13)
cmpq $0x0, 0x18(%rsp)
sete %r14b
jmp 0x1627b5
movb $0x1, %r14b
xorl %r15d, %r15d
movq 0x10(%rsp), %r13
movq 0x20(%rsp), %rdi
callq 0x2220
movq %r12, 0x20(%r13)
shlq $0x2, %r12
movq %r12, %rdi
callq 0x2280
movq %rax, %rbx
movq %rax, 0x28(%r13)
movq %rax, %rdi
movl $0xff, %esi
movq %r12, %rdx
callq 0x20e0
testb %r14b, %r14b
movq 0x28(%rsp), %r8
jne 0x1628d8
movq $0x0, 0x18(%r13)
testq %r15, %r15
je 0x1628d8
addq $0x4, %rbx
xorl %eax, %eax
movdqa 0xceabd(%rip), %xmm0    # 0x2312d0
movdqa 0xceac5(%rip), %xmm1    # 0x2312e0
pcmpeqd %xmm2, %xmm2
movdqa 0xcecd9(%rip), %xmm3    # 0x231500
leaq (%rax,%rax,2), %rcx
movl (%r8,%rcx,4), %edx
cmpl 0x4(%r8,%rcx,4), %edx
setne %sil
testl %edx, %edx
sete %dil
orb %sil, %dil
jne 0x1628cc
leaq (%r8,%rcx,4), %rcx
movl 0x8(%rcx), %esi
leaq 0x1(%rdx), %rcx
andq $-0x2, %rcx
decq %rdx
movq %rdx, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
leaq (%rbx,%rsi,4), %rdx
pxor %xmm1, %xmm4
xorl %esi, %esi
movdqa %xmm0, %xmm5
movdqa %xmm5, %xmm6
pxor %xmm1, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm4, %xmm7
pcmpeqd %xmm4, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edi
notl %edi
testb $0x1, %dil
je 0x1628aa
movl %esi, -0x4(%rdx,%rsi,4)
pxor %xmm2, %xmm6
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0x1628bf
leal 0x1(%rsi), %edi
movl %edi, (%rdx,%rsi,4)
addq $0x2, %rsi
paddq %xmm3, %xmm5
cmpq %rsi, %rcx
jne 0x162871
incq %rax
cmpq %r15, %rax
jne 0x162827
testl %ebp, %ebp
jne 0x1628f8
movq 0x8(%rsp), %rdi
callq 0x2220
movq %r13, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
callq 0x1cdbb
jmp 0x1628dc