// File: /workspace/github_cpp_makefile_star2_O2/shangjingbo1226[P]MACFP/src/methods/MACFP.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();

    cerr << "n = " << dna.size() << endl;

    size_t n = dna.size();

    s = new String(dna);
    reverse(dna.begin(), dna.end());
    rev_s = new String(dna);
    reverse(dna.begin(), dna.end());

    prefixSum.resize(alphabet.size(), vector<int>(dna.size() + 1, 0));
    for (int i = 0; i < dna.size(); ++ i) {
        for (int j = 0; j < alphabet.size(); ++ j) {
            prefixSum[j][i + 1] = prefixSum[j][i];
        }
        int index = alphabet.find(dna[i]);
        prefixSum[index][i + 1] += 1;
    }

    cerr << "initialization done" << endl;

    FILE* out = tryOpen(OUTPUT_FILENAME, "w");
    int lastJ = -1;
    int cnt = 0;
    for (int i = 0, j = 0; i + LEN_THRES - 1 < n; ++ i) {
        j = max(j, i + LEN_THRES - 1);

        bufferLeft.clear();
        vector<PII> sup = getSup(i, j);
        while (j < n && sup.size() >= MIN_SUP) {
            bufferRight.clear();
            vector<PII> newSup = getSup(i, j);
            if (newSup.size() >= MIN_SUP) {
                sup = newSup;
                ++ j;
            } else {
                break;
            }
        }

        if (j > lastJ && sup.size() >= MIN_SUP) {
            //cerr << i << " " << j - 1 << endl;
            lastJ = j;
            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", sup.size());
            FOR (pair, sup) {
                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;
    cerr << "counter = " << counter << 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 $0xf8, %rsp
callq 0x29c5
movq 0x9d78(%rip), %rbx      # 0xdfc8
leaq 0x4ecf(%rip), %rsi      # 0x9126
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x20b0
leaq 0x4ec2(%rip), %rsi      # 0x9130
movq %rbx, %rdi
callq 0x2190
leaq 0x5f6808b(%rip), %rsi   # 0x5f6c308
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
leaq 0x4ea9(%rip), %rsi      # 0x913d
movq %rbx, %rdi
callq 0x2190
movl 0x9f2a(%rip), %esi      # 0xe1cc
movq %rax, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x20b0
leaq 0x4e90(%rip), %rsi      # 0x9149
movq %rbx, %rdi
callq 0x2190
movl 0x9f0d(%rip), %esi      # 0xe1d4
movq %rax, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x20b0
leaq 0x4e79(%rip), %rsi      # 0x9157
movq %rbx, %rdi
callq 0x2190
movl 0x9ee4(%rip), %esi      # 0xe1d0
movq %rax, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x20b0
callq 0x20f0
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2b55
movq 0x9cdb(%rip), %rdi      # 0xdff0
leaq 0x4e4a(%rip), %rsi      # 0x9166
callq 0x2190
movq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x20b0
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
pushq $0x38
popq %rdi
callq 0x21b0
movq %rax, %r14
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2240
leaq 0x98(%rsp), %rsi
movq %r14, %rdi
callq 0x4bea
movq %r14, 0x5f67ff4(%rip)   # 0x5f6c368
leaq 0x98(%rsp), %rdi
callq 0x2378
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq %rdi, %rsi
callq 0x854e
pushq $0x38
popq %rdi
callq 0x21b0
movq %rax, %r14
leaq 0x78(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2240
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x4bea
movq %r14, 0x5f67faf(%rip)   # 0x5f6c370
leaq 0x78(%rsp), %rdi
callq 0x2378
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
addq %rdi, %rsi
callq 0x854e
movq 0x5f67f6c(%rip), %r14   # 0x5f6c350
movq 0x40(%rsp), %rsi
incq %rsi
leaq 0x60(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x4970
leaq 0x5f67f6e(%rip), %rdi   # 0x5f6c378
leaq 0x18(%rsp), %rdx
movq %r14, %rsi
callq 0x4e26
cvtsi2sd %rbx, %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x66a2
xorl %r14d, %r14d
leaq 0x5f67f12(%rip), %rbx   # 0x5f6c348
cmpq %r14, 0x40(%rsp)
jbe 0x4492
movq 0x5f67f0c(%rip), %rax   # 0x5f6c350
movq 0x5f67f2d(%rip), %rcx   # 0x5f6c378
subq $0x1, %rax
jb 0x4463
movq (%rcx), %rdx
movl (%rdx,%r14,4), %esi
movl %esi, 0x4(%rdx,%r14,4)
addq $0x18, %rcx
jmp 0x444b
movq 0x38(%rsp), %rax
movsbl (%rax,%r14), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2220
cltq
movq 0x5f67ef8(%rip), %rcx   # 0x5f6c378
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
incl 0x4(%rax,%r14,4)
incq %r14
jmp 0x4436
movq 0x9b57(%rip), %rdi      # 0xdff0
leaq 0x4ccb(%rip), %rsi      # 0x916b
callq 0x2190
movq %rax, %rdi
callq 0x20b0
leaq 0x5f67e74(%rip), %rsi   # 0x5f6c328
leaq 0xb8(%rsp), %rdi
callq 0x2240
leaq 0x4cb7(%rip), %rsi      # 0x917f
leaq 0xd8(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x48da
leaq 0xb8(%rsp), %rbx
leaq 0xd8(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x288d
movq %rax, %r14
movq %r12, %rdi
callq 0x2378
movq %rbx, %rdi
callq 0x2378
pushq $-0x1
popq %rax
movl %eax, 0x14(%rsp)
leaq 0x60(%rsp), %rbp
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x0, 0x10(%rsp)
movl 0x9cac(%rip), %eax      # 0xe1d4
addl %r12d, %eax
decl %eax
movslq %eax, %rcx
cmpq %rcx, 0x30(%rsp)
jbe 0x46d8
cmpl %eax, %r13d
cmovlel %eax, %r13d
leaq 0x5f67e47(%rip), %rdi   # 0x5f6c390
callq 0x4f3e
leaq 0x18(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x3adf
movl %r13d, %eax
cmpq %rax, 0x30(%rsp)
jbe 0x45d3
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
sarq $0x3, %rax
movslq 0x9c4f(%rip), %rcx      # 0xe1cc
cmpq %rcx, %rax
jb 0x45d3
leaq 0x5f67e3f(%rip), %rdi   # 0x5f6c3c8
callq 0x4f3e
movq %rbp, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x3adf
movq 0x68(%rsp), %rbx
subq 0x60(%rsp), %rbx
sarq $0x3, %rbx
movslq 0x9c1b(%rip), %r15      # 0xe1cc
cmpq %r15, %rbx
jb 0x45c6
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x4e62
incl %r13d
movq %rbp, %rdi
callq 0x733a
cmpq %r15, %rbx
jae 0x455e
cmpl 0x14(%rsp), %r13d
jle 0x46c6
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
sarq $0x3, %rax
movslq 0x9bd9(%rip), %rcx      # 0xe1cc
cmpq %rcx, %rax
jb 0x46c6
leal -0x1(%r13), %ecx
movq %r14, %rdi
leaq 0x4b86(%rip), %rsi      # 0x9190
movl %r12d, %edx
xorl %eax, %eax
callq 0x2260
cmpl %r12d, %r13d
movl %r12d, %ebx
cmovgl %r13d, %ebx
movq %r12, %r15
cmpq %r15, %rbx
je 0x463d
movq 0x38(%rsp), %rax
movsbl (%rax,%r15), %edi
movq %r14, %rsi
callq 0x2200
incq %r15
jmp 0x4621
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x2200
movq 0x20(%rsp), %rdx
subq 0x18(%rsp), %rdx
sarq $0x3, %rdx
movq %r14, %rdi
leaq 0x4b21(%rip), %rsi      # 0x9181
xorl %eax, %eax
callq 0x2260
movq 0x18(%rsp), %rbx
cmpq 0x20(%rsp), %rbx
je 0x46bd
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
movq %r14, %rdi
leaq 0x4b0d(%rip), %rsi      # 0x918f
xorl %eax, %eax
callq 0x2260
movslq (%rbx), %r15
movslq 0x4(%rbx), %rax
cmpq %rax, %r15
jg 0x46ac
movq 0x38(%rsp), %rax
movsbl (%rax,%r15), %edi
movq %r14, %rsi
callq 0x2200
incq %r15
jmp 0x468c
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x2200
addq $0x8, %rbx
jmp 0x466c
incl 0x10(%rsp)
movl %r13d, 0x14(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x733a
incq %r12
jmp 0x4522
movq 0x9911(%rip), %rdi      # 0xdff0
leaq 0x4ab1(%rip), %rsi      # 0x9197
callq 0x2190
movl 0x10(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x2300
movq %rax, %rdi
callq 0x20b0
movq 0x98e8(%rip), %rdi      # 0xdff0
leaq 0x4aa2(%rip), %rsi      # 0x91b1
callq 0x2190
movl 0x5f67ce6(%rip), %esi   # 0x5f6c400
movq %rax, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x21a0
movq 0x988f(%rip), %rdi      # 0xdfc8
leaq 0x4a7c(%rip), %rsi      # 0x91bc
callq 0x2190
movq %rax, %rbx
callq 0x20f0
cvtsi2sd %rax, %xmm0
subsd 0x58(%rsp), %xmm0
divsd 0x48a8(%rip), %xmm0     # 0x9008
movq %rbx, %rdi
callq 0x22d0
movq %rax, %rdi
callq 0x20b0
movq 0x9851(%rip), %rdi      # 0xdfc8
leaq 0x4a4d(%rip), %rsi      # 0x91cb
callq 0x2190
movq %rax, %rdi
movl %ebp, %esi
callq 0x2300
movq %rax, %rdi
callq 0x20b0
leaq 0x38(%rsp), %rdi
callq 0x2378
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x2378
jmp 0x482d
jmp 0x480c
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x66a2
jmp 0x482d
jmp 0x480c
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x47ef
jmp 0x47f6
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2378
jmp 0x47f9
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r14, %rdi
callq 0x21c0
jmp 0x482d
jmp 0x480c
jmp 0x480c
jmp 0x480c
movq %rax, %rbx
jmp 0x482d
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x733a
jmp 0x4823
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x733a
leaq 0x38(%rsp), %rdi
callq 0x2378
movq %rbx, %rdi
callq 0x2310
nop