// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
leaq 0x1363e5(%rip), %rdi    # 0x253758
movslq 0x144(%rdi), %rcx
cvtsi2sd %ecx, %xmm0
divsd 0xca8da(%rip), %xmm0    # 0x1e7c60
cvttsd2si %xmm0, %rdx
movq %rdx, %r8
sarq $0x3f, %r8
subsd 0xc5efe(%rip), %xmm0    # 0x1e3298
cvttsd2si %xmm0, %rax
andq %r8, %rax
orq %rdx, %rax
cmpl $0x0, 0x148(%rdi)
cmovneq %rcx, %rax
movslq 0x1bc(%rdi), %r15
xorl %ebp, %ebp
xorl %edx, %edx
divq %r15
movq %rax, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
movl 0x14(%rsi), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
pushq $0x1
popq %rbx
movq %rbx, %rsi
callq 0x2120
movq %rax, 0x20(%rsp)
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0x2120
movq %rax, %rbx
movq %r15, %rdi
incq %rdi
pushq $0x8
popq %rsi
callq 0x2120
movq %rax, 0x10(%rsp)
movq (%r13), %r12
movq %r12, 0x8(%rbx)
movq %r12, (%rbx)
pushq $0xc
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, %r14
movq %rbx, 0x8(%rsp)
movq %rax, 0x10(%rbx)
movq %rax, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
cmpq %r12, %rbx
jae 0x11d4c7
movl %ebp, 0x8(%r14)
andl $0x0, (%r14)
movslq %r15d, %rax
movq %rax, (%rsp)
movq %r13, %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rbx, %r8
movq 0x30(%rsp), %r9
callq 0x8a815
movl %eax, 0x4(%r14)
movl %eax, %ecx
leaq 0x1362e0(%rip), %rdx    # 0x253758
movslq 0x1bc(%rdx), %r15
cmpq %r15, %rcx
jne 0x11d48f
movl %eax, (%r14)
pushq $0x1
popq %rcx
movq %rcx, 0x18(%rsp)
movl %eax, %eax
addq %rax, %rbp
movq 0x8(%rsp), %rcx
movq %rbp, 0x18(%rcx)
movq 0x18(%r13), %rcx
movq 0x20(%rcx), %rcx
movl (%rcx,%rbx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdx
addq %rcx, (%rdx,%rax,8)
incq %rbx
movq (%r13), %r12
addq $0xc, %r14
jmp 0x11d434
movq 0x20(%rsp), %rdi
callq 0x2220
movq 0x8(%rsp), %r14
movq %rbp, 0x20(%r14)
shlq $0x2, %rbp
movq %rbp, %rdi
callq 0x2280
movq %rax, %rbx
movq %rax, 0x28(%r14)
movq %rax, %rdi
movl $0xff, %esi
movq %rbp, %rdx
callq 0x20e0
cmpq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %r8
je 0x11d548
movq 0x8(%rsp), %rax
andq $0x0, 0x18(%rax)
xorl %eax, %eax
cmpq %r12, %rax
je 0x11d548
imulq $0xc, %rax, %rcx
movl (%r8,%rcx), %edx
cmpl 0x4(%r8,%rcx), %edx
jne 0x11d543
addq %r8, %rcx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x11d543
movl 0x8(%rcx), %edi
leaq (%rbx,%rdi,4), %rdi
movl %esi, (%rdi,%rsi,4)
incq %rsi
jmp 0x11d52f
incq %rax
jmp 0x11d516
pushq $0x1
popq %rbx
movq 0x135a8e(%rip), %r12    # 0x252fe0
leaq 0xd13b2(%rip), %r14     # 0x1ee90b
movslq %r15d, %rax
cmpq %rax, %rbx
ja 0x11d58e
movq (%r12), %rdi
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rcx
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22b0
incq %rbx
leaq 0x1361d3(%rip), %rax    # 0x253758
movl 0x1bc(%rax), %r15d
jmp 0x11d559
movq 0x10(%rsp), %rdi
callq 0x2220
movq 0x8(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq