// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %ebx
movq %rdi, %r13
leaq 0xc(%rsp), %rsi
movl %r9d, (%rsi)
addq $0x118, %r13            # imm = 0x118
movq %r13, %rdi
callq 0x19a5a
cmpq $0x0, 0x8(%rax)
je 0x18aa8
cmpq $0x1, 0x8(%r12)
jne 0x18abc
cmpq $0x1, 0x8(%r15)
jne 0x18abc
cmpq $0x1, 0x8(%r14)
jne 0x18abc
pushq $0x1
jmp 0x18aaa
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x10(%rsp)
movb $0x1, %r13b
testb $0x1, %r13b
je 0x18c02
movq (%r12), %rax
movq 0x8(%r12), %rdx
movb -0x1(%rax,%rdx), %sil
movq (%r15), %rdi
movq 0x8(%r15), %rcx
movq 0x8(%r14), %rax
cmpb -0x1(%rdi,%rcx), %sil
jne 0x18b56
movq (%r14), %rdi
cmpb -0x1(%rdi,%rax), %sil
jne 0x18b56
cmpq $0x2, %rdx
setb %sil
cmpq $0x2, %rcx
setb %dil
orb %sil, %dil
jne 0x18b28
testl %ebx, %ebx
setg %cl
cmpq $0x2, %rax
setae %dl
orb %cl, %dl
jne 0x18b2c
xorl %r13d, %r13d
pushq $0x1
popq %rdx
movq %rdx, %rcx
jmp 0x18b59
testl %ebx, %ebx
jle 0x18b56
movq %r12, %rdi
callq 0x5380
movq %r15, %rdi
callq 0x5380
movq %r14, %rdi
callq 0x5380
movq 0x8(%r12), %rdx
movq 0x8(%r15), %rcx
movq 0x8(%r14), %rax
movb $0x1, %r13b
jmp 0x18b59
xorl %r13d, %r13d
testq %rdx, %rdx
je 0x18b6c
testq %rcx, %rcx
je 0x18b6c
testq %rax, %rax
jne 0x18ac4
movslq %ebx, %rbp
leaq -0x1(%rbp), %rbx
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x19a5a
movq (%rax), %rax
movsbl -0x1(%rax,%rbp), %edi
callq 0x5590
movsbl %al, %esi
movl %esi, 0x8(%rsp)
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rdx
callq 0x1aba1
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5390
movq %rbp, %rdi
callq 0x55e8
movq %rbp, %rdi
movl 0x8(%rsp), %esi
movq %r15, %rdx
callq 0x1aba1
movq %r15, %rdi
movq %rbp, %rsi
callq 0x5390
movq %rbp, %rdi
callq 0x55e8
movq %rbp, %rdi
movl 0x8(%rsp), %esi
movq %r14, %rdx
callq 0x1aba1
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5390
movq %rbp, %rdi
callq 0x55e8
jmp 0x18ac4
pushq $0x1
popq %r13
movq (%r12), %rax
movb (%rax), %al
movq (%r15), %rcx
cmpb (%rcx), %al
jne 0x18aab
movq (%r14), %rcx
cmpb (%rcx), %al
jne 0x18aab
cmpq $0x2, 0x8(%r12)
jb 0x18aab
cmpq $0x2, 0x8(%r15)
jb 0x18aab
cmpq $0x2, 0x8(%r14)
jb 0x18aab
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x50b0
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x50b0
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x50b0
incl %ebx
jmp 0x18c06
nop