// File: chhylp123[P]hifiasm/tovlp.cpp
// Function: get_min_dec(clean_mul_t*, unsigned int, unsigned int, utg_trans_t*, unsigned int*)
int get_min_dec(clean_mul_t *cl, uint32_t positive_flag, uint32_t negative_flag, utg_trans_t *o, uint32_t *v)
{
    uint32_t i, n_pop;
    clean_t *p = NULL;
    (*v) = (uint32_t)-1;
    for (i = 0; i < cl->n; i++) cl->a[i].is_b = 0, cl->a[i].min_v = (uint32_t)-1;    
    kt_for(cl->n, bub_iden_worker, cl, cl->g->n_seq<<1);///fast check if there are bubbles in graph
    for (i = 0; i < cl->n; i++)
    {
        if(cl->a[i].is_b) ///pop bubble
        {
            ///pop all bubbles
            n_pop = asg_pop_bubble_primary_trio(cl->g, cl->ug, cl->bs_flag, &(cl->a[i].b),
            cl->max_dist, positive_flag, negative_flag, o);
            if(n_pop ==0) fprintf(stderr, "ERROR-n_pop\n");
            break;
        } 
    }
    kt_for(cl->n, unitig_iden_worker, cl, cl->g->n_seq<<1);
    for (i = 0; i < cl->n; i++)
    {
        if(cl->a[i].min_v == (uint32_t)-1) continue;
        // if(b->min_v == (uint32_t)-1 || (b->min_d > d) || (b->min_d == d && b->min_v < eid))
        ///looks like select the minum node, and back
        if(!p || p->min_d > cl->a[i].min_d || 
        (p->min_d == cl->a[i].min_d && cl->g->seq[p->min_v>>1].len > cl->g->seq[cl->a[i].min_v>>1].len) ||
        (p->min_d == cl->a[i].min_d && cl->g->seq[p->min_v>>1].len == cl->g->seq[cl->a[i].min_v>>1].len && p->min_v > cl->a[i].min_v))
        {
            p = &(cl->a[i]);
        }
    }
    if(p) (*v) = p->min_v;
    return p?1:0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x273947
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x1a0, %rcx, %rcx      # imm = 0x1A0
addq %rcx, %rax
movl $0x0, 0x198(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x1a0, %rcx, %rcx      # imm = 0x1A0
addq %rcx, %rax
movl $0xffffffff, 0x180(%rax) # imm = 0xFFFFFFFF
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2738f3
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rcx
leaq 0x2ef(%rip), %rsi       # 0x273c60
callq 0x16d710
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x273a33
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x1a0, %rcx, %rcx      # imm = 0x1A0
addq %rcx, %rax
cmpl $0x0, 0x198(%rax)
je 0x273a23
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movl -0x24(%rbp), %eax
imulq $0x1a0, %rax, %rax      # imm = 0x1A0
addq %rax, %rcx
addq $0x118, %rcx            # imm = 0x118
movq -0x8(%rbp), %rax
movq 0x18(%rax), %r8
movl -0xc(%rbp), %r9d
movl -0x10(%rbp), %r10d
movq -0x18(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2734d0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x273a21
movq 0x1505d0(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x11cbab(%rip), %rsi    # 0x3905c5
movb $0x0, %al
callq 0x22a0
jmp 0x273a33
jmp 0x273a25
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x27397d
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movslq %eax, %rcx
leaq 0x293(%rip), %rsi       # 0x273cf0
callq 0x16d710
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x273c2b
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x1a0, %rcx, %rcx      # imm = 0x1A0
addq %rcx, %rax
cmpl $-0x1, 0x180(%rax)
jne 0x273a9c
jmp 0x273c1d
cmpq $0x0, -0x30(%rbp)
je 0x273c03
movq -0x30(%rbp), %rax
movq 0x190(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movl -0x24(%rbp), %edx
imulq $0x1a0, %rdx, %rdx      # imm = 0x1A0
addq %rdx, %rcx
cmpq 0x190(%rcx), %rax
jg 0x273c03
movq -0x30(%rbp), %rax
movq 0x190(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movl -0x24(%rbp), %edx
imulq $0x1a0, %rdx, %rdx      # imm = 0x1A0
addq %rdx, %rcx
cmpq 0x190(%rcx), %rax
jne 0x273b58
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x180(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq (%rdx), %rdx
movl -0x24(%rbp), %esi
imulq $0x1a0, %rsi, %rsi      # imm = 0x1A0
addq %rsi, %rdx
movl 0x180(%rdx), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jg 0x273c03
movq -0x30(%rbp), %rax
movq 0x190(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movl -0x24(%rbp), %edx
imulq $0x1a0, %rdx, %rdx      # imm = 0x1A0
addq %rdx, %rcx
cmpq 0x190(%rcx), %rax
jne 0x273c1b
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x180(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq (%rdx), %rdx
movl -0x24(%rbp), %esi
imulq $0x1a0, %rsi, %rsi      # imm = 0x1A0
addq %rsi, %rdx
movl 0x180(%rdx), %edx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jne 0x273c1b
movq -0x30(%rbp), %rax
movl 0x180(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movl -0x24(%rbp), %edx
imulq $0x1a0, %rdx, %rdx      # imm = 0x1A0
addq %rdx, %rcx
cmpl 0x180(%rcx), %eax
jbe 0x273c1b
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imulq $0x1a0, %rcx, %rcx      # imm = 0x1A0
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x273c1d
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x273a69
cmpq $0x0, -0x30(%rbp)
je 0x273c42
movq -0x30(%rbp), %rax
movl 0x180(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)