// File: /workspace/github_cpp_makefile_star2_O1/shangjingbo1226[P]MACFP/src/methods/TDP.cpp
// Function: main
int main(int argc, char* argv[])
{
    loadConfiguration(argc, argv);

    cout << "settings:" << endl;
    cout << "\tfilename = " << DNA_FILENAME << endl;
    cout << "\tmin_sup = " << MIN_SUP << endl;
    cout << "\tlen_thres = " << LEN_THRES << endl;
    cout << "\tedit_thres = " << EDIT_DIS_THRES << endl;

    double start = clock();

    string dna = loadDNASequence();
    //dna = "acgtacgt";

    int n = dna.size();
    cerr << "length of DNA sequence = " << n << endl;

    //cerr << getSup(dna, n, 1958, 1970).size() << endl; return 0;
    /*cerr << "valid = " << valid(dna, n, 0, 0) << endl;
    cerr << "valid = " << valid(dna, n, 0, 1) << endl;
    return 0;*/

    FILE* out = tryOpen(OUTPUT_FILENAME, "w");
    int lastJ = -1;
    int cnt = 0;
    for (int i = 0, j = 0; i < n; ++ i) {
        j = max(j, i);
        while (j < n && getSup(dna, n, i, j).size() >= MIN_SUP) {
            ++ j;
        }
        if (j > lastJ) {
            lastJ = j;
            if (j - i < LEN_THRES) {
                continue;
            }
            vector< pair<int, int> > sups = getSup(dna, n, i, j - 1);
            //cerr << i << " " << j << endl;
            fprintf(out, "%d %d ", i, j - 1);
            for (int k = i; k < j; ++ k) {
                fprintf(out, "%c", dna[k]);
            }
            fprintf(out, "\n");
            fprintf(out, "supports: %d\n", sups.size());
            FOR (pair, sups) {
                fprintf(out, "\t%d %d ", pair->first, pair->second);
                for (int k = pair->first; k <= pair->second; ++ k) {
                    fprintf(out, "%c", dna[k]);
                }
                fprintf(out, "\n");
            }
            cnt ++;
        }
    }
    cerr << "# approximate patterns = " << cnt << endl;
    fclose(out);

    cout << "running time: " << (clock() - start) / CLOCKS_PER_SEC << endl;
    cout << "# of patterns: " << cnt << endl;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
callq 0x29e5
movq 0x4d52(%rip), %rbx      # 0x7fc8
leaq 0x1e3e(%rip), %rsi      # 0x50bb
movl $0x9, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x1e0d(%rip), %rsi      # 0x50c5
movl $0xc, %edx
movq %rbx, %rdi
callq 0x21b0
movq 0x5f6300c(%rip), %rsi   # 0x5f662d8
movq 0x5f6300d(%rip), %rdx   # 0x5f662e0
movq %rbx, %rdi
callq 0x21b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x1dc6(%rip), %rsi      # 0x50d2
movl $0xb, %edx
movq %rbx, %rdi
callq 0x21b0
movl 0x4e75(%rip), %esi      # 0x8194
movq %rbx, %rdi
callq 0x22b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x1d86(%rip), %rsi      # 0x50de
movl $0xd, %edx
movq %rbx, %rdi
callq 0x21b0
movl 0x4e31(%rip), %esi      # 0x819c
movq %rbx, %rdi
callq 0x22b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x1d48(%rip), %rsi      # 0x50ec
movl $0xe, %edx
movq %rbx, %rdi
callq 0x21b0
movl 0x4de1(%rip), %esi      # 0x8198
movq %rbx, %rdi
callq 0x22b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
callq 0x20f0
movq %rax, %rbp
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x2c17
movq 0x8(%rbx), %r14
movq 0x4be7(%rip), %rdi      # 0x7ff0
leaq 0x1ceb(%rip), %rsi      # 0x50fb
movl $0x19, %edx
callq 0x21b0
movq 0x4bcf(%rip), %rdi      # 0x7ff0
movl %r14d, %esi
callq 0x22b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x70(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x5f62e94(%rip), %rsi   # 0x5f662f8
movq 0x5f62e95(%rip), %rdx   # 0x5f66300
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x3b3a
leaq 0xa8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1c8a(%rip), %rsi      # 0x5115
leaq 0x1c84(%rip), %rdx      # 0x5116
leaq 0x98(%rsp), %rdi
callq 0x4312
leaq 0x60(%rsp), %rdi
leaq 0x98(%rsp), %rbx
movq %rbx, %rsi
callq 0x2889
movq %rax, %r15
movq (%rbx), %rdi
cmpq %r13, %rdi
je 0x34cf
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21a0
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x34e6
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbp, 0x50(%rsp)
testl %r14d, %r14d
jle 0x36cf
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x58(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpl %ebp, %ebx
cmovlel %ebp, %ebx
cmpl %r14d, %ebx
jge 0x3561
leaq 0x80(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl %r14d, %edx
movl %ebp, %ecx
movl %ebx, %r8d
callq 0x2e0e
movq 0x88(%rsp), %rax
subq 0x80(%rsp), %rax
sarq $0x3, %rax
movslq 0x4c3c(%rip), %rcx      # 0x8194
cmpq %rcx, %rax
setae %r12b
jmp 0x3564
xorl %r12d, %r12d
cmpl %r14d, %ebx
jge 0x3586
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x3586
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
testb %r12b, %r12b
je 0x3590
incq %rbx
jmp 0x351e
cmpl 0xc(%rsp), %ebx
jle 0x36ba
movq 0x10(%rsp), %rax
addl %ebx, %eax
cmpl 0x4bf5(%rip), %eax      # 0x819c
jl 0x36b6
leaq -0x1(%rbx), %r12
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl %r14d, %edx
movl %ebp, %ecx
movl %r12d, %r8d
callq 0x2e0e
movl %r13d, 0xc(%rsp)
movq %r15, %rdi
leaq 0x1b4f(%rip), %rsi      # 0x5126
movl %ebp, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2200
movq %rbp, %r12
cmpl %ebp, %ebx
jbe 0x3604
movq 0x30(%rsp), %rax
movsbl (%rax,%r12), %edi
movq %r15, %rsi
callq 0x21e0
incq %r12
cmpq %rbx, %r12
jb 0x35ea
movl $0xa, %edi
movq %r15, %rsi
callq 0x21e0
movq 0x20(%rsp), %rdx
subq 0x18(%rsp), %rdx
sarq $0x3, %rdx
movq %r15, %rdi
leaq 0x1aee(%rip), %rsi      # 0x5117
xorl %eax, %eax
callq 0x2200
movq 0x18(%rsp), %r12
cmpq 0x20(%rsp), %r12
je 0x3697
movl (%r12), %edx
movl 0x4(%r12), %ecx
movq %r15, %rdi
leaq 0x1ad6(%rip), %rsi      # 0x5125
xorl %eax, %eax
callq 0x2200
movslq (%r12), %r13
cmpl 0x4(%r12), %r13d
jg 0x3684
decq %r13
movq 0x30(%rsp), %rax
movsbl 0x1(%rax,%r13), %edi
movq %r15, %rsi
callq 0x21e0
movslq 0x4(%r12), %rax
incq %r13
cmpq %rax, %r13
jl 0x3664
movl $0xa, %edi
movq %r15, %rsi
callq 0x21e0
addq $0x8, %r12
jmp 0x3635
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x36ae
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movl 0xc(%rsp), %r13d
incl %r13d
movl %ebx, 0xc(%rsp)
incq %rbp
decq 0x10(%rsp)
cmpq 0x58(%rsp), %rbp
jne 0x3519
jmp 0x36d2
xorl %r13d, %r13d
movq 0x4917(%rip), %rdi      # 0x7ff0
leaq 0x1a4d(%rip), %rsi      # 0x512d
movl $0x19, %edx
callq 0x21b0
movq 0x48ff(%rip), %rdi      # 0x7ff0
movl %r13d, %esi
callq 0x22b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2180
movq 0x4896(%rip), %rdi      # 0x7fc8
leaq 0x1a0e(%rip), %rsi      # 0x5147
movl $0xe, %edx
callq 0x21b0
cvtsi2sdq 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x20f0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd 0x10(%rsp), %xmm0
divsd 0x189d(%rip), %xmm0     # 0x5008
movq 0x4856(%rip), %rdi      # 0x7fc8
callq 0x2280
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x4820(%rip), %rdi      # 0x7fc8
leaq 0x19a7(%rip), %rsi      # 0x5156
movl $0xf, %edx
callq 0x21b0
movq 0x4808(%rip), %rdi      # 0x7fc8
movl %r13d, %esi
callq 0x22b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x380d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21a0
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x3848
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21a0
jmp 0x3848
jmp 0x3845
jmp 0x3845
jmp 0x3845
jmp 0x3845
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3863
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22c0