// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x21b50
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
callq 0x6630
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
addq $0x40, %rdi
callq 0x6630
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jne 0x21a0c
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
addq $0x20, %rdi
callq 0x6630
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
addq $0x60, %rdi
callq 0x6630
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jne 0x21a0c
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movq -0x18(%rbp), %rsi
addq $0xd0, %rsi
addq $0x40, %rsi
callq 0xdcb0
testb $0x1, %al
jne 0x2197c
jmp 0x21a00
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
addq $0x20, %rdi
movq -0x18(%rbp), %rsi
addq $0xd0, %rsi
addq $0x60, %rsi
callq 0xdcb0
testb $0x1, %al
jne 0x219a5
jmp 0x21a00
movq -0x18(%rbp), %rax
movb $0x1, 0x15d(%rax)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
callq 0x6630
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x150(%rax)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
addq $0x20, %rdi
callq 0x6630
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x154(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x21d19
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21d19
movq -0x18(%rbp), %rax
movb $0x0, 0x15d(%rax)
movl $0x0, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
jge 0x21b44
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x28(%rbp), %eax
addl $0x0, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6630
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x28(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6630
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x13a80
movq (%rax), %rax
movl %eax, %ecx
movslq -0x28(%rbp), %rax
movl %ecx, -0x24(%rbp,%rax,4)
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl 0x150(%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movslq -0x28(%rbp), %rcx
cmpl -0x24(%rbp,%rcx,4), %eax
jge 0x21b1c
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x28(%rbp), %eax
addl $0x0, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movslq -0x3c(%rbp), %rsi
callq 0x6810
movsbl (%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x28(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movslq -0x3c(%rbp), %rsi
callq 0x6810
movq %rax, %rcx
movl -0x74(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x21b0f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21d19
jmp 0x21b11
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x21a9d
movslq -0x28(%rbp), %rax
movl -0x24(%rbp,%rax,4), %edx
subl $0x1, %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, 0x150(%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x21a1e
movl $0x0, -0x4(%rbp)
jmp 0x21d19
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
callq 0x6630
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
addq $0x40, %rdi
callq 0x6630
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jne 0x21bec
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movq -0x18(%rbp), %rsi
addq $0xd0, %rsi
addq $0x40, %rsi
callq 0xdcb0
testb $0x1, %al
jne 0x21ba9
jmp 0x21be0
movq -0x18(%rbp), %rax
movb $0x1, 0x15d(%rax)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
callq 0x6630
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x150(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x21d19
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21d19
movq -0x18(%rbp), %rax
movb $0x0, 0x15d(%rax)
movl $0x0, -0x48(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x48(%rbp), %eax
addl $0x0, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6630
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x48(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
callq 0x6630
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x13a80
movq (%rax), %rax
movl %eax, %ecx
movslq -0x48(%rbp), %rax
movl %ecx, -0x44(%rbp,%rax,4)
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl 0x150(%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movslq -0x48(%rbp), %rcx
cmpl -0x44(%rbp,%rcx,4), %eax
jge 0x21cf8
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x48(%rbp), %eax
addl $0x0, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x6810
movsbl (%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rdi
addq $0xd0, %rdi
movl -0x48(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x5, %rax
addq %rax, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x6810
movq %rax, %rcx
movl -0x84(%rbp), %eax
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x21ce8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21d19
jmp 0x21cea
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x21c73
movslq -0x48(%rbp), %rax
movl -0x44(%rbp,%rax,4), %edx
subl $0x1, %edx
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl %edx, 0x150(%rax,%rcx,4)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)