// File: 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
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x2d70
movq 0xb64c(%rip), %rdi      # 0xefc8
movq %rdi, -0x128(%rbp)
leaq 0x6736(%rip), %rsi      # 0xa0c0
callq 0x21d0
movq %rax, %rdi
movq 0xb617(%rip), %rsi      # 0xefb0
movq %rsi, -0x120(%rbp)
callq 0x2210
movq -0x128(%rbp), %rdi
leaq 0x6717(%rip), %rsi      # 0xa0ca
callq 0x21d0
movq %rax, %rdi
leaq 0x5f69996(%rip), %rsi   # 0x5f6d358
callq 0x21a0
movq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x2210
movq -0x128(%rbp), %rdi
leaq 0x66f3(%rip), %rsi      # 0xa0d7
callq 0x21d0
movq %rax, %rdi
movl 0xb822(%rip), %esi      # 0xf214
callq 0x2370
movq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x2210
movq -0x128(%rbp), %rdi
leaq 0x66cf(%rip), %rsi      # 0xa0e3
callq 0x21d0
movq %rax, %rdi
movl 0xb7fa(%rip), %esi      # 0xf21c
callq 0x2370
movq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x2210
movq -0x128(%rbp), %rdi
leaq 0x66ad(%rip), %rsi      # 0xa0f1
callq 0x21d0
movq %rax, %rdi
movl 0xb7c6(%rip), %esi      # 0xf218
callq 0x2370
movq -0x120(%rbp), %rsi
movq %rax, %rdi
callq 0x2210
callq 0x2120
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x3030
movq -0x118(%rbp), %rdi
callq 0x2140
movl %eax, -0x3c(%rbp)
movq 0xb555(%rip), %rdi      # 0xeff0
leaq 0x665e(%rip), %rsi      # 0xa100
callq 0x21d0
movq %rax, -0x110(%rbp)
jmp 0x3ab0
movq -0x110(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2370
movq %rax, -0x130(%rbp)
jmp 0x3ac8
movq -0x130(%rbp), %rdi
movq 0xb4da(%rip), %rsi      # 0xefb0
callq 0x2210
jmp 0x3add
leaq 0x5f69894(%rip), %rsi   # 0x5f6d378
leaq -0x78(%rbp), %rdi
callq 0x20c0
jmp 0x3aef
leaq -0x99(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x2390
movq -0x138(%rbp), %rdx
leaq 0x660a(%rip), %rsi      # 0xa11a
leaq -0x98(%rbp), %rdi
callq 0x44d0
jmp 0x3b1e
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x2b10
movq %rax, -0x140(%rbp)
jmp 0x3b37
leaq -0x98(%rbp), %rdi
callq 0x2408
leaq -0x99(%rbp), %rdi
callq 0x2230
leaq -0x78(%rbp), %rdi
callq 0x2408
movq -0x140(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0xffffffff, -0xa0(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0xac(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x3f73
leaq -0xac(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4990
movq %rax, -0x148(%rbp)
jmp 0x3bb6
movq -0x148(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %ecx
movl -0x3c(%rbp), %edx
movb $0x0, -0xc9(%rbp)
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x149(%rbp)
jge 0x3c29
movl -0x3c(%rbp), %edx
movl -0xa8(%rbp), %ecx
movl -0xac(%rbp), %r8d
leaq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3350
jmp 0x3c03
movb $0x1, -0xc9(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x4290
movslq 0xb5f7(%rip), %rcx      # 0xf214
cmpq %rcx, %rax
setae %al
movb %al, -0x149(%rbp)
movb -0x149(%rbp), %al
movb %al, -0x14a(%rbp)
testb $0x1, -0xc9(%rbp)
jne 0x3c40
jmp 0x3c4c
leaq -0xc8(%rbp), %rdi
callq 0x4340
movb -0x14a(%rbp), %al
testb $0x1, %al
jne 0x3c58
jmp 0x3cbd
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x3bc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x4097
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3ca3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x2408
leaq -0x99(%rbp), %rdi
callq 0x2230
leaq -0x78(%rbp), %rdi
callq 0x2408
jmp 0x4097
movl -0xac(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jle 0x3f5d
movl -0xac(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0xac(%rbp), %eax
subl -0xa8(%rbp), %eax
cmpl 0xb52f(%rip), %eax      # 0xf21c
jge 0x3cf4
jmp 0x3f5f
movl -0x3c(%rbp), %edx
movl -0xa8(%rbp), %ecx
movl -0xac(%rbp), %r8d
decl %r8d
leaq -0xe8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3350
jmp 0x3d19
movq -0x58(%rbp), %rdi
movl -0xa8(%rbp), %edx
movl -0xac(%rbp), %ecx
subl $0x1, %ecx
leaq 0x63fb(%rip), %rsi      # 0xa12e
movb $0x0, %al
callq 0x22d0
movl -0xa8(%rbp), %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %eax
cmpl -0xac(%rbp), %eax
jge 0x3dc5
movq -0x58(%rbp), %rax
movq %rax, -0x160(%rbp)
movslq -0xec(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x23f0
movq %rax, -0x158(%rbp)
jmp 0x3d78
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rax
movsbl (%rax), %edx
leaq 0x638c(%rip), %rsi      # 0xa11c
movb $0x0, %al
callq 0x22d0
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x3d46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4340
jmp 0x4097
movq -0x58(%rbp), %rdi
leaq 0x635b(%rip), %rsi      # 0xa12b
movb $0x0, %al
callq 0x22d0
movq -0x58(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4290
movq -0x168(%rbp), %rdi
movq %rax, %rdx
leaq 0x6320(%rip), %rsi      # 0xa11f
movb $0x0, %al
callq 0x22d0
leaq -0xe8(%rbp), %rdi
callq 0x4100
movq %rax, -0xf8(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4130
movq %rax, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x4ad0
testb $0x1, %al
jne 0x3e48
jmp 0x3f42
movq -0x58(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x4b10
movl (%rax), %eax
movl %eax, -0x16c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x4b10
movq -0x178(%rbp), %rdi
movl -0x16c(%rbp), %edx
movl 0x4(%rax), %ecx
leaq 0x62a3(%rip), %rsi      # 0xa12d
movb $0x0, %al
callq 0x22d0
leaq -0xf8(%rbp), %rdi
callq 0x4b10
movl (%rax), %eax
movl %eax, -0x104(%rbp)
movl -0x104(%rbp), %eax
movl %eax, -0x17c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x4b10
movq %rax, %rcx
movl -0x17c(%rbp), %eax
cmpl 0x4(%rcx), %eax
jg 0x3f1f
movq -0x58(%rbp), %rax
movq %rax, -0x190(%rbp)
movslq -0x104(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x23f0
movq %rax, -0x188(%rbp)
jmp 0x3eef
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rax
movsbl (%rax), %edx
leaq 0x6215(%rip), %rsi      # 0xa11c
movb $0x0, %al
callq 0x22d0
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x3ea5
movq -0x58(%rbp), %rdi
leaq 0x6201(%rip), %rsi      # 0xa12b
movb $0x0, %al
callq 0x22d0
leaq -0xf8(%rbp), %rdi
callq 0x4b30
jmp 0x3e19
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4340
jmp 0x3f5f
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x3b8b
movq 0xb076(%rip), %rdi      # 0xeff0
leaq 0x61b4(%rip), %rsi      # 0xa135
callq 0x21d0
movq %rax, -0x198(%rbp)
jmp 0x3f8f
movq -0x198(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x2370
movq %rax, -0x1a0(%rbp)
jmp 0x3faa
movq -0x1a0(%rbp), %rdi
movq 0xaff8(%rip), %rsi      # 0xefb0
callq 0x2210
jmp 0x3fbf
movq -0x58(%rbp), %rdi
callq 0x21e0
jmp 0x3fca
movq 0xaff7(%rip), %rdi      # 0xefc8
leaq 0x6177(%rip), %rsi      # 0xa14f
callq 0x21d0
movq %rax, -0x1a8(%rbp)
jmp 0x3fe6
callq 0x2120
movq -0x1a8(%rbp), %rdi
cvtsi2sd %rax, %xmm0
movsd -0x18(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd 0x6000(%rip), %xmm1     # 0xa008
divsd %xmm1, %xmm0
callq 0x23b0
movq %rax, -0x1b0(%rbp)
jmp 0x401a
movq -0x1b0(%rbp), %rdi
movq 0xaf88(%rip), %rsi      # 0xefb0
callq 0x2210
jmp 0x402f
movq 0xaf92(%rip), %rdi      # 0xefc8
leaq 0x6121(%rip), %rsi      # 0xa15e
callq 0x21d0
movq %rax, -0x1b8(%rbp)
jmp 0x404b
movq -0x1b8(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x2370
movq %rax, -0x1c0(%rbp)
jmp 0x4066
movq -0x1c0(%rbp), %rdi
movq 0xaf3c(%rip), %rsi      # 0xefb0
callq 0x2210
jmp 0x407b
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2408
movl -0x4(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x2408
movq -0x48(%rbp), %rdi
callq 0x2380
nopl (%rax)