// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x48(%rbp)
leaq 0x1b9135(%rip), %rax    # 0x3c47f8
cmpl $0x0, 0x148(%rax)
je 0x20b6e0
leaq 0x1b9125(%rip), %rax    # 0x3c47f8
movslq 0x144(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x20b725
leaq 0x1b9111(%rip), %rax    # 0x3c47f8
cvtsi2sdl 0x144(%rax), %xmm0
movsd 0x17b149(%rip), %xmm1   # 0x386840
divsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1768e6(%rip), %xmm1   # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
leaq 0x1b90c8(%rip), %rcx    # 0x3c47f8
movslq 0x1bc(%rcx), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x50(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2140
movq %rax, -0x58(%rbp)
leaq 0x1b9080(%rip), %rax    # 0x3c47f8
movl 0x1bc(%rax), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x2140
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movq (%rax), %rdi
movl $0xc, %esi
callq 0x2140
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq $0x0, 0x18(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x20b928
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %ecx
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x38(%rbp), %r9
leaq 0x1b8fb5(%rip), %rax    # 0x3c47f8
movslq 0x1bc(%rax), %rax
movq %rax, (%rsp)
callq 0x107cf0
movl %eax, %ecx
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
leaq 0x1b8f76(%rip), %rcx    # 0x3c47f8
movslq 0x1bc(%rcx), %rcx
cmpq %rcx, %rax
jne 0x20b8bb
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq $0x1, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
movq -0x58(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0xc, -0x20(%rbp), %rsi
addq %rsi, %rcx
movl 0x4(%rcx), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x20b7e0
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdi
shlq $0x2, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x2100
cmpq $0x0, -0x40(%rbp)
je 0x20ba43
movq -0x58(%rbp), %rax
movq $0x0, 0x18(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x20ba41
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0xc, -0x20(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0xc, -0x20(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x20ba2e
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0xc, -0x20(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
cmpq %rcx, %rax
jae 0x20ba2c
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0xc, -0x20(%rbp), %rsi
addq %rsi, %rcx
movl 0x8(%rcx), %ecx
addq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x20b9da
jmp 0x20ba2e
jmp 0x20ba30
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x20b99a
jmp 0x20ba43
movq $0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
leaq 0x1b8da2(%rip), %rcx    # 0x3c47f8
movslq 0x1bc(%rcx), %rcx
cmpq %rcx, %rax
ja 0x20ba98
movq 0x1b8577(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x181bf9(%rip), %rsi    # 0x38d67c
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x20ba4b
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0x58(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)