// File: /workspace/github_c_makefile_star2_O3/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 0x2c6868
cmpb $0x0, 0x20(%r14)
je 0x2c68d8
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2bc3b3
movb 0x20(%r14), %al
cmpb $0x59, %al
jne 0x2c689a
cmpq $0x0, 0x28(%r14)
jne 0x2c688c
cmpq $0x0, 0x30(%r14)
je 0x2c689a
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x2c68b4
cmpl $0x1, (%rax)
jne 0x2c68b4
testb $0x1, 0x6(%rbx)
je 0x2c68c5
cmpq $0x0, 0x48(%r14)
je 0x2c694f
leaq 0x111373(%rip), %rsi    # 0x3d7c25
jmp 0x2c68bb
leaq 0x111323(%rip), %rsi    # 0x3d7bde
movq %r15, %rdi
xorl %eax, %eax
callq 0x27b48d
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 0x2c6e1d
testq %rax, %rax
je 0x2c68c9
movq %rax, %r12
movq (%r15), %rdi
movq 0x10(%rax), %rsi
xorl %r13d, %r13d
xorl %edx, %edx
callq 0x2c2deb
movq %rax, 0x10(%r14)
movq (%r15), %rdi
movq 0x18(%r12), %rsi
xorl %edx, %edx
callq 0x2c2deb
movq %rax, 0x18(%r14)
movq 0x28(%r12), %rsi
testq %rsi, %rsi
je 0x2c692c
movq (%r15), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c2864
movq %rax, %r13
movq %r13, 0x28(%r14)
movq 0x30(%r12), %rsi
testq %rsi, %rsi
je 0x2c69ff
movq (%r15), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c2864
jmp 0x2c6a01
movq (%r15), %r15
movq 0x38(%rbx), %rax
movl $0x10, %r12d
leaq 0x1f12dd(%rip), %r13    # 0x4b7c40
cmpq -0x10(%r12,%r13), %rax
je 0x2c697c
addq $0x18, %r12
cmpq $0xd0, %r12
jne 0x2c6963
jmp 0x2c68c5
movq 0x28(%r14), %rsi
testq %rsi, %rsi
je 0x2c698d
movq %r15, %rdi
callq 0x2a6164
leaq 0x28(%r14), %rbp
movq 0x30(%r14), %rsi
testq %rsi, %rsi
je 0x2c69a2
movq %r15, %rdi
callq 0x2a6164
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 0x2c68c5
leaq 0xa8022(%rip), %rax     # 0x36e9fa
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
movl $0x1, 0x8(%rdx)
movq %r15, %rdi
movl $0x98, %esi
xorl %ecx, %ecx
callq 0x2b1c27
movq %rax, (%rbp)
jmp 0x2c68c5
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), %cl
movb %cl, 0x24(%r14)
jmp 0x2c687a