// File: chhylp123[P]hifiasm/Hash_Table.cpp
// Function: calculate_overlap_region_by_chaining(Candidates_list*, overlap_region_alloc*, kvec_t_u64_warp*, unsigned long, unsigned long, All_reads*, ul_idx_t const*, double, int, overlap_region*, void*)
void calculate_overlap_region_by_chaining(Candidates_list* candidates, overlap_region_alloc* overlap_list, kvec_t_u64_warp* chain_idx,
                                          uint64_t readID, uint64_t readLength, All_reads* R_INF, const ul_idx_t *uref, double band_width_threshold, int add_beg_end, overlap_region* f_cigar, void *km)
{
    long long i = 0;
    uint64_t current_ID;
    uint64_t current_stand;

    if (candidates->length == 0) return;

    long long sub_region_beg;
    long long sub_region_end;

    clear_fake_cigar(&((*f_cigar).f_cigar));

    i = 0;
    while (i < candidates->length)
    {
        chain_idx->a.n = 0;
        current_ID = candidates->list[i].readID;
        current_stand = candidates->list[i].strand;

        ///reference read
        (*f_cigar).x_id = readID;
        (*f_cigar).x_pos_strand = current_stand;
        ///query read
        (*f_cigar).y_id = current_ID;
        ///here the strand of query is always 0
        (*f_cigar).y_pos_strand = 0;  

        sub_region_beg = i;
        sub_region_end = i;
        i++;

        while (i < candidates->length 
        && 
        current_ID == candidates->list[i].readID
        &&
        current_stand == candidates->list[i].strand)
        {
            sub_region_end = i;
            i++;
        }

        if ((*f_cigar).x_id == (*f_cigar).y_id)
        {
            continue;
        }

		chain_DP(candidates->list + sub_region_beg,
				sub_region_end - sub_region_beg + 1, &(candidates->chainDP), f_cigar, band_width_threshold,
				25, /**Get_READ_LENGTH((*R_INF), (*f_cigar).x_id)**/readLength, 
                R_INF?Get_READ_LENGTH((*R_INF), (*f_cigar).y_id):uref->ug->u.a[(*f_cigar).y_id].len, km);

        ///if (tmp_region.x_id != tmp_region.y_id && tmp_region.shared_seed > 1)
        if ((*f_cigar).x_id != (*f_cigar).y_id)
        {
            append_inexact_overlap_region_alloc(overlap_list, f_cigar, readLength, R_INF?Get_READ_LENGTH((*R_INF), (*f_cigar).y_id):uref->ug->u.a[(*f_cigar).y_id].len, add_beg_end, km);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x22a0f
jmp 0x22cf0
movq 0x20(%rbp), %rdi
addq $0x38, %rdi
callq 0x1e1d0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x22cf0
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x1f, %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movq 0x20(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpq 0x8(%rdx), %rcx
movb %al, -0x61(%rbp)
jge 0x22b2e
movq -0x48(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x61(%rbp)
jne 0x22b2e
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
movq -0x40(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
shrl $0x1f, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
sete %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x22b37
jmp 0x22b50
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x22aca
movq 0x20(%rbp), %rax
movl (%rax), %eax
movq 0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x22b64
jmp 0x22a24
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rax
subq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x80(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x68(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x22bd8
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
jmp 0x22c01
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x98(%rbp)
movl -0x68(%rbp), %r9d
movsd -0x70(%rbp), %xmm0
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rdx
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rax
movl %eax, %r10d
movq 0x28(%rbp), %rax
movl $0x19, %r8d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x21ca0
movq 0x20(%rbp), %rax
movl (%rax), %eax
movq 0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0x22ceb
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x22c99
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb8(%rbp)
jmp 0x22cc2
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rsi
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rcx
movl 0x18(%rbp), %r8d
movq 0x28(%rbp), %r9
callq 0x1f8b0
jmp 0x22a24
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)