// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/blatSrc/blat.c
// Function: main
int main(int argc, char *argv[])
/* Process command line into global variables and call blat. */
{
    boolean tIsProtLike, qIsProtLike;
    char buf[1024];
    char **queryFiles;
    FILE **out;
    struct lineFile **lf;
    int  queryCount;
    int  i, cnt, tmp;

    unsigned faFastBufSize = 0;
    DNA      *faFastBuf = NULL;

#ifdef DEBUG
    {
        char *cmd = "blat hCrea.geno hCrea.mrna foo.psl -t=dnax -q=rnax";
        char *words[16];

        printf("Debugging parameters\n");
        cmd = cloneString(cmd);
        argc = chopLine(cmd, words);
        argv = words;
    }
#endif /* DEBUG */

    optionInit(&argc, argv, options);
    if (argc != 4)
        usage();

    /* Get database and query sequence types and make sure they are
     * legal and compatable. */
    if (optionExists("prot"))
        qType = tType = gftProt;
    if (optionExists("t"))
        tType = gfTypeFromName(optionVal("t", NULL));
    trimA = optionExists("trimA") || optionExists("trima");
    trimT = optionExists("trimT") || optionExists("trimt");
    trimHardA = optionExists("trimHardA");
    switch (tType)
    {
    case gftProt:
    case gftDnaX:
        tIsProtLike = TRUE;
        break;
    case gftDna:
        tIsProtLike = FALSE;
        break;
    default:
        tIsProtLike = FALSE;
        errAbort("Illegal value for 't' parameter");
        break;
    }
    if (optionExists("q"))
        qType = gfTypeFromName(optionVal("q", NULL));
    if (qType == gftRnaX || qType == gftRna)
        trimA = TRUE;
    if (optionExists("noTrimA"))
        trimA = FALSE;
    switch (qType)
    {
    case gftProt:
    case gftDnaX:
    case gftRnaX:
        minIdentity = 25;
        qIsProtLike = TRUE;
        break;
    default:
        qIsProtLike = FALSE;
        break;
    }
    if ((tIsProtLike ^ qIsProtLike) != 0)
        errAbort("t and q must both be either protein or dna");

    /* Set default tile size for protein-based comparisons. */
    if (tIsProtLike)
    {
        tileSize = 5;
        minMatch = 1;
        oneOff = FALSE;
        maxGap = 0;
    }

    /* Get tile size and related parameters from user and make sure
     * they are within range. */
    tileSize = optionInt("tileSize", tileSize);
    stepSize = optionInt("stepSize", tileSize);
    minMatch = optionInt("minMatch", minMatch);
    oneOff = optionExists("oneOff");
    fastMap = optionExists("fastMap");
    minScore = optionInt("minScore", minScore);
    maxGap = optionInt("maxGap", maxGap);
    minRepDivergence = optionFloat("minRepDivergence", minRepDivergence);
    minIdentity = optionFloat("minIdentity", minIdentity);
    gfCheckTileSize(tileSize, tIsProtLike);
    if (minMatch < 0)
        errAbort("minMatch must be at least 1");
    if (maxGap > 100)
        errAbort("maxGap must be less than 100");


    /* Set repMatch parameter from command line, or
     * to reasonable value that depends on tile size. */
    if (optionExists("repMatch"))
        repMatch = optionInt("repMatch", repMatch);
    else
        repMatch = gfDefaultRepMatch(tileSize, stepSize, tIsProtLike);

    /* Gather last few command line options. */
    noHead = optionExists("noHead");
    ooc = optionVal("ooc", NULL);
    makeOoc = optionVal("makeOoc", NULL);
    mask = optionVal("mask", NULL);
    qMask = optionVal("qMask", NULL);
    repeats = optionVal("repeats", NULL);
    if (repeats != NULL && mask != NULL && differentString(repeats, mask))
        errAbort("The -mask and -repeat settings disagree.  "
                 "You can just omit -repeat if -mask is on");
    if (mask != NULL)	/* Mask setting will also set repeats. */
        repeats = mask;
    outputFormat = optionVal("out", outputFormat);
    dotEvery = optionInt("dots", 0);
    /* set global for fuzzy find functions */
    setFfIntronMax(optionInt("maxIntron", ffIntronMaxDefault));
    setFfExtendThroughN(optionExists("extendThroughN"));


    /* Get threads number */
    threads = optionInt("threads", threads);
    if (threads <= 0)
        errAbort("threads must be at least 1");
    if (threads > 1 && (argv[3]==NULL || strcmp(argv[3],"")==0 || strcmp(argv[3], "stdin")==0))
        errAbort("Output name must be specified when using multi-threads");


    gfClientFileArray(argv[2], &queryFiles, &queryCount);
    if (queryCount > 1)
        errAbort("pblat does not support using list of file names as query. Please query each of the input files separately.");

    lf=(struct lineFile **)malloc(sizeof(struct lineFile *) * threads);
    for (i=0; i<threads; i++)
    {
        lf[i] = lineFileOpen(queryFiles[0], TRUE);
    }


    queryCount=0;
    struct lineFile *tlf = lineFileOpen(queryFiles[0], TRUE);
    while (faMixedSpeedReadNext(tlf, NULL, NULL, NULL, &faFastBuf, &faFastBufSize))
        queryCount++;
    if (threads > 1)
        queryCount=queryCount/threads+1;

    lineFileRewind(tlf);
    for (i=1; i<threads; i++)
    {
        cnt=queryCount;
        while (cnt-- && faMixedSpeedReadNext(tlf, NULL, NULL, NULL, &faFastBuf, &faFastBufSize));
        lineFileSeek(lf[i], tlf->bufOffsetInFile + tlf->lineStart, SEEK_SET);
    }
    lineFileClose(&tlf);
    faFreeFastBuf(&faFastBuf, &faFastBufSize);


    out=(FILE**)malloc(sizeof(FILE*) * threads);
    out[0]=mustOpen(argv[3], "w");
    for (i=1; i<threads; i++)
    {
        sprintf(buf, "%s.tmp.%d", argv[3], i);
        out[i] = mustOpen(buf, "w+");
    }
    


    /* Call routine that does the work. */
    blat(argv[1], queryCount, queryFiles, lf, out);
    

    for (i=0; i<threads; i++)
        lineFileClose(&(lf[i]));
    free(lf);

    if (threads>1)
    {
        for (i=1; i<threads; i++)
        {
            rewind(out[i]);
            while((cnt=fread(buf, 1, 1024, out[i]))>0)
            {
                tmp=fwrite(buf, 1, cnt, out[0]);
                if (tmp!=cnt)
                {
                    free(out);
                    errAbort("Merge files failed\n");
                }
            }
            carefulClose(&(out[i]));
            sprintf(buf, "%s.tmp.%d", argv[3], i);
            remove(buf);
        }
    }
    carefulClose(&(out[0]));
    free(out);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
leaq 0x3c(%rsp), %rbx
andl $0x0, 0xc(%rsp)
movl %edi, (%rbx)
andq $0x0, 0x18(%rsp)
leaq 0xab3ab(%rip), %rdx     # 0xb3790
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x2e9f5
cmpl $0x4, (%rbx)
jne 0x8b5b
leaq 0x73fd7(%rip), %rdi     # 0x7c3d9
callq 0x2ed1c
testl %eax, %eax
je 0x841a
pushq $0x2
popq %rax
movl %eax, 0xacaa8(%rip)     # 0xb4ebc
movl %eax, 0xaca9e(%rip)     # 0xb4eb8
leaq 0x803f6(%rip), %rdi     # 0x88817
callq 0x2ed1c
testl %eax, %eax
je 0x8446
leaq 0x803e6(%rip), %rdi     # 0x88817
xorl %esi, %esi
callq 0x2ea39
movq %rax, %rdi
callq 0x166a3
movl %eax, 0xaca76(%rip)     # 0xb4ebc
leaq 0x7425b(%rip), %rdi     # 0x7c6a8
callq 0x2ed1c
pushq $0x1
popq %rbp
movl %ebp, %ecx
testl %eax, %eax
jne 0x846e
leaq 0x7424c(%rip), %rdi     # 0x7c6ae
callq 0x2ed1c
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl %ecx, 0xaca24(%rip)     # 0xb4e98
leaq 0x73fd9(%rip), %rdi     # 0x7c454
callq 0x2ed1c
movl %ebp, %ecx
testl %eax, %eax
jne 0x8499
leaq 0x74227(%rip), %rdi     # 0x7c6b4
callq 0x2ed1c
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl %ecx, 0xaca01(%rip)     # 0xb4ea0
leaq 0x73fbc(%rip), %rdi     # 0x7c462
callq 0x2ed1c
movl %eax, 0xac9eb(%rip)     # 0xb4e9c
movl 0xaca05(%rip), %eax     # 0xb4ebc
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x84c3
xorl %ebx, %ebx
jmp 0x84dd
testl %eax, %eax
jne 0x84cb
xorl %ebp, %ebp
jmp 0x84db
leaq 0x741e8(%rip), %rdi     # 0x7c6ba
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x223fb
movb $0x1, %bl
leaq 0x74f9d(%rip), %rdi     # 0x7d481
callq 0x2ed1c
testl %eax, %eax
je 0x850b
leaq 0x74f8d(%rip), %rdi     # 0x7d481
xorl %esi, %esi
callq 0x2ea39
movq %rax, %rdi
callq 0x166a3
movl %eax, 0xac9af(%rip)     # 0xb4eb8
jmp 0x8511
movl 0xac9a7(%rip), %eax     # 0xb4eb8
cmpl $0x4, %eax
je 0x851b
cmpl $0x1, %eax
jne 0x8525
movl $0x1, 0xac973(%rip)     # 0xb4e98
leaq 0x73f2e(%rip), %rdi     # 0x7c45a
callq 0x2ed1c
testl %eax, %eax
je 0x853c
andl $0x0, 0xac95c(%rip)     # 0xb4e98
movl 0xac976(%rip), %ecx     # 0xb4eb8
addl $-0x2, %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
ja 0x8560
movabsq $0x4039000000000000, %rax # imm = 0x4039000000000000
movq %rax, 0xab223(%rip)     # 0xb3780
pushq $0x1
popq %rax
cmpl %eax, %ebp
je 0x8572
leaq 0x7416f(%rip), %rdi     # 0x7c6da
xorl %eax, %eax
callq 0x223fb
testb %bl, %bl
je 0x857e
movl 0xab1e8(%rip), %esi     # 0xb3764
jmp 0x85a3
movl $0x5, 0xab1dc(%rip)     # 0xb3764
movl $0x1, 0xab1d6(%rip)     # 0xb3768
andl $0x0, 0xac8f7(%rip)     # 0xb4e90
andl $0x0, 0xab1d0(%rip)     # 0xb3770
pushq $0x5
popq %rsi
leaq 0x73e38(%rip), %rdi     # 0x7c3e2
callq 0x2eae6
movl %eax, 0xab1af(%rip)     # 0xb3764
leaq 0x73e2f(%rip), %rdi     # 0x7c3eb
movl %eax, %esi
callq 0x2eae6
movl %eax, 0xac8bf(%rip)     # 0xb4e88
movl 0xab199(%rip), %esi     # 0xb3768
leaq 0x73e25(%rip), %rdi     # 0x7c3fb
callq 0x2eae6
movl %eax, 0xab187(%rip)     # 0xb3768
leaq 0x73e0c(%rip), %rdi     # 0x7c3f4
callq 0x2ed1c
movl %eax, 0xac89d(%rip)     # 0xb4e90
leaq 0x73e72(%rip), %rdi     # 0x7c46c
callq 0x2ed1c
movl %eax, 0xac89f(%rip)     # 0xb4ea4
movl 0xab161(%rip), %esi     # 0xb376c
leaq 0x73df2(%rip), %rdi     # 0x7c404
callq 0x2eae6
movl %eax, 0xab14f(%rip)     # 0xb376c
movl 0xab14d(%rip), %esi     # 0xb3770
leaq 0x73def(%rip), %rdi     # 0x7c419
callq 0x2eae6
movl %eax, 0xab13b(%rip)     # 0xb3770
cvtsd2ss 0xab13b(%rip), %xmm0    # 0xb3778
leaq 0x73dfa(%rip), %rdi     # 0x7c43e
callq 0x2ec14
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xab123(%rip)    # 0xb3778
cvtsd2ss 0xab123(%rip), %xmm0    # 0xb3780
leaq 0x73da9(%rip), %rdi     # 0x7c40d
callq 0x2ec14
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xab10b(%rip)    # 0xb3780
movl 0xab0e9(%rip), %edi     # 0xb3764
movl %ebp, %esi
callq 0xa988
cmpl $0x0, 0xab0df(%rip)     # 0xb3768
jns 0x8699
leaq 0x74073(%rip), %rdi     # 0x7c705
xorl %eax, %eax
callq 0x223fb
cmpl $0x65, 0xab0d0(%rip)    # 0xb3770
jl 0x86b0
leaq 0x74078(%rip), %rdi     # 0x7c721
xorl %eax, %eax
callq 0x223fb
leaq 0x73d78(%rip), %rdi     # 0x7c42f
callq 0x2ed1c
testl %eax, %eax
je 0x86d4
movl 0xab0ae(%rip), %esi     # 0xb3774
leaq 0x73d62(%rip), %rdi     # 0x7c42f
callq 0x2eae6
jmp 0x86e7
movl 0xab08a(%rip), %edi     # 0xb3764
movl 0xac7a8(%rip), %esi     # 0xb4e88
movl %ebp, %edx
callq 0xd440
movl %eax, 0xab087(%rip)     # 0xb3774
leaq 0x73d2c(%rip), %rdi     # 0x7c420
callq 0x2ed1c
movl %eax, 0xac795(%rip)     # 0xb4e94
leaq 0x73cd8(%rip), %rdi     # 0x7c3de
xorl %esi, %esi
callq 0x2ea39
movq %rax, 0xac79c(%rip)     # 0xb4eb0
leaq 0x73d0c(%rip), %rdi     # 0x7c427
xorl %esi, %esi
callq 0x2ea39
movq %rax, 0xac77f(%rip)     # 0xb4ea8
leaq 0x7e321(%rip), %rdi     # 0x86a51
xorl %esi, %esi
callq 0x2ea39
movq %rax, 0xac782(%rip)     # 0xb4ec0
leaq 0x73cf3(%rip), %rdi     # 0x7c438
xorl %esi, %esi
callq 0x2ea39
movq %rax, 0xac77d(%rip)     # 0xb4ed0
leaq 0x7a668(%rip), %rdi     # 0x82dc2
xorl %esi, %esi
callq 0x2ea39
movq %rax, 0xac760(%rip)     # 0xb4ec8
testq %rax, %rax
setne %cl
movq 0xac74b(%rip), %rbx     # 0xb4ec0
testq %rbx, %rbx
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x87a6
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6a50
testl %eax, %eax
je 0x87ab
leaq 0x73fa6(%rip), %rdi     # 0x7c73e
xorl %eax, %eax
callq 0x223fb
movq 0xac71a(%rip), %rbx     # 0xb4ec0
testq %rbx, %rbx
je 0x87b2
movq %rbx, 0xac716(%rip)     # 0xb4ec8
movq 0xaafcf(%rip), %rsi     # 0xb3788
leaq 0x748bf(%rip), %rdi     # 0x7d07f
callq 0x2ea39
movq %rax, 0xaafbc(%rip)     # 0xb3788
leaq 0x73c7c(%rip), %rdi     # 0x7c44f
xorl %esi, %esi
callq 0x2eae6
movl %eax, 0xac6ac(%rip)     # 0xb4e8c
leaq 0x73c92(%rip), %rdi     # 0x7c479
movl $0xb71b0, %esi          # imm = 0xB71B0
callq 0x2eae6
movl %eax, %edi
callq 0x23830
leaq 0x73c84(%rip), %rdi     # 0x7c483
callq 0x2ed1c
movl %eax, %edi
callq 0x8b60
movl 0xaaf4f(%rip), %esi     # 0xb3760
leaq 0x74051(%rip), %rdi     # 0x7c869
callq 0x2eae6
movl %eax, 0xaaf3d(%rip)     # 0xb3760
testl %eax, %eax
jg 0x883b
leaq 0x73f63(%rip), %rdi     # 0x7c791
xorl %eax, %eax
callq 0x223fb
movl 0xaaf25(%rip), %eax     # 0xb3760
cmpl $0x2, %eax
jl 0x8871
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x8863
cmpb $0x0, (%rdi)
je 0x8863
leaq 0x7a19f(%rip), %rsi     # 0x829f9
callq 0x6a50
testl %eax, %eax
jne 0x8871
leaq 0x73f42(%rip), %rdi     # 0x7c7ac
xorl %eax, %eax
callq 0x223fb
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x1027c
cmpl $0x2, (%rbx)
jl 0x889f
leaq 0x73f4b(%rip), %rdi     # 0x7c7e3
xorl %eax, %eax
callq 0x223fb
movslq 0xaaeba(%rip), %r12     # 0xb3760
movq %r12, %rdi
shlq $0x3, %rdi
callq 0x69d0
movq %rax, %r14
xorl %r15d, %r15d
pushq $0x1
popq %rbx
movslq %r12d, %rax
cmpq %rax, %r15
jge 0x88e2
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movl %ebx, %esi
callq 0x25467
movq %rax, (%r14,%r15,8)
incq %r15
movl 0xaae80(%rip), %r12d    # 0xb3760
jmp 0x88bb
andl $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rdi
pushq $0x1
popq %rsi
callq 0x25467
movq %rax, %r15
movq %rax, 0x30(%rsp)
leaq 0x18(%rsp), %rbx
leaq 0xc(%rsp), %r12
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %r12, %r9
callq 0x2311f
testl %eax, %eax
je 0x8927
incl 0x8(%rsp)
jmp 0x8909
movl 0xaae33(%rip), %ecx     # 0xb3760
cmpl $0x2, %ecx
jl 0x893f
movl 0x8(%rsp), %eax
cltd
idivl %ecx
incl %eax
movl %eax, 0x8(%rsp)
movq %r15, %rdi
callq 0x25648
pushq $0x1
popq %r13
leaq 0x18(%rsp), %rbx
leaq 0xc(%rsp), %r12
movslq 0xaae04(%rip), %rax     # 0xb3760
cmpq %rax, %r13
jge 0x899b
movl 0x8(%rsp), %ebp
incl %ebp
decl %ebp
je 0x8983
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %r12, %r9
callq 0x2311f
testl %eax, %eax
jne 0x8967
movq (%r14,%r13,8), %rdi
movslq 0x2c(%r15), %rsi
addq 0x18(%r15), %rsi
xorl %edx, %edx
callq 0x25595
incq %r13
jmp 0x8955
leaq 0x30(%rsp), %rdi
callq 0x25cd8
leaq 0x18(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x22e09
movslq 0xaada5(%rip), %rdi     # 0xb3760
shlq $0x3, %rdi
callq 0x69d0
movq %rax, %r15
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
leaq 0x752a2(%rip), %rsi     # 0x7dc79
callq 0x1ec79
movq %rax, (%r15)
pushq $0x1
popq %rbx
leaq 0x73e65(%rip), %r12     # 0x7c84e
leaq 0x40(%rsp), %r13
leaq 0x73c6c(%rip), %rbp     # 0x7c661
movslq 0xaad64(%rip), %rax     # 0xb3760
cmpq %rax, %rbx
jge 0x8a2d
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdx
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x6170
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1ec79
movq %rax, (%r15,%rbx,8)
incq %rbx
jmp 0x89f5
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x8(%rsp), %esi
movq 0x20(%rsp), %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x7fe4
xorl %r12d, %r12d
movq %r14, %rbx
movslq 0xaad09(%rip), %rbp     # 0xb3760
cmpq %rbp, %r12
jge 0x8a6d
movq %rbx, %rdi
callq 0x25cd8
incq %r12
addq $0x8, %rbx
jmp 0x8a50
movq %r14, %rdi
callq 0x68a0
cmpl $0x2, %ebp
jl 0x8b37
pushq $0x1
popq %r14
leaq 0x40(%rsp), %r12
leaq 0x73bbf(%rip), %r13     # 0x7c64d
movq %r14, %rbx
movslq %ebp, %rax
cmpq %rax, %rbx
jge 0x8b37
leaq (%r15,%rbx,8), %rbp
movq %rbx, 0x28(%rsp)
movq (%r15,%rbx,8), %rdi
callq 0x6110
movq (%rbp), %rcx
movl $0x400, %edx            # imm = 0x400
movq %r12, %rdi
movq %r14, %rsi
callq 0x6b20
movq %rax, %rbx
testl %ebx, %ebx
jle 0x8af8
movl %ebx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq (%r15), %rcx
movq %r12, %rdi
movq %r14, %rsi
callq 0x6e70
cmpl %ebx, %eax
je 0x8aaf
movq %r15, %rdi
callq 0x68a0
movq %r13, %rdi
xorl %eax, %eax
callq 0x223fb
jmp 0x8aaf
movq %rbp, %rdi
callq 0x1f2ea
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdx
movq %r12, %rdi
leaq 0x73d3b(%rip), %rsi     # 0x7c84e
movq 0x28(%rsp), %rbx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x6170
movq %r12, %rdi
callq 0x6da0
incq %rbx
movl 0xaac2e(%rip), %ebp     # 0xb3760
jmp 0x8a91
movq %r15, %rdi
callq 0x1f2ea
movq %r15, %rdi
callq 0x68a0
xorl %eax, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6f8c