// File: /workspace/github_cpp_makefile_star2_O1/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::NormalizeVariantSequence(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, int)
int WholeGenome::NormalizeVariantSequence(int pos, string & parsimonious_ref, string & parsimonious_alt0, string & parsimonious_alt1, int chr_id) {

	int left_index = pos;
	if (genome_sequences[chr_id].size() == 0) return -1;
	if (parsimonious_ref.size() == 1 && parsimonious_alt0.size() == 1 && parsimonious_alt1.size() == 1) return true;

	bool change_in_allels = true;
	while (change_in_allels) {
		change_in_allels = false;
		if (parsimonious_ref.back() == parsimonious_alt0.back() && parsimonious_ref.back() == parsimonious_alt1.back() ) {
			if ((parsimonious_ref.size() > 1 && parsimonious_alt0.size() > 1 && parsimonious_alt1.size() > 1) || left_index > 0) { // when left_index == 0, can not make further changes
				parsimonious_ref.pop_back();
				parsimonious_alt0.pop_back();
				parsimonious_alt1.pop_back();
				change_in_allels = true;
			}
            // else do not make further changes
		}
		if (parsimonious_ref.length() == 0 || parsimonious_alt0.length() == 0 || parsimonious_alt1.length() == 0) {
			left_index--;
			char left_char = toupper(genome_sequences[chr_id][left_index]);
			parsimonious_ref = left_char + parsimonious_ref;
			parsimonious_alt0 = left_char + parsimonious_alt0;
			parsimonious_alt1 = left_char + parsimonious_alt1;
		}
	}
	while (parsimonious_ref[0] == parsimonious_alt0[0] &&
            parsimonious_ref[0] == parsimonious_alt1[0] &&
            parsimonious_ref.size() > 1 &&
            parsimonious_alt0.size() > 1 &&
            parsimonious_alt1.size() > 1)
    {
		parsimonious_ref.erase(0, 1);
		parsimonious_alt0.erase(0, 1);
		parsimonious_alt1.erase(0, 1);
        left_index ++; // left_index indicates variant position, if truncate the leftmost, then
	}
	return left_index;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %r12d
leaq 0x4(%rsp), %rsi
movl %r9d, (%rsi)
addq $0x118, %rdi            # imm = 0x118
movq %rdi, 0x28(%rsp)
callq 0x28988
cmpq $0x0, 0x8(%rax)
je 0x26ca3
cmpq $0x1, 0x8(%r15)
jne 0x26ad6
cmpq $0x1, 0x8(%r14)
jne 0x26ad6
movl $0x1, %ebp
cmpq $0x1, 0x8(%rbx)
je 0x26cad
movq (%r15), %rax
movq 0x8(%r15), %rcx
movb -0x1(%rax,%rcx), %sil
movq (%r14), %rax
movq 0x8(%r14), %rdx
cmpb -0x1(%rax,%rdx), %sil
jne 0x26b38
movq (%rbx), %rdi
movq 0x8(%rbx), %rax
cmpb -0x1(%rdi,%rax), %sil
jne 0x26b38
cmpq $0x2, %rcx
setb %cl
cmpq $0x2, %rdx
setb %dl
orb %cl, %dl
jne 0x26b16
cmpq $0x1, %rax
ja 0x26b1b
testl %r12d, %r12d
jle 0x26b38
movq %r15, %rdi
callq 0x53d0
movq %r14, %rdi
callq 0x53d0
movq %rbx, %rdi
callq 0x53d0
movb $0x1, %bpl
jmp 0x26b3a
xorl %ebp, %ebp
cmpq $0x0, 0x8(%r15)
je 0x26b53
cmpq $0x0, 0x8(%r14)
je 0x26b53
cmpq $0x0, 0x8(%rbx)
jne 0x26c32
movslq %r12d, %r12
movq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x28988
movq (%rax), %rax
movq %r12, 0x30(%rsp)
movsbl -0x1(%rax,%r12), %edi
callq 0x5610
movsbl %al, %r13d
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x29b60
movq %r15, %rdi
movq %r12, %rsi
callq 0x53e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x26bb6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x29b60
movq %r14, %rdi
movq %r12, %rsi
callq 0x53e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x26bf0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x29b60
movq %rbx, %rdi
movq %r12, %rsi
callq 0x53e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x26c2a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x30(%rsp), %r12
decq %r12
testb %bpl, %bpl
jne 0x26ad6
movq (%r15), %rax
movb (%rax), %al
movq (%r14), %rcx
cmpb (%rcx), %al
jne 0x26caa
movl %r12d, %ebp
movq (%rbx), %rcx
cmpb (%rcx), %al
jne 0x26cad
cmpq $0x2, 0x8(%r15)
jb 0x26cad
cmpq $0x2, 0x8(%r14)
jb 0x26cad
cmpq $0x2, 0x8(%rbx)
jb 0x26cad
movl $0x1, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x50b0
movl $0x1, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x50b0
movl $0x1, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x50b0
incl %ebp
movq (%r15), %rax
movb (%rax), %al
movq (%r14), %rcx
cmpb (%rcx), %al
je 0x26c4a
jmp 0x26cad
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x26cad
movl %r12d, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq