// File: /workspace/github_c_makefile_star2_O1/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, -0x48(%rbp)
movl %esi, -0x2c(%rbp)
movq %rdi, %r13
movq (%rdi), %r15
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movq $0x0, 0x30(%rdi)
movq %r13, (%rdi)
movq %r8, %rsi
callq 0x620af
testl %eax, %eax
jne 0x61855
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
callq 0x620af
testl %eax, %eax
jne 0x61855
leaq -0x80(%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0x620af
testl %eax, %eax
je 0x6188a
incl 0x50(%r13)
movq %r15, %rdi
movq %r12, %rsi
callq 0x34068
movq %r15, %rdi
movq %rbx, %rsi
callq 0x34068
movq %r15, %rdi
movq 0x10(%rbp), %rsi
callq 0x34068
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x618b1
cmpb $0x5e, (%r14)
jne 0x6189b
movq 0x8(%r14), %rdx
jmp 0x6189d
xorl %edx, %edx
movq %r13, %rdi
movl -0x2c(%rbp), %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45d75
testl %eax, %eax
jne 0x61859
movq %r13, %rdi
callq 0x45b57
movq %rax, -0x40(%rbp)
movl 0x48(%r13), %eax
cmpl $0x4, %eax
jge 0x618da
movl 0x58(%r13), %eax
leal 0x1(%rax), %ecx
movq %rcx, -0x38(%rbp)
addl $0x4, %eax
movl %eax, 0x58(%r13)
jmp 0x618f0
movl 0x4c(%r13), %ecx
movq %rcx, -0x38(%rbp)
addl $0x4, %ecx
movl %ecx, 0x4c(%r13)
addl $-0x4, %eax
movl %eax, 0x48(%r13)
movq %r13, %rdi
movq %r12, %rsi
movq -0x38(%rbp), %r14
movl %r14d, %edx
callq 0x4e4ba
leal 0x1(%r14), %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4e4ba
leal 0x2(%r14), %edx
movq %r13, %rdi
movq 0x10(%rbp), %rsi
callq 0x4e4ba
movq -0x40(%rbp), %r13
testq %r13, %r13
je 0x61859
movq -0x38(%rbp), %r8
addl $0x3, %r8d
movq -0x48(%rbp), %r14
movswl (%r14), %eax
movl %r8d, %ecx
subl %eax, %ecx
movq %r13, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x45b9e
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x6196a
movb (%r14), %cl
movslq 0x34(%r13), %rdx
leaq (%rdx,%rdx,2), %rdx
movb %cl, -0x15(%rax,%rdx,8)
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r14, %rdx
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
callq 0x11975
xorl %edx, %edx
cmpl $0x18, -0x2c(%rbp)
sete %dl
movq %r13, %rdi
movl $0x84, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
jmp 0x61859