// File: /workspace/github_c_makefile_star2_O3/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, %r15
leaq 0x3c(%rsp), %rbx
movl %edi, (%rbx)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0xb5afc(%rip), %rdx     # 0xbf790
movq %rbx, %rdi
callq 0x3434a
cmpl $0x4, (%rbx)
jne 0xa46c
leaq 0x8372d(%rip), %rdi     # 0x8d3d9
callq 0x3465f
testl %eax, %eax
je 0x9cc6
movl $0x2, %eax
movl %eax, 0xb71dc(%rip)     # 0xc0e9c
movl %eax, 0xb71d2(%rip)     # 0xc0e98
leaq 0x8fdbb(%rip), %rdi     # 0x99a88
callq 0x3465f
testl %eax, %eax
je 0x9cf2
leaq 0x8fdab(%rip), %rdi     # 0x99a88
xorl %esi, %esi
callq 0x34390
movq %rax, %rdi
callq 0x19add
movl %eax, 0xb71aa(%rip)     # 0xc0e9c
leaq 0x839af(%rip), %rdi     # 0x8d6a8
callq 0x3465f
movl $0x1, %ebx
movl $0x1, %ecx
testl %eax, %eax
jne 0x9d1f
leaq 0x8399b(%rip), %rdi     # 0x8d6ae
callq 0x3465f
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl %ecx, 0xb7153(%rip)     # 0xc0e78
leaq 0x83728(%rip), %rdi     # 0x8d454
callq 0x3465f
testl %eax, %eax
jne 0x9d48
leaq 0x83978(%rip), %rdi     # 0x8d6b4
callq 0x3465f
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
movl %ebx, 0xb7132(%rip)     # 0xc0e80
leaq 0x8370d(%rip), %rdi     # 0x8d462
callq 0x3465f
movl %eax, 0xb711c(%rip)     # 0xc0e7c
movl 0xb7136(%rip), %eax     # 0xc0e9c
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x9d77
movl $0x1, %ebp
xorl %ebx, %ebx
jmp 0x9d91
testl %eax, %eax
jne 0x9d7f
xorl %ebp, %ebp
jmp 0x9d8f
leaq 0x83934(%rip), %rdi     # 0x8d6ba
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x26e94
movb $0x1, %bl
leaq 0x84749(%rip), %rdi     # 0x8e4e1
callq 0x3465f
testl %eax, %eax
je 0x9dbf
leaq 0x84739(%rip), %rdi     # 0x8e4e1
xorl %esi, %esi
callq 0x34390
movq %rax, %rdi
callq 0x19add
movl %eax, 0xb70db(%rip)     # 0xc0e98
jmp 0x9dc5
movl 0xb70d3(%rip), %eax     # 0xc0e98
cmpl $0x4, %eax
je 0x9dcf
cmpl $0x1, %eax
jne 0x9dd9
movl $0x1, 0xb709f(%rip)     # 0xc0e78
leaq 0x8367a(%rip), %rdi     # 0x8d45a
callq 0x3465f
testl %eax, %eax
je 0x9df3
movl $0x0, 0xb7085(%rip)     # 0xc0e78
movl 0xb709f(%rip), %ecx     # 0xc0e98
addl $-0x2, %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
ja 0x9e19
movabsq $0x4039000000000000, %rax # imm = 0x4039000000000000
movq %rax, 0xb596c(%rip)     # 0xbf780
movl $0x1, %eax
cmpl %eax, %ebp
je 0x9e2b
leaq 0x838b6(%rip), %rdi     # 0x8d6da
xorl %eax, %eax
callq 0x26e94
testb %bl, %bl
je 0x9e37
movl 0xb592f(%rip), %esi     # 0xbf764
jmp 0x9e5e
movl $0x5, 0xb5923(%rip)     # 0xbf764
movl $0x1, 0xb591d(%rip)     # 0xbf768
xorl %eax, %eax
movl %eax, 0xb701d(%rip)     # 0xc0e70
movl %eax, 0xb5917(%rip)     # 0xbf770
movl $0x5, %esi
leaq 0x8357d(%rip), %rdi     # 0x8d3e2
callq 0x34425
movl %eax, 0xb58f4(%rip)     # 0xbf764
leaq 0x83574(%rip), %rdi     # 0x8d3eb
movl %eax, %esi
callq 0x34425
movl %eax, 0xb6fe4(%rip)     # 0xc0e68
movl 0xb58de(%rip), %esi     # 0xbf768
leaq 0x8356a(%rip), %rdi     # 0x8d3fb
callq 0x34425
movl %eax, 0xb58cc(%rip)     # 0xbf768
leaq 0x83551(%rip), %rdi     # 0x8d3f4
callq 0x3465f
movl %eax, 0xb6fc2(%rip)     # 0xc0e70
leaq 0x835b7(%rip), %rdi     # 0x8d46c
callq 0x3465f
movl %eax, 0xb6fc4(%rip)     # 0xc0e84
movl 0xb58a6(%rip), %esi     # 0xbf76c
leaq 0x83537(%rip), %rdi     # 0x8d404
callq 0x34425
movl %eax, 0xb5894(%rip)     # 0xbf76c
movl 0xb5892(%rip), %esi     # 0xbf770
leaq 0x83534(%rip), %rdi     # 0x8d419
callq 0x34425
movl %eax, 0xb5880(%rip)     # 0xbf770
cvtsd2ss 0xb5880(%rip), %xmm0    # 0xbf778
leaq 0x8353f(%rip), %rdi     # 0x8d43e
callq 0x34557
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb5868(%rip)    # 0xbf778
xorps %xmm0, %xmm0
cvtsd2ss 0xb5865(%rip), %xmm0    # 0xbf780
leaq 0x834eb(%rip), %rdi     # 0x8d40d
callq 0x34557
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb584d(%rip)    # 0xbf780
movl 0xb582b(%rip), %edi     # 0xbf764
movl %ebp, %esi
callq 0xc709
cmpl $0x0, 0xb5821(%rip)     # 0xbf768
jns 0x9f57
leaq 0x837b5(%rip), %rdi     # 0x8d705
xorl %eax, %eax
callq 0x26e94
cmpl $0x65, 0xb5812(%rip)    # 0xbf770
jl 0x9f6e
leaq 0x837ba(%rip), %rdi     # 0x8d721
xorl %eax, %eax
callq 0x26e94
leaq 0x834ba(%rip), %rdi     # 0x8d42f
callq 0x3465f
testl %eax, %eax
je 0x9f92
movl 0xb57f0(%rip), %esi     # 0xbf774
leaq 0x834a4(%rip), %rdi     # 0x8d42f
callq 0x34425
jmp 0x9fa5
movl 0xb57cc(%rip), %edi     # 0xbf764
movl 0xb6eca(%rip), %esi     # 0xc0e68
movl %ebp, %edx
callq 0xf8db
movl %eax, 0xb57c9(%rip)     # 0xbf774
leaq 0x8346e(%rip), %rdi     # 0x8d420
callq 0x3465f
movl %eax, 0xb6eb7(%rip)     # 0xc0e74
leaq 0x8341a(%rip), %rdi     # 0x8d3de
xorl %esi, %esi
callq 0x34390
movq %rax, 0xb6ebe(%rip)     # 0xc0e90
leaq 0x8344e(%rip), %rdi     # 0x8d427
xorl %esi, %esi
callq 0x34390
movq %rax, 0xb6ea1(%rip)     # 0xc0e88
leaq 0x8db63(%rip), %rdi     # 0x97b51
xorl %esi, %esi
callq 0x34390
movq %rax, 0xb6ea4(%rip)     # 0xc0ea0
leaq 0x83435(%rip), %rdi     # 0x8d438
xorl %esi, %esi
callq 0x34390
movq %rax, 0xb6e9f(%rip)     # 0xc0eb0
leaq 0x89eaa(%rip), %rdi     # 0x93ec2
xorl %esi, %esi
callq 0x34390
movq %rax, 0xb6e82(%rip)     # 0xc0ea8
testq %rax, %rax
setne %cl
movq 0xb6e6d(%rip), %rbx     # 0xc0ea0
testq %rbx, %rbx
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xa064
movq %rax, %rdi
movq %rbx, %rsi
callq 0x6a50
testl %eax, %eax
je 0xa069
leaq 0x836e8(%rip), %rdi     # 0x8d73e
xorl %eax, %eax
callq 0x26e94
movq 0xb6e3c(%rip), %rbx     # 0xc0ea0
testq %rbx, %rbx
je 0xa070
movq %rbx, 0xb6e38(%rip)     # 0xc0ea8
movq 0xb5711(%rip), %rsi     # 0xbf788
leaq 0x84061(%rip), %rdi     # 0x8e0df
callq 0x34390
movq %rax, 0xb56fe(%rip)     # 0xbf788
leaq 0x833be(%rip), %rdi     # 0x8d44f
xorl %esi, %esi
callq 0x34425
movl %eax, 0xb6dce(%rip)     # 0xc0e6c
leaq 0x833d4(%rip), %rdi     # 0x8d479
movl $0xb71b0, %esi          # imm = 0xB71B0
callq 0x34425
movl %eax, %edi
callq 0x28440
leaq 0x833c6(%rip), %rdi     # 0x8d483
callq 0x3465f
movl %eax, %edi
callq 0xa494
movl 0xb5691(%rip), %esi     # 0xbf760
leaq 0x83793(%rip), %rdi     # 0x8d869
callq 0x34425
movl %eax, 0xb567f(%rip)     # 0xbf760
testl %eax, %eax
jg 0xa0f9
leaq 0x836a5(%rip), %rdi     # 0x8d791
xorl %eax, %eax
callq 0x26e94
movl 0xb5667(%rip), %eax     # 0xbf760
cmpl $0x2, %eax
jl 0xa12a
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0xa11c
cmpb $0x0, (%rdi)
je 0xa11c
leaq 0x899e6(%rip), %rsi     # 0x93af9
callq 0x6a50
testl %eax, %eax
jne 0xa12a
leaq 0x83689(%rip), %rdi     # 0x8d7ac
xorl %eax, %eax
callq 0x26e94
movq 0x10(%r15), %rdi
leaq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x12c98
cmpl $0x2, (%rbx)
jl 0xa153
leaq 0x83697(%rip), %rdi     # 0x8d7e3
xorl %eax, %eax
callq 0x26e94
movslq 0xb5606(%rip), %rbx     # 0xbf760
leaq (,%rbx,8), %rdi
callq 0x69d0
movq %rax, %r14
testq %rbx, %rbx
jle 0xa196
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x2a550
movq %rax, (%r14,%rbx,8)
incq %rbx
movslq 0xb55cf(%rip), %rax     # 0xbf760
cmpq %rax, %rbx
jl 0xa171
movq %r15, 0x20(%rsp)
movl $0x0, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x2a550
movq %rax, %r15
movq %rax, 0x30(%rsp)
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x27c4e
testl %eax, %eax
je 0xa1ff
leaq 0x10(%rsp), %rbx
leaq 0xc(%rsp), %r12
incl 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %r12, %r9
callq 0x27c4e
testl %eax, %eax
jne 0xa1e3
movl 0xb555b(%rip), %ecx     # 0xbf760
cmpl $0x2, %ecx
jl 0xa217
movl 0x8(%rsp), %eax
cltd
idivl %ecx
incl %eax
movl %eax, 0x8(%rsp)
movq %r15, %rdi
callq 0x2a743
cmpl $0x2, 0xb553a(%rip)     # 0xbf760
jl 0xa27c
movl $0x1, %r13d
leaq 0x10(%rsp), %rbx
leaq 0xc(%rsp), %r12
movl 0x8(%rsp), %ebp
incl %ebp
decl %ebp
je 0xa25a
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %r12, %r9
callq 0x27c4e
testl %eax, %eax
jne 0xa23e
movq (%r14,%r13,8), %rdi
movslq 0x2c(%r15), %rsi
addq 0x18(%r15), %rsi
xorl %edx, %edx
callq 0x2a68a
incq %r13
movslq 0xb54e9(%rip), %rax     # 0xbf760
cmpq %rax, %r13
jl 0xa238
movq %r14, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x2ae73
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x27927
movslq 0xb54bf(%rip), %rdi     # 0xbf760
shlq $0x3, %rdi
callq 0x69d0
movq %rax, %r15
movq 0x20(%rsp), %r14
movq 0x18(%r14), %rdi
leaq 0x84a8c(%rip), %rsi     # 0x8ed49
callq 0x23072
movq %rax, (%r15)
cmpl $0x2, 0xb5494(%rip)     # 0xbf760
jl 0xa317
movl $0x1, %ebx
leaq 0x83574(%rip), %r12     # 0x8d84e
leaq 0x40(%rsp), %r13
leaq 0x8337b(%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 0x23072
movq %rax, (%r15,%rbx,8)
incq %rbx
movslq 0xb544e(%rip), %rax     # 0xbf760
cmpq %rax, %rbx
jl 0xa2e6
movq 0x8(%r14), %rdi
movl 0x8(%rsp), %esi
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %r14
movq %r14, %rcx
movq %r15, %r8
callq 0x9864
cmpl $0x0, 0xb5425(%rip)     # 0xbf760
jle 0xa440
xorl %r12d, %r12d
movq %r14, %rbx
movq %rbx, %rdi
callq 0x2ae73
incq %r12
movslq 0xb5407(%rip), %r13     # 0xbf760
addq $0x8, %rbx
cmpq %r13, %r12
jl 0xa347
movq %r14, %rdi
callq 0x68a0
cmpl $0x2, %r13d
jl 0xa448
movl $0x1, %r14d
leaq 0x40(%rsp), %r12
leaq 0x832c7(%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 0xa3fe
movq %rbp, %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq (%r15), %rcx
movl $0x1, %esi
movq %r12, %rdi
callq 0x6e70
cmpl %eax, %ebp
je 0xa3df
movq %r15, %rdi
callq 0x68a0
movq %r13, %rdi
xorl %eax, %eax
callq 0x26e94
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 0xa3b3
movq %rbx, %rdi
callq 0x2371e
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rdx
movq %r12, %rdi
leaq 0x83435(%rip), %rsi     # 0x8d84e
movl %r14d, %ecx
xorl %eax, %eax
callq 0x6170
movq %r12, %rdi
callq 0x6da0
incq %r14
movslq 0xb532b(%rip), %rax     # 0xbf760
cmpq %rax, %r14
jl 0xa386
jmp 0xa448
movq %r14, %rdi
callq 0x68a0
movq %r15, %rdi
callq 0x2371e
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 0x81bbd(%rip), %rdi     # 0x8c030
leaq 0x82f5a(%rip), %rsi     # 0x8d3d4
movl $0x1388, %edx           # imm = 0x1388
movl $0xb71b0, %ecx          # imm = 0xB71B0
xorl %eax, %eax
callq 0x6070
xorl %edi, %edi
callq 0x68d0
nop