// File: /workspace/github_c_makefile_star2_O1/thegenemyers[P]DAMASKER/tandem.c
// Function: Match_Self
void Match_Self(char *aname, DAZZ_DB *ablock, Align_Spec *aspec)
{ THREAD     threads[NTHREADS];
  Merge_Arg  parmm[NTHREADS];
  Lex_Arg    parmx[NTHREADS];
  Report_Arg parmr[NTHREADS];
  int        pairsort[16];

  int64     nfilt, ncheck;

  KmerPos  *asort, *osort;
  int       alen;
  int64     atot;

  //  Setup 

  atot = ablock->totlen;

  nfilt = ncheck = 0;

  { int64 powr;
    int   i, nbyte;

    for (i = 0; i < NTHREADS; i++)
      parmx[i].sptr = (int64 *) alloca(NTHREADS*BPOWR*sizeof(int64));

    for (i = 0; i < 16; i++)
      pairsort[i] = 0;

    powr = 1;
    for (nbyte = 0; powr < ablock->maxlen; nbyte += 1)
      powr <<= 8;
    for (i = 8; i < 8+nbyte; i++)
      pairsort[i] = 1;

    powr = 1;
    for (nbyte = 0; powr < ablock->nreads; nbyte += 1)
      powr <<= 8;
    for (i = 12; i < 12+nbyte; i++)
      pairsort[i] = 1;
  }

  //  Build K-mer sorted index of ablock

  if (VERBOSE)
    printf("\nIndexing %s\n",aname);

  osort = NULL;   //  Just to shut up dumb compilers
  asort = Sort_Kmers(ablock,&alen,&osort);

  if (VERBOSE)
    printf("\nComparing %s to itself\n",aname);

  if (alen == 0)
    goto zerowork;

  //  Determine equal K-mer links

  { int    i, p;
    uint64 c;

    parmm[0].abeg = 0;
    for (i = 1; i < NTHREADS; i++)
      { p = (int) ((((int64) alen) * i) >> NSHIFT);
        if (p > 0)
          { c = asort[p-1].code;
            while (asort[p].code == c)
              p += 1;
          }
        parmm[i].abeg = parmm[i-1].aend = p;
      }
    parmm[NTHREADS-1].aend = alen;

    for (i = 0; i < NTHREADS; i++)
      { parmm[i].kptr = parmx[i].tptr;
        for (p = 0; p < BPOWR; p++)
          parmm[i].kptr[p] = 0;
      }

    MG_alist = asort;

    for (i = 0; i < NTHREADS; i++)
      pthread_create(threads+i,NULL,count_thread,parmm+i);

    for (i = 0; i < NTHREADS; i++)
      pthread_join(threads[i],NULL);

#ifdef TEST_PAIRS
    printf("\nCROSS SORT %d:\n",alen);
    for (i = 0; i < HOW_MANY && i <= alen; i++)
      { KmerPos *c = asort+i;
        printf(" %5d / %5d / %10lld\n",c->read,c->rpos,c->code);
        fflush(stdout);
      }
#endif
  }

  //  Resort the list on read,rpos

  { int      i;
    KmerPos *rez;

    for (i = 0; i < NTHREADS; i++)
      { parmx[i].beg = parmm[i].abeg;
        parmx[i].end = parmm[i].aend;
      }

    rez = (KmerPos *) lex_sort(pairsort,(Double *) asort,(Double *) osort,parmx);
    if (rez != asort)
      { osort = asort;
        asort = rez;
      }

#ifdef TEST_CSORT
    printf("\nCROSS SORT %d:\n",alen);
    for (i = 0; i < HOW_MANY && i <= alen; i++)
      { KmerPos *c = asort+i;
        printf(" %5d / %5d / %10lld\n",c->read,c->rpos,c->code);
        fflush(stdout);
      }
#endif
  }

  //  Apply the diagonal filter and find local alignments about seed hits

  { int    i, w;
    int64  p;
    int    ar;
    int   *counters;

    MG_alist  = asort;
    MR_ablock = ablock;
    MR_spec   = aspec;
    MR_tspace = Trace_Spacing(aspec);

    asort[alen].read = ablock->nreads;
    parmr[0].beg = 0;
    for (i = 1; i < NTHREADS; i++)
      { p = (int) ((((int64) alen) * i) >> NSHIFT);
        if (p > 0)
          { ar = asort[p-1].read;
            while ((asort[p].read) == ar)
              p += 1;
          }
        parmr[i].beg = parmr[i-1].end = p;
      }
    parmr[NTHREADS-1].end = alen;

    w = ((ablock->maxlen >> Binshift) - ((-ablock->maxlen) >> Binshift)) + 1;
    counters = (int *) Malloc(NTHREADS*3*w*sizeof(int),"Allocating diagonal buckets");
    if (counters == NULL)
      Clean_Exit(1);

    for (i = 0; i < 3*w*NTHREADS; i++)
      counters[i] = 0;
    for (i = 0; i < NTHREADS; i++)
      { if (i == 0)
          parmr[i].score = counters - ((-ablock->maxlen) >> Binshift);
        else
          parmr[i].score = parmr[i-1].lasta + w;
        parmr[i].lastp = parmr[i].score + w;
        parmr[i].lasta = parmr[i].lastp + w;
        parmr[i].work  = New_Work_Data();

        parmr[i].ofile =
             Fopen(Catenate(SORT_PATH,"/",aname,Numbered_Suffix(".T",i+1,".las")),"w");
        if (parmr[i].ofile == NULL)
          Clean_Exit(1);
      }

#ifdef NOTHREAD

    for (i = 0; i < NTHREADS; i++)
      report_thread(parmr+i);

#else

    for (i = 0; i < NTHREADS; i++)
      pthread_create(threads+i,NULL,report_thread,parmr+i);

    for (i = 0; i < NTHREADS; i++)
      pthread_join(threads[i],NULL);

#endif

    if (VERBOSE)
      for (i = 0; i < NTHREADS; i++)
        { nfilt  += parmr[i].nfilt;
          ncheck += parmr[i].ncheck;
        }

    for (i = 0; i < NTHREADS; i++)
      Free_Work_Data(parmr[i].work);
    free(counters);
  }

  //  Finish up

  goto epilogue;

zerowork:
  { FILE *ofile;
    int   i;

    nfilt  = 0;
    for (i = 0; i < NTHREADS; i++)
      { ofile = Fopen(Catenate(SORT_PATH,"/",aname,Numbered_Suffix(".T",i+1,".las")),"w");
        fwrite(&nfilt,sizeof(int64),1,ofile);
        fwrite(&MR_tspace,sizeof(int),1,ofile);
        fclose(ofile);
      }
  }

epilogue:

  free(asort);
  free(osort);

  if (VERBOSE)
    { int width;

      if (nfilt <= 0)
        width = 1;
      else
        width = ((int) log10((double) nfilt)) + 1;
      width += (width-1)/3;

      printf("\n     ");
      Print_Number(nfilt,width,stdout);
      printf(" seed hits (%e of matrix)\n     ",(1.*nfilt/atot)/atot);
      Print_Number(ncheck,width,stdout);
      printf(" confirmed hits (%e of matrix)\n",(1.*ncheck/atot)/atot);
      fflush(stdout);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, -0x40(%rbp)
movq %rdi, %rbx
movl 0x1ffca(%rip), %eax     # 0x241f8
movq %rsp, %r14
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
movq %rsp, %r13
movq %rax, %rcx
shlq $0x4, %rcx
subq %rcx, %r13
movq %r13, %rsp
movq %rsp, %rdi
imulq $0x818, %rax, %rcx      # imm = 0x818
leaq 0xf(%rcx), %rdx
andq $-0x10, %rdx
subq %rdx, %rdi
movq %rdi, %rsp
movq %rsp, %r12
leaq (%rax,%rax,8), %rdx
leaq 0xf(,%rdx,8), %rdx
andq $-0x10, %rdx
subq %rdx, %r12
movq %r12, %rsp
movq %rsi, -0x30(%rbp)
movq 0x28(%rsi), %rdx
movq %rdx, -0x80(%rbp)
movq $0x0, -0x48(%rbp)
testl %eax, %eax
jle 0x42ca
shll $0x8, %eax
shlq $0x3, %rax
xorl %edx, %edx
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rsi
subq %rax, %rsi
movq %rsi, %rsp
movq %rsi, 0x810(%rdi,%rdx)
addq $0x818, %rdx            # imm = 0x818
cmpq %rdx, %rcx
jne 0x42ad
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movapd %xmm0, -0xa0(%rbp)
movapd %xmm0, -0xb0(%rbp)
movapd %xmm0, -0xc0(%rbp)
movq -0x30(%rbp), %rax
movslq 0x20(%rax), %rcx
xorl %eax, %eax
cmpq $0x2, %rcx
jl 0x4310
xorl %eax, %eax
movl $0x1, %edx
shlq $0x8, %rdx
incl %eax
cmpq %rcx, %rdx
jl 0x4305
testl %eax, %eax
je 0x433a
addl $0x8, %eax
cmpl $0xa, %eax
movl $0x9, %ecx
cmovael %eax, %ecx
movl $0x8, %eax
movl $0x1, -0xc0(%rbp,%rax,4)
incq %rax
cmpq %rax, %rcx
jne 0x4327
movq -0x30(%rbp), %rax
movslq 0x30(%rax), %rcx
xorl %eax, %eax
cmpq $0x2, %rcx
jl 0x435c
xorl %eax, %eax
movl $0x1, %edx
shlq $0x8, %rdx
incl %eax
cmpq %rcx, %rdx
jl 0x4351
movq %rdi, -0x58(%rbp)
testl %eax, %eax
je 0x438a
addl $0xc, %eax
cmpl $0xe, %eax
movl $0xd, %ecx
cmovael %eax, %ecx
movl $0xc, %eax
movl $0x1, -0xc0(%rbp,%rax,4)
incq %rax
cmpq %rax, %rcx
jne 0x4377
leaq 0x1fe43(%rip), %r15     # 0x241d4
cmpl $0x0, (%r15)
je 0x43a8
leaq 0x19282(%rip), %rdi     # 0x1d620
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2150
leaq -0x68(%rbp), %rdx
movq $0x0, (%rdx)
leaq -0x6c(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a1c
movq %rax, -0x38(%rbp)
cmpl $0x0, (%r15)
je 0x43db
leaq 0x1925d(%rip), %rdi     # 0x1d62e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2150
movslq -0x6c(%rbp), %r10
testq %r10, %r10
movq -0x38(%rbp), %r9
je 0x4834
movq %r14, -0x50(%rbp)
movl $0x0, (%r13)
movslq 0x1fdf9(%rip), %r14     # 0x241f8
cmpq $0x2, %r14
jl 0x4469
movl 0x1fdf1(%rip), %ecx     # 0x241fc
movl $0x1, %eax
movq %rax, %rdx
imulq %r10, %rdx
sarq %cl, %rdx
testl %edx, %edx
jle 0x4450
leal -0x1(%rdx), %esi
shlq $0x4, %rsi
movq (%r9,%rsi), %rsi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edx, %r8d
decl %r8d
shlq $0x4, %rdx
addq %r9, %rdx
movq %rdx, %rdi
movl %r8d, %edx
incl %edx
leaq 0x10(%rdi), %r8
cmpq %rsi, (%rdi)
movq %r8, %rdi
je 0x4442
movq %rax, %rsi
shlq $0x4, %rsi
movl %edx, -0xc(%r13,%rsi)
movl %edx, (%r13,%rsi)
incq %rax
cmpq %r14, %rax
jne 0x4410
movq %rbx, -0x60(%rbp)
movl %r14d, %eax
shlq $0x4, %r14
movq %r10, -0x78(%rbp)
movl %r10d, -0xc(%r13,%r14)
testl %eax, %eax
jle 0x44b0
movq -0x58(%rbp), %rax
leaq 0x10(%rax), %rbx
xorl %r15d, %r15d
movq %rbx, 0x8(%r13,%r15)
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
addq $0x818, %rbx            # imm = 0x818
addq $0x10, %r15
cmpq %r15, %r14
jne 0x448c
movq -0x38(%rbp), %rax
movq %rax, 0x1fd4d(%rip)     # 0x24208
cmpl $0x0, 0x1fd36(%rip)     # 0x241f8
jle 0x44f8
xorl %ebx, %ebx
movq -0x50(%rbp), %r14
movq %r13, %r15
movq %r14, %rdi
xorl %esi, %esi
leaq 0x904(%rip), %rdx       # 0x4ddd
movq %r15, %rcx
callq 0x2280
incq %rbx
movslq 0x1fd0d(%rip), %rax     # 0x241f8
addq $0x10, %r15
addq $0x8, %r14
cmpq %rax, %rbx
jl 0x44cd
movl 0x1fcfa(%rip), %eax     # 0x241f8
testl %eax, %eax
movq -0x50(%rbp), %r14
jle 0x4522
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
xorl %esi, %esi
callq 0x2300
incq %rbx
movslq 0x1fcdb(%rip), %rax     # 0x241f8
cmpq %rax, %rbx
jl 0x4508
testl %eax, %eax
movq -0x38(%rbp), %r14
movq -0x58(%rbp), %rcx
jle 0x455b
movl %eax, %eax
leaq 0x8(%rcx), %rdi
shlq $0x4, %rax
xorl %edx, %edx
movslq (%r13,%rdx), %rsi
movq %rsi, -0x8(%rdi)
movslq 0x4(%r13,%rdx), %rsi
movq %rsi, (%rdi)
addq $0x818, %rdi            # imm = 0x818
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x453a
movq -0x68(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
movq %r14, %rsi
callq 0x4e78
cmpq %r14, %rax
je 0x457a
movq %r14, -0x68(%rbp)
movq %rax, %r14
movq %r14, 0x1fc87(%rip)     # 0x24208
movq -0x30(%rbp), %rbx
movq %rbx, 0x1fc84(%rip)     # 0x24210
movq -0x40(%rbp), %rdi
movq %rdi, 0x1fc81(%rip)     # 0x24218
callq 0x6668
movl %eax, 0x1fc5e(%rip)     # 0x24200
movl 0x30(%rbx), %eax
movq -0x78(%rbp), %r11
movq %r11, %rcx
shlq $0x4, %rcx
movl %eax, 0xc(%r14,%rcx)
movq $0x0, (%r12)
movslq 0x1fc34(%rip), %rax     # 0x241f8
cmpq $0x2, %rax
jl 0x4629
movl 0x1fc2c(%rip), %ecx     # 0x241fc
leaq 0xc(%r14), %rdx
movl $0x1, %esi
movq %rsi, %rdi
imulq %r11, %rdi
sarq %cl, %rdi
movslq %edi, %rdi
testq %rdi, %rdi
jle 0x4614
leaq -0x1(%rdi), %r9
shlq $0x4, %rdi
addq %rdx, %rdi
movq %rdi, %r8
movq %r9, %rdi
shlq $0x4, %r9
movl 0xc(%r14,%r9), %r9d
incq %rdi
leaq 0x10(%r8), %r10
cmpl %r9d, (%r8)
movq %r10, %r8
je 0x4605
leaq (%rsi,%rsi,8), %r8
movq %rdi, -0x40(%r12,%r8,8)
movq %rdi, (%r12,%r8,8)
incq %rsi
cmpq %rax, %rsi
jne 0x45d9
leaq (%rax,%rax,8), %rcx
movq %r11, -0x40(%r12,%rcx,8)
movq -0x30(%rbp), %rcx
movl 0x20(%rcx), %edx
movb 0x1fba5(%rip), %cl      # 0x241e4
movl %edx, %ebx
sarl %cl, %ebx
negl %edx
sarl %cl, %edx
subl %edx, %ebx
incl %ebx
imull %ebx, %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x18fe8(%rip), %rsi     # 0x1d647
callq 0x14d79
movq %rax, -0x40(%rbp)
testq %rax, %rax
jne 0x4677
movl $0x1, %edi
callq 0x359c
movq %r14, -0x38(%rbp)
movl 0x1fb77(%rip), %eax     # 0x241f8
imull %ebx, %eax
leal (%rax,%rax,2), %eax
testl %eax, %eax
jle 0x469c
movl %eax, %edx
shlq $0x2, %rdx
movq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x2180
cmpl $0x0, 0x1fb55(%rip)     # 0x241f8
jle 0x4785
movslq %ebx, %rax
leaq 0x30(%r12), %rbx
movq %rax, -0x58(%rbp)
leaq (,%rax,4), %r15
xorl %r14d, %r14d
testq %r14, %r14
je 0x46d2
movq -0x58(%rbx), %rax
addq %r15, %rax
movq %rax, -0x20(%rbx)
jmp 0x46f5
xorl %eax, %eax
movq -0x30(%rbp), %rcx
subl 0x20(%rcx), %eax
movb 0x1fb03(%rip), %cl      # 0x241e4
sarl %cl, %eax
cltq
shlq $0x2, %rax
movq -0x40(%rbp), %rcx
subq %rax, %rcx
movq %rcx, 0x10(%r12)
movq -0x20(%rbx), %rax
addq %r15, %rax
movq %rax, -0x18(%rbx)
movq -0x58(%rbp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, -0x10(%rbx)
xorl %eax, %eax
callq 0x6390
movq %rax, -0x8(%rbx)
leaq 0x1faaa(%rip), %rax     # 0x241c8
movq (%rax), %r13
incq %r14
leaq 0x18f3a(%rip), %rdi     # 0x1d665
movl %r14d, %esi
leaq 0x18d8b(%rip), %rdx     # 0x1d4c0
callq 0x15101
movq %r13, %rdi
leaq 0x18f1f(%rip), %rsi     # 0x1d663
movq -0x60(%rbp), %rdx
movq %rax, %rcx
callq 0x15011
movq %rax, %rdi
leaq 0x1992b(%rip), %rsi     # 0x1e085
callq 0x14e95
movq %rax, (%rbx)
testq %rax, %rax
jne 0x4771
movl $0x1, %edi
callq 0x359c
movslq 0x1fa80(%rip), %rax     # 0x241f8
addq $0x48, %rbx
cmpq %rax, %r14
jl 0x46c0
cmpl $0x0, 0x1fa6c(%rip)     # 0x241f8
jle 0x47c6
xorl %r13d, %r13d
leaq 0xa43(%rip), %rbx       # 0x51db
movq -0x50(%rbp), %r14
movq %r12, %r15
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x2280
incq %r13
movslq 0x1fa3f(%rip), %rax     # 0x241f8
addq $0x48, %r15
addq $0x8, %r14
cmpq %rax, %r13
jl 0x479f
movl 0x1fa2c(%rip), %ecx     # 0x241f8
testl %ecx, %ecx
leaq 0x1f9ff(%rip), %r15     # 0x241d4
jle 0x47f7
xorl %ebx, %ebx
movq -0x50(%rbp), %r14
movq (%r14,%rbx,8), %rdi
xorl %esi, %esi
callq 0x2300
incq %rbx
movslq 0x1fa06(%rip), %rcx     # 0x241f8
cmpq %rcx, %rbx
jl 0x47dd
cmpl $0x0, (%r15)
je 0x48e2
movq -0x48(%rbp), %rax
testl %ecx, %ecx
jle 0x48e7
movl %ecx, %ecx
shlq $0x3, %rcx
leaq (%rcx,%rcx,8), %rcx
xorl %edx, %edx
xorl %r15d, %r15d
addq 0x38(%r12,%rdx), %rax
addq 0x40(%r12,%rdx), %r15
addq $0x48, %rdx
cmpq %rdx, %rcx
jne 0x481c
jmp 0x48ea
movq $0x0, -0x48(%rbp)
xorl %r15d, %r15d
cmpl $0x0, 0x1f9b2(%rip)     # 0x241f8
jle 0x4922
leaq 0x1f9ad(%rip), %r14     # 0x24200
xorl %r12d, %r12d
leaq 0x1f96b(%rip), %rax     # 0x241c8
movq (%rax), %r13
incl %r12d
leaq 0x18dfb(%rip), %rdi     # 0x1d665
movl %r12d, %esi
leaq 0x18c4c(%rip), %rdx     # 0x1d4c0
callq 0x15101
movq %r13, %rdi
leaq 0x18de0(%rip), %rsi     # 0x1d663
movq %rbx, %rdx
movq %rax, %rcx
callq 0x15011
movq %rax, %rdi
leaq 0x197ed(%rip), %rsi     # 0x1e085
callq 0x14e95
movq %rax, %r13
movl $0x8, %esi
movl $0x1, %edx
leaq -0x48(%rbp), %rdi
movq %rax, %rcx
callq 0x22f0
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r13, %rcx
callq 0x22f0
movq %r13, %rdi
callq 0x2100
cmpl 0x1f91e(%rip), %r12d    # 0x241f8
jl 0x4856
jmp 0x4922
xorl %r15d, %r15d
jmp 0x48ee
xorl %r15d, %r15d
movq %rax, -0x48(%rbp)
cmpl $0x0, 0x1f903(%rip)     # 0x241f8
jle 0x4919
addq $0x28, %r12
xorl %ebx, %ebx
movq (%r12), %rdi
callq 0x63d7
incq %rbx
movslq 0x1f8e8(%rip), %rax     # 0x241f8
addq $0x48, %r12
cmpq %rax, %rbx
jl 0x48fd
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x68(%rbp), %rdi
callq 0x2030
leaq 0x1f899(%rip), %rax     # 0x241d4
cmpl $0x0, (%rax)
je 0x4a0d
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
jle 0x4962
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
callq 0x21f0
cvttsd2si %xmm0, %eax
incl %eax
jmp 0x4967
movl $0x1, %eax
leal -0x1(%rax), %ecx
movslq %ecx, %rcx
imulq $0x55555556, %rcx, %r14 # imm = 0x55555556
movq %r14, %rcx
shrq $0x3f, %rcx
shrq $0x20, %r14
addl %ecx, %r14d
addl %eax, %r14d
leaq 0x18cf5(%rip), %rdi     # 0x1d681
xorl %eax, %eax
callq 0x2150
movq 0x1f63e(%rip), %r12     # 0x23fd8
movq (%r12), %rdx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x151b4
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
cvtsi2sdq -0x80(%rbp), %xmm1
movsd %xmm1, -0x60(%rbp)
divsd %xmm1, %xmm0
divsd %xmm1, %xmm0
leaq 0x18c9d(%rip), %rdi     # 0x1d668
movb $0x1, %al
callq 0x2150
movq (%r12), %rdx
movq %r15, %rdi
movl %r14d, %esi
callq 0x151b4
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movsd -0x60(%rbp), %xmm1
divsd %xmm1, %xmm0
divsd %xmm1, %xmm0
leaq 0x18c8b(%rip), %rdi     # 0x1d688
movb $0x1, %al
callq 0x2150
movq (%r12), %rdi
callq 0x2250
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq