// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/blatSrc/blat.c
// Function: bigBlat
void bigBlat(struct dnaSeq *untransList, int queryCount, char *queryFiles[], struct lineFile *lf[], boolean transQuery,
             boolean qIsDna, FILE *out[], struct gfOutput *gvo[], boolean showStatus)
/* Run query against translated DNA database (3 frames on each strand). */
{
    int             frame, cnt, i;
    struct dnaSeq   *seq;
    struct genoFind *gfs[3];
    aaSeq           *dbSeqLists[3];
    struct trans3   *t3List = NULL;
    int             isRc;
    struct hash     *t3Hash = NULL;
    boolean         forceUpper = FALSE;
    boolean         forceLower = FALSE;
    boolean         toggle = FALSE;
    boolean         maskUpper = FALSE;
    char            buf[1024];

    pthread_t*      thd = (pthread_t*)malloc(sizeof(pthread_t)*threads);
    void***         args = (void***)malloc(sizeof(void*)*threads);
    int*            id = (int*)malloc(sizeof(int)*threads);
    off_t*          offset = (off_t*)malloc(sizeof(off_t)*threads);


    if (showStatus)
        printf("Blatx %d sequences in database, %d sequences in each query\n", slCount(untransList), queryCount);

    /* Figure out how to manage query case.  Proteins want to be in
     * upper case, generally, nucleotides in lower case.  But there
     * may be repeatMasking based on case as well. */
    if (transQuery)
    {
        if (qMask == NULL)
            forceLower = TRUE;
        else
        {
            maskUpper = TRUE;
            toggle = !sameString(qMask, "upper");
        }
    }
    else
    {
        forceUpper = TRUE;
    }

    if (gvo[0]->fileHead != NULL)
        gvo[0]->fileHead(gvo[0], out[0]);

    for (i=0; i<threads; i++)
        offset[i] = lineFileTell(lf[i]);

    for (isRc = FALSE; isRc <= 1; ++isRc)
    {
        /* Initialize local pointer arrays to NULL to prevent surprises. */
        for (frame = 0; frame < 3; ++frame)
        {
            gfs[frame] = NULL;
            dbSeqLists[frame] = NULL;
        }

        t3List = seqListToTrans3List(untransList, dbSeqLists, &t3Hash);
        for (frame = 0; frame < 3; ++frame)
        {
            gfs[frame] = gfIndexSeq(dbSeqLists[frame], minMatch, maxGap, tileSize,
                                    repMatch, ooc, TRUE, oneOff, FALSE, stepSize);
        }

        /* multi-threads */
        for (i=0; i<threads; i++)
        {
            args[i]=(void**)malloc(sizeof(void*)*15);
            args[i][1]=&queryCount;
            args[i][2]=queryFiles;
            args[i][4]=gfs;
            args[i][5]=t3Hash;
            args[i][6]=&isRc;
            args[i][7]=&qIsDna;

            args[i][9]=&transQuery;
            args[i][10]=&forceLower;
            args[i][11]=&forceUpper;
            args[i][12]=&maskUpper;
            args[i][13]=&toggle;

            id[i]=i;
            args[i][0]=&(id[i]);
            args[i][3]=lf[i];
            args[i][8]=out[i];
            args[i][14]=gvo[i];
            if (pthread_create(&(thd[i]), NULL, performBigblat, (void*)(args[i])) != 0)
            {
                printf("Failed to create threads\n");
                return;
            }
        }

        for (i=0; i<threads; i++)
            pthread_join(thd[i], NULL);
        for (i=0; i<threads; i++)
            free(args[i]);


        /* Clean up time. */
        trans3FreeList(&t3List);
        freeHash(&t3Hash);
        for (frame = 0; frame < 3; ++frame)
        {
            genoFindFree(&gfs[frame]);
        }

        for (seq = untransList; seq != NULL; seq = seq->next)
        {
            reverseComplement(seq->dna, seq->size);
        }

        /* Rewind each input file pointer for RC run */
        if (isRc == FALSE)
        {
            for (i=0; i<threads; i++)
                lineFileSeek(lf[i], offset[i], SEEK_SET);
            if (threads > 1)
            {
                for (i=1; i<threads; i++)
                {
                    rewind(out[i]);
                    while((cnt=fread(buf, 1, 1024, out[i])) > 0)
                    {
                        frame = fwrite(buf, 1, cnt, out[0]);
                        if (frame != cnt)
                        {
                            free(thd);
                            free(args);
                            free(id);
                            free(offset);
                            errAbort("Merge files failed\n");
                        }
                    }
                    out[i] = freopen(NULL, "w+", out[i]);
                }
            }
        }
    }

    free(thd);
    free(args);
    free(id);
    free(offset);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movslq 0xfd63e(%rip), %rdi     # 0x105760
shlq $0x3, %rdi
callq 0x69c0
movq %rax, -0x4b8(%rbp)
movslq 0xfd627(%rip), %rdi     # 0x105760
shlq $0x3, %rdi
callq 0x69c0
movq %rax, -0x4c0(%rbp)
movslq 0xfd610(%rip), %rdi     # 0x105760
shlq $0x2, %rdi
callq 0x69c0
movq %rax, -0x4c8(%rbp)
movslq 0xfd5f9(%rip), %rdi     # 0x105760
shlq $0x3, %rdi
callq 0x69c0
movq %rax, -0x4d0(%rbp)
cmpl $0x0, 0x20(%rbp)
je 0x8199
movq -0x8(%rbp), %rdi
callq 0x2a810
movl %eax, %esi
movl -0xc(%rbp), %edx
leaq 0xcf4a3(%rip), %rdi     # 0xd7635
movb $0x0, %al
callq 0x6070
cmpl $0x0, -0x24(%rbp)
je 0x81e7
cmpq $0x0, 0xff149(%rip)     # 0x1072f0
jne 0x81b5
movl $0x1, -0xa0(%rbp)
jmp 0x81e5
movl $0x1, -0xa8(%rbp)
movq 0xff12a(%rip), %rdi     # 0x1072f0
leaq 0xcf4a4(%rip), %rsi     # 0xd7671
callq 0x6a40
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xa4(%rbp)
jmp 0x81f1
movl $0x1, -0x9c(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x20(%rax)
je 0x821a
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rdi
movq 0x10(%rbp), %rcx
movq (%rcx), %rsi
callq *%rax
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xfd536(%rip), %eax     # 0x105760
jge 0x8269
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rdx
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x2c(%rax), %rax
addq %rax, %rdx
movq -0x4d0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x8221
movl $0x0, -0x8c(%rbp)
cmpl $0x1, -0x8c(%rbp)
jg 0x87b5
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jge 0x82b2
movslq -0x2c(%rbp), %rax
movq $0x0, -0x60(%rbp,%rax,8)
movslq -0x2c(%rbp), %rax
movq $0x0, -0x80(%rbp,%rax,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x8287
movq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x7bd0
movq %rax, -0x88(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jge 0x8347
movslq -0x2c(%rbp), %rax
movq -0x80(%rbp,%rax,8), %rdi
movl 0xfd47f(%rip), %esi     # 0x105768
movl 0xfd481(%rip), %edx     # 0x105770
movl 0xfd46f(%rip), %ecx     # 0x105764
movl 0xfd478(%rip), %r8d     # 0x105774
movq 0xfefcd(%rip), %r9      # 0x1072d0
movl 0xfefa6(%rip), %r10d    # 0x1072b0
movl 0xfef98(%rip), %eax     # 0x1072a8
xorl %r11d, %r11d
movl $0x1, (%rsp)
movl %r10d, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0xe170
movq %rax, %rcx
movslq -0x2c(%rbp), %rax
movq %rcx, -0x60(%rbp,%rax,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x82d4
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xfd409(%rip), %eax     # 0x105760
jge 0x8573
movl $0x78, %edi
callq 0x69c0
movq %rax, %rdx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0xc(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x10(%rax)
leaq -0x60(%rbp), %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x20(%rax)
movq -0x98(%rbp), %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x28(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0x8c(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0x28(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0x24(%rbp), %rcx
movq %rcx, 0x48(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0xa0(%rbp), %rcx
movq %rcx, 0x50(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0x9c(%rbp), %rcx
movq %rcx, 0x58(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0xa8(%rbp), %rcx
movq %rcx, 0x60(%rax)
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
leaq -0xa4(%rbp), %rcx
movq %rcx, 0x68(%rax)
movl -0x34(%rbp), %edx
movq -0x4c8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x4c8(%rbp), %rcx
movslq -0x34(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x40(%rax)
movq 0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x70(%rax)
movq -0x4b8(%rbp), %rdi
movslq -0x34(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x736(%rip), %rdx      # 0x7e10
callq 0x6dc0
cmpl $0x0, %eax
je 0x8563
leaq 0xcf0c4(%rip), %rdi     # 0xd761b
movb $0x0, %al
callq 0x6070
jmp 0x87e5
jmp 0x8565
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x834e
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xfd1dd(%rip), %eax     # 0x105760
jge 0x85a8
movq -0x4b8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6610
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x857a
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xfd1a8(%rip), %eax     # 0x105760
jge 0x85d9
movq -0x4c0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x6880
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x85af
leaq -0x88(%rbp), %rdi
callq 0x1a5c0
leaq -0x98(%rbp), %rdi
callq 0x3a080
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jge 0x861d
movslq -0x2c(%rbp), %rax
leaq -0x60(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
callq 0xcb10
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x85f8
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x864e
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movslq 0x18(%rax), %rsi
callq 0x33300
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x8625
cmpl $0x0, -0x8c(%rbp)
jne 0x879f
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xfd0f5(%rip), %eax     # 0x105760
jge 0x869a
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x4d0(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
xorl %edx, %edx
callq 0x3b460
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x8662
cmpl $0x1, 0xfd0bf(%rip)     # 0x105760
jle 0x879d
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xfd0a9(%rip), %eax     # 0x105760
jge 0x879b
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x6110
leaq -0x4b0(%rbp), %rdi
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x6b20
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
jle 0x8762
leaq -0x4b0(%rbp), %rdi
movslq -0x30(%rbp), %rdx
movq 0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x6e80
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x875d
movq -0x4b8(%rbp), %rdi
callq 0x6880
movq -0x4c0(%rbp), %rdi
callq 0x6880
movq -0x4c8(%rbp), %rdi
callq 0x6880
movq -0x4d0(%rbp), %rdi
callq 0x6880
leaq 0xcef21(%rip), %rdi     # 0xd7677
movb $0x0, %al
callq 0x35d40
jmp 0x86ce
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0xcef12(%rip), %rsi     # 0xd768b
callq 0x66a0
movq %rax, %rdx
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x86ae
jmp 0x879d
jmp 0x879f
jmp 0x87a1
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x8273
movq -0x4b8(%rbp), %rdi
callq 0x6880
movq -0x4c0(%rbp), %rdi
callq 0x6880
movq -0x4c8(%rbp), %rdi
callq 0x6880
movq -0x4d0(%rbp), %rdi
callq 0x6880
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
nop