// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3WindowUpdate
SQLITE_PRIVATE void sqlite3WindowUpdate(
  Parse *pParse,
  Window *pList,                  /* List of named windows for this SELECT */
  Window *pWin,                   /* Window frame to update */
  FuncDef *pFunc                  /* Window function definition */
){
  if( pWin->zName && pWin->eFrmType==0 ){
    Window *p = windowFind(pParse, pList, pWin->zName);
    if( p==0 ) return;
    pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
    pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
    pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
    pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
    pWin->eStart = p->eStart;
    pWin->eEnd = p->eEnd;
    pWin->eFrmType = p->eFrmType;
    pWin->eExclude = p->eExclude;
  }else{
    sqlite3WindowChain(pParse, pWin, pList);
  }
  if( (pWin->eFrmType==TK_RANGE)
   && (pWin->pStart || pWin->pEnd)
   && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
  ){
    sqlite3ErrorMsg(pParse,
      "RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression"
    );
  }else
  if( pFunc->funcFlags & SQLITE_FUNC_WINDOW ){
    sqlite3 *db = pParse->db;
    if( pWin->pFilter ){
      sqlite3ErrorMsg(pParse,
          "FILTER clause may only be used with aggregate window functions"
      );
    }else{
      struct WindowUpdate {
        const char *zFunc;
        int eFrmType;
        int eStart;
        int eEnd;
      } aUp[] = {
        { row_numberName,   TK_ROWS,   TK_UNBOUNDED, TK_CURRENT },
        { dense_rankName,   TK_RANGE,  TK_UNBOUNDED, TK_CURRENT },
        { rankName,         TK_RANGE,  TK_UNBOUNDED, TK_CURRENT },
        { percent_rankName, TK_GROUPS, TK_CURRENT,   TK_UNBOUNDED },
        { cume_distName,    TK_GROUPS, TK_FOLLOWING, TK_UNBOUNDED },
        { ntileName,        TK_ROWS,   TK_CURRENT,   TK_UNBOUNDED },
        { leadName,         TK_ROWS,   TK_UNBOUNDED, TK_UNBOUNDED },
        { lagName,          TK_ROWS,   TK_UNBOUNDED, TK_CURRENT },
      };
      int i;
      for(i=0; i<ArraySize(aUp); i++){
        if( pFunc->zName==aUp[i].zFunc ){
          sqlite3ExprDelete(db, pWin->pStart);
          sqlite3ExprDelete(db, pWin->pEnd);
          pWin->pEnd = pWin->pStart = 0;
          pWin->eFrmType = aUp[i].eFrmType;
          pWin->eStart = aUp[i].eStart;
          pWin->eEnd = aUp[i].eEnd;
          pWin->eExclude = 0;
          if( pWin->eStart==TK_FOLLOWING ){
            pWin->pStart = sqlite3Expr(db, TK_INTEGER, "1");
          }
          break;
        }
      }
    }
  }
  pWin->pFunc = pFunc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %r15
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x2cff45
cmpb $0x0, 0x20(%r14)
je 0x2cffb4
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2c5b54
cmpb $0x59, 0x20(%r14)
jne 0x2cff76
cmpq $0x0, 0x28(%r14)
jne 0x2cff68
cmpq $0x0, 0x30(%r14)
je 0x2cff76
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x2cff90
cmpl $0x1, (%rax)
jne 0x2cff90
testb $0x1, 0x6(%rbx)
je 0x2cffa1
cmpq $0x0, 0x48(%r14)
je 0x2d002b
leaq 0x1113ec(%rip), %rsi    # 0x3e137a
jmp 0x2cff97
leaq 0x11139c(%rip), %rsi    # 0x3e1333
movq %r15, %rdi
xorl %eax, %eax
callq 0x284eb8
movq %rbx, 0x50(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %rax, %rsi
callq 0x2d0492
testq %rax, %rax
je 0x2cffa5
movq %rax, %r12
movq (%r15), %rdi
movq 0x10(%rax), %rsi
xorl %r13d, %r13d
xorl %edx, %edx
callq 0x2cc525
movq %rax, 0x10(%r14)
movq (%r15), %rdi
movq 0x18(%r12), %rsi
xorl %edx, %edx
callq 0x2cc525
movq %rax, 0x18(%r14)
movq 0x28(%r12), %rsi
testq %rsi, %rsi
je 0x2d0008
movq (%r15), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cbf97
movq %rax, %r13
movq %r13, 0x28(%r14)
movq 0x30(%r12), %rsi
testq %rsi, %rsi
je 0x2d00db
movq (%r15), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cbf97
jmp 0x2d00dd
movq (%r15), %r15
movq 0x38(%rbx), %rax
movl $0x10, %r12d
leaq 0x1f2c11(%rip), %r13    # 0x4c2c50
cmpq -0x10(%r12,%r13), %rax
je 0x2d0058
addq $0x18, %r12
cmpq $0xd0, %r12
jne 0x2d003f
jmp 0x2cffa1
movq 0x28(%r14), %rsi
testq %rsi, %rsi
je 0x2d0069
movq %r15, %rdi
callq 0x2afd54
leaq 0x28(%r14), %rbp
movq 0x30(%r14), %rsi
testq %rsi, %rsi
je 0x2d007e
movq %r15, %rdi
callq 0x2afd54
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
movb -0x8(%r12,%r13), %al
movb -0x4(%r12,%r13), %cl
movb %al, 0x20(%r14)
movb %cl, 0x21(%r14)
movb (%r12,%r13), %al
movb %al, 0x22(%r14)
movb $0x0, 0x24(%r14)
cmpb $0x56, %cl
jne 0x2cffa1
leaq 0xa7bb6(%rip), %rax     # 0x377c6a
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
movl $0x1, 0x8(%rdx)
movq %r15, %rdi
movl $0x98, %esi
xorl %ecx, %ecx
callq 0x2bb38d
movq %rax, (%rbp)
jmp 0x2cffa1
xorl %eax, %eax
movq %rax, 0x30(%r14)
movb 0x21(%r12), %al
movb %al, 0x21(%r14)
movb 0x22(%r12), %al
movb %al, 0x22(%r14)
movb 0x20(%r12), %al
movb %al, 0x20(%r14)
movb 0x24(%r12), %al
movb %al, 0x24(%r14)
testq %r12, %r12
jne 0x2cff53
jmp 0x2cffa5