// File: schneebergerlab[P]DrLink/DrLink_v1.sp.cpp
// Function: main
int main(int argc, char* argv[])
{
    if(argc < 2)
    {
        cout << endl;
        cout << "   Given linked-read sequencing of recombinants, this tool identifies meiotic recombinations." << endl;
        const char *buildString = __DATE__ ", " __TIME__ "";
        cout << "   (version 1.0 - compiled on " << buildString << ")"                   << endl  << endl;
        cout << "   Usage: DrLink subprogram [options] "                                          << endl;
        cout << "\n   Subprograms: "                                                              << endl;
        cout << "   \tpreprocess \t(Usage: please check options with DrLink preprocess)"          << endl;  
        cout << "   \tmolecule   \t(Usage: please check options with DrLink molecule)"            << endl;
        cout << "   \trecombis   \t(Usage: please check options with DrLink recombis)"            << endl;
        cout << "   \tintersec   \t(Usage: please check options with DrLink intersec)"    << endl << endl;        
        exit(1);
    }
    double startT= clock();
    string subprogram = (string)argv[1];
    // step 1. select info from bam with samtools view
    if(subprogram.compare("preprocess")==0 && !convertBam(argc, argv))
    {
        if(argc < 4)
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: no bam info coverted - please check you bam file with BX? " << endl << endl;
        }
        return false;
    }
    // step 2. analyze molecules with the selected information
    if(subprogram.compare("molecule")==0 && !analyze_molecule(argc, argv))
    {
        if(argc < 6) 
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: failed in molecule analysis. " << endl << endl;
        }
        return false;
    }   
    // step 3. detect recombination sites with vcf and known markers
    if(subprogram.compare("recombis")==0 && !detect_recombsite(argc, argv))
    {
        if(argc < 13) 
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: failed in recombination site detection. " << endl << endl;
        }
        return false;
    }     
    // func 4. find intersection of two sets of recombination site predictions
    if(subprogram.compare("intersec")==0 && !find_intersection(argc, argv))
    {
        if(argc < 7) 
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: failed in finding intersection of the two predictions. " << endl << endl;
        }
        return false;
    }
    // func 5. sample molecules according to molecule size distribution (for >=2 pools)
    if(subprogram.compare("resample")==0 && !sample_molecule(argc, argv))
    {
        if(argc < 7) 
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: failed in sampling molecules. " << endl << endl;
        }
        return false;
    }    
    // func 6. sample molecules - with both size and base coverage
    if(subprogram.compare("separate_kb")==0 && !separate_kb_molecule(argc, argv))
    {
        if(argc < 5) 
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: failed in sampling molecules. " << endl << endl;
        }
        return false;
    }  
    // func 7. sample molecules according to base coverage distribution for 1kb,2kb,...
    if(subprogram.compare("resample_v2")==0 && !sample_molecule_v2(argc, argv))
    {
        if(argc < 8)
        {
            cout << "\n   Info: not enough inputs. "          << endl << endl;
        }
        else
        {
            cout << "   Error: failed in sampling molecules. " << endl << endl;
        }
        return false;
    }        
    //
    //
    double finishT= clock();
    cout << "   Time consumed: " << (finishT-startT)/1000000 << " seconds" << endl << endl;
    return 0;
}

// Assembly:
subq $0x1a8, %rsp            # imm = 0x1A8
movl $0x0, 0x1a4(%rsp)
movl %edi, 0x1a0(%rsp)
movq %rsi, 0x198(%rsp)
cmpl $0x2, 0x1a0(%rsp)
jge 0x5f88
movq 0x7f1b2(%rip), %rdi     # 0x84fc8
movq 0x7f193(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f19f(%rip), %rdi     # 0x84fc8
leaq 0x601e0(%rip), %rsi     # 0x66010
callq 0x5460
movq %rax, %rdi
movq 0x7f171(%rip), %rsi     # 0x84fb0
callq 0x54b0
leaq 0x60223(%rip), %rax     # 0x6606e
movq %rax, 0x190(%rsp)
movq 0x7f16e(%rip), %rdi     # 0x84fc8
leaq 0x60223(%rip), %rsi     # 0x66084
callq 0x5460
movq %rax, %rdi
movq 0x190(%rsp), %rsi
callq 0x5460
movq %rax, %rdi
leaq 0x64550(%rip), %rsi     # 0x6a3d0
callq 0x5460
movq %rax, %rdi
movq 0x7f121(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, %rdi
movq 0x7f112(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f11e(%rip), %rdi     # 0x84fc8
leaq 0x601f2(%rip), %rsi     # 0x660a3
callq 0x5460
movq %rax, %rdi
movq 0x7f0f0(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f0fc(%rip), %rdi     # 0x84fc8
leaq 0x601f7(%rip), %rsi     # 0x660ca
callq 0x5460
movq %rax, %rdi
movq 0x7f0ce(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f0da(%rip), %rdi     # 0x84fc8
leaq 0x601e7(%rip), %rsi     # 0x660dc
callq 0x5460
movq %rax, %rdi
movq 0x7f0ac(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f0b8(%rip), %rdi     # 0x84fc8
leaq 0x6020a(%rip), %rsi     # 0x66121
callq 0x5460
movq %rax, %rdi
movq 0x7f08a(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f096(%rip), %rdi     # 0x84fc8
leaq 0x6022b(%rip), %rsi     # 0x66164
callq 0x5460
movq %rax, %rdi
movq 0x7f068(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq 0x7f074(%rip), %rdi     # 0x84fc8
leaq 0x6024c(%rip), %rsi     # 0x661a7
callq 0x5460
movq %rax, %rdi
movq 0x7f046(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, %rdi
movq 0x7f037(%rip), %rsi     # 0x84fb0
callq 0x54b0
movl $0x1, %edi
callq 0x5540
callq 0x52e0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x188(%rsp)
movq 0x198(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x138(%rsp)
leaq 0x167(%rsp), %rdi
movq %rdi, 0x140(%rsp)
callq 0x57c0
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x168(%rsp), %rdi
callq 0x6880
jmp 0x5fe3
leaq 0x167(%rsp), %rdi
callq 0x54d0
leaq 0x168(%rsp), %rdi
leaq 0x601eb(%rip), %rsi     # 0x661ea
callq 0x5140
cmpl $0x0, %eax
jne 0x6159
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x6be0
movb %al, 0x137(%rsp)
jmp 0x602a
movb 0x137(%rsp), %al
testb $0x1, %al
jne 0x6159
jmp 0x603b
cmpl $0x4, 0x1a0(%rsp)
jge 0x60eb
movq 0x7ef78(%rip), %rdi     # 0x84fc8
leaq 0x6019e(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0x128(%rsp)
jmp 0x6066
movq 0x128(%rsp), %rdi
movq 0x7ef3b(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x120(%rsp)
jmp 0x6084
movq 0x120(%rsp), %rdi
movq 0x7ef1d(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x609a
jmp 0x613e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x167(%rsp), %rdi
callq 0x54d0
jmp 0x6868
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x58b8
jmp 0x6868
movq 0x7eed6(%rip), %rdi     # 0x84fc8
leaq 0x6011a(%rip), %rsi     # 0x66213
callq 0x5460
movq %rax, 0x118(%rsp)
jmp 0x6108
movq 0x118(%rsp), %rdi
movq 0x7ee99(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x110(%rsp)
jmp 0x6126
movq 0x110(%rsp), %rdi
movq 0x7ee7b(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x613c
jmp 0x613e
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
leaq 0x168(%rsp), %rdi
leaq 0x645da(%rip), %rsi     # 0x6a742
callq 0x5140
cmpl $0x0, %eax
jne 0x626f
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x8de0
movb %al, 0x10f(%rsp)
jmp 0x6193
movb 0x10f(%rsp), %al
testb $0x1, %al
jne 0x626f
jmp 0x61a4
cmpl $0x6, 0x1a0(%rsp)
jge 0x6201
movq 0x7ee13(%rip), %rdi     # 0x84fc8
leaq 0x60039(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0x100(%rsp)
jmp 0x61cb
movq 0x100(%rsp), %rdi
movq 0x7edd6(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0xf8(%rsp)
jmp 0x61e9
movq 0xf8(%rsp), %rdi
movq 0x7edb8(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x61ff
jmp 0x6254
movq 0x7edc0(%rip), %rdi     # 0x84fc8
leaq 0x60049(%rip), %rsi     # 0x66258
callq 0x5460
movq %rax, 0xf0(%rsp)
jmp 0x621e
movq 0xf0(%rsp), %rdi
movq 0x7ed83(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0xe8(%rsp)
jmp 0x623c
movq 0xe8(%rsp), %rdi
movq 0x7ed65(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6252
jmp 0x6254
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
leaq 0x168(%rsp), %rdi
leaq 0x60002(%rip), %rsi     # 0x66280
callq 0x5140
cmpl $0x0, %eax
jne 0x6385
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x19480
movb %al, 0xe7(%rsp)
jmp 0x62a9
movb 0xe7(%rsp), %al
testb $0x1, %al
jne 0x6385
jmp 0x62ba
cmpl $0xd, 0x1a0(%rsp)
jge 0x6317
movq 0x7ecfd(%rip), %rdi     # 0x84fc8
leaq 0x5ff23(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0xd8(%rsp)
jmp 0x62e1
movq 0xd8(%rsp), %rdi
movq 0x7ecc0(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0xd0(%rsp)
jmp 0x62ff
movq 0xd0(%rsp), %rdi
movq 0x7eca2(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6315
jmp 0x636a
movq 0x7ecaa(%rip), %rdi     # 0x84fc8
leaq 0x5ff64(%rip), %rsi     # 0x66289
callq 0x5460
movq %rax, 0xc8(%rsp)
jmp 0x6334
movq 0xc8(%rsp), %rdi
movq 0x7ec6d(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0xc0(%rsp)
jmp 0x6352
movq 0xc0(%rsp), %rdi
movq 0x7ec4f(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6368
jmp 0x636a
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
leaq 0x168(%rsp), %rdi
leaq 0x5ff28(%rip), %rsi     # 0x662bc
callq 0x5140
cmpl $0x0, %eax
jne 0x649b
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x3b0b0
movb %al, 0xbf(%rsp)
jmp 0x63bf
movb 0xbf(%rsp), %al
testb $0x1, %al
jne 0x649b
jmp 0x63d0
cmpl $0x7, 0x1a0(%rsp)
jge 0x642d
movq 0x7ebe7(%rip), %rdi     # 0x84fc8
leaq 0x5fe0d(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0xb0(%rsp)
jmp 0x63f7
movq 0xb0(%rsp), %rdi
movq 0x7ebaa(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0xa8(%rsp)
jmp 0x6415
movq 0xa8(%rsp), %rdi
movq 0x7eb8c(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x642b
jmp 0x6480
movq 0x7eb94(%rip), %rdi     # 0x84fc8
leaq 0x5fe8a(%rip), %rsi     # 0x662c5
callq 0x5460
movq %rax, 0xa0(%rsp)
jmp 0x644a
movq 0xa0(%rsp), %rdi
movq 0x7eb57(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x98(%rsp)
jmp 0x6468
movq 0x98(%rsp), %rdi
movq 0x7eb39(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x647e
jmp 0x6480
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
leaq 0x168(%rsp), %rdi
leaq 0x5fe5d(%rip), %rsi     # 0x66307
callq 0x5140
cmpl $0x0, %eax
jne 0x65a5
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x3ef90
movb %al, 0x97(%rsp)
jmp 0x64d5
movb 0x97(%rsp), %al
testb $0x1, %al
jne 0x65a5
jmp 0x64e6
cmpl $0x7, 0x1a0(%rsp)
jge 0x6543
movq 0x7ead1(%rip), %rdi     # 0x84fc8
leaq 0x5fcf7(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0x88(%rsp)
jmp 0x650d
movq 0x88(%rsp), %rdi
movq 0x7ea94(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x80(%rsp)
jmp 0x652b
movq 0x80(%rsp), %rdi
movq 0x7ea76(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6541
jmp 0x658a
movq 0x7ea7e(%rip), %rdi     # 0x84fc8
leaq 0x5fdbf(%rip), %rsi     # 0x66310
callq 0x5460
movq %rax, 0x78(%rsp)
jmp 0x655d
movq 0x78(%rsp), %rdi
movq 0x7ea47(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x70(%rsp)
jmp 0x6575
movq 0x70(%rsp), %rdi
movq 0x7ea2f(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6588
jmp 0x658a
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
leaq 0x168(%rsp), %rdi
leaq 0x6425b(%rip), %rsi     # 0x6a80f
callq 0x5140
cmpl $0x0, %eax
jne 0x669d
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x5c950
movb %al, 0x6f(%rsp)
jmp 0x65dc
movb 0x6f(%rsp), %al
testb $0x1, %al
jne 0x669d
jmp 0x65ea
cmpl $0x5, 0x1a0(%rsp)
jge 0x663b
movq 0x7e9cd(%rip), %rdi     # 0x84fc8
leaq 0x5fbf3(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0x60(%rsp)
jmp 0x660e
movq 0x60(%rsp), %rdi
movq 0x7e996(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x58(%rsp)
jmp 0x6626
movq 0x58(%rsp), %rdi
movq 0x7e97e(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6639
jmp 0x6682
movq 0x7e986(%rip), %rdi     # 0x84fc8
leaq 0x5fcc7(%rip), %rsi     # 0x66310
callq 0x5460
movq %rax, 0x50(%rsp)
jmp 0x6655
movq 0x50(%rsp), %rdi
movq 0x7e94f(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x48(%rsp)
jmp 0x666d
movq 0x48(%rsp), %rdi
movq 0x7e937(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6680
jmp 0x6682
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
leaq 0x168(%rsp), %rdi
leaq 0x5fc8d(%rip), %rsi     # 0x66339
callq 0x5140
cmpl $0x0, %eax
jne 0x6795
movl 0x1a0(%rsp), %edi
movq 0x198(%rsp), %rsi
callq 0x4ac60
movb %al, 0x47(%rsp)
jmp 0x66d4
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x6795
jmp 0x66e2
cmpl $0x8, 0x1a0(%rsp)
jge 0x6733
movq 0x7e8d5(%rip), %rdi     # 0x84fc8
leaq 0x5fafb(%rip), %rsi     # 0x661f5
callq 0x5460
movq %rax, 0x38(%rsp)
jmp 0x6706
movq 0x38(%rsp), %rdi
movq 0x7e89e(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x30(%rsp)
jmp 0x671e
movq 0x30(%rsp), %rdi
movq 0x7e886(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6731
jmp 0x677a
movq 0x7e88e(%rip), %rdi     # 0x84fc8
leaq 0x5fbcf(%rip), %rsi     # 0x66310
callq 0x5460
movq %rax, 0x28(%rsp)
jmp 0x674d
movq 0x28(%rsp), %rdi
movq 0x7e857(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, 0x20(%rsp)
jmp 0x6765
movq 0x20(%rsp), %rdi
movq 0x7e83f(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6778
jmp 0x677a
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
jmp 0x684c
callq 0x52e0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x148(%rsp)
movq 0x7e819(%rip), %rdi     # 0x84fc8
leaq 0x5fb8f(%rip), %rsi     # 0x66345
callq 0x5460
movq %rax, 0x18(%rsp)
jmp 0x67c2
movq 0x18(%rsp), %rdi
movsd 0x148(%rsp), %xmm0
movsd 0x188(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0x5f823(%rip), %xmm1    # 0x66008
divsd %xmm1, %xmm0
callq 0x5830
movq %rax, 0x10(%rsp)
jmp 0x67f5
movq 0x10(%rsp), %rdi
leaq 0x5fb57(%rip), %rsi     # 0x66358
callq 0x5460
movq %rax, 0x8(%rsp)
jmp 0x680d
movq 0x8(%rsp), %rdi
movq 0x7e797(%rip), %rsi     # 0x84fb0
callq 0x54b0
movq %rax, (%rsp)
jmp 0x6824
movq (%rsp), %rdi
movq 0x7e781(%rip), %rsi     # 0x84fb0
callq 0x54b0
jmp 0x6836
movl $0x0, 0x1a4(%rsp)
movl $0x1, 0x150(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x58b8
movl 0x1a4(%rsp), %eax
addq $0x1a8, %rsp            # imm = 0x1A8
retq
movq 0x158(%rsp), %rdi
callq 0x57b0
nopw %cs:(%rax,%rax)
nop