// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x1, -0x30(%rbp)
jne 0xa052c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
imulq $0x38, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
jne 0xa0434
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
imulq $0x38, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movsbl 0x18(%rax), %esi
callq 0xa0840
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rax
shlq $0x7, %rax
addq %rax, %rdi
addq $0x18, %rdi
movq 0x10(%rbp), %rdx
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x1c6a0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa063e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
imulq $0x38, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movsbl 0x18(%rax), %esi
callq 0xa0840
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movb $0x0, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movzbl 0x18(%rax), %eax
movl %eax, %ecx
leaq 0x3241a1(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x41(%rbp)
movsbl -0x41(%rbp), %eax
shll $0x3, %eax
movb %al, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movsbl -0x41(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq -0x40(%rbp), %rdx
shlq $0x7, %rdx
addq %rdx, %rcx
movzbl 0x18(%rcx), %ecx
movl %ecx, %edx
leaq 0x32414e(%rip), %rcx    # 0x3c4650
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
movq 0x10(%rbp), %rdx
leaq -0x41(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, %esi
callq 0x1c6a0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa063e
cmpq $0x3, -0x30(%rbp)
jne 0xa059b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x40(%rax), %rax
imulq $0x38, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
subq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq 0x18(%rbp), %rdi
addq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rax
subq -0x28(%rbp), %rax
movl %eax, %esi
movq 0x10(%rbp), %rdx
movl $0x3, %ecx
callq 0x1c6a0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa063e
cmpq $0x2, -0x30(%rbp)
jne 0xa061a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rdi
addq $0x70, %rdi
leaq -0x50(%rbp), %rsi
callq 0xc3460
cmpl $0x0, %eax
je 0xa0610
movq -0x50(%rbp), %rax
movb %al, -0x51(%rbp)
movq -0x20(%rbp), %rdi
movsbl -0x51(%rbp), %esi
callq 0xa0840
movq 0x10(%rbp), %rdx
leaq -0x51(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %ecx
callq 0x1c6a0
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0xa05bd
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa063e
movq 0x3239bf(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2e5e32(%rip), %rsi    # 0x38645d
movb $0x0, %al
callq 0x22a0
jmp 0xa0634
jmp 0xa0636
movq $-0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)