// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: worker_ovec(void*, long, int)
static void worker_ovec(void *data, long i, int tid)
{
	ha_ovec_buf_t *b = ((ha_ovec_buf_t**)data)[tid];
	int fully_cov, abnormal;
    // if(i != 12578) return;
    // fprintf(stderr, "[M::%s-beg] rid->%ld\n", __func__, i);
    // if (memcmp("7897e875-76e5-42c8-bc37-94b370c4cc8d", Get_NAME((R_INF), i), Get_NAME_LENGTH((R_INF),i)) == 0) {
    //     fprintf(stderr, "[M::%s-beg] rid->%ld\n", __func__, i);
    // } else {
    //     return;
    // }

    ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist, 
    0.02, asm_opt.max_n_chain, 1, NULL/**&(b->k_flag)**/, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));

    // prt_chain(&b->olist);
    // return;

	clear_Cigar_record(&b->cigar1);
	clear_Round2_alignment(&b->round2);

	correct_overlap(&b->olist, &R_INF, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
			&b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 1, &fully_cov, &abnormal);

	b->num_read_base += b->self_read.length;
	b->num_correct_base += b->correct.corrected_base;
	b->num_recorrect_base += b->round2.dumy.corrected_base;

	push_cigar(R_INF.cigars, i, &b->cigar1);
	push_cigar(R_INF.second_round_cigar, i, &b->round2.cigar);

	R_INF.paf[i].is_fully_corrected = 0;
	if (fully_cov) {
		if (get_cigar_errors(&b->cigar1) == 0 && get_cigar_errors(&b->round2.cigar) == 0)
			R_INF.paf[i].is_fully_corrected = 1;
	}
	R_INF.paf[i].is_abnormal = abnormal;

    R_INF.trio_flag[i] = AMBIGU;
    
    ///need to be fixed in r305
    // if(ha_idx_hp == NULL)
    // {
    //     R_INF.trio_flag[i] += collect_hp_regions(&b->olist, &R_INF, &(b->k_flag), RESEED_HP_RATE, Get_READ_LENGTH(R_INF, i), NULL);
    // }

    if (R_INF.trio_flag[i] != AMBIGU || b->save_ov) {
		int is_rev = (asm_opt.number_of_round % 2 == 0);
		push_overlaps(&(R_INF.paf[i]), &b->olist, 1, &R_INF, is_rev);
		push_overlaps(&(R_INF.reverse_paf[i]), &b->olist, 2, &R_INF, is_rev);
	}

    if(het_cnt) het_cnt[i] = get_het_cnt(&b->hap);
    // fprintf(stderr, "[M::%s-end] rid->%ld\n", __func__, i);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movl %edx, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0xe0(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x8, %rdx
movq -0x48(%rbp), %rcx
addq $0xa0, %rcx
movq -0x48(%rbp), %r8
addq $0xc0, %r8
movq -0x48(%rbp), %r9
addq $0x48, %r9
leaq 0x3ae22d(%rip), %rax    # 0x3c47f8
movl 0xe8(%rax), %r15d
movq -0x48(%rbp), %r14
addq $0x12160, %r14          # imm = 0x12160
movq 0x3aed64(%rip), %rbx    # 0x3c5348
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rbx
movq 0x3aed5d(%rip), %r11    # 0x3c5350
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %r11
movq -0x48(%rbp), %r10
addq $0x121a0, %r10          # imm = 0x121A0
movq -0x48(%rbp), %rax
addq $0x12250, %rax          # imm = 0x12250
movsd 0x368a30(%rip), %xmm0   # 0x37f048
xorl %r12d, %r12d
movl %r15d, (%rsp)
movl $0x1, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq %rax, 0x40(%rsp)
callq 0x1a3450
movq -0x48(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x31d60
movq -0x48(%rbp), %rdi
addq $0x9330, %rdi           # imm = 0x9330
callq 0x31cb0
movq -0x48(%rbp), %rdi
addq $0xa0, %rdi
movq -0x48(%rbp), %rdx
addq $0x8, %rdx
movq -0x48(%rbp), %rcx
addq $0x2c0, %rcx            # imm = 0x2C0
movq -0x48(%rbp), %r8
addq $0x28, %r8
movq -0x48(%rbp), %r9
addq $0x148, %r9             # imm = 0x148
movq -0x48(%rbp), %r13
addq $0x200, %r13            # imm = 0x200
movq -0x48(%rbp), %r12
addq $0x108, %r12            # imm = 0x108
movq -0x48(%rbp), %r15
addq $0x9040, %r15           # imm = 0x9040
movq -0x48(%rbp), %r14
addq $0x9330, %r14           # imm = 0x9330
movq -0x48(%rbp), %rbx
addq $0x12160, %rbx          # imm = 0x12160
movq -0x48(%rbp), %r11
addq $0x121a0, %r11          # imm = 0x121A0
addq $0x48, %r11
leaq 0x3aebdb(%rip), %rsi    # 0x3c52d0
xorl %eax, %eax
leaq -0x4c(%rbp), %r10
leaq -0x50(%rbp), %rax
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x1, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq %rax, 0x48(%rsp)
callq 0x4c230
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x48(%rbp), %rax
addq 0xf0(%rax), %rcx
movq %rcx, 0xf0(%rax)
movq -0x48(%rbp), %rax
movq 0x2e0(%rax), %rcx
movq -0x48(%rbp), %rax
addq 0xf8(%rax), %rcx
movq %rcx, 0xf8(%rax)
movq -0x48(%rbp), %rax
movq 0x9350(%rax), %rcx
movq -0x48(%rbp), %rax
addq 0x100(%rax), %rcx
movq %rcx, 0x100(%rax)
movq 0x3aeba2(%rip), %rdi    # 0x3c5338
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x108, %rdx            # imm = 0x108
callq 0x1c8a0
movq 0x3aeb8f(%rip), %rdi    # 0x3c5340
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq $0x9330, %rdx           # imm = 0x9330
addq $0x8d80, %rdx           # imm = 0x8D80
callq 0x1c8a0
movq 0x3aeb75(%rip), %rax    # 0x3c5348
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movb $0x0, 0x10(%rax)
cmpl $0x0, -0x4c(%rbp)
je 0x1682b
movq -0x48(%rbp), %rdi
addq $0x108, %rdi            # imm = 0x108
callq 0x1ca30
cmpl $0x0, %eax
jne 0x16829
movq -0x48(%rbp), %rdi
addq $0x9330, %rdi           # imm = 0x9330
addq $0x8d80, %rdi           # imm = 0x8D80
callq 0x1ca30
cmpl $0x0, %eax
jne 0x16829
movq 0x3aeb2b(%rip), %rax    # 0x3c5348
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
movb $0x1, 0x10(%rax)
jmp 0x1682b
movl -0x50(%rbp), %eax
movb %al, %cl
movq 0x3aeb11(%rip), %rax    # 0x3c5348
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rax
movb %cl, 0x11(%rax)
movq 0x3aeaaf(%rip), %rax    # 0x3c52f8
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x3aeaa0(%rip), %rax    # 0x3c52f8
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x16873
movq -0x48(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x168f4
leaq 0x3adf7e(%rip), %rax    # 0x3c47f8
movl 0xf8(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x54(%rbp)
movq 0x3aeaab(%rip), %rdi    # 0x3c5348
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
addq $0xa0, %rsi
movl -0x54(%rbp), %r8d
movl $0x1, %edx
leaq 0x3aea10(%rip), %rcx    # 0x3c52d0
callq 0x141e0
movq 0x3aea84(%rip), %rdi    # 0x3c5350
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
addq $0xa0, %rsi
movl -0x54(%rbp), %r8d
movl $0x2, %edx
leaq 0x3ae9e1(%rip), %rcx    # 0x3c52d0
callq 0x141e0
cmpq $0x0, 0x3aeb8c(%rip)    # 0x3c5488
je 0x1691e
movq -0x48(%rbp), %rdi
addq $0x9040, %rdi           # imm = 0x9040
callq 0x15570
movl %eax, %edx
movq 0x3aeb71(%rip), %rax    # 0x3c5488
movq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq