// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq 0xd8(%rsi), %r14
movq 0x118(%rsi), %rax
testl %edx, %edx
je 0x17143
cmpq %rax, %r14
jne 0x171d4
testq %r14, %r14
je 0x1712b
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 0x172a0
movb $0x1, 0x15d(%rbx)
decl %r14d
movl %r14d, 0x150(%rbx)
xorl %eax, %eax
jmp 0x172a0
cmpq %rax, %r14
jne 0x1721e
movq 0xf8(%rbx), %r15
cmpq 0x138(%rbx), %r15
jne 0x1721e
testq %r14, %r14
je 0x1718a
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 0x172a0
testq %r15, %r15
je 0x171b4
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 0x172a0
movb $0x1, 0x15d(%rbx)
decl %r14d
movl %r14d, 0x150(%rbx)
decl %r15d
movl %r15d, 0x154(%rbx)
jmp 0x1713c
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 0x17132
movb (%rax,%rcx), %dil
leaq 0x1(%rcx), %r8
cmpb (%rdx,%rcx), %dil
movq %r8, %rcx
je 0x171fa
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x172a0
leaq 0xd0(%rbx), %rax
movb $0x0, 0x15d(%rbx)
movb $0x1, %cl
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x5, %rsi
leaq (%rax,%rsi), %r9
addq $0x40, %r9
movq -0x38(%r9), %rdi
movq 0x8(%r9), %r8
cmpq %rdi, %r8
cmovbq %r8, %rdi
leaq (%rax,%rsi), %r10
movslq 0x150(%rbx,%rdx,4), %r11
movslq %edi, %rsi
incq %r11
movq %r11, %r8
cmpq %rsi, %r11
jge 0x1727e
movq (%r10), %r11
movb (%r11,%r8), %bpl
movq (%r9), %r14
leaq 0x1(%r8), %r11
cmpb (%r14,%r8), %bpl
je 0x17260
jmp 0x17296
decl %edi
movl %edi, 0x150(%rbx,%rdx,4)
movl $0x1, %edx
testb $0x1, %cl
movl $0x0, %ecx
jne 0x17230
xorl %eax, %eax
cmpq %rsi, %r8
setl %al
negl %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop