// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path.c
// Function: make_cluster
static clust_t *make_cluster(clust_dp_t *dps, int n_dps, int n_clust, int min_len)
{
    int i, c;
    clust_t *clusts;
    
    MYCALLOC(clusts, n_clust);
    // get dps number for each cluster
    for (i = 0; i < n_dps; ++i)
        ++clusts[dps[i].clust].n_dps;
    for (i = 0; i < n_clust; ++i) {
        clusts[i].clust = i;
        MYMALLOC(clusts[i].dps, clusts[i].n_dps);
        clusts[i].n_dps = 0;
    }
    for (i = 0; i < n_dps; ++i) {
        c = dps[i].clust;
        clusts[c].dps[clusts[c].n_dps] = dps[i].index;
        clusts[c].mean += dps[i].val;
        clusts[c].size += dps[i].size;
        clusts[c].n_dps++;
    }
    for (i = 0; i < n_clust; ++i)
        clusts[i].mean /= clusts[i].n_dps;
    
    /***
    // for each cluster determine if is a major or minor cluster
    // major cluster tends to be low-copy sequences
    // minor cluster is allowed to have higher copy numbers
    // decision made mainly based on the sequence size
    // mark a major cluster if 
    // the cluster size is larger than 10% of the total size
    // and at least one sequence is larger than min_len
    // mark major cluster using the last bit of 'clust'
    // TODO estiamte size proportion (10%) with sequences of similar coverage
    int j;
    double size = 0.;
    for (i = 0; i < n_clust; ++i)
        size += clusts[i].size;
    size *= 0.1;
    for (i = 0; i < n_clust; ++i) {
        clusts[i].clust <<= 1;
        if (clusts[i].size < size)
            continue;
        for (j = 0; j < clusts[i].n_dps; ++j) {
            if (dps[clusts[i].dps[j]].size >= min_len) {
                clusts[i].clust |= 1; // mark major cluster
                break;
            }
        }
    }
    **/

    return clusts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movslq -0x10(%rbp), %rdi
movl $0x48, %esi
callq 0x2240
movq %rax, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x11618
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x18(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movslq 0x14(%rcx), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x115de
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x1168e
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq -0x18(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rdi
shlq $0x2, %rdi
callq 0x22f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movslq -0x18(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x4(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1161f
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x1176a
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movslq -0x1c(%rbp), %rsi
imulq $0x48, %rsi, %rsi
addq %rsi, %rcx
movslq 0x4(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
addsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rax)
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x11695
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x117b5
movq -0x28(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x4(%rax), %xmm1
movq -0x28(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd 0x18(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x11771
movq -0x28(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop