// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3AddPrimaryKey
SQLITE_PRIVATE void sqlite3AddPrimaryKey(
  Parse *pParse,    /* Parsing context */
  ExprList *pList,  /* List of field names to be indexed */
  int onError,      /* What to do with a uniqueness conflict */
  int autoInc,      /* True if the AUTOINCREMENT keyword is present */
  int sortOrder     /* SQLITE_SO_ASC or SQLITE_SO_DESC */
){
  Table *pTab = pParse->pNewTable;
  char *zType = 0;
  int iCol = -1, i;
  if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
  if( pTab->tabFlags & TF_HasPrimaryKey ){
    sqlite3ErrorMsg(pParse, 
      "table \"%s\" has more than one primary key", pTab->zName);
    goto primary_key_exit;
  }
  pTab->tabFlags |= TF_HasPrimaryKey;
  if( pList==0 ){
    iCol = pTab->nCol - 1;
    pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
  }else{
    for(i=0; i<pList->nExpr; i++){
      for(iCol=0; iCol<pTab->nCol; iCol++){
        if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
          break;
        }
      }
      if( iCol<pTab->nCol ){
        pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
      }
    }
    if( pList->nExpr>1 ) iCol = -1;
  }
  if( iCol>=0 && iCol<pTab->nCol ){
    zType = pTab->aCol[iCol].zType;
  }
  if( zType && sqlite3StrICmp(zType, "INTEGER")==0
        && sortOrder==SQLITE_SO_ASC ){
    pTab->iPKey = iCol;
    pTab->keyConf = (u8)onError;
    assert( autoInc==0 || autoInc==1 );
    pTab->tabFlags |= autoInc*TF_Autoincrement;
  }else if( autoInc ){
#ifndef SQLITE_OMIT_AUTOINCREMENT
    sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
       "INTEGER PRIMARY KEY");
#endif
  }else{
    Index *p;
    p = sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0,
                           0, sortOrder, 0);
    if( p ){
      p->autoIndex = 2;
    }
    pList = 0;
  }

primary_key_exit:
  sqlite3ExprListDelete(pParse->db, pList);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x238(%rdi), %r9
testq %r9, %r9
je 0x3a2b1
cmpb $0x0, 0x201(%rbx)
jne 0x3a2b1
movl %edx, %eax
movb 0x46(%r9), %dl
testb $0x4, %dl
jne 0x3a17b
orb $0x4, %dl
movb %dl, -0x29(%rbp)
movb %dl, 0x46(%r9)
testq %r14, %r14
je 0x3a194
movl %r8d, -0x3c(%rbp)
movl %ecx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movq %rbx, -0x58(%rbp)
movslq (%r14), %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %rcx, -0x50(%rbp)
testq %rcx, %rcx
jle 0x3a15f
movswq 0x42(%r9), %r11
testq %r11, %r11
setg -0x2a(%rbp)
xorl %r12d, %r12d
leaq 0x3bfcc(%rip), %r13     # 0x76060
movq %r14, -0x38(%rbp)
movl $0x0, %esi
testw %r11w, %r11w
jle 0x3a152
movq 0x8(%r14), %rcx
movq %r12, %rdx
shlq $0x5, %rdx
movq 0x8(%rcx,%rdx), %r14
movq %r9, %rax
movq 0x8(%r9), %rdx
movb (%r14), %cl
incq %r14
xorl %esi, %esi
movb -0x2a(%rbp), %r15b
leaq (%rsi,%rsi,2), %r8
shlq $0x4, %r8
movq (%rdx,%r8), %r8
testb %cl, %cl
je 0x3a102
movq %r14, %r10
movl %ecx, %r9d
movzbl %r9b, %ebx
movb (%rbx,%r13), %bl
movzbl (%r8), %edi
cmpb (%rdi,%r13), %bl
jne 0x3a105
incq %r8
movb (%r10), %r9b
incq %r10
testb %r9b, %r9b
jne 0x3a0e0
jmp 0x3a105
movl %ecx, %r9d
movzbl %r9b, %edi
movb (%rdi,%r13), %dil
movzbl (%r8), %r8d
cmpb (%r8,%r13), %dil
je 0x3a128
incq %rsi
cmpq %r11, %rsi
setl %r15b
jne 0x3a0ca
movl %r11d, %esi
jmp 0x3a14b
testb $0x1, %r15b
je 0x3a14b
movq %rax, %r9
movq 0x8(%rax), %rcx
movl %esi, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
orw $0x1, 0x2a(%rcx,%rdx)
movq -0x38(%rbp), %r14
jmp 0x3a152
movq -0x38(%rbp), %r14
movq %rax, %r9
incq %r12
cmpq -0x50(%rbp), %r12
jne 0x3a098
cmpl $0x2, -0x50(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovgel %eax, %esi
movq -0x58(%rbp), %rbx
movl -0x44(%rbp), %eax
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r8d
jmp 0x3a1b1
movq (%r9), %rdx
leaq 0x41254(%rip), %rsi     # 0x7b3d9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11724
jmp 0x3a2b1
movswl 0x42(%r9), %edx
movslq %edx, %rdi
leal -0x1(%rdi), %esi
movq 0x8(%r9), %rdx
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
orw $0x1, -0x6(%rdi,%rdx)
testl %esi, %esi
js 0x3a1d3
movswl 0x42(%r9), %edx
cmpl %edx, %esi
jge 0x3a1d3
movq 0x8(%r9), %rdi
movl %esi, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq 0x18(%rdi,%rdx), %rdx
jmp 0x3a1d5
xorl %edx, %edx
testq %rdx, %rdx
je 0x3a23e
movq %r9, %r12
movb (%rdx), %dil
testb %dil, %dil
je 0x3a218
incq %rdx
leaq 0x41081(%rip), %r11     # 0x7b270
leaq 0x3be6a(%rip), %r15     # 0x76060
movzbl %dil, %r9d
movb (%r9,%r15), %r9b
movzbl (%r11), %r10d
cmpb (%r10,%r15), %r9b
jne 0x3a21f
incq %r11
movb (%rdx), %dil
incq %rdx
testb %dil, %dil
jne 0x3a1f6
jmp 0x3a21f
leaq 0x41051(%rip), %r11     # 0x7b270
movzbl %dil, %edx
leaq 0x3be36(%rip), %rdi     # 0x76060
movzbl (%rdx,%rdi), %edx
movzbl (%r11), %r9d
movzbl (%r9,%rdi), %edi
subl %edi, %edx
orl %r8d, %edx
je 0x3a299
testl %ecx, %ecx
je 0x3a255
leaq 0x411b9(%rip), %rsi     # 0x7b402
movq %rbx, %rdi
xorl %eax, %eax
callq 0x11724
jmp 0x3a2b1
movl %r8d, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
movl $0x0, 0x18(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movl %eax, %r9d
callq 0x3a2ca
movl $0x0, %r14d
testq %rax, %rax
je 0x3a2b1
movb 0x57(%rax), %cl
andb $-0x4, %cl
orb $0x2, %cl
movb %cl, 0x57(%rax)
xorl %r14d, %r14d
jmp 0x3a2b1
movw %si, 0x40(%r12)
movb %al, 0x47(%r12)
shlb $0x3, %cl
movb -0x29(%rbp), %al
orb %cl, %al
movb %al, 0x46(%r12)
movq (%rbx), %rdi
movq %r14, %rsi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3410b