// File: chhylp123[P]hifiasm/Correct.cpp
// Function: return_t_chain(overlap_region*, Candidates_list*)
int64_t return_t_chain(overlap_region *z, Candidates_list *cl)
{
    int64_t i, cn = cl->length, scn; uint64_t pid; k_mer_hit *ca;

    // if(z->y_id == 30129) {
    //     fprintf(stderr, "\n-0-[M::%s]\tutg%.6ul\tx::[%u,\t%u)\t%c\tutg%.6ul\ty::[%u,\t%u)\n", 
    //         __func__, z->x_id+1, z->x_pos_s, z->x_pos_e+1,
	// 		"+-"[z->y_pos_strand], z->y_id+1, z->y_pos_s, z->y_pos_e+1);
    //     i = z->shared_seed; pid = cl->list[i].readID;
    //     for (; i < cn && cl->list[i].readID == pid && cl->list[i].readID != ((uint32_t)(0x7fffffff)); i++) {
    //         fprintf(stderr, "i::%ld[M::%s]\treadID::%u\tself_offset::%u\toffset::%u\t%c\n", 
    //             i, __func__, cl->list[i].readID, cl->list[i].self_offset, cl->list[i].offset, 
    //             "+-"[cl->list[i].strand]);
    //     }
    // }



    i = z->shared_seed; pid = cl->list[i].readID;
    for (; i < cn && cl->list[i].readID == pid && cl->list[i].readID != ((uint32_t)(0x7fffffff)); i++);
    scn = i - z->shared_seed; ca = cl->list+z->shared_seed;
    i = lchain_refine(ca, scn, ca, &(cl->chainDP), 50, 5000, 512, 16); cn = i;
    for (; i < scn; i++) ca[i].readID = ((uint32_t)(0x7fffffff));
    // if(z->y_id == 30129) fprintf(stderr, "\n-a-[M::%s]\tcn::%ld\n", __func__, cn);


    // if(z->y_id == 30129) {
    //     fprintf(stderr, "\n-1-[M::%s]\tutg%.6ul\tx::[%u,\t%u)\t%c\tutg%.6ul\ty::[%u,\t%u)\n", 
    //         __func__, z->x_id+1, z->x_pos_s, z->x_pos_e+1,
	// 		"+-"[z->y_pos_strand], z->y_id+1, z->y_pos_s, z->y_pos_e+1);
    //     i = z->shared_seed; pid = cl->list[i].readID; cn = cl->length;
    //     for (; i < cn && cl->list[i].readID == pid && cl->list[i].readID != ((uint32_t)(0x7fffffff)); i++) {
    //         fprintf(stderr, "i::%ld[M::%s]\treadID::%u\tself_offset::%u\toffset::%u\t%c\n", 
    //             i, __func__, cl->list[i].readID, cl->list[i].self_offset, cl->list[i].offset, 
    //             "+-"[cl->list[i].strand]);
    //     }
    // }
    return cn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movslq 0x24(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x39(%rbp)
jge 0x8dc22
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x30(%rbp), %rcx
movb %al, -0x39(%rbp)
jne 0x8dc22
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x8dc2b
jmp 0x8dc3b
jmp 0x8dc2d
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x8dbc7
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x24(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x24(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rcx
addq $0x18, %rcx
movl $0x32, %r8d
movl $0x1388, %r9d           # imm = 0x1388
movq $0x200, (%rsp)          # imm = 0x200
movq $0x10, 0x8(%rsp)
callq 0x29e80
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x8dce1
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
orl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x8dcaa
movq -0x20(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)