// File: /workspace/github_cpp_makefile_star2_O3/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 0x2851c
cmpq $0x0, 0x8(%rax)
je 0x267c5
cmpq $0x1, 0x8(%r15)
jne 0x265dc
cmpq $0x1, 0x8(%r14)
jne 0x265dc
movl $0x1, %ebp
cmpq $0x1, 0x8(%rbx)
je 0x267cf
movq (%r15), %rax
movq 0x8(%r15), %rdx
movb -0x1(%rax,%rdx), %sil
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq 0x8(%rbx), %rax
cmpb -0x1(%rdi,%rcx), %sil
jne 0x26660
movq (%rbx), %rdi
cmpb -0x1(%rdi,%rax), %sil
jne 0x26660
cmpq $0x2, %rdx
setb %sil
cmpq $0x2, %rcx
setb %dil
orb %sil, %dil
jne 0x26632
cmpq $0x1, %rax
ja 0x26637
testl %r12d, %r12d
jg 0x26637
xorl %ebp, %ebp
movl $0x1, %ecx
movl $0x1, %edx
jmp 0x26662
testl %r12d, %r12d
jle 0x26660
movq %r15, %rdi
callq 0x53d0
movq %r14, %rdi
callq 0x53d0
movq %rbx, %rdi
callq 0x53d0
movq 0x8(%r15), %rdx
movq 0x8(%r14), %rcx
movq 0x8(%rbx), %rax
movb $0x1, %bpl
jmp 0x26662
xorl %ebp, %ebp
testq %rdx, %rdx
je 0x26675
testq %rcx, %rcx
je 0x26675
testq %rax, %rax
jne 0x26754
movslq %r12d, %r12
movq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x2851c
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 0x296c8
movq %r15, %rdi
movq %r12, %rsi
callq 0x53e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x266d8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x296c8
movq %r14, %rdi
movq %r12, %rsi
callq 0x53e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x26712
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x296c8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x53e0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2674c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x30(%rsp), %r12
decq %r12
testb %bpl, %bpl
jne 0x265dc
movq (%r15), %rax
movb (%rax), %al
movq (%r14), %rcx
cmpb (%rcx), %al
jne 0x267cc
movl %r12d, %ebp
movq (%rbx), %rcx
cmpb (%rcx), %al
jne 0x267cf
cmpq $0x2, 0x8(%r15)
jb 0x267cf
cmpq $0x2, 0x8(%r14)
jb 0x267cf
cmpq $0x2, 0x8(%rbx)
jb 0x267cf
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 0x2676c
jmp 0x267cf
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x267cf
movl %r12d, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq