// File: /workspace/github_cpp_makefile_star2_O1/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 0x2bc5
movq 0x9469(%rip), %rbx      # 0xdfc8
leaq 0x55bb(%rip), %rsi      # 0xa121
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x558a(%rip), %rsi      # 0xa12b
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2210
movq 0x5f67753(%rip), %rsi   # 0x5f6c308
movq 0x5f67754(%rip), %rdx   # 0x5f6c310
movq %rbx, %rdi
callq 0x2210
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x5543(%rip), %rsi      # 0xa138
movl $0xb, %edx
movq %rbx, %rdi
callq 0x2210
movl 0x95c4(%rip), %esi      # 0xe1cc
movq %rbx, %rdi
callq 0x2320
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x5503(%rip), %rsi      # 0xa144
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2210
movl 0x9580(%rip), %esi      # 0xe1d4
movq %rbx, %rdi
callq 0x2320
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x54c5(%rip), %rsi      # 0xa152
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2210
movl 0x9530(%rip), %esi      # 0xe1d0
movq %rbx, %rdi
callq 0x2320
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
callq 0x2120
movq %rax, %r12
leaq 0x38(%rsp), %rdi
callq 0x2df7
movq 0x9305(%rip), %rdi      # 0xdff0
leaq 0x546f(%rip), %rsi      # 0xa161
movl $0x4, %edx
callq 0x2210
movq 0x40(%rsp), %rsi
movq 0x92e8(%rip), %rdi      # 0xdff0
callq 0x2130
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0x38, %edi
callq 0x21e0
movq %rax, %r14
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x38(%rsp), %rsi
movq 0x8(%rsp), %rax
leaq (%rsi,%rax), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x78c4
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x589c
movq %r14, 0x5f675dc(%rip)   # 0x5f6c368
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x4da9
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
testq %rcx, %rcx
setne %dl
addq %rax, %rcx
decq %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4ded
incq %rax
movb -0x1(%rax), %dl
movb (%rcx), %sil
movb %sil, -0x1(%rax)
movb %dl, (%rcx)
decq %rcx
leaq 0x1(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0x4dd2
movl $0x38, %edi
callq 0x21e0
movq %rax, %r14
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x78c4
leaq 0x98(%rsp), %rsi
movq %r14, %rdi
callq 0x589c
movq %r14, 0x5f67539(%rip)   # 0x5f6c370
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x4e54
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
testq %rcx, %rcx
setne %dl
addq %rax, %rcx
decq %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4e98
incq %rax
movb -0x1(%rax), %dl
movb (%rcx), %sil
movb %sil, -0x1(%rax)
movb %dl, (%rcx)
decq %rcx
leaq 0x1(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0x4e7d
movq 0x5f674b1(%rip), %rbx   # 0x5f6c350
movq 0x40(%rsp), %rsi
incq %rsi
leaq 0x58(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x5632
leaq 0x5f674b0(%rip), %rdi   # 0x5f6c378
leaq 0x18(%rsp), %rdx
movq %rbx, %rsi
callq 0x5bb2
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x4eec
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpq $0x0, 0x40(%rsp)
je 0x4f5a
xorl %r14d, %r14d
leaq 0x5f6744a(%rip), %rbx   # 0x5f6c348
movq 0x5f6744b(%rip), %rax   # 0x5f6c350
testq %rax, %rax
je 0x4f26
movq 0x5f67467(%rip), %rcx   # 0x5f6c378
movq (%rcx), %rdx
movl (%rdx,%r14,4), %esi
movl %esi, 0x4(%rdx,%r14,4)
addq $0x18, %rcx
decq %rax
jne 0x4f11
movq 0x38(%rsp), %rax
movsbl (%rax,%r14), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2250
cltq
movq 0x5f67435(%rip), %rcx   # 0x5f6c378
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
incl 0x4(%rax,%r14,4)
incq %r14
cmpq %r14, 0x40(%rsp)
ja 0x4efe
movq 0x908f(%rip), %rbx      # 0xdff0
leaq 0x51fe(%rip), %rsi      # 0xa166
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x905d(%rip), %rdi      # 0xdff0
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq %r12, 0x70(%rsp)
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x5f67370(%rip), %rsi   # 0x5f6c328
movq 0x5f67371(%rip), %rdx   # 0x5f6c330
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x78c4
leaq 0xe8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x519a(%rip), %rsi      # 0xa17a
leaq 0x5194(%rip), %rdx      # 0xa17b
leaq 0xd8(%rsp), %rdi
callq 0x809c
leaq 0x78(%rsp), %rdi
leaq 0xd8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2a69
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r12, %rdi
je 0x5024
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x503e
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21f0
movl 0x9190(%rip), %eax      # 0xe1d4
decl %eax
movslq %eax, %rcx
movl $0x0, 0x10(%rsp)
cmpq %rcx, 0x8(%rsp)
jbe 0x5257
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
leaq 0x58(%rsp), %rbx
xorl %r15d, %r15d
movl $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movl %r12d, %ecx
cmpl %eax, %r12d
movl %eax, %r12d
cmovgl %ecx, %r12d
leaq 0x5f67305(%rip), %rdi   # 0x5f6c390
callq 0x5d2e
leaq 0x18(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x422a
movl %r12d, %eax
cmpq %rax, 0x8(%rsp)
jbe 0x5128
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
sarq $0x3, %rax
movslq 0x910d(%rip), %rcx      # 0xe1cc
cmpq %rcx, %rax
jb 0x5128
leaq 0x5f672fd(%rip), %rdi   # 0x5f6c3c8
callq 0x5d2e
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x422a
movq 0x60(%rsp), %r13
subq 0x58(%rsp), %r13
sarq $0x3, %r13
movslq 0x90d9(%rip), %rbp      # 0xe1cc
cmpq %rbp, %r13
jb 0x5108
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x5bf4
incl %r12d
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x511f
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
cmpq %rbp, %r13
jae 0x50a0
cmpl 0x34(%rsp), %r12d
jle 0x5226
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
sarq $0x3, %rax
movslq 0x9084(%rip), %rcx      # 0xe1cc
cmpq %rcx, %rax
jb 0x5226
leal -0x1(%r12), %ecx
movq %r14, %rdi
leaq 0x502b(%rip), %rsi      # 0xa18b
movl %r15d, %edx
xorl %eax, %eax
callq 0x2270
cmpl %r15d, %r12d
jle 0x518e
movl %r12d, %r13d
movq %r15, %rbp
movq 0x38(%rsp), %rax
movsbl (%rax,%rbp), %edi
movq %r14, %rsi
callq 0x2240
incq %rbp
cmpq %rbp, %r13
jne 0x5175
movl $0xa, %edi
movq %r14, %rsi
callq 0x2240
movq 0x20(%rsp), %rdx
subq 0x18(%rsp), %rdx
sarq $0x3, %rdx
movq %r14, %rdi
leaq 0x4fc9(%rip), %rsi      # 0xa17c
xorl %eax, %eax
callq 0x2270
movq 0x18(%rsp), %r13
cmpq 0x20(%rsp), %r13
je 0x521d
movl (%r13), %edx
movl 0x4(%r13), %ecx
movq %r14, %rdi
leaq 0x4fb2(%rip), %rsi      # 0xa18a
xorl %eax, %eax
callq 0x2270
movslq (%r13), %rbp
cmpl 0x4(%r13), %ebp
jg 0x520a
decq %rbp
movq 0x38(%rsp), %rax
movsbl 0x1(%rax,%rbp), %edi
movq %r14, %rsi
callq 0x2240
movslq 0x4(%r13), %rax
incq %rbp
cmpq %rax, %rbp
jl 0x51ec
movl $0xa, %edi
movq %r14, %rsi
callq 0x2240
addq $0x8, %r13
jmp 0x51bf
incl 0x10(%rsp)
movl %r12d, 0x34(%rsp)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x523d
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movl 0x8f91(%rip), %eax      # 0xe1d4
addl %r15d, %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, 0x8(%rsp)
ja 0x5077
movq 0x8d92(%rip), %rdi      # 0xdff0
leaq 0x4f2d(%rip), %rsi      # 0xa192
movl $0x19, %edx
callq 0x2210
movl 0x10(%rsp), %ebp
movq 0x8d76(%rip), %rdi      # 0xdff0
movl %ebp, %esi
callq 0x2320
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x8d3e(%rip), %rdi      # 0xdff0
leaq 0x4ef3(%rip), %rsi      # 0xa1ac
movl $0xa, %edx
callq 0x2210
movl 0x5f67137(%rip), %esi   # 0x5f6c400
movq 0x8d20(%rip), %rdi      # 0xdff0
callq 0x2320
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq %r14, %rdi
callq 0x21d0
movq 0x8cba(%rip), %rdi      # 0xdfc8
leaq 0x4ea2(%rip), %rsi      # 0xa1b7
movl $0xe, %edx
callq 0x2210
cvtsi2sdq 0x70(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x2120
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subsd 0x8(%rsp), %xmm0
divsd 0x4cc1(%rip), %xmm0     # 0xa008
movq 0x8c7a(%rip), %rdi      # 0xdfc8
callq 0x22f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x8c44(%rip), %rdi      # 0xdfc8
leaq 0x4e3b(%rip), %rsi      # 0xa1c6
movl $0xf, %edx
callq 0x2210
movq 0x8c2c(%rip), %rdi      # 0xdfc8
movl %ebp, %esi
callq 0x2320
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x53e8
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x54af
movq 0x88(%rsp), %rsi
incq %rsi
jmp 0x54aa
jmp 0x5474
jmp 0x5495
jmp 0x5474
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x5464
movq 0xa8(%rsp), %rsi
jmp 0x5457
jmp 0x5461
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x5464
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x5464
movq %rax, %rbx
movl $0x38, %esi
movq %r14, %rdi
jmp 0x54aa
jmp 0x5474
jmp 0x5474
jmp 0x5474
movq %rax, %rbx
jmp 0x54af
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5498
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
jmp 0x5498
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x54af
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x54ca
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330