// File: /workspace/github_cpp_makefile_star2_O1/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::CheckPathEqualProperty(SequencePath&, int)
int WholeGenome::CheckPathEqualProperty(SequencePath & sp, int match_mode)
{

    if(match_mode == 0){
        //bool equal_sequences = false;
        // same ref position, same donor length, same donor sequence, keep
        if(sp.donor_sequences[0].length() == sp.donor_sequences[2].length() &&
           sp.donor_sequences[1].length() == sp.donor_sequences[3].length()){
            if(sp.donor_sequences[0] == sp.donor_sequences[2] && sp.donor_sequences[1] == sp.donor_sequences[3]){
                sp.same_donor_len = true;
                sp.current_equal_donor_pos[0] = sp.donor_sequences[0].length()-1;
                sp.current_equal_donor_pos[1] = sp.donor_sequences[1].length()-1;
                return 0;
            }else{
                //dout << "delete this path at pos: " << sp.current_genome_pos << " for not equal donor sequence";
                //PrintPath(sp);
                return -1;
            }
        }else{
            sp.same_donor_len = false;
            int min_donor_identical_len[2];
            for(int i = 0; i < 2; i++){
                // compare each strain
                min_donor_identical_len[i] = min(sp.donor_sequences[0+i].length(), sp.donor_sequences[2+i].length());
                for(int k = sp.current_equal_donor_pos[i]+1; k < min_donor_identical_len[i]; k++){
                    if(sp.donor_sequences[0+i][k] != sp.donor_sequences[2+i][k]){
                        return -1;
                    }
                }
                sp.current_equal_donor_pos[i] = min_donor_identical_len[i]-1;
            }
            return 0;
        }
    }else{
        if(sp.donor_sequences[0].length() == sp.donor_sequences[2].length()){
            if(sp.donor_sequences[0] == sp.donor_sequences[2]){
                sp.same_donor_len = true;
                sp.current_equal_donor_pos[0] = sp.donor_sequences[0].length()-1;
                //sp.current_equal_donor_pos[1] = sp.donor_sequences[1].length()-1;
                return 0;
            }else{
                //dout << "delete this path at pos: " << sp.current_genome_pos << " for not equal donor sequence";
                //PrintPath(sp);
                return -1;
            }
        }else{
            sp.same_donor_len = false;
            int min_donor_identical_len[2];
            //for(int i = 0; i < 2; i++)
            int i = 0;
            {
                // compare each strain
                min_donor_identical_len[i] = min(sp.donor_sequences[0+i].length(), sp.donor_sequences[2+i].length());
                for(int k = sp.current_equal_donor_pos[i]+1; k < min_donor_identical_len[i]; k++){
                    if(sp.donor_sequences[0+i][k] != sp.donor_sequences[2+i][k]){
                        return -1;
                    }
                }
                sp.current_equal_donor_pos[i] = min_donor_identical_len[i]-1;
            }
            return 0;
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq 0xd8(%rsi), %r14
movq 0x118(%rsi), %rax
testl %edx, %edx
je 0x17345
cmpq %rax, %r14
jne 0x173d6
testq %r14, %r14
je 0x1732d
movq 0xd0(%rbx), %rdi
movq 0x110(%rbx), %rsi
movq %r14, %rdx
callq 0x5350
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1749c
movb $0x1, 0x15d(%rbx)
decl %r14d
movl %r14d, 0x150(%rbx)
xorl %eax, %eax
jmp 0x1749c
cmpq %rax, %r14
jne 0x1741d
movq 0xf8(%rbx), %r15
cmpq 0x138(%rbx), %r15
jne 0x1741d
testq %r14, %r14
je 0x1738c
movq 0xd0(%rbx), %rdi
movq 0x110(%rbx), %rsi
movq %r14, %rdx
callq 0x5350
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1749c
testq %r15, %r15
je 0x173b6
movq 0xf0(%rbx), %rdi
movq 0x130(%rbx), %rsi
movq %r15, %rdx
callq 0x5350
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1749c
movb $0x1, 0x15d(%rbx)
decl %r14d
movl %r14d, 0x150(%rbx)
decl %r15d
movl %r15d, 0x154(%rbx)
jmp 0x1733e
movb $0x0, 0x15d(%rbx)
cmovaq %rax, %r14
movslq 0x150(%rbx), %rcx
movq 0xd0(%rbx), %rax
movq 0x110(%rbx), %rdx
movslq %r14d, %rsi
incq %rcx
cmpq %rsi, %rcx
jge 0x17334
movb (%rax,%rcx), %dil
leaq 0x1(%rcx), %r8
cmpb (%rdx,%rcx), %dil
movq %r8, %rcx
je 0x173fc
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1749c
leaq 0xd0(%rbx), %rax
movb $0x0, 0x15d(%rbx)
movb $0x1, %cl
xorl %edx, %edx
movq %rdx, %r8
shlq $0x5, %r8
leaq (%rax,%r8), %rdi
addq $0x40, %rdi
movq -0x38(%rdi), %rsi
movq 0x8(%rdi), %r9
cmpq %rsi, %r9
cmovbq %r9, %rsi
addq %rax, %r8
movslq 0x150(%rbx,%rdx,4), %r10
movslq %esi, %r9
incq %r10
cmpq %r9, %r10
jge 0x1747c
movq (%r8), %r11
movb (%r11,%r10), %r11b
movq (%rdi), %r14
leaq 0x1(%r10), %r15
cmpb (%r14,%r10), %r11b
movq %r15, %r10
je 0x1745e
jmp 0x17494
decl %esi
movl %esi, 0x150(%rbx,%rdx,4)
leaq 0x1(%rdx), %rsi
testq %rdx, %rdx
sete %cl
movq %rsi, %rdx
je 0x1742f
movzbl %cl, %eax
andl $0x1, %eax
negl %eax
popq %rbx
popq %r14
popq %r15
retq