// File: /workspace/github_cpp_makefile_star2_O1/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 0x87198
cmpq $0x2, %r8
je 0x871de
cmpq $0x1, %r8
jne 0x87363
movq 0x18(%r13), %rcx
shlq $0x7, %r12
movq 0x20(%rcx,%r12), %rdx
imulq $0x38, %r9, %rdi
movq 0x8(%rdx,%rdi), %r15
movq %r15, %r12
shlq $0x7, %r12
movq 0x8(%r14), %rax
movq 0x18(%r14), %rsi
addq $0x2, %rax
cmpq $0x0, 0x20(%rdx,%rdi)
movb 0x18(%rcx,%r12), %bpl
je 0x872ca
cmpq %rsi, %rax
jle 0x87114
addq %rsi, %rsi
movq %rsi, 0x18(%r14)
movq (%r14), %rdi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movb %bpl, (%rax,%rcx)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
xorl %edx, %edx
movb %dl, 0x1(%rax,%rcx)
incq 0x20(%r14)
movb %dl, 0x6(%rsp)
movq 0x18(%r13), %rax
movzbl 0x18(%rax,%r12), %ecx
leaq 0x2034e3(%rip), %rdx    # 0x28a630
movb (%rdx,%rcx), %cl
shlb $0x3, %cl
movb %cl, 0x6(%rsp)
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 0x87316
leaq 0x6(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x59767
jmp 0x8732d
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 0x872b5
movq %rbx, %rdi
movl $0x3, %edx
callq 0x59767
jmp 0x872c2
movq %rsi, %r15
movq 0x18(%r13), %rax
movq %r12, %rcx
shlq $0x7, %rcx
movq $0x0, 0x10(%rax,%rcx)
leaq 0x7(%rsp), %r13
movq 0x70(%r15), %rax
movq 0x78(%r15), %rcx
movb $-0x1, %bpl
cmpq %rcx, %rax
je 0x8721d
movq 0x90(%r15), %rdx
movb (%rdx,%rax,8), %bpl
leaq 0x1(%rax), %rdx
movq %rdx, 0x70(%r15)
cmpq %rcx, %rax
je 0x872ad
movb %bpl, 0x7(%rsp)
movq 0x8(%r14), %rax
movq 0x18(%r14), %rsi
addq $0x2, %rax
cmpq %rsi, %rax
jle 0x8724e
addq %rsi, %rsi
movq %rsi, 0x18(%r14)
movq (%r14), %rdi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
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 0x87289
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2, %edx
movq %r13, %rcx
callq 0x59767
jmp 0x8729e
movq %rbx, %rdi
movl $0x1, %esi
movl $0x2, %edx
movq %r13, %rcx
callq 0x596c5
incl 0x20(%rbx)
movb $0x2, (%rbx)
incq 0x20(%r14)
jmp 0x871fa
movq %r12, %r15
jmp 0x87351
movq %rbx, %rdi
movl $0x3, %edx
callq 0x596c5
movb $0x3, (%rbx)
jmp 0x87351
cmpq %rsi, %rax
jle 0x872e1
addq %rsi, %rsi
movq %rsi, 0x18(%r14)
movq (%r14), %rdi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
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 0x87335
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x5965e
jmp 0x8734b
leaq 0x6(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x596c5
incl 0x20(%rbx)
movb $0x1, (%rbx)
jmp 0x87351
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 0x58b4
movq $-0x1, %r15
jmp 0x87351