// File: chhylp123[P]hifiasm/Correct.cpp
// Function: gen_gov_idx(overlap_region_alloc*, ul_idx_t const*, ug_opt_t const*, long, double, asg64_v*)
void gen_gov_idx(overlap_region_alloc* ol, const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, asg64_v* idx)
{
    int64_t on = ol->length, k, i; uint64_t os, oe, ovlp; ul_ov_t p, q, *li, *lj;
    kv_resize(uint64_t, *idx, (uint64_t)on); memset(idx->a, 0, sizeof(*(idx->a))*on);
    for (k = 0, idx->n = on; k < on; k++) {
        convert_ul_ov_t(&p, &(ol->list[k]), uref->ug); p.qn = k; 
        // idx->a[k] = idx->n; idx->a[k] <<= 32;
        for (i = on - 1; i >= 0 && i > k && ol->list[i].x_pos_e >= ol->list[k].x_pos_s; i--) {
            // if(k >= i) continue;
            convert_ul_ov_t(&q, &(ol->list[i]), uref->ug); q.qn = i;

            if(p.qe > q.qe) li = &p, lj = &q;
			else if(p.qe == q.qe && p.qs >= q.qs) li = &p, lj = &q;
			else lj = &p, li = &q;
			os = MAX(li->qs, lj->qs), oe = MIN(li->qe, lj->qe);
			ovlp = ((oe > os)? (oe - os):0);
			if(!ovlp) continue;//no overlap

            if(lj->qs <= li->qs+G_CHAIN_INDEL) {
				if(govlp_check(uref, uopt, bw, diff_ec_ul, li, lj)) {
                    idx->a[k]++; idx->a[i]++; 
                    kv_push(uint64_t, *idx, (((uint64_t)k)<<32)|((uint64_t)i));
                    kv_push(uint64_t, *idx, (((uint64_t)i)<<32)|((uint64_t)k));
                }
			} else if((lj->qe+G_CHAIN_INDEL>=li->qe) && (lj->qs+G_CHAIN_INDEL>=li->qs)) {
				if(govlp_check(uref, uopt, bw, diff_ec_ul, lj, li)) {
                    idx->a[k]++; idx->a[i]++; 
                    kv_push(uint64_t, *idx, (((uint64_t)k)<<32)|((uint64_t)i));
                    kv_push(uint64_t, *idx, (((uint64_t)i)<<32)|((uint64_t)k));
                }
			}
        }
    }
    radix_sort_bc64(idx->a + on, idx->a + idx->n);
    for (k = 0, os = oe = on; k < on; k++) {
        oe = os + idx->a[k];
        idx->a[k] = (os<<32)|oe;
        os = oe;
    }

    // for (k = 0; k < on; k++) {
    //     int64_t s, e;
    //     s = idx->a[k]>>32; e = (uint32_t)idx->a[k];
    //     for (i = s; i < e; i++) {
    //         assert((idx->a[i]>>32) == (uint32_t)k);
    //         fprintf(stderr, "k::%ld[M::%s::utg%.6dl] utg%.6dl\n", k, __func__, 
    //             (int32_t)ol->list[k].y_id+1, (int32_t)ol->list[(uint32_t)idx->a[i]].y_id+1);
    //     }
    // }   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x38(%rbp), %rax
jae 0x72cb9
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x72cbb
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x2100
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x732aa
movq -0x8(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x40(%rbp), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq -0x7c(%rbp), %rdi
callq 0x720e0
movq -0x40(%rbp), %rax
movl %eax, -0x7c(%rbp)
movq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x48(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x48(%rbp)
movb %al, -0xa9(%rbp)
jl 0x72d7c
movq -0x48(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0xa9(%rbp)
jle 0x72d7c
movq -0x8(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
setae %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x72d8b
jmp 0x73297
movq -0x8(%rbp), %rax
movq (%rax), %rsi
imulq $0xa8, -0x48(%rbp), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq -0x98(%rbp), %rdi
callq 0x720e0
movq -0x48(%rbp), %rax
movl %eax, -0x98(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x90(%rbp), %eax
jbe 0x72de0
leaq -0x7c(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x72e2c
movl -0x74(%rbp), %eax
cmpl -0x90(%rbp), %eax
jne 0x72e11
movl -0x78(%rbp), %eax
cmpl -0x94(%rbp), %eax
jb 0x72e11
leaq -0x7c(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x72e2a
leaq -0x7c(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x72e2c
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xa8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x72e54
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xb0(%rbp)
jmp 0x72e64
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %eax
movq -0xa8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x72e98
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xb4(%rbp)
jmp 0x72ea8
movq -0xa8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0x72ecf
movq -0x58(%rbp), %rax
subq -0x50(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x72eda
xorl %eax, %eax
movq %rax, -0xc0(%rbp)
jmp 0x72eda
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x72ef1
jmp 0x73286
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xa0(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl $0x80, %ecx
cmpl %ecx, %eax
ja 0x730ad
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movsd -0x28(%rbp), %xmm0
movq -0xa0(%rbp), %rcx
movq -0xa8(%rbp), %r8
callq 0x72aa0
cmpl $0x0, %eax
je 0x730a8
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x72fe1
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x72fa0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xc8(%rbp)
jmp 0x72fae
movl $0x2, %eax
movq %rax, -0xc8(%rbp)
jmp 0x72fae
movq -0xc8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdx
shlq $0x20, %rdx
orq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x7300c
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x7307d
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x7303c
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xd0(%rbp)
jmp 0x7304a
movl $0x2, %eax
movq %rax, -0xd0(%rbp)
jmp 0x7304a
movq -0xd0(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rdx
shlq $0x20, %rdx
orq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x730a8
jmp 0x73284
movq -0xa8(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0xa0(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jb 0x73282
movq -0xa8(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x80, %eax
movq -0xa0(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x73282
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movsd -0x28(%rbp), %xmm0
movq -0xa8(%rbp), %rcx
movq -0xa0(%rbp), %r8
callq 0x72aa0
cmpl $0x0, %eax
je 0x73280
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x731b9
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x73178
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xd8(%rbp)
jmp 0x73186
movl $0x2, %eax
movq %rax, -0xd8(%rbp)
jmp 0x73186
movq -0xd8(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdx
shlq $0x20, %rdx
orq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x731e4
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x73255
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x73214
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0xe0(%rbp)
jmp 0x73222
movl $0x2, %eax
movq %rax, -0xe0(%rbp)
jmp 0x73222
movq -0xe0(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rdx
shlq $0x20, %rdx
orq -0x40(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x73280
jmp 0x73282
jmp 0x73284
jmp 0x73286
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x72d28
jmp 0x73299
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x72ce5
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x2da20
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x73340
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
addq (%rcx,%rdx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdx
shlq $0x20, %rdx
orq -0x58(%rbp), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x732ec
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)