// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: codeAttach
static void codeAttach(
  Parse *pParse,       /* The parser context */
  int type,            /* Either SQLITE_ATTACH or SQLITE_DETACH */
  FuncDef const *pFunc,/* FuncDef wrapper for detachFunc() or attachFunc() */
  Expr *pAuthArg,      /* Expression to pass to authorization callback */
  Expr *pFilename,     /* Name of database file */
  Expr *pDbname,       /* Name of the database to use internally */
  Expr *pKey           /* Database key for encryption extension */
){
  int rc;
  NameContext sName;
  Vdbe *v;
  sqlite3* db = pParse->db;
  int regArgs;

  memset(&sName, 0, sizeof(NameContext));
  sName.pParse = pParse;

  if( 
      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pDbname)) ||
      SQLITE_OK!=(rc = resolveAttachExpr(&sName, pKey))
  ){
    pParse->nErr++;
    goto attach_end;
  }

#ifndef SQLITE_OMIT_AUTHORIZATION
  if( pAuthArg ){
    char *zAuthArg;
    if( pAuthArg->op==TK_STRING ){
      zAuthArg = pAuthArg->u.zToken;
    }else{
      zAuthArg = 0;
    }
    rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
    if(rc!=SQLITE_OK ){
      goto attach_end;
    }
  }
#endif /* SQLITE_OMIT_AUTHORIZATION */


  v = sqlite3GetVdbe(pParse);
  regArgs = sqlite3GetTempRange(pParse, 4);
  sqlite3ExprCode(pParse, pFilename, regArgs);
  sqlite3ExprCode(pParse, pDbname, regArgs+1);
  sqlite3ExprCode(pParse, pKey, regArgs+2);

  assert( v || db->mallocFailed );
  if( v ){
    sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
    assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
    sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
    sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);

    /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
    ** statement only). For DETACH, set it to false (expire all existing
    ** statements).
    */
    sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));
  }
  
attach_end:
  sqlite3ExprDelete(db, pFilename);
  sqlite3ExprDelete(db, pDbname);
  sqlite3ExprDelete(db, pKey);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movq %r8, %r12
movq %rcx, %r14
movq %rdx, -0x40(%rbp)
movl %esi, -0x2c(%rbp)
movq %rdi, %r13
movq (%rdi), %r15
xorps %xmm0, %xmm0
leaq -0x78(%rbp), %rdi
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x8(%rdi)
movq %r13, (%rdi)
movq %r8, %rsi
callq 0x56f08
testl %eax, %eax
jne 0x56877
leaq -0x78(%rbp), %rdi
movq %rbx, %rsi
callq 0x56f08
testl %eax, %eax
jne 0x56877
leaq -0x78(%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0x56f08
testl %eax, %eax
je 0x568ac
incl 0x50(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2f476
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2f476
movq %r15, %rdi
movq 0x10(%rbp), %rsi
callq 0x2f476
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x568d3
cmpb $0x5e, (%r14)
jne 0x568bd
movq 0x8(%r14), %rdx
jmp 0x568bf
xorl %edx, %edx
movq %r13, %rdi
movl -0x2c(%rbp), %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x42151
testl %eax, %eax
jne 0x5687b
movq %r13, %rdi
callq 0x41ef4
movq %rax, -0x38(%rbp)
pushq $0x4
popq %rsi
movq %r13, %rdi
callq 0x47c2c
movl %eax, %r14d
movq %r13, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x494eb
leal 0x1(%r14), %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x494eb
leal 0x2(%r14), %edx
movq %r13, %rdi
movq 0x10(%rbp), %rsi
callq 0x494eb
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x5687b
movq %rax, %rdi
addl $0x3, %r14d
movq -0x40(%rbp), %r13
movswl (%r13), %eax
movl %r14d, %ecx
subl %eax, %ecx
pushq $0x1
popq %rsi
xorl %edx, %edx
movl %r14d, %r8d
movq %rdi, %r14
callq 0x41f4c
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x56964
movb (%r13), %cl
movslq 0x34(%r14), %rdx
imulq $0x18, %rdx, %rdx
movb %cl, -0x15(%rax,%rdx)
pushq $-0x1
popq %rsi
pushq $-0x5
popq %rcx
movq %r14, %rdi
movq %r13, %rdx
callq 0x1074b
xorl %edx, %edx
cmpl $0x18, -0x2c(%rbp)
sete %dl
movq %r14, %rdi
movl $0x84, %esi
callq 0x42436
jmp 0x5687b