// File: /workspace/github_cpp_makefile_star2_O1/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)
leaq 0x12eb66(%rip), %r8     # 0x28a758
movslq 0x144(%r8), %rcx
cvtsi2sd %ecx, %xmm0
divsd 0xcdf63(%rip), %xmm0    # 0x229b68
cvttsd2si %xmm0, %rdx
movq %rdx, %r9
sarq $0x3f, %r9
subsd 0xc964f(%rip), %xmm0    # 0x225268
cvttsd2si %xmm0, %rax
andq %r9, %rax
orq %rdx, %rax
cmpl $0x0, 0x148(%r8)
cmovneq %rcx, %rax
movq %rdi, %rbp
movslq 0x1bc(%r8), %r15
xorl %edx, %edx
divq %r15
movq %rax, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movl 0x14(%rsi), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0x1, %esi
callq 0x2120
movq %rax, %r14
movl $0x1, %edi
movl $0x30, %esi
callq 0x2120
movq %rax, %r12
incq %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x10(%rsp)
movq (%rbp), %rdi
movq %rdi, 0x8(%r12)
movq %rdi, (%r12)
movl $0xc, %esi
callq 0x2120
movq %rax, %r15
movq %rax, 0x10(%r12)
movq $0x0, 0x18(%r12)
movq (%rbp), %r13
testq %r13, %r13
je 0x15bd7e
movq %r12, 0x28(%rsp)
movq 0x18(%r12), %rbx
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl %ebx, 0x8(%r15)
movl $0x0, (%r15)
leaq 0x12ea70(%rip), %r13    # 0x28a758
movslq 0x1bc(%r13), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r14, %rcx
movq %r12, %r8
movq 0x30(%rsp), %r9
callq 0xc5f2c
movl %eax, 0x4(%r15)
movl %eax, %ecx
movslq 0x1bc(%r13), %rdx
cmpq %rdx, %rcx
jne 0x15bd2f
movl %eax, (%r15)
movl $0x1, %ecx
movq %rcx, 0x18(%rsp)
movl %eax, %eax
addq %rax, %rbx
movq 0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%r12,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdx
addq %rcx, (%rdx,%rax,8)
incq %r12
movq (%rbp), %r13
addq $0xc, %r15
cmpq %r13, %r12
jb 0x15bcd6
movq 0x28(%rsp), %r12
movq %rbx, 0x18(%r12)
cmpq $0x0, 0x18(%rsp)
sete %bpl
movq 0x20(%rsp), %r15
jmp 0x15bd81
movb $0x1, %bpl
movq %r14, %rdi
callq 0x2220
movq 0x18(%r12), %r14
movq %r14, 0x20(%r12)
shlq $0x2, %r14
movq %r14, %rdi
callq 0x2280
movq %rax, %rbx
movq %rax, 0x28(%r12)
movq %rax, %rdi
movl $0xff, %esi
movq %r14, %rdx
callq 0x20e0
testb %bpl, %bpl
jne 0x15be03
movq $0x0, 0x18(%r12)
testq %r13, %r13
je 0x15be03
xorl %eax, %eax
leaq (%rax,%rax,2), %rcx
movl (%r15,%rcx,4), %edx
cmpl 0x4(%r15,%rcx,4), %edx
jne 0x15bdfb
leaq (%r15,%rcx,4), %rdx
movl 0x4(%rdx), %ecx
testq %rcx, %rcx
je 0x15bdfb
movl 0x8(%rdx), %edx
leaq (%rbx,%rdx,4), %rdx
xorl %esi, %esi
movl %esi, (%rdx,%rsi,4)
incq %rsi
cmpq %rsi, %rcx
jne 0x15bdf0
incq %rax
cmpq %r13, %rax
jne 0x15bdcc
leaq 0x12e94e(%rip), %rax    # 0x28a758
cmpl $0x0, 0x1bc(%rax)
jne 0x15be2f
movq 0x10(%rsp), %rdi
callq 0x2220
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
callq 0x1db5d
jmp 0x15be13