// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rsi, -0xc8(%rbp)
movq %rdi, %rax
movq -0xc8(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
movq %rax, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
callq 0x6630
movl %eax, -0x20(%rbp)
cmpl $0x1, -0x20(%rbp)
jne 0x1f3e5
movb $0x1, -0x1(%rbp)
jmp 0x1f5be
movq -0xc0(%rbp), %rdi
callq 0x63c0
movq -0xc0(%rbp), %rdi
movq %rax, -0x28(%rbp)
callq 0x6270
movq -0xc0(%rbp), %rdi
movq %rax, -0x30(%rbp)
callq 0x63c0
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq 0x54bb0(%rip), %rcx     # 0x73fd8
callq 0x33ca0
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movb $0x0, -0x45(%rbp)
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x10420
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl $0x1, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x44(%rbp), %eax
jg 0x1f5b6
movq -0xc0(%rbp), %rsi
movb $0x1, -0x55(%rbp)
movl $0x1, -0x5c(%rbp)
movslq -0x54(%rbp), %rcx
leaq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x6460
movl -0x54(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x1f569
movl -0x84(%rbp), %eax
addl -0x54(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x1f4c2
jmp 0x1f569
movq -0xc0(%rbp), %rsi
movslq -0x84(%rbp), %rdx
movslq -0x54(%rbp), %rcx
leaq -0xa8(%rbp), %rdi
callq 0x6460
jmp 0x1f4e2
leaq -0xa8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x125b0
testb $0x1, %al
jne 0x1f4f8
jmp 0x1f528
movb $0x0, -0x55(%rbp)
movl $0x6, -0xb8(%rbp)
jmp 0x1f54a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6828
jmp 0x1f5cc
movl -0x54(%rbp), %eax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0xb8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x6828
movl -0xb8(%rbp), %eax
testl %eax, %eax
je 0x1f564
jmp 0x1f562
jmp 0x1f569
jmp 0x1f4a0
testb $0x1, -0x55(%rbp)
je 0x1f585
cmpl $0x1, -0x5c(%rbp)
jle 0x1f585
movb $0x1, -0x45(%rbp)
movl $0x2, -0xb8(%rbp)
jmp 0x1f58f
movl $0x0, -0xb8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6828
movl -0xb8(%rbp), %eax
testl %eax, %eax
je 0x1f5a6
jmp 0x1f5a4
jmp 0x1f5b6
jmp 0x1f5a8
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1f468
movb -0x45(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x6750
nopl (%rax,%rax)