// File: /workspace/github_cpp_makefile_star2_O1/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), %rbp
movb $0x1, %r14b
cmpl $0x1, %ebp
je 0x1507a
testq %rbp, %rbp
je 0x14f61
movq 0x10(%rsp), %rax
movq (%rax), %rbx
xorl %r14d, %r14d
movsbl (%rbx,%r14), %edi
callq 0x5610
movb %al, (%rbx,%r14)
incq %r14
cmpq %r14, %rbp
jne 0x14f4b
cmpl $-0x1, %ebp
jge 0x14f6e
xorl %r14d, %r14d
jmp 0x1507a
movl %ebp, %eax
shrl $0x1f, %eax
addl %ebp, %eax
sarl %eax
addl $0x2, %eax
movq %rax, 0x38(%rsp)
movl $0x1, %r13d
xorl %r14d, %r14d
movq %r14, 0x40(%rsp)
leaq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x5360
movb $0x1, %r14b
movl $0x1, 0xc(%rsp)
movl %r13d, %r15d
cmpl %ebp, %r15d
jge 0x1502b
leal (%r15,%r13), %ebx
cmpl %ebp, %ebx
jg 0x1502b
movslq %r15d, %rdx
leaq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rcx
callq 0x5360
movq 0x50(%rsp), %rdx
xorl %r12d, %r12d
cmpq 0x20(%rsp), %rdx
jne 0x14ffb
testq %rdx, %rdx
je 0x15000
movq 0x18(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x5350
xorl %r12d, %r12d
testl %eax, %eax
je 0x15000
xorl %r14d, %r14d
jmp 0x1500a
incl 0xc(%rsp)
movb $0x1, %r12b
movl %ebx, %r15d
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x15026
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5340
testb %r12b, %r12b
jne 0x14faf
cmpl $0x2, 0xc(%rsp)
setge %bl
andb %r14b, %bl
movq 0x40(%rsp), %r14
movzbl %r14b, %r14d
movl $0x1, %eax
cmovnel %eax, %r14d
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x15064
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
incq %r13
cmpq 0x38(%rsp), %r13
sete %al
orb %al, %bl
cmpb $0x1, %bl
jne 0x14f88
andb $0x1, %r14b
movl %r14d, %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 0x150af
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5340
movq %rbx, %rdi
callq 0x55c0
nop