// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqliteProcessJoin
static int sqliteProcessJoin(Parse *pParse, Select *p){
  SrcList *pSrc;                  /* All tables in the FROM clause */
  int i, j;                       /* Loop counters */
  struct SrcList_item *pLeft;     /* Left table being joined */
  struct SrcList_item *pRight;    /* Right table being joined */

  pSrc = p->pSrc;
  pLeft = &pSrc->a[0];
  pRight = &pLeft[1];
  for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
    Table *pRightTab = pRight->pTab;
    int isOuter;

    if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
    isOuter = (pRight->fg.jointype & JT_OUTER)!=0;

    /* When the NATURAL keyword is present, add WHERE clause terms for
    ** every column that the two tables have in common.
    */
    if( pRight->fg.jointype & JT_NATURAL ){
      if( pRight->pOn || pRight->pUsing ){
        sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
           "an ON or USING clause", 0);
        return 1;
      }
      for(j=0; j<pRightTab->nCol; j++){
        char *zName;   /* Name of column in the right table */
        int iLeft;     /* Matching left table */
        int iLeftCol;  /* Matching column in the left table */

        if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue;
        zName = pRightTab->aCol[j].zName;
        if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){
          addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,
                isOuter, &p->pWhere);
        }
      }
    }

    /* Disallow both ON and USING clauses in the same join
    */
    if( pRight->pOn && pRight->pUsing ){
      sqlite3ErrorMsg(pParse, "cannot have both ON and USING "
        "clauses in the same join");
      return 1;
    }

    /* Add the ON clause to the end of the WHERE clause, connected by
    ** an AND operator.
    */
    if( pRight->pOn ){
      if( isOuter ) sqlite3SetJoinExpr(pRight->pOn, pRight->iCursor);
      p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->pOn);
      pRight->pOn = 0;
    }

    /* Create extra terms on the WHERE clause for each column named
    ** in the USING clause.  Example: If the two tables to be joined are
    ** A and B and the USING clause names X, Y, and Z, then add this
    ** to the WHERE clause:    A.X=B.X AND A.Y=B.Y AND A.Z=B.Z
    ** Report an error if any column mentioned in the USING clause is
    ** not contained in both tables to be joined.
    */
    if( pRight->pUsing ){
      IdList *pList = pRight->pUsing;
      for(j=0; j<pList->nId; j++){
        char *zName;     /* Name of the term in the USING clause */
        int iLeft;       /* Table on the left with matching column name */
        int iLeftCol;    /* Column number of matching column on the left */
        int iRightCol;   /* Column number of matching column on the right */

        zName = pList->a[j].zName;
        iRightCol = columnIndex(pRightTab, zName);
        if( iRightCol<0
         || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 0)
        ){
          sqlite3ErrorMsg(pParse, "cannot join using column %s - column "
            "not present in both tables", zName);
          return 1;
        }
        addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, iRightCol,
                     isOuter, &p->pWhere);
      }
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, 0x10(%rsp)
movq 0x28(%rsi), %r15
cmpl $0x2, (%r15)
jl 0x2d23a0
movq %rsi, %rbx
leaq 0x8(%r15), %r12
leaq 0x78(%r15), %r14
leaq 0x30(%rsi), %rax
movq %rax, 0x58(%rsp)
leaq 0x28(%r15), %rax
movq %rax, 0x68(%rsp)
xorl %edx, %edx
movq %rsi, 0x50(%rsp)
movq %r15, 0x70(%rsp)
movq 0x20(%r14), %rsi
cmpq $0x0, 0x20(%r12)
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
movl $0x4, %eax
jne 0x2d2198
movq %rdx, 0x8(%rsp)
movq %r14, 0x20(%rsp)
movzbl 0x3c(%r14), %eax
movl %eax, %ebp
andl $0x20, %ebp
movl %ebp, %ecx
shrl $0x5, %ecx
movq %rcx, 0x60(%rsp)
testb $0x4, %al
movq %rsi, 0x28(%rsp)
jne 0x2d2162
movq 0x20(%rsp), %r14
movq 0x48(%r14), %rdi
testq %rdi, %rdi
je 0x2d21f4
cmpq $0x0, 0x50(%r14)
je 0x2d21bf
movq 0x10(%rsp), %rdi
leaq 0x10f4d8(%rip), %rsi    # 0x3e1631
xorl %eax, %eax
callq 0x284eb8
jmp 0x2d218e
movq 0x20(%rsp), %r14
cmpq $0x0, 0x48(%r14)
jne 0x2d2179
cmpq $0x0, 0x50(%r14)
je 0x2d230b
movq 0x10(%rsp), %rdi
leaq 0x10f47a(%rip), %rsi    # 0x3e15ff
xorl %edx, %edx
xorl %eax, %eax
callq 0x284eb8
movl $0x1, %eax
movq 0x8(%rsp), %rdx
testb $0x3, %al
jne 0x2d23b1
incq %rdx
addq $0x70, %r14
addq $0x70, %r12
movslq (%r15), %rax
decq %rax
cmpq %rax, %rdx
jl 0x2d20ed
jmp 0x2d23a0
testq %rdi, %rdi
je 0x2d21f4
testl %ebp, %ebp
je 0x2d21d1
movl 0x40(%r14), %esi
callq 0x2d2b83
movq 0x30(%rbx), %rsi
movq 0x48(%r14), %rdx
movq 0x10(%rsp), %rdi
callq 0x2c02f0
movq %rax, 0x30(%rbx)
movq $0x0, 0x48(%r14)
movq 0x28(%rsp), %rsi
movq 0x50(%r14), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x2d2193
cmpl $0x0, 0x8(%rcx)
movq 0x8(%rsp), %rdx
jle 0x2d2198
movq %r12, 0x30(%rsp)
leal 0x1(%rdx), %eax
movl %eax, 0x3c(%rsp)
leaq 0x1(%rdx), %r12
xorl %r14d, %r14d
movq %rcx, 0x18(%rsp)
movq (%rcx), %rax
movq %r14, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %r13
movq %rsi, %rdi
movq %r13, %rsi
callq 0x2d2bfc
testl %eax, %eax
js 0x2d22dc
movl %eax, %ebp
movq 0x68(%rsp), %r15
xorl %ebx, %ebx
movq (%r15), %rdi
movq %r13, %rsi
callq 0x2d2bfc
testl %eax, %eax
jns 0x2d2271
incq %rbx
addq $0x70, %r15
cmpq %rbx, %r12
jne 0x2d224c
movl 0x44(%rsp), %ecx
movl 0x40(%rsp), %edx
jmp 0x2d2275
movl %ebx, %edx
movl %eax, %ecx
testl %eax, %eax
movq 0x70(%rsp), %r15
movl %ecx, 0x44(%rsp)
movl %edx, 0x40(%rsp)
js 0x2d22dc
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl 0x3c(%rsp), %r8d
movl %ebp, %r9d
pushq 0x58(%rsp)
pushq 0x68(%rsp)
callq 0x2d2af4
addq $0x10, %rsp
incq %r14
movq 0x18(%rsp), %rcx
movslq 0x8(%rcx), %rax
cmpq %rax, %r14
movq 0x28(%rsp), %rsi
jl 0x2d2222
movq 0x50(%rsp), %rbx
movq 0x30(%rsp), %r12
movq 0x20(%rsp), %r14
movq 0x8(%rsp), %rdx
xorl %eax, %eax
jmp 0x2d2198
movq 0x30(%rsp), %r12
movq 0x10(%rsp), %rdi
leaq 0x10f37b(%rip), %rsi    # 0x3e1668
movq %r13, %rdx
xorl %eax, %eax
callq 0x284eb8
movl $0x1, %eax
movq 0x50(%rsp), %rbx
movq 0x20(%rsp), %r14
jmp 0x2d2193
cmpw $0x0, 0x46(%rsi)
jle 0x2d2134
movq 0x8(%rsp), %rax
incl %eax
movl %eax, 0x18(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%rsi), %rax
testb $0x2, 0x1c(%rax,%r14)
jne 0x2d238a
movq (%rax,%r14), %rdx
movq %r15, %rdi
movl 0x18(%rsp), %esi
leaq 0x4c(%rsp), %rcx
leaq 0x48(%rsp), %r8
movl $0x1, %r9d
callq 0x2d23b8
movq 0x28(%rsp), %rsi
testl %eax, %eax
je 0x2d238a
movl 0x4c(%rsp), %edx
movl 0x48(%rsp), %ecx
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl 0x18(%rsp), %r8d
movl %r13d, %r9d
pushq 0x58(%rsp)
pushq 0x68(%rsp)
callq 0x2d2af4
movq 0x38(%rsp), %rsi
addq $0x10, %rsp
incq %r13
movswq 0x46(%rsi), %rax
addq $0x20, %r14
cmpq %rax, %r13
jl 0x2d2327
jmp 0x2d2134
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0x2d23a2