// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, %r13
leaq 0x3c(%rsp), %rbx
movl %edi, (%rbx)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0xb5a31(%rip), %rdx     # 0xbf790
movq %rbx, %rdi
callq 0x34018
cmpl $0x4, (%rbx)
jne 0xa535
leaq 0x83662(%rip), %rdi     # 0x8d3d9
callq 0x34334
testl %eax, %eax
je 0x9d91
movl $0x2, %eax
movl %eax, 0xb7111(%rip)     # 0xc0e9c
movl %eax, 0xb7107(%rip)     # 0xc0e98
leaq 0x8fac7(%rip), %rdi     # 0x9985f
callq 0x34334
testl %eax, %eax
je 0x9dbd
leaq 0x8fab7(%rip), %rdi     # 0x9985f
xorl %esi, %esi
callq 0x3405e
movq %rax, %rdi
callq 0x19881
movl %eax, 0xb70df(%rip)     # 0xc0e9c
leaq 0x838e4(%rip), %rdi     # 0x8d6a8
callq 0x34334
movl $0x1, %ebx
movl $0x1, %ecx
testl %eax, %eax
jne 0x9dea
leaq 0x838d0(%rip), %rdi     # 0x8d6ae
callq 0x34334
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl %ecx, 0xb7088(%rip)     # 0xc0e78
leaq 0x8365d(%rip), %rdi     # 0x8d454
callq 0x34334
testl %eax, %eax
jne 0x9e13
leaq 0x838ad(%rip), %rdi     # 0x8d6b4
callq 0x34334
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
movl %ebx, 0xb7067(%rip)     # 0xc0e80
leaq 0x83642(%rip), %rdi     # 0x8d462
callq 0x34334
movl %eax, 0xb7051(%rip)     # 0xc0e7c
movl 0xb706b(%rip), %eax     # 0xc0e9c
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x9e42
movl $0x1, %ebp
xorl %ebx, %ebx
jmp 0x9e5c
testl %eax, %eax
jne 0x9e4a
xorl %ebp, %ebp
jmp 0x9e5a
leaq 0x83869(%rip), %rdi     # 0x8d6ba
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x26b6f
movb $0x1, %bl
leaq 0x8463e(%rip), %rdi     # 0x8e4a1
callq 0x34334
testl %eax, %eax
je 0x9e88
leaq 0x8462e(%rip), %rdi     # 0x8e4a1
xorl %esi, %esi
callq 0x3405e
movq %rax, %rdi
callq 0x19881
movl %eax, 0xb7010(%rip)     # 0xc0e98
movl 0xb700a(%rip), %eax     # 0xc0e98
cmpl $0x4, %eax
je 0x9e98
cmpl $0x1, %eax
jne 0x9ea2
movl $0x1, 0xb6fd6(%rip)     # 0xc0e78
leaq 0x835b1(%rip), %rdi     # 0x8d45a
callq 0x34334
testl %eax, %eax
je 0x9ebc
movl $0x0, 0xb6fbc(%rip)     # 0xc0e78
movl 0xb6fd6(%rip), %ecx     # 0xc0e98
addl $-0x2, %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
ja 0x9ee2
movabsq $0x4039000000000000, %rax # imm = 0x4039000000000000
movq %rax, 0xb58a3(%rip)     # 0xbf780
movl $0x1, %eax
cmpl %eax, %ebp
je 0x9ef4
leaq 0x837ed(%rip), %rdi     # 0x8d6da
xorl %eax, %eax
callq 0x26b6f
testb %bl, %bl
jne 0x9f1a
movl $0x5, 0xb5862(%rip)     # 0xbf764
movl $0x1, 0xb585c(%rip)     # 0xbf768
xorl %eax, %eax
movl %eax, 0xb6f5c(%rip)     # 0xc0e70
movl %eax, 0xb5856(%rip)     # 0xbf770
movl 0xb5844(%rip), %esi     # 0xbf764
leaq 0x834bb(%rip), %rdi     # 0x8d3e2
callq 0x340f1
movl %eax, 0xb5832(%rip)     # 0xbf764
leaq 0x834b2(%rip), %rdi     # 0x8d3eb
movl %eax, %esi
callq 0x340f1
movl %eax, 0xb6f22(%rip)     # 0xc0e68
movl 0xb581c(%rip), %esi     # 0xbf768
leaq 0x834a8(%rip), %rdi     # 0x8d3fb
callq 0x340f1
movl %eax, 0xb580a(%rip)     # 0xbf768
leaq 0x8348f(%rip), %rdi     # 0x8d3f4
callq 0x34334
movl %eax, 0xb6f00(%rip)     # 0xc0e70
leaq 0x834f5(%rip), %rdi     # 0x8d46c
callq 0x34334
movl %eax, 0xb6f02(%rip)     # 0xc0e84
movl 0xb57e4(%rip), %esi     # 0xbf76c
leaq 0x83475(%rip), %rdi     # 0x8d404
callq 0x340f1
movl %eax, 0xb57d2(%rip)     # 0xbf76c
movl 0xb57d0(%rip), %esi     # 0xbf770
leaq 0x83472(%rip), %rdi     # 0x8d419
callq 0x340f1
movl %eax, 0xb57be(%rip)     # 0xbf770
cvtsd2ss 0xb57be(%rip), %xmm0    # 0xbf778
leaq 0x8347d(%rip), %rdi     # 0x8d43e
callq 0x3422c
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb57a6(%rip)    # 0xbf778
xorps %xmm0, %xmm0
cvtsd2ss 0xb57a3(%rip), %xmm0    # 0xbf780
leaq 0x83429(%rip), %rdi     # 0x8d40d
callq 0x3422c
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb578b(%rip)    # 0xbf780
movl 0xb5769(%rip), %edi     # 0xbf764
movl %ebp, %esi
callq 0xc786
cmpl $0x0, 0xb575f(%rip)     # 0xbf768
jns 0xa019
leaq 0x836f3(%rip), %rdi     # 0x8d705
xorl %eax, %eax
callq 0x26b6f
cmpl $0x65, 0xb5750(%rip)    # 0xbf770
jl 0xa030
leaq 0x836f8(%rip), %rdi     # 0x8d721
xorl %eax, %eax
callq 0x26b6f
leaq 0x833f8(%rip), %rdi     # 0x8d42f
callq 0x34334
testl %eax, %eax
je 0xa054
movl 0xb572e(%rip), %esi     # 0xbf774
leaq 0x833e2(%rip), %rdi     # 0x8d42f
callq 0x340f1
jmp 0xa067
movl 0xb570a(%rip), %edi     # 0xbf764
movl 0xb6e08(%rip), %esi     # 0xc0e68
movl %ebp, %edx
callq 0xf7a0
movl %eax, 0xb5707(%rip)     # 0xbf774
leaq 0x833ac(%rip), %rdi     # 0x8d420
callq 0x34334
movl %eax, 0xb6df5(%rip)     # 0xc0e74
leaq 0x83358(%rip), %rdi     # 0x8d3de
xorl %esi, %esi
callq 0x3405e
movq %rax, 0xb6dfc(%rip)     # 0xc0e90
leaq 0x8338c(%rip), %rdi     # 0x8d427
xorl %esi, %esi
callq 0x3405e
movq %rax, 0xb6ddf(%rip)     # 0xc0e88
leaq 0x8d9c1(%rip), %rdi     # 0x97a71
xorl %esi, %esi
callq 0x3405e
movq %rax, 0xb6de2(%rip)     # 0xc0ea0
leaq 0x83373(%rip), %rdi     # 0x8d438
xorl %esi, %esi
callq 0x3405e
movq %rax, 0xb6ddd(%rip)     # 0xc0eb0
leaq 0x89d18(%rip), %rdi     # 0x93df2
xorl %esi, %esi
callq 0x3405e
movq %rax, 0xb6dc0(%rip)     # 0xc0ea8
testq %rax, %rax
setne %cl
movq 0xb6dab(%rip), %rsi     # 0xc0ea0
testq %rsi, %rsi
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xa11c
movq %rax, %rdi
callq 0x6a50
testl %eax, %eax
je 0xa11c
leaq 0x83629(%rip), %rdi     # 0x8d73e
xorl %eax, %eax
callq 0x26b6f
movq 0xb6d7d(%rip), %rax     # 0xc0ea0
testq %rax, %rax
je 0xa12f
movq %rax, 0xb6d79(%rip)     # 0xc0ea8
movq 0xb5652(%rip), %rsi     # 0xbf788
leaq 0x83f62(%rip), %rdi     # 0x8e09f
callq 0x3405e
movq %rax, 0xb563f(%rip)     # 0xbf788
leaq 0x832ff(%rip), %rdi     # 0x8d44f
xorl %esi, %esi
callq 0x340f1
movl %eax, 0xb6d0f(%rip)     # 0xc0e6c
leaq 0x83315(%rip), %rdi     # 0x8d479
movl $0xb71b0, %esi          # imm = 0xB71B0
callq 0x340f1
movl %eax, %edi
callq 0x280fc
leaq 0x83307(%rip), %rdi     # 0x8d483
callq 0x34334
movl %eax, %edi
callq 0xa55c
movl 0xb55d2(%rip), %esi     # 0xbf760
leaq 0x836d4(%rip), %rdi     # 0x8d869
callq 0x340f1
movl %eax, 0xb55c0(%rip)     # 0xbf760
testl %eax, %eax
jg 0xa1b2
leaq 0x835e6(%rip), %rdi     # 0x8d791
xorl %eax, %eax
callq 0x26b6f
cmpl $0x2, 0xb55a7(%rip)     # 0xbf760
jl 0xa1e7
movq 0x18(%r13), %rdi
testq %rdi, %rdi
je 0xa1d9
cmpb $0x0, (%rdi)
je 0xa1d9
leaq 0x8985c(%rip), %rsi     # 0x93a2c
callq 0x6a50
testl %eax, %eax
jne 0xa1e7
leaq 0x835cc(%rip), %rdi     # 0x8d7ac
xorl %eax, %eax
callq 0x26b6f
movq 0x10(%r13), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x12b6c
cmpl $0x2, (%rbx)
jl 0xa210
leaq 0x835da(%rip), %rdi     # 0x8d7e3
xorl %eax, %eax
callq 0x26b6f
movslq 0xb5549(%rip), %rbx     # 0xbf760
leaq (,%rbx,8), %rdi
callq 0x69d0
movq %rax, %r14
testq %rbx, %rbx
jle 0xa253
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x2a1fc
movq %rax, (%r14,%rbx,8)
incq %rbx
movslq 0xb5512(%rip), %rax     # 0xbf760
cmpq %rax, %rbx
jl 0xa22e
movl $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x2a1fc
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2790a
testl %eax, %eax
je 0xa2b6
leaq 0x18(%rsp), %rbx
leaq 0xc(%rsp), %r15
incl 0x8(%rsp)
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %r15, %r9
callq 0x2790a
testl %eax, %eax
jne 0xa298
movl 0xb54a4(%rip), %ecx     # 0xbf760
cmpl $0x2, %ecx
jl 0xa2ce
movl 0x8(%rsp), %eax
cltd
idivl %ecx
incl %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rdi
callq 0x2a3ef
cmpl $0x2, 0xb5481(%rip)     # 0xbf760
jl 0xa33c
movl $0x1, %r12d
leaq 0x18(%rsp), %rbx
leaq 0xc(%rsp), %r15
movl 0x8(%rsp), %ebp
incl %ebp
decl %ebp
je 0xa315
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %r15, %r9
callq 0x2790a
testl %eax, %eax
jne 0xa2f7
movq (%r14,%r12,8), %rdi
movq 0x10(%rsp), %rax
movslq 0x2c(%rax), %rsi
addq 0x18(%rax), %rsi
xorl %edx, %edx
callq 0x2a336
incq %r12
movslq 0xb5429(%rip), %rax     # 0xbf760
cmpq %rax, %r12
jl 0xa2f1
movq %r14, 0x28(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x2ab48
leaq 0x18(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x275e3
movslq 0xb53ff(%rip), %rdi     # 0xbf760
shlq $0x3, %rdi
callq 0x69d0
movq %rax, %r15
movq 0x18(%r13), %rdi
leaq 0x84911(%rip), %rsi     # 0x8ec89
callq 0x22d5a
movq %rax, (%r15)
cmpl $0x2, 0xb53d9(%rip)     # 0xbf760
movq %r13, %r14
jl 0xa3d5
movl $0x1, %ebx
leaq 0x834b6(%rip), %r12     # 0x8d84e
leaq 0x40(%rsp), %r13
leaq 0x832bd(%rip), %rbp     # 0x8d661
movq 0x18(%r14), %rdx
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x6170
movq %r13, %rdi
movq %rbp, %rsi
callq 0x22d5a
movq %rax, (%r15,%rbx,8)
incq %rbx
movslq 0xb5390(%rip), %rax     # 0xbf760
cmpq %rax, %rbx
jl 0xa3a4
movq 0x8(%r14), %rdi
movl 0x8(%rsp), %esi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rbx
movq %rbx, %rcx
movq %r15, %r8
callq 0x9946
cmpl $0x0, 0xb5367(%rip)     # 0xbf760
movq %r14, 0x30(%rsp)
jle 0xa426
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x2ab48
incq %r12
movslq 0xb534b(%rip), %rax     # 0xbf760
addq $0x8, %rbx
cmpq %rax, %r12
jl 0xa403
cmpl $0x2, %eax
setge %bl
jmp 0xa428
xorl %ebx, %ebx
movq 0x28(%rsp), %rdi
callq 0x68a0
testb %bl, %bl
je 0xa511
cmpl $0x2, 0xb531f(%rip)     # 0xbf760
jl 0xa511
movl $0x1, %r14d
leaq 0x40(%rsp), %r12
leaq 0x831f4(%rip), %r13     # 0x8d64d
leaq (%r15,%r14,8), %rbx
movq (%r15,%r14,8), %rdi
callq 0x6110
movq (%r15,%r14,8), %rcx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
movq %r12, %rdi
callq 0x6b20
movq %rax, %rbp
testl %ebp, %ebp
jle 0xa4d1
movq %rbp, %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq (%r15), %rcx
movl $0x1, %esi
movq %r12, %rdi
callq 0x6e70
cmpl %eax, %ebp
je 0xa4b2
movq %r15, %rdi
callq 0x68a0
movq %r13, %rdi
xorl %eax, %eax
callq 0x26b6f
movq (%rbx), %rcx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
movq %r12, %rdi
callq 0x6b20
movq %rax, %rbp
movq %rax, %rdx
testl %ebp, %ebp
jg 0xa486
movq %rbx, %rdi
callq 0x23400
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdx
movq %r12, %rdi
leaq 0x83362(%rip), %rsi     # 0x8d84e
movl %r14d, %ecx
xorl %eax, %eax
callq 0x6170
movq %r12, %rdi
callq 0x6da0
incq %r14
movslq 0xb5258(%rip), %rax     # 0xbf760
cmpq %rax, %r14
jl 0xa459
movq %r15, %rdi
callq 0x23400
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
leaq 0x81af4(%rip), %rdi     # 0x8c030
leaq 0x82e91(%rip), %rsi     # 0x8d3d4
movl $0x1388, %edx           # imm = 0x1388
movl $0xb71b0, %ecx          # imm = 0xB71B0
xorl %eax, %eax
callq 0x6070
xorl %edi, %edi
callq 0x68d0
nop