// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movq %rcx, %r12
movq %rdx, %r14
movq %rdi, %r13
movq 0x40(%rsp), %rbx
cmpq $0x3, %r8
je 0x86705
cmpq $0x2, %r8
je 0x8674b
cmpq $0x1, %r8
jne 0x868ca
movq 0x18(%r13), %rsi
shlq $0x7, %r12
movq 0x20(%rsi,%r12), %rdi
imulq $0x38, %r9, %r8
movq 0x8(%rdi,%r8), %r15
movq %r15, %r12
shlq $0x7, %r12
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x2(%rcx), %rdx
cmpq $0x0, 0x20(%rdi,%r8)
movb 0x18(%rsi,%r12), %bpl
movq 0x18(%r14), %rsi
je 0x86834
cmpq %rsi, %rdx
jle 0x86691
addq %rsi, %rsi
movq %rsi, 0x18(%r14)
movq %rax, %rdi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%r14), %rcx
movb %bpl, (%rax,%rcx)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movb $0x0, 0x1(%rax,%rcx)
incq 0x20(%r14)
movq 0x18(%r13), %rax
movzbl 0x18(%rax,%r12), %ecx
leaq 0x20ef72(%rip), %rdx    # 0x295630
movb (%rdx,%rcx), %cl
shlb $0x3, %cl
movq 0x20(%rax,%r12), %rsi
movq 0x8(%rsi), %r15
movq %r15, %rsi
shlq $0x7, %rsi
movzbl 0x18(%rax,%rsi), %eax
orb (%rdx,%rax), %cl
movb %cl, 0x6(%rsp)
cmpb $0x1, (%rbx)
jne 0x8687d
leaq 0x6(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x58c0f
jmp 0x86894
movq 0x18(%r13), %rax
movq %r12, %rcx
shlq $0x7, %rcx
movq 0x40(%rax,%rcx), %rax
imulq $0x38, %r9, %rcx
movq 0x8(%rax,%rcx), %r15
movq %r15, %rsi
subq %r12, %rsi
addq %rsi, 0x20(%r14)
movq 0x48(%rsp), %rcx
addq %r12, %rcx
cmpb $0x3, (%rbx)
jne 0x8681f
movq %rbx, %rdi
movl $0x3, %edx
callq 0x58c0f
jmp 0x8682c
movq %rsi, %r15
movq 0x18(%r13), %rax
movq %r12, %rcx
shlq $0x7, %rcx
movq $0x0, 0x10(%rax,%rcx)
movq 0x70(%rsi), %rax
cmpq 0x78(%rsi), %rax
je 0x86817
leaq 0x7(%rsp), %r13
movq 0x90(%r15), %rcx
movb (%rcx,%rax,8), %bpl
incq %rax
movq %rax, 0x70(%r15)
movb %bpl, 0x7(%rsp)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x2(%rcx), %rdx
movq 0x18(%r14), %rsi
cmpq %rsi, %rdx
jle 0x867b6
addq %rsi, %rsi
movq %rsi, 0x18(%r14)
movq %rax, %rdi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%r14), %rcx
movb %bpl, (%rax,%rcx)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movb $0x0, 0x1(%rax,%rcx)
cmpb $0x2, (%rbx)
jne 0x867ea
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2, %edx
movq %r13, %rcx
callq 0x58c0f
jmp 0x867ff
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2, %edx
movq %r13, %rcx
callq 0x58b64
incl 0x20(%rbx)
movb $0x2, (%rbx)
incq 0x20(%r14)
movq 0x70(%r15), %rax
cmpq 0x78(%r15), %rax
jne 0x86775
movq %r12, %r15
jmp 0x868b8
movq %rbx, %rdi
movl $0x3, %edx
callq 0x58b64
movb $0x3, (%rbx)
jmp 0x868b8
cmpq %rsi, %rdx
jle 0x8684f
addq %rsi, %rsi
movq %rsi, 0x18(%r14)
movq %rax, %rdi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%r14), %rcx
movb %bpl, (%rax,%rcx)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movb $0x0, 0x1(%rax,%rcx)
cmpb $0x0, (%rbx)
je 0x8689c
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x58afb
jmp 0x868b2
leaq 0x6(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x58b64
incl 0x20(%rbx)
movb $0x1, (%rbx)
jmp 0x868b8
movq 0x8(%rbx), %rax
movq 0x18(%rbx), %rcx
movl -0x4(%rax,%rcx,4), %edx
andl $-0x4, %edx
addl $0x4, %edx
movl %edx, -0x4(%rax,%rcx,4)
incl 0x20(%rbx)
movb $0x0, (%rbx)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5978
movq $-0x1, %r15
jmp 0x868b8