// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
callq 0x2815
movq 0x50ff(%rip), %rbx      # 0x7fc8
leaq 0x21f0(%rip), %rsi      # 0x50c0
movq %rbx, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x2090
leaq 0x21e3(%rip), %rsi      # 0x50ca
movq %rbx, %rdi
callq 0x2140
leaq 0x5f633e2(%rip), %rsi   # 0x5f662d8
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x2090
leaq 0x21ca(%rip), %rsi      # 0x50d7
movq %rbx, %rdi
callq 0x2140
movl 0x5279(%rip), %esi      # 0x8194
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x2090
leaq 0x21b1(%rip), %rsi      # 0x50e3
movq %rbx, %rdi
callq 0x2140
movl 0x525c(%rip), %esi      # 0x819c
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x2090
leaq 0x219a(%rip), %rsi      # 0x50f1
movq %rbx, %rdi
callq 0x2140
movl 0x5233(%rip), %esi      # 0x8198
movq %rax, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x2090
callq 0x20c0
movq %rax, %rbx
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0x29a5
movl 0x8(%r14), %ebp
movq 0x505b(%rip), %rdi      # 0x7ff0
leaq 0x2164(%rip), %rsi      # 0x5100
callq 0x2140
movq %rax, %rdi
movl %ebp, %esi
callq 0x2290
movq %rax, %rdi
callq 0x2090
leaq 0x5f6333e(%rip), %rsi   # 0x5f662f8
leaq 0x58(%rsp), %rdi
callq 0x21d0
leaq 0x214f(%rip), %rsi      # 0x511a
leaq 0x78(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3322
cvtsi2sd %rbx, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x58(%rsp), %rbx
leaq 0x78(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x26dd
movq %rax, %r14
movq %r15, %rdi
callq 0x2308
movq %rbx, %rdi
callq 0x2308
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movq %rax, 0x30(%rsp)
pushq $-0x1
popq %rax
movl %eax, (%rsp)
leaq 0x8(%rsp), %r15
movq $0x0, 0x20(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
movl $0x0, 0x4(%rsp)
cmpq 0x30(%rsp), %rbx
je 0x31a9
cmpl %ebx, %r13d
cmovlel %ebx, %r13d
cmpl %ebp, %r13d
jge 0x3096
movq %r15, %rdi
leaq 0x38(%rsp), %rsi
movl %ebp, %edx
movl %ebx, %ecx
movl %r13d, %r8d
callq 0x2b0f
movq 0x10(%rsp), %r15
subq 0x8(%rsp), %r15
sarq $0x3, %r15
movslq 0x5117(%rip), %r12      # 0x8194
leaq 0x8(%rsp), %rdi
callq 0x3bfe
cmpq %r12, %r15
leaq 0x8(%rsp), %r15
jb 0x3096
incq %r13
jmp 0x304f
cmpl (%rsp), %r13d
jle 0x319c
movq 0x20(%rsp), %rax
addl %r13d, %eax
cmpl 0x50ee(%rip), %eax      # 0x819c
jl 0x3198
leaq -0x1(%r13), %r12
movq %r15, %rdi
leaq 0x38(%rsp), %rsi
movl %ebp, %edx
movl %ebx, %ecx
movl %r12d, %r8d
callq 0x2b0f
movq %r14, %rdi
leaq 0x2055(%rip), %rsi      # 0x512b
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x21f0
movq %rbx, %r15
cmpq %r13, %r15
jae 0x3101
movq 0x38(%rsp), %rax
movsbl (%rax,%r15), %edi
movq %r14, %rsi
callq 0x21a0
incq %r15
jmp 0x30e5
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x21a0
movq 0x10(%rsp), %rdx
subq 0x8(%rsp), %rdx
sarq $0x3, %rdx
movq %r14, %rdi
leaq 0x1ff8(%rip), %rsi      # 0x511c
xorl %eax, %eax
callq 0x21f0
movq 0x8(%rsp), %r12
cmpq 0x10(%rsp), %r12
je 0x3187
movl (%r12), %edx
movl 0x4(%r12), %ecx
movq %r14, %rdi
leaq 0x1fe0(%rip), %rsi      # 0x512a
xorl %eax, %eax
callq 0x21f0
movslq (%r12), %r15
movslq 0x4(%r12), %rax
cmpq %rax, %r15
jg 0x3176
movq 0x38(%rsp), %rax
movsbl (%rax,%r15), %edi
movq %r14, %rsi
callq 0x21a0
incq %r15
jmp 0x3155
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x21a0
addq $0x8, %r12
jmp 0x3130
incl 0x4(%rsp)
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x3bfe
movl %r13d, (%rsp)
incq %rbx
decq 0x20(%rsp)
jmp 0x303d
movq 0x4e40(%rip), %rdi      # 0x7ff0
leaq 0x1f7b(%rip), %rsi      # 0x5132
callq 0x2140
movl 0x4(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x2290
movq %rax, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2150
movq 0x4de7(%rip), %rdi      # 0x7fc8
leaq 0x1f64(%rip), %rsi      # 0x514c
callq 0x2140
movq %rax, %rbx
callq 0x20c0
cvtsi2sd %rax, %xmm0
subsd 0x28(%rsp), %xmm0
divsd 0x1e00(%rip), %xmm0     # 0x5008
movq %rbx, %rdi
callq 0x2260
movq %rax, %rdi
callq 0x2090
movq 0x4da9(%rip), %rdi      # 0x7fc8
leaq 0x1f35(%rip), %rsi      # 0x515b
callq 0x2140
movq %rax, %rdi
movl %ebp, %esi
callq 0x2290
movq %rax, %rdi
callq 0x2090
leaq 0x38(%rsp), %rdi
callq 0x2308
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x2308
jmp 0x3275
jmp 0x3272
jmp 0x3272
jmp 0x3272
jmp 0x3272
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2308
movq %rbx, %rdi
callq 0x22a0
nop