// File: /workspace/github_cpp_makefile_star2_O3/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::CheckTandemRepeat(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
bool WholeGenome::CheckTandemRepeat(string sequence, int unit_threshold) {
    int sequence_length = (int)sequence.length();
    //cout << sequence_length << "," << unit_threshold << endl;
    if(sequence_length == 1) return true;
    transform(sequence.begin(), sequence.end(), sequence.begin(), ::toupper);
    int end_index = sequence_length / 2 + 1;
    bool final_checking = false;
    int repeat_threshold = min(end_index-1, unit_threshold);
    for (int repeat_length = 1; repeat_length <= end_index; repeat_length++) {
        bool is_tandem_repeat = true;
        int repeat_time = 1;
        string repeat_region = sequence.substr(0, repeat_length);
        int start_position = repeat_length;
        while (start_position < sequence_length) {
            if (start_position + repeat_length > sequence_length)
                break;
            string matching_region = sequence.substr(start_position, repeat_length);
            if (matching_region != repeat_region) {
                is_tandem_repeat = false;
                break;
            }
            start_position += repeat_length;
            repeat_time ++;
        }
        if (is_tandem_repeat && repeat_time > 1) {
            final_checking = true;
            break;
        }
    }
    return final_checking;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, 0x10(%rsp)
movq 0x8(%rsi), %r13
movb $0x1, %al
cmpl $0x1, %r13d
je 0x14f48
testq %r13, %r13
je 0x14e45
movq 0x10(%rsp), %rax
movq (%rax), %rbx
xorl %r14d, %r14d
movsbl (%rbx,%r14), %edi
callq 0x5610
movb %al, (%rbx,%r14)
incq %r14
cmpq %r14, %r13
jne 0x14e25
cmpl $-0x1, %r13d
jl 0x14f46
movl %r13d, %eax
shrl $0x1f, %eax
addl %r13d, %eax
sarl %eax
movq %rax, 0x38(%rsp)
addl $0x2, %eax
movq %rax, 0x40(%rsp)
movl $0x1, %eax
movq %rax, %r15
leaq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x5360
movl $0x1, 0xc(%rsp)
movb $0x1, %r14b
movl %r15d, %r12d
cmpl %r13d, %r12d
jge 0x14f00
leal (%r12,%r15), %ebx
cmpl %r13d, %ebx
jg 0x14f00
movslq %r12d, %rdx
leaq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rcx
callq 0x5360
movq 0x50(%rsp), %rdx
cmpq 0x20(%rsp), %rdx
jne 0x14ece
testq %rdx, %rdx
je 0x14ed5
movq 0x18(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x5350
testl %eax, %eax
je 0x14ed5
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0x14edf
incl 0xc(%rsp)
movb $0x1, %bpl
movl %ebx, %r12d
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x14efb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5340
testb %bpl, %bpl
jne 0x14e87
cmpl $0x2, 0xc(%rsp)
setge %bl
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x14f24
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
andb %bl, %r14b
jne 0x14f42
leaq 0x1(%r15), %rax
cmpq 0x40(%rsp), %rax
jne 0x14e62
cmpq 0x38(%rsp), %r15
setbe %al
jmp 0x14f48
movb $0x1, %al
jmp 0x14f48
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x14f76
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
movq %rbx, %rdi
callq 0x55c0