// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: add_path_to_correct_read_new(Graph*, Graph*, Correct_dumy*, long long, long long, long long, Cigar_record*, char*)
long long inline add_path_to_correct_read_new(Graph* backbone, Graph* DAGCon, Correct_dumy* dumy, long long currentNodeID, 
long long type, long long edgeID, Cigar_record* current_cigar, char* self_string)
{
    //long long i;
    long long nodeID;

    ///Note: currentNodeID must be a backbone node
    ///currentNodeID = 0 means a fake node
    ///currentNodeID = i means self_string[i - 1]
    ///include match/mismatch
    if (type == MISMATCH)
    {
        ///match
        if(backbone->g_nodes.list[currentNodeID].mismatch_edges.list[edgeID].length == 0)
        {
            nodeID = backbone->g_nodes.list[currentNodeID].mismatch_edges.list[edgeID].out_node;
            add_base_to_correct_read_directly(dumy, backbone->g_nodes.list[nodeID].base);
            ///nodeID = i means self_string[i - 1]
            ///add_cigar_record(self_string+nodeID-1, 1, current_cigar, 0);
            add_cigar_record(&(backbone->g_nodes.list[nodeID].base), 1, current_cigar, 0);
            return nodeID;
        }
        else ///mismatch
        {
            nodeID = backbone->g_nodes.list[currentNodeID].mismatch_edges.list[edgeID].out_node;
            add_base_to_correct_read_directly(dumy, backbone->g_nodes.list[nodeID].base);
            dumy->corrected_base++;
            char merge_base = 0;
            merge_base = seq_nt6_table[(uint8_t)backbone->g_nodes.list[nodeID].base];
            merge_base = merge_base << 3;
            nodeID = backbone->g_nodes.list[nodeID].mismatch_edges.list[0].out_node;
            merge_base = merge_base | seq_nt6_table[(uint8_t)backbone->g_nodes.list[nodeID].base];
            add_cigar_record(&merge_base, 1, current_cigar, 1);
            return nodeID;
        }
    }
    else if (type == DELETION)
    {
        nodeID = backbone->g_nodes.list[currentNodeID].deletion_edges.list[edgeID].out_node;
        dumy->corrected_base += nodeID - currentNodeID;
        add_cigar_record(self_string + currentNodeID, nodeID - currentNodeID, current_cigar, DELETION);
        return nodeID;
    }
    else if (type == INSERTION)
    {
        ///pay attention to this line
        backbone->g_nodes.list[currentNodeID].num_insertions = 0;
        long long str;
        char str_c;
        while (pop_from_Queue(&(DAGCon->node_q), &str))
        {
            str_c = (char)str;
            add_base_to_correct_read_directly(dumy, str_c);
            add_cigar_record(&str_c, 1, current_cigar, INSERTION);
            dumy->corrected_base++;
        }

        return currentNodeID;
    }
    else
    {
        fprintf(stderr, "error type\n");
    }
    
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rdi, %r13
cmpq $0x3, %r8
je 0x52e7b
cmpq $0x2, %r8
je 0x52eb5
cmpq $0x1, %r8
jne 0x52f4b
movq 0x18(%r13), %rax
shlq $0x7, %rcx
movq 0x20(%rax,%rcx), %rcx
imulq $0x38, %r9, %rdx
movq 0x20(%rcx,%rdx), %r14
movq 0x8(%rcx,%rdx), %r12
movq %r12, %rbx
shlq $0x7, %rbx
movsbl 0x18(%rax,%rbx), %esi
movq %r15, %rdi
callq 0x5307f
testq %r14, %r14
je 0x52f30
incq 0x20(%r15)
movq 0x18(%r13), %rax
movzbl 0x18(%rax,%rbx), %ecx
leaq 0x2007e1(%rip), %rdx    # 0x253630
movb (%rdx,%rcx), %cl
shlb $0x3, %cl
movq 0x20(%rax,%rbx), %rsi
movq 0x8(%rsi), %r12
movq %r12, %rsi
shlq $0x7, %rsi
movzbl 0x18(%rax,%rsi), %eax
orb (%rdx,%rax), %cl
leaq 0x7(%rsp), %rdi
movb %cl, (%rdi)
pushq $0x1
popq %rcx
movl %ecx, %esi
jmp 0x52ea9
movq 0x58(%rsp), %rdi
movq 0x18(%r13), %rax
movq %rcx, %rdx
shlq $0x7, %rdx
movq 0x40(%rax,%rdx), %rax
imulq $0x38, %r9, %rdx
movq 0x8(%rax,%rdx), %r12
movq %r12, %rsi
subq %rcx, %rsi
addq %rsi, 0x20(%r15)
addq %rcx, %rdi
pushq $0x3
popq %rcx
movq 0x50(%rsp), %rdx
callq 0x109b4
jmp 0x52f1e
movq %rsi, %r12
movq 0x18(%r13), %rax
movq %rcx, 0x8(%rsp)
shlq $0x7, %rcx
andq $0x0, 0x10(%rax,%rcx)
addq $0x70, %r12
leaq 0x10(%rsp), %r13
leaq 0x6(%rsp), %rbp
pushq $0x1
popq %rbx
pushq $0x2
popq %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0x637ed
testl %eax, %eax
je 0x52f19
movsbl 0x10(%rsp), %esi
movb %sil, 0x6(%rsp)
movq %r15, %rdi
callq 0x5307f
movq %rbp, %rdi
movl %ebx, %esi
movq 0x50(%rsp), %rdx
movl %r14d, %ecx
callq 0x109b4
incq 0x20(%r15)
jmp 0x52ee0
movq 0x8(%rsp), %r12
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r13), %rax
leaq (%rax,%rbx), %rdi
addq $0x18, %rdi
pushq $0x1
popq %rsi
movq 0x50(%rsp), %rdx
xorl %ecx, %ecx
jmp 0x52eae
movq 0x20008e(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x194889(%rip), %rdi    # 0x1e77e5
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
pushq $-0x1
popq %r12
jmp 0x52f1e