// Code generated for linux/s390x by 'generator -mlong-double-64 --package-name libsqlite3 --prefix-enumerator=_ --prefix-external=x_ --prefix-field=F --prefix-static-internal=_ --prefix-static-none=_ --prefix-tagged-enum=_ --prefix-tagged-struct=T --prefix-tagged-union=T --prefix-typename=T --prefix-undefined=_ -ignore-unsupported-alignment -ignore-link-errors -import=sync -DHAVE_USLEEP -DLONGDOUBLE_TYPE=double -DNDEBUG -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DISABLE_INTRINSIC -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_GEOPOLY -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_OFFSET_SQL_FUNC -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_RBU -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_SNAPSHOT -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_HAVE_ZLIB=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_SOUNDEX -DSQLITE_THREADSAFE=1 -DSQLITE_WITHOUT_ZONEMALLOC -D_LARGEFILE64_SOURCE -I /home/jnml/src/modernc.org/builder/.exclude/modernc.org/libc/include/linux/s390x -I /home/jnml/src/modernc.org/builder/.exclude/modernc.org/libz/include/linux/s390x -I /home/jnml/src/modernc.org/builder/.exclude/modernc.org/libtcl8.6/include/linux/s390x -extended-errors -o sqlite3.go sqlite3.c -DSQLITE_OS_UNIX=1 -eval-all-macros', DO NOT EDIT.

//go:build linux && s390x

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

const BYTE_ORDER = 4321

const POSIX_FADV_DONTNEED = 6

const POSIX_FADV_NOREUSE = 7

const SQLITE_BIGENDIAN = 1

const SQLITE_BYTEORDER = 4321

const SQLITE_LITTLEENDIAN = 0

const SQLITE_UTF16NATIVE = 3

type Tstat = struct {
	Fst_dev     Tdev_t
	Fst_ino     Tino_t
	Fst_nlink   Tnlink_t
	Fst_mode    Tmode_t
	Fst_uid     Tuid_t
	Fst_gid     Tgid_t
	Fst_rdev    Tdev_t
	Fst_size    Toff_t
	Fst_atim    Ttimespec
	Fst_mtim    Ttimespec
	Fst_ctim    Ttimespec
	Fst_blksize Tblksize_t
	Fst_blocks  Tblkcnt_t
	F__unused   [3]uint64
}

func Xsqlite3_bind_text16(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, n int32, __ccgo_fp_xDel uintptr) (r int32) {
	return _bindText(tls, pStmt, i, zData, libc.Int64FromUint64(libc.Uint64FromInt32(n) & ^libc.Uint64FromInt32(1)), __ccgo_fp_xDel, uint8(SQLITE_UTF16BE))
}

func Xsqlite3_bind_text64(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Tsqlite3_uint64, __ccgo_fp_xDel uintptr, enc uint8) (r int32) {
	if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) && libc.Int32FromUint8(enc) != int32(SQLITE_UTF8_ZT) {
		if libc.Int32FromUint8(enc) == int32(SQLITE_UTF16) {
			enc = uint8(SQLITE_UTF16BE)
		}
		nData = nData & ^libc.Uint64FromInt32(1)
	}
	return _bindText(tls, pStmt, i, zData, libc.Int64FromUint64(nData), __ccgo_fp_xDel, enc)
}

// C documentation
//
//	/*
//	** Set all the parameters in the compiled SQL statement to NULL.
//	*/
func Xsqlite3_clear_bindings(tls *libc.TLS, pStmt uintptr) (r int32) {
	var i, rc int32
	var mutex, p uintptr
	_, _, _, _ = i, mutex, p, rc
	rc = SQLITE_OK
	p = pStmt
	mutex = (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex
	Xsqlite3_mutex_enter(tls, mutex)
	i = 0
	for {
		if !(i < int32((*TVdbe)(unsafe.Pointer(p)).FnVar)) {
			break
		}
		_sqlite3VdbeMemRelease(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar+uintptr(i)*56)
		(**(**TMem)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(i)*56))).Fflags = uint16(MEM_Null)
		goto _1
	_1:
		;
		i = i + 1
	}
	if (*TVdbe)(unsafe.Pointer(p)).Fexpmask != 0 {
		libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 14, 0xc000)
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return rc
}

// C documentation
//
//	/*
//	** This routine is the same as the sqlite3_complete() routine described
//	** above, except that the parameter is required to be UTF-16 encoded, not
//	** UTF-8.
//	*/
func Xsqlite3_complete16(tls *libc.TLS, zSql uintptr) (r int32) {
	var pVal, zSql8 uintptr
	var rc int32
	_, _, _ = pVal, rc, zSql8
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	pVal = _sqlite3ValueNew(tls, uintptr(0))
	_sqlite3ValueSetStr(tls, pVal, -int32(1), zSql, uint8(SQLITE_UTF16BE), libc.UintptrFromInt32(0))
	zSql8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zSql8 != 0 {
		rc = Xsqlite3_complete(tls, zSql8)
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	_sqlite3ValueFree(tls, pVal)
	return rc & int32(0xff)
}

/************** End of rtree.h ***********************************************/
/************** Continuing where we left off in main.c ***********************/

// C documentation
//
//	/*
//	** Register a new collation sequence with the database handle db.
//	*/
func Xsqlite3_create_collation16(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, __ccgo_fp_xCompare uintptr) (r int32) {
	var rc int32
	var zName8 uintptr
	_, _ = rc, zName8
	rc = SQLITE_OK
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	zName8 = _sqlite3Utf16to8(tls, db, zName, -int32(1), uint8(SQLITE_UTF16BE))
	if zName8 != 0 {
		rc = _createCollation(tls, db, zName8, libc.Uint8FromInt32(enc), pCtx, __ccgo_fp_xCompare, uintptr(0))
		_sqlite3DbFree(tls, db, zName8)
	}
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_create_function16(tls *libc.TLS, db uintptr, zFunctionName uintptr, nArg int32, eTextRep int32, p uintptr, __ccgo_fp_xSFunc uintptr, __ccgo_fp_xStep uintptr, __ccgo_fp_xFinal uintptr) (r int32) {
	var rc int32
	var zFunc8 uintptr
	_, _ = rc, zFunc8
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	zFunc8 = _sqlite3Utf16to8(tls, db, zFunctionName, -int32(1), uint8(SQLITE_UTF16BE))
	rc = _sqlite3CreateFunc(tls, db, zFunc8, nArg, eTextRep, p, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, uintptr(0), uintptr(0), uintptr(0))
	_sqlite3DbFree(tls, db, zFunc8)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** This function is used to set the schema of a virtual table.  It is only
//	** valid to call this function from within the xCreate() or xConnect() of a
//	** virtual table module.
//	*/
func Xsqlite3_declare_vtab(tls *libc.TLS, db uintptr, zCreateTable uintptr) (r int32) {
	bp := tls.Alloc(448)
	defer tls.Free(448)
	var i, initBusy, rc int32
	var pCtx, pIdx, pNew, pTab, z, v3 uintptr
	var v2 Ti16
	var _ /* sParse at bp+0 */ TParse
	var _ /* tokenType at bp+424 */ int32
	_, _, _, _, _, _, _, _, _, _ = i, initBusy, pCtx, pIdx, pNew, pTab, rc, z, v2, v3
	rc = SQLITE_OK
	/* Verify that the first two keywords in the CREATE TABLE statement
	 ** really are "CREATE" and "TABLE".  If this is not the case, then
	 ** sqlite3_declare_vtab() is being misused.
	 */
	z = zCreateTable
	i = 0
	for {
		if !(_aKeyword1[i] != 0) {
			break
		}
		**(**int32)(__ccgo_up(bp + 424)) = 0
		for cond := true; cond; cond = **(**int32)(__ccgo_up(bp + 424)) == int32(TK_SPACE) || **(**int32)(__ccgo_up(bp + 424)) == int32(TK_COMMENT) {
			z = z + uintptr(_sqlite3GetToken(tls, z, bp+424))
		}
		if **(**int32)(__ccgo_up(bp + 424)) != libc.Int32FromUint8(_aKeyword1[i]) {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), __ccgo_ts+23609, 0)
			return int32(SQLITE_ERROR)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	pCtx = (*Tsqlite3)(unsafe.Pointer(db)).FpVtabCtx
	if !(pCtx != 0) || (*TVtabCtx)(unsafe.Pointer(pCtx)).FbDeclared != 0 {
		_sqlite3Error(tls, db, _sqlite3MisuseError(tls, int32(162730)))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
		return _sqlite3MisuseError(tls, int32(162732))
	}
	pTab = (*TVtabCtx)(unsafe.Pointer(pCtx)).FpTab
	_sqlite3ParseObjectInit(tls, bp, db)
	(**(**TParse)(__ccgo_up(bp))).FeParseMode = uint8(PARSE_MODE_DECLARE_VTAB)
	libc.SetBitFieldPtr16Uint32(bp+40, libc.Uint32FromInt32(1), 15, 0x8000)
	/* We should never be able to reach this point while loading the
	 ** schema.  Nevertheless, defend against that (turn off db->init.busy)
	 ** in case a bug arises. */
	initBusy = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy)
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
	(**(**TParse)(__ccgo_up(bp))).FnQueryLoop = int16(1)
	if SQLITE_OK == _sqlite3RunParser(tls, bp, zCreateTable) {
		if !((*TTable)(unsafe.Pointer(pTab)).FaCol != 0) {
			pNew = (**(**TParse)(__ccgo_up(bp))).FpNewTable
			(*TTable)(unsafe.Pointer(pTab)).FaCol = (*TTable)(unsafe.Pointer(pNew)).FaCol
			_sqlite3ExprListDelete(tls, db, (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pNew + 64))).FpDfltList)
			v2 = (*TTable)(unsafe.Pointer(pNew)).FnCol
			(*TTable)(unsafe.Pointer(pTab)).FnCol = v2
			(*TTable)(unsafe.Pointer(pTab)).FnNVCol = v2
			**(**Tu32)(__ccgo_up(pTab + 48)) |= (*TTable)(unsafe.Pointer(pNew)).FtabFlags & libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid)|libc.Int32FromInt32(TF_NoVisibleRowid))
			(*TTable)(unsafe.Pointer(pNew)).FnCol = 0
			(*TTable)(unsafe.Pointer(pNew)).FaCol = uintptr(0)
			if !((*TTable)(unsafe.Pointer(pNew)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && (*Tsqlite3_module)(unsafe.Pointer((*TModule)(unsafe.Pointer((*TVTable)(unsafe.Pointer((*TVtabCtx)(unsafe.Pointer(pCtx)).FpVTable)).FpMod)).FpModule)).FxUpdate != uintptr(0) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(_sqlite3PrimaryKeyIndex(tls, pNew))).FnKeyCol) != int32(1) {
				/* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
				 ** or else must have a single-column PRIMARY KEY */
				rc = int32(SQLITE_ERROR)
			}
			pIdx = (*TTable)(unsafe.Pointer(pNew)).FpIndex
			if pIdx != 0 {
				(*TTable)(unsafe.Pointer(pTab)).FpIndex = pIdx
				(*TTable)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
				(*TIndex)(unsafe.Pointer(pIdx)).FpTable = pTab
			}
		}
		(*TVtabCtx)(unsafe.Pointer(pCtx)).FbDeclared = int32(1)
	} else {
		if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
			v3 = __ccgo_ts + 3944
		} else {
			v3 = uintptr(0)
		}
		_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_ERROR), v3, libc.VaList(bp+440, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
		_sqlite3DbFree(tls, db, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
		rc = int32(SQLITE_ERROR)
	}
	(**(**TParse)(__ccgo_up(bp))).FeParseMode = uint8(PARSE_MODE_NORMAL)
	if (**(**TParse)(__ccgo_up(bp))).FpVdbe != 0 {
		_sqlite3VdbeFinalize(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe)
	}
	_sqlite3DeleteTable(tls, db, (**(**TParse)(__ccgo_up(bp))).FpNewTable)
	_sqlite3ParseObjectReset(tls, bp)
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = libc.Uint8FromInt32(initBusy)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/* Convert zSchema to a MemDB and initialize its content.
//	*/
func Xsqlite3_deserialize(tls *libc.TLS, db uintptr, zSchema uintptr, pData uintptr, szDb Tsqlite3_int64, szBuf Tsqlite3_int64, mFlags uint32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var iDb, rc int32
	var p, pStore, zSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _ = iDb, p, pStore, rc, zSql
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema == uintptr(0) {
		zSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
	}
	iDb = _sqlite3FindDbName(tls, db, zSchema)
	if iDb < int32(2) && iDb != 0 {
		rc = int32(SQLITE_ERROR)
		goto end_deserialize
	}
	zSql = Xsqlite3_mprintf(tls, __ccgo_ts+4185, libc.VaList(bp+16, zSchema))
	if zSql == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -int32(1), bp, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	if rc != 0 {
		goto end_deserialize
	}
	(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
	libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(1), 4, 0x10)
	Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp)))
	libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(0), 4, 0x10)
	rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc != SQLITE_OK {
		goto end_deserialize
	}
	p = _memdbFromDbSchema(tls, db, zSchema)
	if p == uintptr(0) {
		rc = int32(SQLITE_ERROR)
	} else {
		pStore = (*TMemFile)(unsafe.Pointer(p)).FpStore
		(*TMemStore)(unsafe.Pointer(pStore)).FaData = pData
		pData = uintptr(0)
		(*TMemStore)(unsafe.Pointer(pStore)).Fsz = szDb
		(*TMemStore)(unsafe.Pointer(pStore)).FszAlloc = szBuf
		(*TMemStore)(unsafe.Pointer(pStore)).FszMax = szBuf
		if (*TMemStore)(unsafe.Pointer(pStore)).FszMax < _sqlite3Config.FmxMemdbSize {
			(*TMemStore)(unsafe.Pointer(pStore)).FszMax = _sqlite3Config.FmxMemdbSize
		}
		(*TMemStore)(unsafe.Pointer(pStore)).FmFlags = mFlags
		rc = SQLITE_OK
	}
	goto end_deserialize
end_deserialize:
	;
	if pData != 0 && mFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != uint32(0) {
		Xsqlite3_free(tls, pData)
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Return TRUE (non-zero) of the statement supplied as an argument needs
//	** to be recompiled.  A statement needs to be recompiled whenever the
//	** execution environment changes in a way that would alter the program
//	** that sqlite3_prepare() generates.  For example, if new functions or
//	** collating sequences are registered or if an authorizer function is
//	** added or changed.
//	*/
func Xsqlite3_expired(tls *libc.TLS, pStmt uintptr) (r int32) {
	var iRet int32
	var p uintptr
	_, _ = iRet, p
	iRet = int32(1)
	if pStmt != 0 {
		p = pStmt
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		iRet = int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200)) & 0xc000 >> 14))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return iRet
}

// C documentation
//
//	/*
//	** Open a new database handle.
//	*/
func Xsqlite3_open16(tls *libc.TLS, zFilename uintptr, ppDb uintptr) (r int32) {
	var pVal, zFilename8 uintptr
	var rc int32
	var v1 Tu8
	_, _, _, _ = pVal, rc, zFilename8, v1
	**(**uintptr)(__ccgo_up(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if zFilename == uintptr(0) {
		zFilename = __ccgo_ts + 26268
	}
	pVal = _sqlite3ValueNew(tls, uintptr(0))
	_sqlite3ValueSetStr(tls, pVal, -int32(1), zFilename, uint8(SQLITE_UTF16BE), libc.UintptrFromInt32(0))
	zFilename8 = _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zFilename8 != 0 {
		rc = _openDatabase(tls, zFilename8, ppDb, libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OPEN_READWRITE)|libc.Int32FromInt32(SQLITE_OPEN_CREATE)), uintptr(0))
		if rc == SQLITE_OK && !(libc.Int32FromUint16((*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).FschemaFlags)&libc.Int32FromInt32(DB_SchemaLoaded) == libc.Int32FromInt32(DB_SchemaLoaded)) {
			v1 = libc.Uint8FromInt32(SQLITE_UTF16BE)
			(*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).Fenc = v1
			(*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppDb)))).FaDb))).FpSchema)).Fenc = v1
		}
	} else {
		rc = int32(SQLITE_NOMEM)
	}
	_sqlite3ValueFree(tls, pVal)
	return rc & int32(0xff)
}

func Xsqlite3_result_error16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32) {
	(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = int32(SQLITE_ERROR)
	_sqlite3VdbeMemSetStr(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, z, int64(n), uint8(SQLITE_UTF16BE), uintptr(-libc.Int32FromInt32(1)))
}

func Xsqlite3_result_text16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, __ccgo_fp_xDel uintptr) {
	_setResultStrOrError(tls, pCtx, z, libc.Int32FromUint64(libc.Uint64FromInt32(n) & ^libc.Uint64FromInt32(1)), uint8(SQLITE_UTF16BE), __ccgo_fp_xDel)
}

func Xsqlite3_result_text64(tls *libc.TLS, pCtx uintptr, z uintptr, n Tsqlite3_uint64, __ccgo_fp_xDel uintptr, enc uint8) {
	if libc.Int32FromUint8(enc) != int32(SQLITE_UTF8) && libc.Int32FromUint8(enc) != int32(SQLITE_UTF8_ZT) {
		if libc.Int32FromUint8(enc) == int32(SQLITE_UTF16) {
			enc = uint8(SQLITE_UTF16BE)
		}
		n = n & ^libc.Uint64FromInt32(1)
	}
	if n > uint64(0x7fffffff) {
		_invokeValueDestructor(tls, z, __ccgo_fp_xDel, pCtx)
	} else {
		_setResultStrOrError(tls, pCtx, z, libc.Int32FromUint64(n), enc, __ccgo_fp_xDel)
		_sqlite3VdbeMemZeroTerminateIfAble(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut)
	}
}

// C documentation
//
//	/*
//	** Set the explain mode for a statement.
//	*/
func Xsqlite3_stmt_explain(tls *libc.TLS, pStmt uintptr, eMode int32) (r int32) {
	var rc int32
	var v uintptr
	_, _ = rc, v
	v = pStmt
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).Fdb)).Fmutex)
	if int32(Tbft(*(*uint16)(unsafe.Pointer(v + 200))&0x3000>>12)) == eMode {
		rc = SQLITE_OK
	} else {
		if eMode < 0 || eMode > int32(2) {
			rc = int32(SQLITE_ERROR)
		} else {
			if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(v)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) == 0 {
				rc = int32(SQLITE_ERROR)
			} else {
				if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(v)).FeVdbeState) != int32(VDBE_READY_STATE) {
					rc = int32(SQLITE_BUSY)
				} else {
					if (*TVdbe)(unsafe.Pointer(v)).FnMem >= int32(10) && (eMode != int32(2) || int32(Tbft(*(*uint16)(unsafe.Pointer(v + 200))&0x80>>7)) != 0) {
						/* No reprepare necessary */
						libc.SetBitFieldPtr16Uint32(v+200, libc.Uint32FromInt32(eMode), 12, 0x3000)
						rc = SQLITE_OK
					} else {
						libc.SetBitFieldPtr16Uint32(v+200, libc.Uint32FromInt32(eMode), 12, 0x3000)
						rc = _sqlite3Reprepare(tls, v)
						libc.SetBitFieldPtr16Uint32(v+200, libc.BoolUint32(eMode == libc.Int32FromInt32(2)), 7, 0x80)
					}
				}
			}
		}
	}
	if int32(Tbft(*(*uint16)(unsafe.Pointer(v + 200))&0x3000>>12)) != 0 {
		(*TVdbe)(unsafe.Pointer(v)).FnResColumn = libc.Uint16FromInt32(int32(12) - int32(4)*int32(Tbft(*(*uint16)(unsafe.Pointer(v + 200))&0x3000>>12)))
	} else {
		(*TVdbe)(unsafe.Pointer(v)).FnResColumn = (*TVdbe)(unsafe.Pointer(v)).FnResAlloc
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(v)).Fdb)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Return 1 if the statement is an EXPLAIN and return 2 if the
//	** statement is an EXPLAIN QUERY PLAN
//	*/
func Xsqlite3_stmt_isexplain(tls *libc.TLS, pStmt uintptr) (r int32) {
	var v1 int32
	_ = v1
	if pStmt != 0 {
		v1 = int32(Tbft(*(*uint16)(unsafe.Pointer(pStmt + 200)) & 0x3000 >> 12))
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Return true if the prepared statement is guaranteed to not modify the
//	** database.
//	*/
func Xsqlite3_stmt_readonly(tls *libc.TLS, pStmt uintptr) (r int32) {
	var v1 int32
	_ = v1
	if pStmt != 0 {
		v1 = int32(Tbft(*(*uint16)(unsafe.Pointer(pStmt + 200)) & 0x200 >> 9))
	} else {
		v1 = int32(1)
	}
	return v1
}

// C documentation
//
//	/*
//	** Render a string given by "fmt" into the StrAccum object.
//	*/
func Xsqlite3_str_vappendf(tls *libc.TLS, pAccum uintptr, fmt uintptr, ap Tva_list) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var adj, c, e2, exp, iRound, idx, ii, ix, j, length, nOut, needQuote, nn, nn1, nn2, nn3, precision, width, x, v2, v3 int32
	var bArgList, base Tu8
	var bufpt, cset, escarg, infop, pArgList, pExpr, pItem, pSel, pToken, pre, z, zExtra, zOut, v4 uintptr
	var cThousand, done, flag_alternateform, flag_altform2, flag_dp, flag_leftjustify, flag_long, flag_prefix, flag_rtz, flag_zeropad, xtype, v5, v6, v7, v8, v9 TetByte
	var ch, px, wx uint32
	var ch1, prefix, q, x1, v54 uint8
	var i, j1, k, n1, nBack, nCopyBytes, nCtrl, nPad, nPrior, szBufNeeded, v, v90 Ti64
	var longvalue Tsqlite_uint64
	var n Tu64
	var realvalue float64
	var v12 bool
	var _ /* buf at bp+0 */ [70]uint8
	var _ /* s at bp+72 */ TFpDecode
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = adj, bArgList, base, bufpt, c, cThousand, ch, ch1, cset, done, e2, escarg, exp, flag_alternateform, flag_altform2, flag_dp, flag_leftjustify, flag_long, flag_prefix, flag_rtz, flag_zeropad, i, iRound, idx, ii, infop, ix, j, j1, k, length, longvalue, n, n1, nBack, nCopyBytes, nCtrl, nOut, nPad, nPrior, needQuote, nn, nn1, nn2, nn3, pArgList, pExpr, pItem, pSel, pToken, pre, precision, prefix, px, q, realvalue, szBufNeeded, v, width, wx, x, x1, xtype, z, zExtra, zOut, v12, v2, v3, v4, v5, v54, v6, v7, v8, v9, v90 /* Thousands separator for %d and %u */
	xtype = uint8(etINVALID)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /* Size of the rendering buffer */
	zExtra = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* True if trailing zeros should be removed */
	pArgList = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* Conversion buffer */
	/* pAccum never starts out with an empty buffer that was obtained from
	 ** malloc().  This precondition is required by the mprintf("%z...")
	 ** optimization. */
	bufpt = uintptr(0)
	if libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_SQLFUNC) != 0 {
		pArgList = libc.VaUintptr(&ap)
		bArgList = uint8(1)
	} else {
		bArgList = uint8(0)
	}
	for {
		v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(fmt)))
		c = v2
		if !(v2 != 0) {
			break
		}
		if c != int32('%') {
			bufpt = fmt
			fmt = libc.Xstrchr(tls, fmt, int32('%'))
			if fmt == uintptr(0) {
				fmt = bufpt + uintptr(libc.Xstrlen(tls, bufpt))
			}
			Xsqlite3_str_append(tls, pAccum, bufpt, int32(int64(fmt)-int64(bufpt)))
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(fmt))) == 0 {
				break
			}
		}
		fmt = fmt + 1
		v4 = fmt
		v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
		c = v2
		if v2 == 0 {
			Xsqlite3_str_append(tls, pAccum, __ccgo_ts+1688, int32(1))
			break
		}
		/* Find out what flags are present */
		v9 = libc.Uint8FromInt32(0)
		flag_zeropad = v9
		v8 = v9
		flag_altform2 = v8
		v7 = v8
		flag_alternateform = v7
		v6 = v7
		cThousand = v6
		v5 = v6
		flag_prefix = v5
		flag_leftjustify = v5
		done = uint8(0)
		width = 0
		flag_long = uint8(0)
		precision = -int32(1)
		for {
			switch c {
			case int32('-'):
				flag_leftjustify = uint8(1)
			case int32('+'):
				flag_prefix = uint8('+')
			case int32(' '):
				flag_prefix = uint8(' ')
			case int32('#'):
				flag_alternateform = uint8(1)
			case int32('!'):
				flag_altform2 = uint8(1)
			case int32('0'):
				flag_zeropad = uint8(1)
			case int32(','):
				cThousand = uint8(',')
			default:
				done = uint8(1)
			case int32('l'):
				flag_long = uint8(1)
				fmt = fmt + 1
				v4 = fmt
				c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
				if c == int32('l') {
					fmt = fmt + 1
					v4 = fmt
					c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
					flag_long = uint8(2)
				}
				done = uint8(1)
			case int32('1'):
				fallthrough
			case int32('2'):
				fallthrough
			case int32('3'):
				fallthrough
			case int32('4'):
				fallthrough
			case int32('5'):
				fallthrough
			case int32('6'):
				fallthrough
			case int32('7'):
				fallthrough
			case int32('8'):
				fallthrough
			case int32('9'):
				wx = libc.Uint32FromInt32(c - int32('0'))
				for {
					fmt = fmt + 1
					v4 = fmt
					v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
					c = v2
					if !(v2 >= int32('0') && c <= int32('9')) {
						break
					}
					wx = wx*uint32(10) + libc.Uint32FromInt32(c) - uint32('0')
				}
				width = libc.Int32FromUint32(wx & uint32(0x7fffffff))
				if c != int32('.') && c != int32('l') {
					done = uint8(1)
				} else {
					fmt = fmt - 1
				}
			case int32('*'):
				if bArgList != 0 {
					width = int32(_getIntArg(tls, pArgList))
				} else {
					width = libc.VaInt32(&ap)
				}
				if width < 0 {
					flag_leftjustify = uint8(1)
					if width >= -int32(2147483647) {
						v2 = -width
					} else {
						v2 = 0
					}
					width = v2
				}
				v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(fmt + 1)))
				c = v2
				if v2 != int32('.') && c != int32('l') {
					fmt = fmt + 1
					v4 = fmt
					c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
					done = uint8(1)
				}
			case int32('.'):
				fmt = fmt + 1
				v4 = fmt
				c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
				if c == int32('*') {
					if bArgList != 0 {
						precision = int32(_getIntArg(tls, pArgList))
					} else {
						precision = libc.VaInt32(&ap)
					}
					if precision < 0 {
						if precision >= -int32(2147483647) {
							v2 = -precision
						} else {
							v2 = -int32(1)
						}
						precision = v2
					}
					fmt = fmt + 1
					v4 = fmt
					c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
				} else {
					px = uint32(0)
					for c >= int32('0') && c <= int32('9') {
						px = px*uint32(10) + libc.Uint32FromInt32(c) - uint32('0')
						fmt = fmt + 1
						v4 = fmt
						c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
					}
					precision = libc.Int32FromUint32(px & uint32(0x7fffffff))
				}
				if c == int32('l') {
					fmt = fmt - 1
				} else {
					done = uint8(1)
				}
				break
			}
			goto _13
		_13:
			;
			if v12 = !(done != 0); v12 {
				fmt = fmt + 1
				v4 = fmt
				v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
				c = v2
			}
			if !(v12 && v2 != 0) {
				break
			}
		}
		/* Fetch the info entry for the field */
		/* Fast hash-table lookup */
		idx = libc.Int32FromUint32(libc.Uint32FromInt32(c) % uint32(23))
		if v12 = libc.Int32FromUint8(_fmtinfo[idx].Ffmttype) == c; !v12 {
			v2 = libc.Int32FromUint8(_fmtinfo[idx].FiNxt)
			idx = v2
		}
		if v12 || libc.Int32FromUint8(_fmtinfo[v2].Ffmttype) == c {
			infop = uintptr(unsafe.Pointer(&_fmtinfo)) + uintptr(idx)*7
			xtype = (*Tet_info)(unsafe.Pointer(infop)).Ftype1
		} else {
			infop = uintptr(unsafe.Pointer(&_fmtinfo))
			xtype = uint8(etINVALID)
		}
		/*
		 ** At this point, variables are initialized as follows:
		 **
		 **   flag_alternateform          TRUE if a '#' is present.
		 **   flag_altform2               TRUE if a '!' is present.
		 **   flag_prefix                 '+' or ' ' or zero
		 **   flag_leftjustify            TRUE if a '-' is present or if the
		 **                               field width was negative.
		 **   flag_zeropad                TRUE if the width began with 0.
		 **   flag_long                   1 for "l", 2 for "ll"
		 **   width                       The specified field width.  This is
		 **                               always non-negative.  Zero is the default.
		 **   precision                   The specified precision.  The default
		 **                               is -1.
		 **   xtype                       The class of the conversion.
		 **   infop                       Pointer to the appropriate info struct.
		 */
		switch libc.Int32FromUint8(xtype) {
		case int32(etPOINTER):
			goto _27
		case etRADIX:
			goto _28
		case int32(etORDINAL):
			goto _29
		case int32(etDECIMAL):
			goto _30
		case int32(etGENERIC):
			goto _31
		case int32(etEXP):
			goto _32
		case int32(etFLOAT):
			goto _33
		case int32(etSIZE):
			goto _34
		case int32(etPERCENT):
			goto _35
		case int32(etCHARX):
			goto _36
		case int32(etDYNSTRING):
			goto _37
		case int32(etSTRING):
			goto _38
		case int32(etESCAPE_w):
			goto _39
		case int32(etESCAPE_Q):
			goto _40
		case int32(etESCAPE_q):
			goto _41
		case int32(etTOKEN):
			goto _42
		case int32(etSRCITEM):
			goto _43
		default:
			goto _44
		}
		goto _45
	_27:
		;
		flag_long = uint8(2)
	_29:
		;
	_28:
		;
		cThousand = uint8(0)
	_30:
		;
		if libc.Int32FromUint8((*Tet_info)(unsafe.Pointer(infop)).Fflags)&int32(FLAG_SIGNED) != 0 {
			if bArgList != 0 {
				v = _getIntArg(tls, pArgList)
			} else {
				if flag_long != 0 {
					if libc.Int32FromUint8(flag_long) == int32(2) {
						v = libc.VaInt64(&ap)
					} else {
						v = int64(libc.VaInt64(&ap))
					}
				} else {
					v = int64(libc.VaInt32(&ap))
				}
			}
			if v < 0 {
				longvalue = libc.Uint64FromInt64(^v)
				longvalue = longvalue + 1
				prefix = uint8('-')
			} else {
				longvalue = libc.Uint64FromInt64(v)
				prefix = flag_prefix
			}
		} else {
			if bArgList != 0 {
				longvalue = libc.Uint64FromInt64(_getIntArg(tls, pArgList))
			} else {
				if flag_long != 0 {
					if libc.Int32FromUint8(flag_long) == int32(2) {
						longvalue = libc.VaUint64(&ap)
					} else {
						longvalue = uint64(libc.VaUint64(&ap))
					}
				} else {
					longvalue = uint64(libc.VaUint32(&ap))
				}
			}
			prefix = uint8(0)
		}
		if longvalue == uint64(0) {
			flag_alternateform = uint8(0)
		}
		if flag_zeropad != 0 && precision < width-libc.BoolInt32(libc.Int32FromUint8(prefix) != 0) {
			precision = width - libc.BoolInt32(libc.Int32FromUint8(prefix) != 0)
		}
		if precision < libc.Int32FromInt32(SQLITE_PRINT_BUF_SIZE)-libc.Int32FromInt32(10)-libc.Int32FromInt32(SQLITE_PRINT_BUF_SIZE)/libc.Int32FromInt32(3) {
			nOut = int32(SQLITE_PRINT_BUF_SIZE)
			zOut = bp
		} else {
			n = libc.Uint64FromInt32(precision) + uint64(10)
			if cThousand != 0 {
				n = n + libc.Uint64FromInt32(precision/int32(3))
			}
			v4 = _printfTempBuf(tls, pAccum, libc.Int64FromUint64(n))
			zExtra = v4
			zOut = v4
			if zOut == uintptr(0) {
				return
			}
			nOut = libc.Int32FromUint64(n)
		}
		bufpt = zOut + uintptr(nOut-int32(1))
		if libc.Int32FromUint8(xtype) == int32(etORDINAL) {
			x = libc.Int32FromUint64(longvalue % libc.Uint64FromInt32(10))
			if x >= int32(4) || longvalue/uint64(10)%uint64(10) == uint64(1) {
				x = 0
			}
			bufpt = bufpt - 1
			v4 = bufpt
			**(**uint8)(__ccgo_up(v4)) = _zOrd[x*int32(2)+int32(1)]
			bufpt = bufpt - 1
			v4 = bufpt
			**(**uint8)(__ccgo_up(v4)) = _zOrd[x*int32(2)]
		}
		cset = uintptr(unsafe.Pointer(&_aDigits)) + uintptr((*Tet_info)(unsafe.Pointer(infop)).Fcharset)
		base = (*Tet_info)(unsafe.Pointer(infop)).Fbase
		for cond := true; cond; cond = longvalue > uint64(0) { /* Convert to ascii */
			bufpt = bufpt - 1
			v4 = bufpt
			**(**uint8)(__ccgo_up(v4)) = **(**uint8)(__ccgo_up(cset + uintptr(longvalue%uint64(base))))
			longvalue = longvalue / uint64(base)
		}
		length = int32(t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int64(bufpt))
		if precision > length { /* zero pad */
			nn = precision - length
			bufpt = bufpt - uintptr(nn)
			libc.Xmemset(tls, bufpt, int32('0'), libc.Uint64FromInt32(nn))
			length = precision
		}
		if cThousand != 0 {
			nn1 = (length - int32(1)) / int32(3) /* Number of "," to insert */
			ix = (length-int32(1))%int32(3) + int32(1)
			bufpt = bufpt - uintptr(nn1)
			idx = 0
			for {
				if !(nn1 > 0) {
					break
				}
				**(**uint8)(__ccgo_up(bufpt + uintptr(idx))) = **(**uint8)(__ccgo_up(bufpt + uintptr(idx+nn1)))
				ix = ix - 1
				if ix == 0 {
					idx = idx + 1
					v2 = idx
					**(**uint8)(__ccgo_up(bufpt + uintptr(v2))) = cThousand
					nn1 = nn1 - 1
					ix = int32(3)
				}
				goto _50
			_50:
				;
				idx = idx + 1
			}
		}
		if prefix != 0 {
			bufpt = bufpt - 1
			v4 = bufpt
			**(**uint8)(__ccgo_up(v4)) = prefix
		} /* Add sign */
		if flag_alternateform != 0 && (*Tet_info)(unsafe.Pointer(infop)).Fprefix != 0 {
			pre = uintptr(unsafe.Pointer(&_aPrefix)) + uintptr((*Tet_info)(unsafe.Pointer(infop)).Fprefix)
			for {
				v54 = **(**uint8)(__ccgo_up(pre))
				x1 = v54
				if !(libc.Int32FromUint8(v54) != 0) {
					break
				}
				bufpt = bufpt - 1
				v4 = bufpt
				**(**uint8)(__ccgo_up(v4)) = x1
				goto _53
			_53:
				;
				pre = pre + 1
			}
		}
		length = int32(t__predefined_ptrdiff_t(zOut+uintptr(nOut-int32(1))) - int64(bufpt))
		goto _45
	_33:
		;
	_32:
		;
	_31:
		; /* Size needed to hold the output */
		if bArgList != 0 {
			realvalue = _getDoubleArg(tls, pArgList)
		} else {
			realvalue = libc.VaFloat64(&ap)
		}
		if precision < 0 {
			precision = int32(6)
		} /* Set default precision */
		if precision > int32(SQLITE_FP_PRECISION_LIMIT) {
			precision = int32(SQLITE_FP_PRECISION_LIMIT)
		}
		if libc.Int32FromUint8(xtype) == int32(etFLOAT) {
			iRound = -precision
		} else {
			if libc.Int32FromUint8(xtype) == int32(etGENERIC) {
				if precision == 0 {
					precision = int32(1)
				}
				iRound = precision
			} else {
				iRound = precision + int32(1)
			}
		}
		if flag_altform2 != 0 {
			v2 = int32(20)
		} else {
			v2 = int32(16)
		}
		_sqlite3FpDecode(tls, bp+72, realvalue, iRound, v2)
		if (**(**TFpDecode)(__ccgo_up(bp + 72))).FisSpecial != 0 {
			if libc.Int32FromUint8((**(**TFpDecode)(__ccgo_up(bp + 72))).FisSpecial) == int32(2) {
				if flag_zeropad != 0 {
					v4 = __ccgo_ts + 1690
				} else {
					v4 = __ccgo_ts + 1695
				}
				bufpt = v4
				length = _sqlite3Strlen30(tls, bufpt)
				goto _45
			} else {
				if flag_zeropad != 0 {
					**(**uint8)(__ccgo_up((**(**TFpDecode)(__ccgo_up(bp + 72))).Fz)) = uint8('9')
					(**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP = int32(1000)
					(**(**TFpDecode)(__ccgo_up(bp + 72))).Fn = int32(1)
				} else {
					libc.Xmemcpy(tls, bp, __ccgo_ts+1699, uint64(5))
					bufpt = bp
					if libc.Int32FromUint8((**(**TFpDecode)(__ccgo_up(bp + 72))).Fsign) == int32('-') {
						/* no-op */
					} else {
						if flag_prefix != 0 {
							(**(**[70]uint8)(__ccgo_up(bp)))[0] = flag_prefix
						} else {
							bufpt = bufpt + 1
						}
					}
					length = _sqlite3Strlen30(tls, bufpt)
					goto _45
				}
			}
		}
		if libc.Int32FromUint8((**(**TFpDecode)(__ccgo_up(bp + 72))).Fsign) == int32('-') {
			if flag_alternateform != 0 && !(flag_prefix != 0) && libc.Int32FromUint8(xtype) == int32(etFLOAT) && (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP <= iRound {
				/* Suppress the minus sign if all of the following are true:
				 **   *  The value displayed is zero
				 **   *  The '#' flag is used
				 **   *  The '+' flag is not used, and
				 **   *  The format is %f
				 */
				prefix = uint8(0)
			} else {
				prefix = uint8('-')
			}
		} else {
			prefix = flag_prefix
		}
		exp = (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP - int32(1)
		/*
		 ** If the field type is etGENERIC, then convert to either etEXP
		 ** or etFLOAT, as appropriate.
		 */
		if libc.Int32FromUint8(xtype) == int32(etGENERIC) {
			precision = precision - 1
			flag_rtz = libc.BoolUint8(!(flag_alternateform != 0))
			if exp < -int32(4) || exp > precision {
				xtype = uint8(etEXP)
			} else {
				precision = precision - exp
				xtype = uint8(etFLOAT)
			}
		} else {
			flag_rtz = flag_altform2
		}
		if libc.Int32FromUint8(xtype) == int32(etEXP) {
			e2 = 0
		} else {
			e2 = (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP - int32(1)
		}
		if e2 > 0 {
			v2 = e2
		} else {
			v2 = 0
		}
		szBufNeeded = int64(v2) + int64(precision) + int64(width) + int64(10)
		if cThousand != 0 && e2 > 0 {
			szBufNeeded = szBufNeeded + int64((e2+int32(2))/int32(3))
		}
		if szBufNeeded+libc.Int64FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar) >= libc.Int64FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc) {
			if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc == uint32(0) && libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FaccError) == 0 {
				/* Unable to allocate space in pAccum, perhaps because it
				 ** is coming from sqlite3_snprintf() or similar.  We'll have
				 ** to render into temporary space and the memcpy() it over. */
				bufpt = Xsqlite3_malloc(tls, int32(szBufNeeded))
				if bufpt == uintptr(0) {
					_sqlite3StrAccumSetError(tls, pAccum, uint8(SQLITE_NOMEM))
					return
				}
				zExtra = bufpt
			} else {
				if int64(_sqlite3StrAccumEnlarge(tls, pAccum, szBufNeeded)) < szBufNeeded {
					v2 = libc.Int32FromInt32(0)
					length = v2
					width = v2
					goto _45
				} else {
					bufpt = (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText + uintptr((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
				}
			}
		} else {
			bufpt = (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText + uintptr((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
		}
		zOut = bufpt
		if precision > 0 {
			v2 = int32(1)
		} else {
			v2 = 0
		}
		flag_dp = libc.Uint8FromInt32(v2 | libc.Int32FromUint8(flag_alternateform) | libc.Int32FromUint8(flag_altform2))
		/* The sign in front of the number */
		if prefix != 0 {
			v4 = bufpt
			bufpt = bufpt + 1
			**(**uint8)(__ccgo_up(v4)) = prefix
		}
		/* Digits prior to the decimal point */
		j = 0
		if e2 < 0 {
			v4 = bufpt
			bufpt = bufpt + 1
			**(**uint8)(__ccgo_up(v4)) = uint8('0')
		} else {
			if cThousand != 0 {
				for {
					if !(e2 >= 0) {
						break
					}
					v4 = bufpt
					bufpt = bufpt + 1
					if j < (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn {
						v3 = j
						j = j + 1
						v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up((**(**TFpDecode)(__ccgo_up(bp + 72))).Fz + uintptr(v3))))
					} else {
						v2 = int32('0')
					}
					**(**uint8)(__ccgo_up(v4)) = libc.Uint8FromInt32(v2)
					if e2%int32(3) == 0 && e2 > int32(1) {
						v4 = bufpt
						bufpt = bufpt + 1
						**(**uint8)(__ccgo_up(v4)) = uint8(',')
					}
					goto _63
				_63:
					;
					e2 = e2 - 1
				}
			} else {
				j = e2 + int32(1)
				if j > (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn {
					j = (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn
				}
				libc.Xmemcpy(tls, bufpt, (**(**TFpDecode)(__ccgo_up(bp + 72))).Fz, libc.Uint64FromInt32(j))
				bufpt = bufpt + uintptr(j)
				e2 = e2 - j
				if e2 >= 0 {
					libc.Xmemset(tls, bufpt, int32('0'), libc.Uint64FromInt32(e2+int32(1)))
					bufpt = bufpt + uintptr(e2+int32(1))
					e2 = -int32(1)
				}
			}
		}
		/* The decimal point */
		if flag_dp != 0 {
			v4 = bufpt
			bufpt = bufpt + 1
			**(**uint8)(__ccgo_up(v4)) = uint8('.')
		}
		/* "0" digits after the decimal point but before the first
		 ** significant digit of the number */
		if e2 < -int32(1) && precision > 0 {
			nn2 = -int32(1) - e2
			if nn2 > precision {
				nn2 = precision
			}
			libc.Xmemset(tls, bufpt, int32('0'), libc.Uint64FromInt32(nn2))
			bufpt = bufpt + uintptr(nn2)
			precision = precision - nn2
		}
		/* Significant digits after the decimal point */
		if precision > 0 {
			nn3 = (**(**TFpDecode)(__ccgo_up(bp + 72))).Fn - j
			if nn3 > precision {
				nn3 = precision
			}
			if nn3 > 0 {
				libc.Xmemcpy(tls, bufpt, (**(**TFpDecode)(__ccgo_up(bp + 72))).Fz+uintptr(j), libc.Uint64FromInt32(nn3))
				bufpt = bufpt + uintptr(nn3)
				precision = precision - nn3
			}
			if precision > 0 && !(flag_rtz != 0) {
				libc.Xmemset(tls, bufpt, int32('0'), libc.Uint64FromInt32(precision))
				bufpt = bufpt + uintptr(precision)
			}
		}
		/* Remove trailing zeros and the "." if no digits follow the "." */
		if flag_rtz != 0 && flag_dp != 0 {
			for libc.Int32FromUint8(**(**uint8)(__ccgo_up(bufpt + uintptr(-libc.Int32FromInt32(1))))) == int32('0') {
				bufpt = bufpt - 1
				v4 = bufpt
				**(**uint8)(__ccgo_up(v4)) = uint8(0)
			}
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(bufpt + uintptr(-libc.Int32FromInt32(1))))) == int32('.') {
				if flag_altform2 != 0 {
					v4 = bufpt
					bufpt = bufpt + 1
					**(**uint8)(__ccgo_up(v4)) = uint8('0')
				} else {
					bufpt = bufpt - 1
					v4 = bufpt
					**(**uint8)(__ccgo_up(v4)) = uint8(0)
				}
			}
		}
		/* Add the "eNNN" suffix */
		if libc.Int32FromUint8(xtype) == int32(etEXP) {
			exp = (**(**TFpDecode)(__ccgo_up(bp + 72))).FiDP - int32(1)
			v4 = bufpt
			bufpt = bufpt + 1
			**(**uint8)(__ccgo_up(v4)) = _aDigits[(*Tet_info)(unsafe.Pointer(infop)).Fcharset]
			if exp < 0 {
				v4 = bufpt
				bufpt = bufpt + 1
				**(**uint8)(__ccgo_up(v4)) = uint8('-')
				exp = -exp
			} else {
				v4 = bufpt
				bufpt = bufpt + 1
				**(**uint8)(__ccgo_up(v4)) = uint8('+')
			}
			if exp >= int32(100) {
				v4 = bufpt
				bufpt = bufpt + 1
				**(**uint8)(__ccgo_up(v4)) = libc.Uint8FromInt32(exp/libc.Int32FromInt32(100) + libc.Int32FromUint8('0')) /* 100's digit */
				exp = exp % int32(100)
			}
			v4 = bufpt
			bufpt = bufpt + 1
			**(**uint8)(__ccgo_up(v4)) = libc.Uint8FromInt32(exp/libc.Int32FromInt32(10) + libc.Int32FromUint8('0')) /* 10's digit */
			v4 = bufpt
			bufpt = bufpt + 1
			**(**uint8)(__ccgo_up(v4)) = libc.Uint8FromInt32(exp%libc.Int32FromInt32(10) + libc.Int32FromUint8('0')) /* 1's digit */
		}
		length = int32(int64(bufpt) - int64(zOut))
		if length < width {
			nPad = int64(width - length)
			if flag_leftjustify != 0 {
				libc.Xmemset(tls, bufpt, int32(' '), libc.Uint64FromInt64(nPad))
			} else {
				if !(flag_zeropad != 0) {
					libc.Xmemmove(tls, zOut+uintptr(nPad), zOut, libc.Uint64FromInt32(length))
					libc.Xmemset(tls, zOut, int32(' '), libc.Uint64FromInt64(nPad))
				} else {
					adj = libc.BoolInt32(libc.Int32FromUint8(prefix) != 0)
					libc.Xmemmove(tls, zOut+uintptr(nPad)+uintptr(adj), zOut+uintptr(adj), libc.Uint64FromInt32(length-adj))
					libc.Xmemset(tls, zOut+uintptr(adj), int32('0'), libc.Uint64FromInt64(nPad))
				}
			}
			length = width
		}
		if zExtra == uintptr(0) {
			/* The result is being rendered directory into pAccum.  This
			 ** is the command and fast case */
			**(**Tu32)(__ccgo_up(pAccum + 24)) += libc.Uint32FromInt32(length)
			**(**uint8)(__ccgo_up(zOut + uintptr(length))) = uint8(0)
			goto _1
		} else {
			/* We were unable to render directly into pAccum because we
			 ** couldn't allocate sufficient memory.  We need to memcpy()
			 ** the rendering (or some prefix thereof) into the output
			 ** buffer. */
			**(**uint8)(__ccgo_up(bufpt)) = uint8(0)
			bufpt = zExtra
			goto _45
		}
	_34:
		;
		if !(bArgList != 0) {
			**(**int32)(__ccgo_up(libc.VaUintptr(&ap))) = libc.Int32FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
		}
		v2 = libc.Int32FromInt32(0)
		width = v2
		length = v2
		goto _45
	_35:
		;
		(**(**[70]uint8)(__ccgo_up(bp)))[0] = uint8('%')
		bufpt = bp
		length = int32(1)
		goto _45
	_36:
		;
		if bArgList != 0 {
			bufpt = _getTextArg(tls, pArgList)
			length = int32(1)
			if bufpt != 0 {
				v4 = bufpt
				bufpt = bufpt + 1
				v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4)))
				c = v2
				(**(**[70]uint8)(__ccgo_up(bp)))[0] = libc.Uint8FromInt32(v2)
				if c&int32(0xc0) == int32(0xc0) {
					for length < int32(4) && libc.Int32FromUint8(**(**uint8)(__ccgo_up(bufpt)))&int32(0xc0) == int32(0x80) {
						v2 = length
						length = length + 1
						v4 = bufpt
						bufpt = bufpt + 1
						(**(**[70]uint8)(__ccgo_up(bp)))[v2] = **(**uint8)(__ccgo_up(v4))
					}
				}
			} else {
				(**(**[70]uint8)(__ccgo_up(bp)))[0] = uint8(0)
			}
		} else {
			ch = libc.VaUint32(&ap)
			length = _sqlite3AppendOneUtf8Character(tls, bp, ch)
		}
		if precision > int32(1) {
			nPrior = int64(1)
			width = width - (precision - int32(1))
			if width > int32(1) && !(flag_leftjustify != 0) {
				Xsqlite3_str_appendchar(tls, pAccum, width-int32(1), uint8(' '))
				width = 0
			}
			Xsqlite3_str_append(tls, pAccum, bp, length)
			precision = precision - 1
			for precision > int32(1) {
				if nPrior > int64(precision-int32(1)) {
					nPrior = int64(precision - int32(1))
				}
				nCopyBytes = int64(length) * nPrior
				if _sqlite3StrAccumEnlargeIfNeeded(tls, pAccum, nCopyBytes) != 0 {
					break
				}
				Xsqlite3_str_append(tls, pAccum, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText+uintptr(libc.Int64FromUint32((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar)-nCopyBytes), int32(nCopyBytes))
				precision = int32(int64(precision) - nPrior)
				nPrior = nPrior * int64(2)
			}
		}
		bufpt = bp
		flag_altform2 = uint8(1)
		goto adjust_width_for_utf8
	_38:
		;
	_37:
		;
		if bArgList != 0 {
			bufpt = _getTextArg(tls, pArgList)
			xtype = uint8(etSTRING)
		} else {
			bufpt = libc.VaUintptr(&ap)
		}
		if bufpt == uintptr(0) {
			bufpt = __ccgo_ts + 1704
		} else {
			if libc.Int32FromUint8(xtype) == int32(etDYNSTRING) {
				if (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar == uint32(0) && (*Tsqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc != 0 && width == 0 && precision < 0 && libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FaccError) == 0 {
					/* Special optimization for sqlite3_mprintf("%z..."):
					 ** Extend an existing memory allocation rather than creating
					 ** a new one. */
					(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FzText = bufpt
					(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc = libc.Uint32FromInt32(_sqlite3DbMallocSize(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, bufpt))
					(*Tsqlite3_str)(unsafe.Pointer(pAccum)).FnChar = libc.Uint32FromInt32(int32(0x7fffffff) & libc.Int32FromUint64(libc.Xstrlen(tls, bufpt)))
					v4 = pAccum + 29
					*(*Tu8)(unsafe.Pointer(v4)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v4))) | libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
					length = 0
					goto _45
				}
				zExtra = bufpt
			}
		}
		if precision >= 0 {
			if flag_altform2 != 0 {
				/* Set length to the number of bytes needed in order to display
				 ** precision characters */
				z = bufpt
				for {
					v2 = precision
					precision = precision - 1
					if !(v2 > 0 && **(**uint8)(__ccgo_up(z)) != 0) {
						break
					}
					v4 = z
					z = z + 1
					if libc.Int32FromUint8(**(**uint8)(__ccgo_up(v4))) >= int32(0xc0) {
						for libc.Int32FromUint8(**(**uint8)(__ccgo_up(z)))&int32(0xc0) == int32(0x80) {
							z = z + 1
						}
					}
				}
				length = int32(int64(z) - int64(bufpt))
			} else {
				length = 0
				for {
					if !(length < precision && **(**uint8)(__ccgo_up(bufpt + uintptr(length))) != 0) {
						break
					}
					goto _86
				_86:
					;
					length = length + 1
				}
			}
		} else {
			length = int32(0x7fffffff) & libc.Int32FromUint64(libc.Xstrlen(tls, bufpt))
		}
		goto adjust_width_for_utf8
	adjust_width_for_utf8:
		;
		if flag_altform2 != 0 && width > 0 {
			/* Adjust width to account for extra bytes in UTF-8 characters */
			ii = length - int32(1)
			for ii >= 0 {
				v2 = ii
				ii = ii - 1
				if libc.Int32FromUint8(**(**uint8)(__ccgo_up(bufpt + uintptr(v2))))&int32(0xc0) == int32(0x80) {
					width = width + 1
				}
			}
		}
		goto _45
	_41:
		; /* %q: Escape ' characters */
	_40:
		; /* %Q: Escape ' and enclose in '...' */
	_39:
		;
		needQuote = 0
		if bArgList != 0 {
			escarg = _getTextArg(tls, pArgList)
		} else {
			escarg = libc.VaUintptr(&ap)
		}
		if escarg == uintptr(0) {
			if libc.Int32FromUint8(xtype) == int32(etESCAPE_Q) {
				v4 = __ccgo_ts + 1705
			} else {
				v4 = __ccgo_ts + 1710
			}
			escarg = v4
		} else {
			if libc.Int32FromUint8(xtype) == int32(etESCAPE_Q) {
				needQuote = int32(1)
			}
		}
		if libc.Int32FromUint8(xtype) == int32(etESCAPE_w) {
			q = uint8('"')
			flag_alternateform = uint8(0)
		} else {
			q = uint8('\'')
		}
		/* For %q, %Q, and %w, the precision is the number of bytes (or
		 ** characters if the ! flags is present) to use from the input.
		 ** Because of the extra quoting characters inserted, the number
		 ** of output characters may be larger than the precision.
		 */
		k = int64(precision)
		v90 = libc.Int64FromInt32(0)
		n1 = v90
		i = v90
		for {
			if v12 = k != 0; v12 {
				v54 = **(**uint8)(__ccgo_up(escarg + uintptr(i)))
				ch1 = v54
			}
			if !(v12 && libc.Int32FromUint8(v54) != 0) {
				break
			}
			if libc.Int32FromUint8(ch1) == libc.Int32FromUint8(q) {
				n1 = n1 + 1
			}
			if flag_altform2 != 0 && libc.Int32FromUint8(ch1)&int32(0xc0) == int32(0xc0) {
				for libc.Int32FromUint8(**(**uint8)(__ccgo_up(escarg + uintptr(i+int64(1)))))&int32(0xc0) == int32(0x80) {
					i = i + 1
				}
			}
			goto _89
		_89:
			;
			i = i + 1
			k = k - 1
		}
		if flag_alternateform != 0 {
			/* For %#q, do unistr()-style backslash escapes for
			 ** all control characters, and for backslash itself.
			 ** For %#Q, do the same but only if there is at least
			 ** one control character. */
			nBack = 0
			nCtrl = 0
			k = 0
			for {
				if !(k < i) {
					break
				}
				if libc.Int32FromUint8(**(**uint8)(__ccgo_up(escarg + uintptr(k)))) == int32('\\') {
					nBack = nBack + 1
				} else {
					if libc.Int32FromUint8(**(**Tu8)(__ccgo_up(escarg + uintptr(k)))) <= int32(0x1f) {
						nCtrl = nCtrl + 1
					}
				}
				goto _93
			_93:
				;
				k = k + 1
			}
			if nCtrl != 0 || libc.Int32FromUint8(xtype) == int32(etESCAPE_q) {
				n1 = n1 + (nBack + int64(5)*nCtrl)
				if libc.Int32FromUint8(xtype) == int32(etESCAPE_Q) {
					n1 = n1 + int64(10)
					needQuote = int32(2)
				}
			} else {
				flag_alternateform = uint8(0)
			}
		}
		n1 = n1 + (i + int64(3))
		if n1 > int64(SQLITE_PRINT_BUF_SIZE) {
			v4 = _printfTempBuf(tls, pAccum, n1)
			zExtra = v4
			bufpt = v4
			if bufpt == uintptr(0) {
				return
			}
		} else {
			bufpt = bp
		}
		j1 = 0
		if needQuote != 0 {
			if needQuote == int32(2) {
				libc.Xmemcpy(tls, bufpt+uintptr(j1), __ccgo_ts+1717, uint64(8))
				j1 = j1 + int64(8)
			} else {
				v90 = j1
				j1 = j1 + 1
				**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8('\'')
			}
		}
		k = i
		if flag_alternateform != 0 {
			i = 0
			for {
				if !(i < k) {
					break
				}
				v90 = j1
				j1 = j1 + 1
				v54 = **(**uint8)(__ccgo_up(escarg + uintptr(i)))
				ch1 = v54
				**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = v54
				if libc.Int32FromUint8(ch1) == libc.Int32FromUint8(q) {
					v90 = j1
					j1 = j1 + 1
					**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = ch1
				} else {
					if libc.Int32FromUint8(ch1) == int32('\\') {
						v90 = j1
						j1 = j1 + 1
						**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8('\\')
					} else {
						if libc.Int32FromUint8(ch1) <= int32(0x1f) {
							**(**uint8)(__ccgo_up(bufpt + uintptr(j1-int64(1)))) = uint8('\\')
							v90 = j1
							j1 = j1 + 1
							**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8('u')
							v90 = j1
							j1 = j1 + 1
							**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8('0')
							v90 = j1
							j1 = j1 + 1
							**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8('0')
							v90 = j1
							j1 = j1 + 1
							if libc.Int32FromUint8(ch1) >= int32(0x10) {
								v2 = int32('1')
							} else {
								v2 = int32('0')
							}
							**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = libc.Uint8FromInt32(v2)
							v90 = j1
							j1 = j1 + 1
							**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = **(**uint8)(__ccgo_up(__ccgo_ts + 1726 + uintptr(libc.Int32FromUint8(ch1)&int32(0xf))))
						}
					}
				}
				goto _96
			_96:
				;
				i = i + 1
			}
		} else {
			i = 0
			for {
				if !(i < k) {
					break
				}
				v90 = j1
				j1 = j1 + 1
				v54 = **(**uint8)(__ccgo_up(escarg + uintptr(i)))
				ch1 = v54
				**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = v54
				if libc.Int32FromUint8(ch1) == libc.Int32FromUint8(q) {
					v90 = j1
					j1 = j1 + 1
					**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = ch1
				}
				goto _107
			_107:
				;
				i = i + 1
			}
		}
		if needQuote != 0 {
			v90 = j1
			j1 = j1 + 1
			**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8('\'')
			if needQuote == int32(2) {
				v90 = j1
				j1 = j1 + 1
				**(**uint8)(__ccgo_up(bufpt + uintptr(v90))) = uint8(')')
			}
		}
		**(**uint8)(__ccgo_up(bufpt + uintptr(j1))) = uint8(0)
		length = int32(j1)
		goto adjust_width_for_utf8
	_42:
		;
		if libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_INTERNAL) == 0 {
			return
		}
		if flag_alternateform != 0 {
			/* %#T means an Expr pointer that uses Expr.u.zToken */
			pExpr = libc.VaUintptr(&ap)
			if pExpr != 0 && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue)) != libc.Uint32FromInt32(0)) {
				Xsqlite3_str_appendall(tls, pAccum, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
				_sqlite3RecordErrorOffsetOfExpr(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, pExpr)
			}
		} else {
			/* %T means a Token pointer */
			pToken = libc.VaUintptr(&ap)
			if pToken != 0 && (*TToken)(unsafe.Pointer(pToken)).Fn != 0 {
				Xsqlite3_str_append(tls, pAccum, (*TToken)(unsafe.Pointer(pToken)).Fz, libc.Int32FromUint32((*TToken)(unsafe.Pointer(pToken)).Fn))
				_sqlite3RecordErrorByteOffset(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, (*TToken)(unsafe.Pointer(pToken)).Fz)
			}
		}
		v2 = libc.Int32FromInt32(0)
		width = v2
		length = v2
		goto _45
	_43:
		;
		if libc.Int32FromUint8((*Tsqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&int32(SQLITE_PRINTF_INTERNAL) == 0 {
			return
		}
		pItem = libc.VaUintptr(&ap)
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 && !(flag_altform2 != 0) {
			Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias)
		} else {
			if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
				if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8000>>15) == 0 && int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
					Xsqlite3_str_appendall(tls, pAccum, *(*uintptr)(unsafe.Pointer(pItem + 72)))
					Xsqlite3_str_append(tls, pAccum, __ccgo_ts+1743, int32(1))
				}
				Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
			} else {
				if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
					Xsqlite3_str_appendall(tls, pAccum, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias)
				} else {
					if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 { /* Because of tag-20240424-1 */
						pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
						if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_NestedFrom) != 0 {
							Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1745, libc.VaList(bp+120, (*TSelect)(unsafe.Pointer(pSel)).FselId))
						} else {
							if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_MultiValue) != 0 {
								Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1755, libc.VaList(bp+120, *(*Tu32)(unsafe.Pointer(&(*TSrcItem)(unsafe.Pointer(pItem)).Fu1))))
							} else {
								Xsqlite3_str_appendf(tls, pAccum, __ccgo_ts+1776, libc.VaList(bp+120, (*TSelect)(unsafe.Pointer(pSel)).FselId))
							}
						}
					}
				}
			}
		}
		v2 = libc.Int32FromInt32(0)
		width = v2
		length = v2
		goto _45
	_44:
		;
		return
	_45:
		; /* End switch over the format type */
		/*
		 ** The text of the conversion is pointed to by "bufpt" and is
		 ** "length" characters long.  The field width is "width".  Do
		 ** the output.  Both length and width are in bytes, not characters,
		 ** at this point.  If the "!" flag was present on string conversions
		 ** indicating that width and precision should be expressed in characters,
		 ** then the values have been translated prior to reaching this point.
		 */
		width = width - length
		if width > 0 {
			if !(flag_leftjustify != 0) {
				Xsqlite3_str_appendchar(tls, pAccum, width, uint8(' '))
			}
			Xsqlite3_str_append(tls, pAccum, bufpt, length)
			if flag_leftjustify != 0 {
				Xsqlite3_str_appendchar(tls, pAccum, width, uint8(' '))
			}
		} else {
			Xsqlite3_str_append(tls, pAccum, bufpt, length)
		}
		if zExtra != 0 {
			_sqlite3DbFree(tls, (*Tsqlite3_str)(unsafe.Pointer(pAccum)).Fdb, zExtra)
			zExtra = uintptr(0)
		}
		goto _1
	_1:
		;
		fmt = fmt + 1
	} /* End for loop over the format string */
}

// C documentation
//
//	/*
//	** Return meta information about a specific column of a database table.
//	** See comment in sqlite3.h (sqlite.h.in) for details.
//	*/
func Xsqlite3_table_column_metadata(tls *libc.TLS, db uintptr, zDbName uintptr, zTableName uintptr, zColumnName uintptr, pzDataType uintptr, pzCollSeq uintptr, pNotNull uintptr, pPrimaryKey uintptr, pAutoinc uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var autoinc, iCol, notnull, primarykey, rc int32
	var pCol, pTab, zCollSeq, zDataType, v1 uintptr
	var _ /* zErrMsg at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = autoinc, iCol, notnull, pCol, pTab, primarykey, rc, zCollSeq, zDataType, v1
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pTab = uintptr(0)
	pCol = uintptr(0)
	iCol = 0
	zDataType = uintptr(0)
	zCollSeq = uintptr(0)
	notnull = 0
	primarykey = 0
	autoinc = 0
	/* Ensure the database schema has been loaded */
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	rc = _sqlite3Init(tls, db, bp)
	if SQLITE_OK != rc {
		goto error_out
	}
	/* Locate the table in question */
	pTab = _sqlite3FindTable(tls, db, zTableName, zDbName)
	if !(pTab != 0) || libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		pTab = uintptr(0)
		goto error_out
	}
	/* Find the column for which info is requested */
	if zColumnName == uintptr(0) {
		/* Query for existence of table only */
	} else {
		iCol = _sqlite3ColumnIndex(tls, pTab, zColumnName)
		if iCol >= 0 {
			pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
		} else {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && _sqlite3IsRowid(tls, zColumnName) != 0 {
				iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				if iCol >= 0 {
					v1 = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
				} else {
					v1 = uintptr(0)
				}
				pCol = v1
			} else {
				pTab = uintptr(0)
				goto error_out
			}
		}
	}
	/* The following block stores the meta information that will be returned
	 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
	 ** and autoinc. At this point there are two possibilities:
	 **
	 **     1. The specified column name was rowid", "oid" or "_rowid_"
	 **        and there is no explicitly declared IPK column.
	 **
	 **     2. The table is not a view and the column name identified an
	 **        explicitly declared column. Copy meta information from *pCol.
	 */
	if pCol != 0 {
		zDataType = _sqlite3ColumnType(tls, pCol, uintptr(0))
		zCollSeq = _sqlite3ColumnColl(tls, pCol)
		notnull = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) != 0)
		primarykey = libc.BoolInt32(libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0)
		autoinc = libc.BoolInt32(int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) == iCol && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Autoincrement) != uint32(0))
	} else {
		zDataType = __ccgo_ts + 1178
		primarykey = int32(1)
	}
	if !(zCollSeq != 0) {
		zCollSeq = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
	}
	goto error_out
error_out:
	;
	_sqlite3BtreeLeaveAll(tls, db)
	/* Whether the function call succeeded or failed, set the output parameters
	 ** to whatever their local counterparts contain. If an error did occur,
	 ** this has the effect of zeroing all output parameters.
	 */
	if pzDataType != 0 {
		**(**uintptr)(__ccgo_up(pzDataType)) = zDataType
	}
	if pzCollSeq != 0 {
		**(**uintptr)(__ccgo_up(pzCollSeq)) = zCollSeq
	}
	if pNotNull != 0 {
		**(**int32)(__ccgo_up(pNotNull)) = notnull
	}
	if pPrimaryKey != 0 {
		**(**int32)(__ccgo_up(pPrimaryKey)) = primarykey
	}
	if pAutoinc != 0 {
		**(**int32)(__ccgo_up(pAutoinc)) = autoinc
	}
	if SQLITE_OK == rc && !(pTab != 0) {
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
		**(**uintptr)(__ccgo_up(bp)) = _sqlite3MPrintf(tls, db, __ccgo_ts+26340, libc.VaList(bp+16, zTableName, zColumnName))
		rc = int32(SQLITE_ERROR)
	}
	if **(**uintptr)(__ccgo_up(bp)) != 0 {
		v1 = __ccgo_ts + 3944
	} else {
		v1 = uintptr(0)
	}
	_sqlite3ErrorWithMsg(tls, db, rc, v1, libc.VaList(bp+16, **(**uintptr)(__ccgo_up(bp))))
	_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp)))
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Interface to the testing logic.
//	*/
func Xsqlite3_test_control(tls *libc.TLS, op int32, va uintptr) (r int32) {
	var aProg, db, db1, db2, db3, db4, db5, db6, db7, pCtx, pI1, pI2, pN, pR, pU64, pn, ptr, xBenignBegin, xBenignEnd, z uintptr
	var ap Tva_list
	var b, iDb, opTrace, rc, sz, x, x1, x2, y, v1 int32
	var newVal uint32
	var rIn float64
	var rLogEst TLogEst
	var v2 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aProg, ap, b, db, db1, db2, db3, db4, db5, db6, db7, iDb, newVal, opTrace, pCtx, pI1, pI2, pN, pR, pU64, pn, ptr, rIn, rLogEst, rc, sz, x, x1, x2, xBenignBegin, xBenignEnd, y, z, v1, v2
	rc = 0
	ap = va
	switch op {
	/*
	 ** Save the current state of the PRNG.
	 */
	case int32(SQLITE_TESTCTRL_PRNG_SAVE):
		_sqlite3PrngSaveState(tls)
		break
		/*
		 ** Restore the state of the PRNG to the last state saved using
		 ** PRNG_SAVE.  If PRNG_SAVE has never before been called, then
		 ** this verb acts like PRNG_RESET.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_PRNG_RESTORE):
		_sqlite3PrngRestoreState(tls)
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, int x, sqlite3 *db);
		 **
		 ** Control the seed for the pseudo-random number generator (PRNG) that
		 ** is built into SQLite.  Cases:
		 **
		 **    x!=0 && db!=0       Seed the PRNG to the current value of the
		 **                        schema cookie in the main database for db, or
		 **                        x if the schema cookie is zero.  This case
		 **                        is convenient to use with database fuzzers
		 **                        as it allows the fuzzer some control over the
		 **                        the PRNG seed.
		 **
		 **    x!=0 && db==0       Seed the PRNG to the value of x.
		 **
		 **    x==0 && db==0       Revert to default behavior of using the
		 **                        xRandomness method on the primary VFS.
		 **
		 ** This test-control also resets the PRNG so that the new seed will
		 ** be used for the next call to sqlite3_randomness().
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_PRNG_SEED):
		x = libc.VaInt32(&ap)
		db = libc.VaUintptr(&ap)
		if v2 = db != 0; v2 {
			v1 = (*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fschema_cookie
			y = v1
		}
		if v2 && v1 != 0 {
			x = y
		}
		_sqlite3Config.FiPrngSeed = libc.Uint32FromInt32(x)
		Xsqlite3_randomness(tls, 0, uintptr(0))
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_FK_NO_ACTION, sqlite3 *db, int b);
		 **
		 ** If b is true, then activate the SQLITE_FkNoAction setting.  If b is
		 ** false then clear that setting.  If the SQLITE_FkNoAction setting is
		 ** enabled, all foreign key ON DELETE and ON UPDATE actions behave as if
		 ** they were NO ACTION, regardless of how they are defined.
		 **
		 ** NB:  One must usually run "PRAGMA writable_schema=RESET" after
		 ** using this test-control, before it will take full effect.  failing
		 ** to reset the schema can result in some unexpected behavior.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_FK_NO_ACTION):
		db1 = libc.VaUintptr(&ap)
		b = libc.VaInt32(&ap)
		if b != 0 {
			**(**Tu64)(__ccgo_up(db1 + 48)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32)
		} else {
			**(**Tu64)(__ccgo_up(db1 + 48)) &= ^(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008)) << libc.Int32FromInt32(32))
		}
		break
		/*
		 **  sqlite3_test_control(BITVEC_TEST, size, program)
		 **
		 ** Run a test against a Bitvec object of size.  The program argument
		 ** is an array of integers that defines the test.  Return -1 on a
		 ** memory allocation error, 0 on success, or non-zero for an error.
		 ** See the sqlite3BitvecBuiltinTest() for additional information.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_BITVEC_TEST):
		sz = libc.VaInt32(&ap)
		aProg = libc.VaUintptr(&ap)
		rc = _sqlite3BitvecBuiltinTest(tls, sz, aProg)
		break
		/*
		 **  sqlite3_test_control(FAULT_INSTALL, xCallback)
		 **
		 ** Arrange to invoke xCallback() whenever sqlite3FaultSim() is called,
		 ** if xCallback is not NULL.
		 **
		 ** As a test of the fault simulator mechanism itself, sqlite3FaultSim(0)
		 ** is called immediately after installing the new callback and the return
		 ** value from sqlite3FaultSim(0) becomes the return from
		 ** sqlite3_test_control().
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_FAULT_INSTALL):
		_sqlite3Config.FxTestCallback = libc.VaUintptr(&ap)
		rc = _sqlite3FaultSim(tls, 0)
		break
		/*
		 **  sqlite3_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
		 **
		 ** Register hooks to call to indicate which malloc() failures
		 ** are benign.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS):
		xBenignBegin = libc.VaUintptr(&ap)
		xBenignEnd = libc.VaUintptr(&ap)
		_sqlite3BenignMallocHooks(tls, xBenignBegin, xBenignEnd)
		break
		/*
		 **  sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, unsigned int X)
		 **
		 ** Set the PENDING byte to the value in the argument, if X>0.
		 ** Make no changes if X==0.  Return the value of the pending byte
		 ** as it existing before this routine was called.
		 **
		 ** IMPORTANT:  Changing the PENDING byte from 0x40000000 results in
		 ** an incompatible database file format.  Changing the PENDING byte
		 ** while any database connection is open results in undefined and
		 ** deleterious behavior.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_PENDING_BYTE):
		rc = _sqlite3PendingByte
		newVal = libc.VaUint32(&ap)
		if newVal != 0 {
			_sqlite3PendingByte = libc.Int32FromUint32(newVal)
		}
		break
		/*
		 **  sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X)
		 **
		 ** This action provides a run-time test to see whether or not
		 ** assert() was enabled at compile-time.  If X is true and assert()
		 ** is enabled, then the return value is true.  If X is true and
		 ** assert() is disabled, then the return value is zero.  If X is
		 ** false and assert() is enabled, then the assertion fires and the
		 ** process aborts.  If X is false and assert() is disabled, then the
		 ** return value is zero.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_ASSERT):
		x1 = 0
		rc = x1
		break
		/*
		 **  sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
		 **
		 ** This action provides a run-time test to see how the ALWAYS and
		 ** NEVER macros were defined at compile-time.
		 **
		 ** The return value is ALWAYS(X) if X is true, or 0 if X is false.
		 **
		 ** The recommended test is X==2.  If the return value is 2, that means
		 ** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
		 ** default setting.  If the return value is 1, then ALWAYS() is either
		 ** hard-coded to true or else it asserts if its argument is false.
		 ** The first behavior (hard-coded to true) is the case if
		 ** SQLITE_TESTCTRL_ASSERT shows that assert() is disabled and the second
		 ** behavior (assert if the argument to ALWAYS() is false) is the case if
		 ** SQLITE_TESTCTRL_ASSERT shows that assert() is enabled.
		 **
		 ** The run-time test procedure might look something like this:
		 **
		 **    if( sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, 2)==2 ){
		 **      // ALWAYS() and NEVER() are no-op pass-through macros
		 **    }else if( sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, 1) ){
		 **      // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
		 **    }else{
		 **      // ALWAYS(x) is a constant 1.  NEVER(x) is a constant 0.
		 **    }
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_ALWAYS):
		x2 = libc.VaInt32(&ap)
		if x2 != 0 {
			v1 = x2
		} else {
			v1 = 0
		}
		rc = v1
		break
		/*
		 **   sqlite3_test_control(SQLITE_TESTCTRL_BYTEORDER);
		 **
		 ** The integer returned reveals the byte-order of the computer on which
		 ** SQLite is running:
		 **
		 **       1     big-endian,    determined at run-time
		 **      10     little-endian, determined at run-time
		 **  432101     big-endian,    determined at compile-time
		 **  123410     little-endian, determined at compile-time
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_BYTEORDER):
		rc = libc.Int32FromInt32(SQLITE_BYTEORDER)*libc.Int32FromInt32(100) + libc.Int32FromInt32(SQLITE_LITTLEENDIAN)*libc.Int32FromInt32(10) + libc.Int32FromInt32(SQLITE_BIGENDIAN)
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, sqlite3 *db, int N)
		 **
		 ** Enable or disable various optimizations for testing purposes.  The
		 ** argument N is a bitmask of optimizations to be disabled.  For normal
		 ** operation N should be 0.  The idea is that a test program (like the
		 ** SQL Logic Test or SLT test module) can run the same SQL multiple times
		 ** with various optimizations disabled to verify that the same answer
		 ** is obtained in every case.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_OPTIMIZATIONS):
		db2 = libc.VaUintptr(&ap)
		(*Tsqlite3)(unsafe.Pointer(db2)).FdbOptFlags = libc.VaUint32(&ap)
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_GETOPT, sqlite3 *db, int *N)
		 **
		 ** Write the current optimization settings into *N.  A zero bit means that
		 ** the optimization is on, and a 1 bit means that the optimization is off.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_GETOPT):
		db3 = libc.VaUintptr(&ap)
		pN = libc.VaUintptr(&ap)
		**(**int32)(__ccgo_up(pN)) = libc.Int32FromUint32((*Tsqlite3)(unsafe.Pointer(db3)).FdbOptFlags)
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt);
		 **
		 ** If parameter onoff is 1, subsequent calls to localtime() fail.
		 ** If 2, then invoke xAlt() instead of localtime().  If 0, normal
		 ** processing.
		 **
		 ** xAlt arguments are void pointers, but they really want to be:
		 **
		 **    int xAlt(const time_t*, struct tm*);
		 **
		 ** xAlt should write results in to struct tm object of its 2nd argument
		 ** and return zero on success, or return non-zero on failure.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_LOCALTIME_FAULT):
		_sqlite3Config.FbLocaltimeFault = libc.VaInt32(&ap)
		if _sqlite3Config.FbLocaltimeFault == int32(2) {
			_sqlite3Config.FxAltLocaltime = libc.VaUintptr(&ap)
		} else {
			_sqlite3Config.FxAltLocaltime = uintptr(0)
		}
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
		 **
		 ** Toggle the ability to use internal functions on or off for
		 ** the database connection given in the argument.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS):
		db4 = libc.VaUintptr(&ap)
		**(**Tu32)(__ccgo_up(db4 + 44)) ^= uint32(DBFLAG_InternalFunc)
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
		 **
		 ** Set or clear a flag that indicates that the database file is always well-
		 ** formed and never corrupt.  This flag is clear by default, indicating that
		 ** database files might have arbitrary corruption.  Setting the flag during
		 ** testing causes certain assert() statements in the code to be activated
		 ** that demonstrate invariants on well-formed database files.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_NEVER_CORRUPT):
		_sqlite3Config.FneverCorrupt = libc.VaInt32(&ap)
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
		 **
		 ** Set or clear a flag that causes SQLite to verify that type, name,
		 ** and tbl_name fields of the sqlite_schema table.  This is normally
		 ** on, but it is sometimes useful to turn it off for testing.
		 **
		 ** 2020-07-22:  Disabling EXTRA_SCHEMA_CHECKS also disables the
		 ** verification of rootpage numbers when parsing the schema.  This
		 ** is useful to make it easier to reach strange internal error states
		 ** during testing.  The EXTRA_SCHEMA_CHECKS setting is always enabled
		 ** in production.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS):
		_sqlite3Config.FbExtraSchemaChecks = libc.Uint8FromInt32(libc.VaInt32(&ap))
		break
		/* Set the threshold at which OP_Once counters reset back to zero.
		 ** By default this is 0x7ffffffe (over 2 billion), but that value is
		 ** too big to test in a reasonable amount of time, so this control is
		 ** provided to set a small and easily reachable reset value.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD):
		_sqlite3Config.FiOnceResetThreshold = libc.VaInt32(&ap)
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
		 **
		 ** Set the VDBE coverage callback function to xCallback with context
		 ** pointer ptr.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_VDBE_COVERAGE):
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, nMax); */
		fallthrough
	case int32(SQLITE_TESTCTRL_SORTER_MMAP):
		db5 = libc.VaUintptr(&ap)
		(*Tsqlite3)(unsafe.Pointer(db5)).FnMaxSorterMmap = libc.VaInt32(&ap)
		break
		/*   sqlite3_test_control(SQLITE_TESTCTRL_ISINIT);
		 **
		 ** Return SQLITE_OK if SQLite has been initialized and SQLITE_ERROR if
		 ** not.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_ISINIT):
		if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+340) == 0 {
			rc = int32(SQLITE_ERROR)
		}
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, mode, tnum);
		 **
		 ** This test control is used to create imposter tables.  "db" is a pointer
		 ** to the database connection.  dbName is the database name (ex: "main" or
		 ** "temp") which will receive the imposter.  "mode" turns imposter mode on
		 ** or off.  mode==0 means imposter mode is off.  mode==1 means imposter mode
		 ** is on.  mode==2 means imposter mode is on but results in an imposter
		 ** table that is read-only unless writable_schema is on.  "tnum" is the
		 ** root page of the b-tree to which the imposter table should connect.
		 **
		 ** Enable imposter mode only when the schema has already been parsed.  Then
		 ** run a single CREATE TABLE statement to construct the imposter table in
		 ** the parsed schema.  Then turn imposter mode back off again.
		 **
		 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
		 ** the schema to be reparsed the next time it is needed.  This has the
		 ** effect of erasing all imposter tables.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_IMPOSTER):
		db6 = libc.VaUintptr(&ap)
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db6)).Fmutex)
		iDb = _sqlite3FindDbName(tls, db6, libc.VaUintptr(&ap))
		if iDb >= 0 {
			(*Tsqlite3)(unsafe.Pointer(db6)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
			(*Tsqlite3)(unsafe.Pointer(db6)).Finit1.Fbusy = uint8(libc.AssignBitFieldPtr8Uint32(db6+192+8, libc.Uint32FromInt32(libc.VaInt32(&ap)), 2, 5, 0x60))
			(*Tsqlite3)(unsafe.Pointer(db6)).Finit1.FnewTnum = libc.Uint32FromInt32(libc.VaInt32(&ap))
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db6)).Finit1.Fbusy) == 0 && (*Tsqlite3)(unsafe.Pointer(db6)).Finit1.FnewTnum > uint32(0) {
				_sqlite3ResetAllSchemasOfConnection(tls, db6)
			}
		}
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db6)).Fmutex)
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL, sqlite3_context*);
		 **
		 ** This test-control causes the most recent sqlite3_result_int64() value
		 ** to be interpreted as a MEM_IntReal instead of as an MEM_Int.  Normally,
		 ** MEM_IntReal values only arise during an INSERT operation of integer
		 ** values into a REAL column, so they can be challenging to test.  This
		 ** test-control enables us to write an intreal() SQL function that can
		 ** inject an intreal() value at arbitrary places in an SQL statement,
		 ** for testing purposes.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_RESULT_INTREAL):
		pCtx = libc.VaUintptr(&ap)
		_sqlite3ResultIntReal(tls, pCtx)
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_SEEK_COUNT,
		 **    sqlite3 *db,    // Database connection
		 **    u64 *pnSeek     // Write seek count here
		 **  );
		 **
		 ** This test-control queries the seek-counter on the "main" database
		 ** file.  The seek-counter is written into *pnSeek and is then reset.
		 ** The seek-count is only available if compiled with SQLITE_DEBUG.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_SEEK_COUNT):
		db7 = libc.VaUintptr(&ap)
		pn = libc.VaUintptr(&ap)
		**(**Tu64)(__ccgo_up(pn)) = uint64(0)
		_ = db7 /* Silence harmless unused variable warning */
		break
		/*  sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, op, ptr)
		 **
		 **  "ptr" is a pointer to a u32.
		 **
		 **   op==0       Store the current sqlite3TreeTrace in *ptr
		 **   op==1       Set sqlite3TreeTrace to the value *ptr
		 **   op==2       Store the current sqlite3WhereTrace in *ptr
		 **   op==3       Set sqlite3WhereTrace to the value *ptr
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_TRACEFLAGS):
		opTrace = libc.VaInt32(&ap)
		ptr = libc.VaUintptr(&ap)
		switch opTrace {
		case 0:
			**(**Tu32)(__ccgo_up(ptr)) = _sqlite3TreeTrace
		case int32(1):
			_sqlite3TreeTrace = **(**Tu32)(__ccgo_up(ptr))
		case int32(2):
			**(**Tu32)(__ccgo_up(ptr)) = _sqlite3WhereTrace
		case int32(3):
			_sqlite3WhereTrace = **(**Tu32)(__ccgo_up(ptr))
			break
		}
		break
		/* sqlite3_test_control(SQLITE_TESTCTRL_LOGEST,
		 **      double fIn,     // Input value
		 **      int *pLogEst,   // sqlite3LogEstFromDouble(fIn)
		 **      u64 *pInt,      // sqlite3LogEstToInt(*pLogEst)
		 **      int *pLogEst2   // sqlite3LogEst(*pInt)
		 ** );
		 **
		 ** Test access for the LogEst conversion routines.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_LOGEST):
		rIn = libc.VaFloat64(&ap)
		rLogEst = _sqlite3LogEstFromDouble(tls, rIn)
		pI1 = libc.VaUintptr(&ap)
		pU64 = libc.VaUintptr(&ap)
		pI2 = libc.VaUintptr(&ap)
		**(**int32)(__ccgo_up(pI1)) = int32(rLogEst)
		**(**Tu64)(__ccgo_up(pU64)) = _sqlite3LogEstToInt(tls, rLogEst)
		**(**int32)(__ccgo_up(pI2)) = int32(_sqlite3LogEst(tls, **(**Tu64)(__ccgo_up(pU64))))
		break
		/* sqlite3_test_control(SQLITE_TESTCTRL_ATOF, const char *z, double *p);
		 **
		 ** Test access to the sqlite3AtoF() routine.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_ATOF):
		z = libc.VaUintptr(&ap)
		pR = libc.VaUintptr(&ap)
		rc = _sqlite3AtoF(tls, z, pR)
		break
		/* sqlite3_test_control(SQLITE_TESTCTRL_JSON_SELFCHECK, &onOff);
		 **
		 ** Activate or deactivate validation of JSONB that is generated from
		 ** text.  Off by default, as the validation is slow.  Validation is
		 ** only available if compiled using SQLITE_DEBUG.
		 **
		 ** If onOff is initially 1, then turn it on.  If onOff is initially
		 ** off, turn it off.  If onOff is initially -1, then change onOff
		 ** to be the current setting.
		 */
		fallthrough
	case int32(SQLITE_TESTCTRL_JSON_SELFCHECK):
		break
	}
	_ = ap
	return rc
}

// C documentation
//
//	/*
//	** Deprecated external interface.  Internal/core SQLite code
//	** should call sqlite3TransferBindings.
//	**
//	** It is misuse to call this routine with statements from different
//	** database connections.  But as this is a deprecated interface, we
//	** will not bother to check for that condition.
//	**
//	** If the two statements contain a different number of bindings, then
//	** an SQLITE_ERROR is returned.  Nothing else can go wrong, so otherwise
//	** SQLITE_OK is returned.
//	*/
func Xsqlite3_transfer_bindings(tls *libc.TLS, pFromStmt uintptr, pToStmt uintptr) (r int32) {
	var pFrom, pTo uintptr
	_, _ = pFrom, pTo
	pFrom = pFromStmt
	pTo = pToStmt
	if int32((*TVdbe)(unsafe.Pointer(pFrom)).FnVar) != int32((*TVdbe)(unsafe.Pointer(pTo)).FnVar) {
		return int32(SQLITE_ERROR)
	}
	if (*TVdbe)(unsafe.Pointer(pTo)).Fexpmask != 0 {
		libc.SetBitFieldPtr16Uint32(pTo+200, libc.Uint32FromInt32(1), 14, 0xc000)
	}
	if (*TVdbe)(unsafe.Pointer(pFrom)).Fexpmask != 0 {
		libc.SetBitFieldPtr16Uint32(pFrom+200, libc.Uint32FromInt32(1), 14, 0xc000)
	}
	return _sqlite3TransferBindings(tls, pFromStmt, pToStmt)
}

func Xsqlite3_value_bytes16(tls *libc.TLS, pVal uintptr) (r int32) {
	return _sqlite3ValueBytes(tls, pVal, uint8(SQLITE_UTF16BE))
}

func Xsqlite3_value_text16(tls *libc.TLS, pVal uintptr) (r uintptr) {
	return _sqlite3ValueText(tls, pVal, uint8(SQLITE_UTF16BE))
}

const __ARCH__ = 9

const __BYTE_ORDER = 4321

const __BYTE_ORDER__ = 4321

const __FLOAT_WORD_ORDER__ = 4321

const __GNUC_WIDE_EXECUTION_CHARSET_NAME = "UTF-32BE"

const __s390__ = 1

const __s390x__ = 1

const __zarch__ = 1

// C documentation
//
//	/*
//	** Allocate and populate an sqlite3_index_info structure. It is the
//	** responsibility of the caller to eventually release the structure
//	** by passing the pointer returned by this function to freeIndexInfo().
//	*/
func _allocateIndexInfo(tls *libc.TLS, pWInfo uintptr, pWC uintptr, mUnusable TBitmask, pSrc uintptr, pmNoOmit uintptr) (r uintptr) {
	var bSortByGroup, eDistinct, i, iCol, j, n, nLast, nOrderBy, nTerm, v10 int32
	var mNoOmit, op Tu16
	var p, pE2, pExpr, pExpr1, pHidden, pIdxCons, pIdxInfo, pIdxOrderBy, pOrderBy, pParse, pPk, pTab, pTerm, pUsage, zColl, v3 uintptr
	var v12 uint32
	var v7 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bSortByGroup, eDistinct, i, iCol, j, mNoOmit, n, nLast, nOrderBy, nTerm, op, p, pE2, pExpr, pExpr1, pHidden, pIdxCons, pIdxInfo, pIdxOrderBy, pOrderBy, pParse, pPk, pTab, pTerm, pUsage, zColl, v10, v12, v3, v7
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	mNoOmit = uint16(0)
	eDistinct = 0
	pOrderBy = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy
	pTab = (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab
	/* Find all WHERE clause constraints referring to this virtual table.
	 ** Mark each term with the TERM_OK flag.  Set nTerm to the number of
	 ** terms found.
	 */
	p = pWC
	nTerm = libc.Int32FromInt32(0)
	for {
		if !(p != 0) {
			break
		}
		i = 0
		pTerm = (*TWhereClause)(unsafe.Pointer(p)).Fa
		for {
			if !(i < (*TWhereClause)(unsafe.Pointer(p)).FnTerm) {
				break
			}
			v3 = pTerm + 18
			*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) & ^libc.Int32FromInt32(TERM_OK))
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
				goto _2
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUnusable != 0 {
				goto _2
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & ^libc.Int32FromInt32(WO_EQUIV) == 0 {
				goto _2
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) != 0 {
				goto _2
			}
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 && !(_constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
				goto _2
			}
			nTerm = nTerm + 1
			v3 = pTerm + 18
			*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(TERM_OK))
			goto _2
		_2:
			;
			i = i + 1
			pTerm += 56
		}
		goto _1
	_1:
		;
		p = (*TWhereClause)(unsafe.Pointer(p)).FpOuter
	}
	/* If the ORDER BY clause contains only columns in the current
	 ** virtual table then allocate space for the aOrderBy part of
	 ** the sqlite3_index_info structure.
	 */
	nOrderBy = 0
	if pOrderBy != 0 {
		n = (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr
		i = 0
		for {
			if !(i < n) {
				break
			}
			pExpr = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr
			/* Skip over constant terms in the ORDER BY clause */
			if _sqlite3ExprIsConstant(tls, uintptr(0), pExpr) != 0 {
				goto _5
			}
			/* Virtual tables are unable to deal with NULLS FIRST */
			if libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
				break
			}
			/* First case - a direct column references without a COLLATE operator */
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor {
				goto _5
			}
			/* 2nd case - a column reference with a COLLATE operator.  Only match
			 ** of the COLLATE operator matches the collation of the column. */
			if v7 = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE); v7 {
				v3 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
				pE2 = v3
			}
			if v7 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(v3)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pE2)).FiTable == (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor { /* The collating sequence name */
				(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = (*TExpr)(unsafe.Pointer(pE2)).FiColumn
				if int32((*TExpr)(unsafe.Pointer(pE2)).FiColumn) < 0 {
					goto _5
				} /* Collseq does not matter for rowid */
				zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr((*TExpr)(unsafe.Pointer(pE2)).FiColumn)*16)
				if zColl == uintptr(0) {
					zColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
				}
				if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), zColl) == 0 {
					goto _5
				}
			}
			/* No matches cause a break out of the loop */
			break
			goto _5
		_5:
			;
			i = i + 1
		}
		if i == n {
			bSortByGroup = libc.BoolInt32(libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_SORTBYGROUP) != 0)
			nOrderBy = n
			if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) != 0 && !(int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x10000>>16) != 0) {
				eDistinct = int32(2) + bSortByGroup
			} else {
				if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_GROUPBY) != 0 {
					eDistinct = int32(1) - bSortByGroup
				} else {
					if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
						eDistinct = int32(3)
					}
				}
			}
		}
	}
	/* Allocate the sqlite3_index_info structure
	 */
	pIdxInfo = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(96)+(libc.Uint64FromInt64(12)+libc.Uint64FromInt64(8))*libc.Uint64FromInt32(nTerm)+uint64(8)*libc.Uint64FromInt32(nOrderBy)+(uint64(libc.UintptrFromInt32(0)+32)+libc.Uint64FromInt32(nTerm)*uint64(8))))
	if pIdxInfo == uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1674, 0)
		return uintptr(0)
	}
	pHidden = pIdxInfo + 1*96
	pIdxCons = pHidden + 32 + uintptr(nTerm)*8
	pIdxOrderBy = pIdxCons + uintptr(nTerm)*12
	pUsage = pIdxOrderBy + uintptr(nOrderBy)*8
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint = pIdxCons
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy = pIdxOrderBy
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage = pUsage
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FcolUsed = libc.Uint64FromInt64(libc.Int64FromUint64((*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed))
	if libc.BoolInt32((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)) == 0 {
		/* Ensure that all bits associated with PK columns are set. This is to
		 ** ensure they are available for cases like RIGHT joins or OR loops. */
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		i = 0
		for {
			if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))
			if iCol >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
				iCol = libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1)
			}
			**(**Tsqlite3_uint64)(__ccgo_up(pIdxInfo + 88)) |= libc.Uint64FromInt32(1) << iCol
			goto _8
		_8:
			;
			i = i + 1
		}
	}
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FpWC = pWC
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FpParse = pParse
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FeDistinct = eDistinct
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmIn = uint32(0)
	p = pWC
	v10 = libc.Int32FromInt32(0)
	j = v10
	i = v10
	for {
		if !(p != 0) {
			break
		}
		nLast = i + (*TWhereClause)(unsafe.Pointer(p)).FnTerm
		pTerm = (*TWhereClause)(unsafe.Pointer(p)).Fa
		for {
			if !(i < nLast) {
				break
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_OK) == 0 {
				goto _11
			}
			(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).FiColumn = (*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pTerm + 32))).FleftColumn
			(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).FiTermOffset = i
			op = libc.Uint16FromInt32(libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & int32(WO_ALL))
			if libc.Int32FromUint16(op) == int32(WO_IN) {
				if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_SLICE) == 0 {
					if j <= int32(31) {
						v12 = libc.Uint32FromInt32(1) << j
					} else {
						v12 = uint32(0)
					}
					**(**Tu32)(__ccgo_up(pHidden + 20)) |= v12
				}
				op = uint16(WO_EQ)
			}
			if libc.Int32FromUint16(op) == int32(WO_AUX) {
				(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = (*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp
			} else {
				if libc.Int32FromUint16(op)&(libc.Int32FromInt32(WO_ISNULL)|libc.Int32FromInt32(WO_IS)) != 0 {
					if libc.Int32FromUint16(op) == int32(WO_ISNULL) {
						(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = uint8(SQLITE_INDEX_CONSTRAINT_ISNULL)
					} else {
						(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = uint8(SQLITE_INDEX_CONSTRAINT_IS)
					}
				} else {
					(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = uint8(op)
					/* The direct assignment in the previous line is possible only because
					 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical.  The
					 ** following asserts verify this fact. */
					if libc.Int32FromUint16(op)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0 && _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight) != 0 {
						if j < int32(16) {
							mNoOmit = libc.Uint16FromInt32(int32(mNoOmit) | libc.Int32FromInt32(1)<<j)
						}
						if libc.Int32FromUint16(op) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) {
							(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = libc.Uint8FromInt32(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_LE) - libc.Int32FromInt32(TK_EQ)))
						}
						if libc.Int32FromUint16(op) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) {
							(**(**Tsqlite3_index_constraint)(__ccgo_up(pIdxCons + uintptr(j)*12))).Fop = libc.Uint8FromInt32(libc.Int32FromInt32(WO_EQ) << (libc.Int32FromInt32(TK_GE) - libc.Int32FromInt32(TK_EQ)))
						}
					}
				}
			}
			j = j + 1
			goto _11
		_11:
			;
			i = i + 1
			pTerm += 56
		}
		goto _9
	_9:
		;
		p = (*TWhereClause)(unsafe.Pointer(p)).FpOuter
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint = j
	v10 = libc.Int32FromInt32(0)
	j = v10
	i = v10
	for {
		if !(i < nOrderBy) {
			break
		}
		pExpr1 = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr
		if _sqlite3ExprIsConstant(tls, uintptr(0), pExpr1) != 0 {
			goto _13
		}
		(**(**Tsqlite3_index_orderby)(__ccgo_up(pIdxOrderBy + uintptr(j)*8))).FiColumn = int32((*TExpr)(unsafe.Pointer(pExpr1)).FiColumn)
		(**(**Tsqlite3_index_orderby)(__ccgo_up(pIdxOrderBy + uintptr(j)*8))).Fdesc = libc.Uint8FromInt32(libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags) & int32(KEYINFO_ORDER_DESC))
		j = j + 1
		goto _13
	_13:
		;
		i = i + 1
	}
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy = j
	**(**Tu16)(__ccgo_up(pmNoOmit)) = mNoOmit
	return pIdxInfo
}

// C documentation
//
//	/*
//	** This callback is invoked once for each index when reading the
//	** sqlite_stat1 table.
//	**
//	**     argv[0] = name of the table
//	**     argv[1] = name of the index (might be NULL)
//	**     argv[2] = results of analysis - on integer for each column
//	**
//	** Entries for which argv[1]==NULL simply record the number of rows in
//	** the table.
//	*/
func _analysisLoader(tls *libc.TLS, pData uintptr, argc int32, argv uintptr, NotUsed uintptr) (r int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var aiRowEst, pIndex, pInfo, pTable, z uintptr
	var nCol int32
	var _ /* fakeIdx at bp+0 */ TIndex
	_, _, _, _, _, _ = aiRowEst, nCol, pIndex, pInfo, pTable, z
	pInfo = pData
	_ = NotUsed
	_ = argc
	if argv == uintptr(0) || **(**uintptr)(__ccgo_up(argv)) == uintptr(0) || **(**uintptr)(__ccgo_up(argv + 2*8)) == uintptr(0) {
		return 0
	}
	pTable = _sqlite3FindTable(tls, (*TanalysisInfo)(unsafe.Pointer(pInfo)).Fdb, **(**uintptr)(__ccgo_up(argv)), (*TanalysisInfo)(unsafe.Pointer(pInfo)).FzDatabase)
	if pTable == uintptr(0) {
		return 0
	}
	if **(**uintptr)(__ccgo_up(argv + 1*8)) == uintptr(0) {
		pIndex = uintptr(0)
	} else {
		if Xsqlite3_stricmp(tls, **(**uintptr)(__ccgo_up(argv)), **(**uintptr)(__ccgo_up(argv + 1*8))) == 0 {
			pIndex = _sqlite3PrimaryKeyIndex(tls, pTable)
		} else {
			pIndex = _sqlite3FindIndex(tls, (*TanalysisInfo)(unsafe.Pointer(pInfo)).Fdb, **(**uintptr)(__ccgo_up(argv + 1*8)), (*TanalysisInfo)(unsafe.Pointer(pInfo)).FzDatabase)
		}
	}
	z = **(**uintptr)(__ccgo_up(argv + 2*8))
	if pIndex != 0 {
		aiRowEst = uintptr(0)
		nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol) + int32(1)
		/* Index.aiRowEst may already be set here if there are duplicate
		 ** sqlite_stat1 entries for this index. In that case just clobber
		 ** the old data with the new instead of allocating a new array.  */
		if (*TIndex)(unsafe.Pointer(pIndex)).FaiRowEst == uintptr(0) {
			(*TIndex)(unsafe.Pointer(pIndex)).FaiRowEst = _sqlite3MallocZero(tls, uint64(uint64(8)*libc.Uint64FromInt32(nCol)))
			if (*TIndex)(unsafe.Pointer(pIndex)).FaiRowEst == uintptr(0) {
				_sqlite3OomFault(tls, (*TanalysisInfo)(unsafe.Pointer(pInfo)).Fdb)
			}
		}
		aiRowEst = (*TIndex)(unsafe.Pointer(pIndex)).FaiRowEst
		libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 13, 0x2000)
		_decodeIntArray(tls, z, nCol, aiRowEst, (*TIndex)(unsafe.Pointer(pIndex)).FaiRowLogEst, pIndex)
		libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 8, 0x100)
		if (*TIndex)(unsafe.Pointer(pIndex)).FpPartIdxWhere == uintptr(0) {
			(*TTable)(unsafe.Pointer(pTable)).FnRowLogEst = **(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiRowLogEst))
			**(**Tu32)(__ccgo_up(pTable + 48)) |= uint32(TF_HasStat1)
		}
	} else {
		(**(**TIndex)(__ccgo_up(bp))).FszIdxRow = (*TTable)(unsafe.Pointer(pTable)).FszTabRow
		_decodeIntArray(tls, z, int32(1), uintptr(0), pTable+58, bp)
		(*TTable)(unsafe.Pointer(pTable)).FszTabRow = (**(**TIndex)(__ccgo_up(bp))).FszIdxRow
		**(**Tu32)(__ccgo_up(pTable + 48)) |= uint32(TF_HasStat1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Generate code to do an analysis of all indices associated with
//	** a single table.
//	*/
func _analyzeOneTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr, iStatCur int32, iMem int32, iTab int32) {
	var aGotoChng, db, pColl, pIdx, pPk, pStat1, pX, v, zIdxName uintptr
	var addrGotoEnd, addrIsNull, addrNext, addrNextRow, doOnce, endDistinctTest, i, iDb, iIdxCur, iTabCur, j, j1, j2, j3, jZeroRows, k, mxCol, nCol, nColTest, nColX, regChng, regCol, regDLt, regEq, regIdxname, regKey, regLt, regNewRowid, regPrev, regRowid, regSample, regSampleRowid, regStat, regStat1, regTabname, regTemp, regTemp2, v1, v2, v3, v4, v5, v6, v7, v8, v9 int32
	var needTableCnt, seekOp Tu8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aGotoChng, addrGotoEnd, addrIsNull, addrNext, addrNextRow, db, doOnce, endDistinctTest, i, iDb, iIdxCur, iTabCur, j, j1, j2, j3, jZeroRows, k, mxCol, nCol, nColTest, nColX, needTableCnt, pColl, pIdx, pPk, pStat1, pX, regChng, regCol, regDLt, regEq, regIdxname, regKey, regLt, regNewRowid, regPrev, regRowid, regSample, regSampleRowid, regStat, regStat1, regTabname, regTemp, regTemp2, seekOp, v, zIdxName, v1, v2, v3, v4, v5, v6, v7, v8, v9
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Loop counter */
	jZeroRows = -int32(1)                      /* Index of database containing pTab */
	needTableCnt = uint8(1)
	v1 = iMem
	iMem = iMem + 1 /* True to count the table */
	regNewRowid = v1
	v2 = iMem
	iMem = iMem + 1 /* Rowid for the inserted record */
	regStat = v2
	v3 = iMem
	iMem = iMem + 1 /* Register to hold StatAccum object */
	regChng = v3
	v4 = iMem
	iMem = iMem + 1 /* Index of changed index field */
	regRowid = v4
	v5 = iMem
	iMem = iMem + 1 /* Rowid argument passed to stat_push() */
	regTemp = v5
	v6 = iMem
	iMem = iMem + 1 /* Temporary use register */
	regTemp2 = v6
	v7 = iMem
	iMem = iMem + 1 /* Second temporary use register */
	regTabname = v7
	v8 = iMem
	iMem = iMem + 1 /* Register containing table name */
	regIdxname = v8
	v9 = iMem
	iMem = iMem + 1   /* Register containing index name */
	regStat1 = v9     /* Value for the stat column of sqlite_stat1 */
	regPrev = iMem    /* MUST BE LAST (see below) */
	doOnce = int32(1) /* Flag for a one-time computation */
	pStat1 = uintptr(0)
	_sqlite3TouchRegister(tls, pParse, iMem)
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) || pTab == uintptr(0) {
		return
	}
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		/* Do not gather statistics on views or virtual tables */
		return
	}
	if Xsqlite3_strlike(tls, __ccgo_ts+13034, (*TTable)(unsafe.Pointer(pTab)).FzName, uint32('\\')) == 0 {
		/* Do not gather statistics on system tables */
		return
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ANALYZE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
		return
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
		pStat1 = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt64(120)+libc.Uint64FromInt32(13)))
		if pStat1 == uintptr(0) {
			return
		}
		(*TTable)(unsafe.Pointer(pStat1)).FzName = pStat1 + 1*120
		libc.Xmemcpy(tls, (*TTable)(unsafe.Pointer(pStat1)).FzName, __ccgo_ts+12837, uint64(13))
		(*TTable)(unsafe.Pointer(pStat1)).FnCol = int16(3)
		(*TTable)(unsafe.Pointer(pStat1)).FiPKey = int16(-int32(1))
		_sqlite3VdbeAddOp4(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Noop), 0, 0, 0, pStat1, -int32(7))
	}
	/* Establish a read-lock on the table at the shared-cache level.
	 ** Open a read-only cursor on the table. Also allocate a cursor number
	 ** to use for scanning indexes (iIdxCur). No index cursor is opened at
	 ** this time though.  */
	_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
	v1 = iTab
	iTab = iTab + 1
	iTabCur = v1
	v1 = iTab
	iTab = iTab + 1
	iIdxCur = v1
	if (*TParse)(unsafe.Pointer(pParse)).FnTab > iTab {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FnTab
	} else {
		v1 = iTab
	}
	(*TParse)(unsafe.Pointer(pParse)).FnTab = v1
	_sqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab, int32(OP_OpenRead))
	_sqlite3VdbeLoadString(tls, v, regTabname, (*TTable)(unsafe.Pointer(pTab)).FzName)
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		} /* Number of columns to test for changes */
		if pOnlyIdx != 0 && pOnlyIdx != pIdx {
			goto _13
		}
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
			needTableCnt = uint8(0)
		}
		if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
			zIdxName = (*TTable)(unsafe.Pointer(pTab)).FzName
			nColTest = nCol - int32(1)
		} else {
			nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
			zIdxName = (*TIndex)(unsafe.Pointer(pIdx)).FzName
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x1000>>12)) != 0 {
				v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) - int32(1)
			} else {
				v1 = nCol - int32(1)
			}
			nColTest = v1
		}
		/* Populate the register containing the index name. */
		_sqlite3VdbeLoadString(tls, v, regIdxname, zIdxName)
		/*
		 ** Pseudo-code for loop that calls stat_push():
		 **
		 **   regChng = 0
		 **   Rewind csr
		 **   if eof(csr){
		 **      stat_init() with count = 0;
		 **      goto end_of_scan;
		 **   }
		 **   count()
		 **   stat_init()
		 **   goto chng_addr_0;
		 **
		 **  next_row:
		 **   regChng = 0
		 **   if( idx(0) != regPrev(0) ) goto chng_addr_0
		 **   regChng = 1
		 **   if( idx(1) != regPrev(1) ) goto chng_addr_1
		 **   ...
		 **   regChng = N
		 **   goto chng_addr_N
		 **
		 **  chng_addr_0:
		 **   regPrev(0) = idx(0)
		 **  chng_addr_1:
		 **   regPrev(1) = idx(1)
		 **  ...
		 **
		 **  endDistinctTest:
		 **   regRowid = idx(rowid)
		 **   stat_push(P, regChng, regRowid)
		 **   Next csr
		 **   if !eof(csr) goto next_row;
		 **
		 **  end_of_scan:
		 */
		/* Make sure there are enough memory cells allocated to accommodate
		 ** the regPrev array and a trailing rowid (the rowid slot is required
		 ** when building a record to insert into the sample column of
		 ** the sqlite_stat4 table.  */
		_sqlite3TouchRegister(tls, pParse, regPrev+nColTest)
		/* Open a read-only cursor on the index being analyzed. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iIdxCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
		_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
		/* Implementation of the following:
		 **
		 **   regChng = 0
		 **   Rewind csr
		 **   if eof(csr){
		 **      stat_init() with count = 0;
		 **      goto end_of_scan;
		 **   }
		 **   count()
		 **   stat_init()
		 **   goto chng_addr_0;
		 */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit, regTemp2)
		/* Arguments to stat_init():
		 **    (1) the number of columns in the index including the rowid
		 **        (or for a WITHOUT ROWID table, the number of PK columns),
		 **    (2) the number of columns in the key without the rowid/pk
		 **    (3) estimated number of rows in the index. */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nCol, regStat+int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), regRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Count), iIdxCur, regTemp, libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) != uint32(0)))
		_sqlite3VdbeAddFunctionCall(tls, pParse, 0, regStat+int32(1), regStat, int32(4), uintptr(unsafe.Pointer(&_statInitFuncdef)), 0)
		addrGotoEnd = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iIdxCur)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regChng)
		addrNextRow = _sqlite3VdbeCurrentAddr(tls, v)
		if nColTest > 0 {
			endDistinctTest = _sqlite3VdbeMakeLabel(tls, pParse) /* Array of jump instruction addresses */
			aGotoChng = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nColTest)))
			if aGotoChng == uintptr(0) {
				goto _13
			}
			/*
			 **  next_row:
			 **   regChng = 0
			 **   if( idx(0) != regPrev(0) ) goto chng_addr_0
			 **   regChng = 1
			 **   if( idx(1) != regPrev(1) ) goto chng_addr_1
			 **   ...
			 **   regChng = N
			 **   goto endDistinctTest
			 */
			_sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
			addrNextRow = _sqlite3VdbeCurrentAddr(tls, v)
			if nColTest == int32(1) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == int32(1) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None {
				/* For a single-column UNIQUE index, once we have found a non-NULL
				 ** row, we know that all the rest will be distinct, so skip
				 ** subsequent distinctness tests. */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), regPrev, endDistinctTest)
			}
			i = 0
			for {
				if !(i < nColTest) {
					break
				}
				pColl = _sqlite3LocateCollSeq(tls, pParse, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8)))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), i, regChng)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regTemp)
				**(**int32)(__ccgo_up(aGotoChng + uintptr(i)*4)) = _sqlite3VdbeAddOp4(tls, v, int32(OP_Ne), regTemp, 0, regPrev+i, pColl, -int32(2))
				_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
				goto _15
			_15:
				;
				i = i + 1
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nColTest, regChng)
			_sqlite3VdbeGoto(tls, v, endDistinctTest)
			/*
			 **  chng_addr_0:
			 **   regPrev(0) = idx(0)
			 **  chng_addr_1:
			 **   regPrev(1) = idx(1)
			 **  ...
			 */
			_sqlite3VdbeJumpHere(tls, v, addrNextRow-int32(1))
			i = 0
			for {
				if !(i < nColTest) {
					break
				}
				_sqlite3VdbeJumpHere(tls, v, **(**int32)(__ccgo_up(aGotoChng + uintptr(i)*4)))
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, i, regPrev+i)
				goto _16
			_16:
				;
				i = i + 1
			}
			_sqlite3VdbeResolveLabel(tls, v, endDistinctTest)
			_sqlite3DbFree(tls, db, aGotoChng)
		}
		/*
		 **  chng_addr_N:
		 **   regRowid = idx(rowid)            // STAT4 only
		 **   stat_push(P, regChng, regRowid)  // 3rd parameter STAT4 only
		 **   Next csr
		 **   if !eof(csr) goto next_row;
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iIdxCur, regRowid)
			} else {
				pPk = _sqlite3PrimaryKeyIndex(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable)
				regKey = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
				j = 0
				for {
					if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
						break
					}
					k = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, regKey+j)
					goto _17
				_17:
					;
					j = j + 1
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regKey, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol), regRowid)
				_sqlite3ReleaseTempRange(tls, pParse, regKey, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
			}
		}
		_sqlite3VdbeAddFunctionCall(tls, pParse, int32(1), regStat, regTemp, libc.Int32FromInt32(2)+libc.Int32FromInt32(IsStat4), uintptr(unsafe.Pointer(&_statPushFuncdef)), 0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit != 0 {
			j1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regTemp)
			j2 = _sqlite3VdbeAddOp1(tls, v, int32(OP_If), regTemp)
			j3 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_SeekGT), iIdxCur, 0, regPrev, int32(1))
			_sqlite3VdbeJumpHere(tls, v, j1)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iIdxCur, addrNextRow)
			_sqlite3VdbeJumpHere(tls, v, j2)
			_sqlite3VdbeJumpHere(tls, v, j3)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iIdxCur, addrNextRow)
		}
		/* Add the entry to the stat1 table. */
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			/* Partial indexes might get a zero-entry in sqlite_stat1.  But
			 ** an empty table is omitted from sqlite_stat1. */
			_sqlite3VdbeJumpHere(tls, v, addrGotoEnd)
			addrGotoEnd = 0
		}
		_callStatGet(tls, pParse, regStat, STAT_GET_STAT1, regStat1)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regTabname, int32(3), regTemp, __ccgo_ts+13044, 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur, regNewRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur, regTemp, regNewRowid)
		_sqlite3VdbeChangeP4(tls, v, -int32(1), pStat1, -int32(5))
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		/* Add the entries to the stat4 table. */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) && (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit == 0 {
			regEq = regStat1
			regLt = regStat1 + int32(1)
			regDLt = regStat1 + int32(2)
			regSample = regStat1 + int32(3)
			regCol = regStat1 + int32(4)
			regSampleRowid = regCol + nCol
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				v1 = int32(OP_NotExists)
			} else {
				v1 = int32(OP_NotFound)
			}
			seekOp = libc.Uint8FromInt32(v1)
			/* No STAT4 data is generated if the number of rows is zero */
			if addrGotoEnd == 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Cast), regStat1, int32(SQLITE_AFF_INTEGER))
				addrGotoEnd = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regStat1)
			}
			if doOnce != 0 {
				mxCol = nCol
				/* Compute the maximum number of columns in any index */
				pX = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pX != 0) {
						break
					} /* Number of columns in pX */
					if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pX + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
						nColX = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pX)).FnKeyCol)
					} else {
						nColX = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pX)).FnColumn)
					}
					if nColX > mxCol {
						mxCol = nColX
					}
					goto _19
				_19:
					;
					pX = (*TIndex)(unsafe.Pointer(pX)).FpNext
				}
				/* Allocate space to compute results for the largest index */
				_sqlite3TouchRegister(tls, pParse, regCol+mxCol)
				doOnce = 0
				_sqlite3ClearTempRegCache(tls, pParse) /* tag-20230325-1 */
			}
			addrNext = _sqlite3VdbeCurrentAddr(tls, v)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_ROWID), regSampleRowid)
			addrIsNull = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), regSampleRowid)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_NEQ), regEq)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_NLT), regLt)
			_callStatGet(tls, pParse, regStat, int32(STAT_GET_NDLT), regDLt)
			_sqlite3VdbeAddOp4Int(tls, v, libc.Int32FromUint8(seekOp), iTabCur, addrNext, regSampleRowid, 0)
			i = 0
			for {
				if !(i < nCol) {
					break
				}
				_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iTabCur, i, regCol+i)
				goto _20
			_20:
				;
				i = i + 1
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regCol, nCol, regSample)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regTabname, int32(6), regTemp)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur+int32(1), regNewRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur+int32(1), regTemp, regNewRowid)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), int32(1), addrNext) /* P1==1 for end-of-loop */
			_sqlite3VdbeJumpHere(tls, v, addrIsNull)
		}
		/* End of analysis */
		if addrGotoEnd != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrGotoEnd)
		}
		goto _13
	_13:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	/* Create a single sqlite_stat1 entry containing NULL as the index
	 ** name and the row count as the content.
	 */
	if pOnlyIdx == uintptr(0) && needTableCnt != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Count), iTabCur, regStat1)
		jZeroRows = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNot), regStat1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regIdxname)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), regTabname, int32(3), regTemp, __ccgo_ts+13044, 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iStatCur, regNewRowid)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iStatCur, regTemp, regNewRowid)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		_sqlite3VdbeChangeP4(tls, v, -int32(1), pStat1, -int32(5))
		_sqlite3VdbeJumpHere(tls, v, jZeroRows)
	}
}

// C documentation
//
//	/*
//	** An SQL user-function registered to do the work of an ATTACH statement. The
//	** three arguments to the function come directly from an attach statement:
//	**
//	**     ATTACH DATABASE x AS y KEY z
//	**
//	**     SELECT sqlite_attach(x, y, z)
//	**
//	** If the optional "KEY z" syntax is omitted, an SQL NULL is passed as the
//	** third argument.
//	**
//	** If the db->init.reopenMemdb flags is set, then instead of attaching a
//	** new database, close the database on db->init.iDb and reopen it as an
//	** empty MemDB.
//	*/
func _attachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aNew, db, pNew, pNewSchema, pPager, zFile, zName uintptr
	var i, iDb, rc int32
	var _ /* flags at bp+16 */ uint32
	var _ /* pNewBt at bp+40 */ uintptr
	var _ /* pVfs at bp+32 */ uintptr
	var _ /* zErr at bp+8 */ uintptr
	var _ /* zErrDyn at bp+24 */ uintptr
	var _ /* zPath at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = aNew, db, i, iDb, pNew, pNewSchema, pPager, rc, zFile, zName
	rc = 0
	db = Xsqlite3_context_db_handle(tls, context)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* New array of Db pointers */
	pNew = uintptr(0)                             /* Db object for the newly attached database */
	**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
	_ = NotUsed
	zFile = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zName = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
	if zFile == uintptr(0) {
		zFile = __ccgo_ts + 1704
	}
	if zName == uintptr(0) {
		zName = __ccgo_ts + 1704
	}
	if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x10>>4)) != 0 {
		/* This is not a real ATTACH.  Instead, this routine is being called
		 ** from sqlite3_deserialize() to close database db->init.iDb and
		 ** reopen it as a MemDB */
		**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
		pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)*32
		if _sqlite3BtreeTxnState(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt) != SQLITE_TXN_NONE || _sqlite3BtreeIsInBackup(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt) != 0 {
			rc = int32(SQLITE_BUSY)
			goto attach_error
		}
		**(**uintptr)(__ccgo_up(bp + 32)) = Xsqlite3_vfs_find(tls, __ccgo_ts+4116)
		if **(**uintptr)(__ccgo_up(bp + 32)) == uintptr(0) {
			return
		}
		rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 32)), __ccgo_ts+13251, db, bp+40, 0, int32(SQLITE_OPEN_MAIN_DB))
		if rc == SQLITE_OK {
			pNewSchema = _sqlite3SchemaGet(tls, db, **(**uintptr)(__ccgo_up(bp + 40)))
			if pNewSchema != 0 {
				/* Both the Btree and the new Schema were allocated successfully.
				 ** Close the old db and update the aDb[] slot with the new memdb
				 ** values.  */
				_sqlite3BtreeClose(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
				(*TDb)(unsafe.Pointer(pNew)).FpBt = **(**uintptr)(__ccgo_up(bp + 40))
				(*TDb)(unsafe.Pointer(pNew)).FpSchema = pNewSchema
			} else {
				_sqlite3BtreeClose(tls, **(**uintptr)(__ccgo_up(bp + 40)))
				rc = int32(SQLITE_NOMEM)
			}
		}
		if rc != 0 {
			goto attach_error
		}
	} else {
		/* This is a real ATTACH
		 **
		 ** Check for the following errors:
		 **
		 **     * Too many attached databases,
		 **     * Transaction currently open
		 **     * Specified database name already being used.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FnDb >= **(**int32)(__ccgo_up(db + 136 + 7*4))+int32(2) {
			**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13254, libc.VaList(bp+56, **(**int32)(__ccgo_up(db + 136 + 7*4))))
			goto attach_error
		}
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if _sqlite3DbIsNamed(tls, db, i, zName) != 0 {
				**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13291, libc.VaList(bp+56, zName))
				goto attach_error
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		/* Allocate the new entry in the db->aDb[] array and initialize the schema
		 ** hash tables.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FaDb == db+696 {
			aNew = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint64FromInt64(32)*libc.Uint64FromInt32(3)))
			if aNew == uintptr(0) {
				return
			}
			libc.Xmemcpy(tls, aNew, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, libc.Uint64FromInt64(32)*libc.Uint64FromInt32(2))
		} else {
			aNew = _sqlite3DbRealloc(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaDb, uint64(32)*libc.Uint64FromInt64(libc.Int64FromInt32(1)+int64((*Tsqlite3)(unsafe.Pointer(db)).FnDb)))
			if aNew == uintptr(0) {
				return
			}
		}
		(*Tsqlite3)(unsafe.Pointer(db)).FaDb = aNew
		pNew = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Tsqlite3)(unsafe.Pointer(db)).FnDb)*32
		libc.Xmemset(tls, pNew, 0, uint64(32))
		/* Open the database file. If the btree is successfully opened, use
		 ** it to obtain the database schema. At this point the schema may
		 ** or may not be initialized.
		 */
		**(**uint32)(__ccgo_up(bp + 16)) = (*Tsqlite3)(unsafe.Pointer(db)).FopenFlags
		rc = _sqlite3ParseUri(tls, (*Tsqlite3_vfs)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpVfs)).FzName, zFile, bp+16, bp+32, bp, bp+8)
		if rc != SQLITE_OK {
			if rc == int32(SQLITE_NOMEM) {
				_sqlite3OomFault(tls, db)
			}
			Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 8)), -int32(1))
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
			return
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00020))<<libc.Int32FromInt32(32)) == uint64(0) {
			**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) & libc.Uint32FromInt32(^(libc.Int32FromInt32(SQLITE_OPEN_CREATE) | libc.Int32FromInt32(SQLITE_OPEN_READWRITE)))
			**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) | uint32(SQLITE_OPEN_READONLY)
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00010))<<libc.Int32FromInt32(32)) == uint64(0) {
				**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) & libc.Uint32FromInt32(^libc.Int32FromInt32(SQLITE_OPEN_CREATE))
			}
		}
		**(**uint32)(__ccgo_up(bp + 16)) = **(**uint32)(__ccgo_up(bp + 16)) | uint32(SQLITE_OPEN_MAIN_DB)
		rc = _sqlite3BtreeOpen(tls, **(**uintptr)(__ccgo_up(bp + 32)), **(**uintptr)(__ccgo_up(bp)), db, pNew+8, 0, libc.Int32FromUint32(**(**uint32)(__ccgo_up(bp + 16))))
		(*Tsqlite3)(unsafe.Pointer(db)).FnDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb + 1
		(*TDb)(unsafe.Pointer(pNew)).FzDbSName = _sqlite3DbStrDup(tls, db, zName)
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache = uint8(0)
	if rc == int32(SQLITE_CONSTRAINT) {
		rc = int32(SQLITE_ERROR)
		**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13321, 0)
	} else {
		if rc == SQLITE_OK {
			(*TDb)(unsafe.Pointer(pNew)).FpSchema = _sqlite3SchemaGet(tls, db, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			if !((*TDb)(unsafe.Pointer(pNew)).FpSchema != 0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pNew)).FpSchema)).Ffile_format != 0 && libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pNew)).FpSchema)).Fenc) != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc) {
					**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13350, 0)
					rc = int32(SQLITE_ERROR)
				}
			}
			_sqlite3BtreeEnter(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			pPager = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
			_sqlite3PagerLockingMode(tls, pPager, libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode))
			_sqlite3BtreeSecureDelete(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt, _sqlite3BtreeSecureDelete(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpBt, -int32(1)))
			_sqlite3BtreeSetPagerFlags(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt, uint32(uint64(PAGER_SYNCHRONOUS_FULL)|(*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK)))
			_sqlite3BtreeLeave(tls, (*TDb)(unsafe.Pointer(pNew)).FpBt)
		}
	}
	(*TDb)(unsafe.Pointer(pNew)).Fsafety_level = libc.Uint8FromInt32(libc.Int32FromInt32(SQLITE_DEFAULT_SYNCHRONOUS) + libc.Int32FromInt32(1))
	if rc == SQLITE_OK && (*TDb)(unsafe.Pointer(pNew)).FzDbSName == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	}
	Xsqlite3_free_filename(tls, **(**uintptr)(__ccgo_up(bp)))
	/* If the file was opened successfully, read the schema for the new database.
	 ** If this fails, or if opening the file failed, then close the file and
	 ** remove the entry from the db->aDb[] array. i.e. put everything back the
	 ** way we found it.
	 */
	if rc == SQLITE_OK {
		_sqlite3BtreeEnterAll(tls, db)
		(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = uint8(0)
		**(**Tu32)(__ccgo_up(db + 44)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
		if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x10>>4)) != 0) {
			rc = _sqlite3Init(tls, db, bp+24)
		}
		_sqlite3BtreeLeaveAll(tls, db)
	}
	if rc != 0 {
		if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x10>>4)) != 0) {
			iDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
			if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt != 0 {
				_sqlite3BtreeClose(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt)
				(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt = uintptr(0)
				(**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema = uintptr(0)
			}
			_sqlite3ResetAllSchemasOfConnection(tls, db)
			(*Tsqlite3)(unsafe.Pointer(db)).FnDb = iDb
			if rc == int32(SQLITE_NOMEM) || rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
				_sqlite3OomFault(tls, db)
				_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 24)))
				**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+1674, 0)
			} else {
				if **(**uintptr)(__ccgo_up(bp + 24)) == uintptr(0) {
					**(**uintptr)(__ccgo_up(bp + 24)) = _sqlite3MPrintf(tls, db, __ccgo_ts+13418, libc.VaList(bp+56, zFile))
				}
			}
		}
		goto attach_error
	}
	return
	goto attach_error
attach_error:
	;
	/* Return an error if we get here */
	if **(**uintptr)(__ccgo_up(bp + 24)) != 0 {
		Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 24)), -int32(1))
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 24)))
	}
	if rc != 0 {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

// C documentation
//
//	/*
//	** If the DateTime p is raw number, try to figure out if it is
//	** a julian day number of a unix timestamp.  Set the p value
//	** appropriately.
//	*/
func _autoAdjustDate(tls *libc.TLS, p uintptr) {
	var r float64
	_ = r
	if !(int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x80>>7)) != 0) || (*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0 {
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
	} else {
		if (*TDateTime)(unsafe.Pointer(p)).Fs >= float64(int64(-libc.Int32FromInt32(21086676))*libc.Int64FromInt32(10000)) && (*TDateTime)(unsafe.Pointer(p)).Fs <= float64(libc.Int64FromInt32(25340230)*libc.Int64FromInt32(10000)+libc.Int64FromInt32(799)) {
			r = float64((*TDateTime)(unsafe.Pointer(p)).Fs*float64(1000)) + float64(2.1086676e+14)
			_clearYMD_HMS_TZ(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(r + libc.Float64FromFloat64(0.5))
			(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
		}
	}
}

// C documentation
//
//	/*
//	** This routine redistributes cells on the iParentIdx'th child of pParent
//	** (hereafter "the page") and up to 2 siblings so that all pages have about the
//	** same amount of free space. Usually a single sibling on either side of the
//	** page are used in the balancing, though both siblings might come from one
//	** side if the page is the first or last child of its parent. If the page
//	** has fewer than 2 siblings (something which can only happen if the page
//	** is a root page or a child of a root page) then all available siblings
//	** participate in the balancing.
//	**
//	** The number of siblings of the page might be increased or decreased by
//	** one or two in an effort to keep pages nearly full but not over full.
//	**
//	** Note that when this routine is called, some of the cells on the page
//	** might not actually be stored in MemPage.aData[]. This can happen
//	** if the page is overfull. This routine ensures that all cells allocated
//	** to the page and its siblings fit into MemPage.aData[] before returning.
//	**
//	** In the course of balancing the page and its siblings, cells may be
//	** inserted into or removed from the parent page (pParent). Doing so
//	** may cause the parent page to become overfull or underfull. If this
//	** happens, it is the responsibility of the caller to invoke the correct
//	** balancing routine to fix this problem (see the balance() routine).
//	**
//	** If this routine fails for any reason, it might leave the database
//	** in a corrupted state. So if this routine fails, the database should
//	** be rolled back.
//	**
//	** The third argument to this function, aOvflSpace, is a pointer to a
//	** buffer big enough to hold one page. If while inserting cells into the parent
//	** page (pParent) the parent page becomes overfull, this buffer is
//	** used to store the parent's overflow cells. Because this function inserts
//	** a maximum of four divider cells into the parent page, and the maximum
//	** size of a cell stored within an internal node is always less than 1/4
//	** of the page-size, the aOvflSpace[] buffer is guaranteed to be large
//	** enough for all overflow cells.
//	**
//	** If aOvflSpace is set to a null pointer, this function returns
//	** SQLITE_NOMEM.
//	*/
func _balance_nonroot(tls *libc.TLS, pParent uintptr, iParentIdx int32, aOvflSpace uintptr, isRoot int32, bBulk int32) (r1 int32) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var aData, aSpace1, p, pBt, pCell, pCell1, pNew1, pNew2, pOld, pOld1, pOld2, pRight, pSrcEnd, pTemp, pTemp1, piCell, piEnd, v17 uintptr
	var aPgno [5]TPgno
	var apDiv [2]uintptr
	var apNew [5]uintptr
	var cntNew, cntOld [5]int32
	var cntOldNext, d, i, iB, iNew, iNew1, iOff, iOld, iOld1, iOvflSpace, iPg, iSpace1, j, k, leafData, limit, nMaxCells, nNew, nNewCell, nOld, nxDiv, pageFlags, r, sz1, sz2, szD, szLeft, szR, szRight, usableSpace, v1 int32
	var fgA, fgB, leafCorrection, maskPage, sz Tu16
	var key Tu32
	var pgnoA, pgnoB, pgnoTemp TPgno
	var szScratch Tu64
	var v13, v14 bool
	var v18 uint32
	var _ /* abDone at bp+60 */ [5]Tu8
	var _ /* apOld at bp+8 */ [3]uintptr
	var _ /* b at bp+72 */ TCellArray
	var _ /* info at bp+184 */ TCellInfo
	var _ /* pNew at bp+176 */ uintptr
	var _ /* pgno at bp+52 */ TPgno
	var _ /* rc at bp+0 */ int32
	var _ /* szNew at bp+32 */ [5]int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aPgno, aSpace1, apDiv, apNew, cntNew, cntOld, cntOldNext, d, fgA, fgB, i, iB, iNew, iNew1, iOff, iOld, iOld1, iOvflSpace, iPg, iSpace1, j, k, key, leafCorrection, leafData, limit, maskPage, nMaxCells, nNew, nNewCell, nOld, nxDiv, p, pBt, pCell, pCell1, pNew1, pNew2, pOld, pOld1, pOld2, pRight, pSrcEnd, pTemp, pTemp1, pageFlags, pgnoA, pgnoB, pgnoTemp, piCell, piEnd, r, sz, sz1, sz2, szD, szLeft, szR, szRight, szScratch, usableSpace, v1, v13, v14, v17, v18 /* The whole database */
	nMaxCells = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* Allocated size of apCell, szCell, aFrom. */
	nNew = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /* Next divider slot in pParent->aCell[] */
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       /* Value of pPage->aData[0] */
	iSpace1 = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* First unused byte of aSpace1[] */
	iOvflSpace = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Parsed information on cells being balanced */
	libc.Xmemset(tls, bp+60, 0, uint64(5))
	libc.Xmemset(tls, bp+72, 0, libc.Uint64FromInt64(104)-libc.Uint64FromInt64(4))
	**(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(libc.Int32FromInt32(NB)*libc.Int32FromInt32(2)-libc.Int32FromInt32(1))*4)) = int32(0x7fffffff)
	pBt = (*TMemPage)(unsafe.Pointer(pParent)).FpBt
	/* At this point pParent may have at most one overflow cell. And if
	 ** this overflow cell is present, it must be the cell with
	 ** index iParentIdx. This scenario comes about when this function
	 ** is called (indirectly) from sqlite3BtreeDelete().
	 */
	if !(aOvflSpace != 0) {
		return int32(SQLITE_NOMEM)
	}
	/* Find the sibling pages to balance. Also locate the cells in pParent
	 ** that divide the siblings. An attempt is made to find NN siblings on
	 ** either side of pPage. More siblings are taken from one side, however,
	 ** if there are fewer than NN siblings on the other side. If pParent
	 ** has NB or fewer children then all children of pParent are taken.
	 **
	 ** This loop also drops the divider cells from the parent page. This
	 ** way, the remainder of the function does not have to deal with any
	 ** overflow cells in the parent page, since if any existed they will
	 ** have already been removed.
	 */
	i = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow) + libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell)
	if i < int32(2) {
		nxDiv = 0
	} else {
		if iParentIdx == 0 {
			nxDiv = 0
		} else {
			if iParentIdx == i {
				nxDiv = i - int32(2) + bBulk
			} else {
				nxDiv = iParentIdx - int32(1)
			}
		}
		i = int32(2) - bBulk
	}
	nOld = i + int32(1)
	if i+nxDiv-libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow) == libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell) {
		pRight = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset)+int32(8))
	} else {
		pRight = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(int32(2)*(i+nxDiv-libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow)))))))
	}
	**(**TPgno)(__ccgo_up(bp + 52)) = _sqlite3Get4byte(tls, pRight)
	for int32(1) != 0 {
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = _getAndInitPage(tls, pBt, **(**TPgno)(__ccgo_up(bp + 52)), bp+8+uintptr(i)*8, 0)
		}
		if **(**int32)(__ccgo_up(bp)) != 0 {
			libc.Xmemset(tls, bp+8, 0, libc.Uint64FromInt32(i+libc.Int32FromInt32(1))*uint64(8))
			goto balance_cleanup
		}
		if (*TMemPage)(unsafe.Pointer((**(**[3]uintptr)(__ccgo_up(bp + 8)))[i])).FnFree < 0 {
			**(**int32)(__ccgo_up(bp)) = _btreeComputeFreeSpace(tls, (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i])
			if **(**int32)(__ccgo_up(bp)) != 0 {
				libc.Xmemset(tls, bp+8, 0, libc.Uint64FromInt32(i)*uint64(8))
				goto balance_cleanup
			}
		}
		nMaxCells = nMaxCells + (libc.Int32FromUint16((*TMemPage)(unsafe.Pointer((**(**[3]uintptr)(__ccgo_up(bp + 8)))[i])).FnCell) + libc.Int32FromUint64(libc.Uint64FromInt64(32)/libc.Uint64FromInt64(8)))
		v1 = i
		i = i - 1
		if v1 == 0 {
			break
		}
		if (*TMemPage)(unsafe.Pointer(pParent)).FnOverflow != 0 && i+nxDiv == libc.Int32FromUint16(**(**Tu16)(__ccgo_up(pParent + 28))) {
			apDiv[i] = **(**uintptr)(__ccgo_up(pParent + 40))
			**(**TPgno)(__ccgo_up(bp + 52)) = _sqlite3Get4byte(tls, apDiv[i])
			(**(**[5]int32)(__ccgo_up(bp + 32)))[i] = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pParent)).FxCellSize})))(tls, pParent, apDiv[i]))
			(*TMemPage)(unsafe.Pointer(pParent)).FnOverflow = uint8(0)
		} else {
			apDiv[i] = (*TMemPage)(unsafe.Pointer(pParent)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(int32(2)*(i+nxDiv-libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow)))))))
			**(**TPgno)(__ccgo_up(bp + 52)) = _sqlite3Get4byte(tls, apDiv[i])
			(**(**[5]int32)(__ccgo_up(bp + 32)))[i] = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pParent)).FxCellSize})))(tls, pParent, apDiv[i]))
			/* Drop the cell from the parent page. apDiv[i] still points to
			 ** the cell within the parent, even though it has been dropped.
			 ** This is safe because dropping a cell only overwrites the first
			 ** four bytes of it, and this function does not need the first
			 ** four bytes of the divider cell. So the pointer is safe to use
			 ** later on.
			 **
			 ** But not if we are in secure-delete mode. In secure-delete mode,
			 ** the dropCell() routine will overwrite the entire cell with zeroes.
			 ** In this case, temporarily copy the cell into the aOvflSpace[]
			 ** buffer. It will be copied out again as soon as the aSpace[] buffer
			 ** is allocated.  */
			if libc.Int32FromUint16((*TBtShared)(unsafe.Pointer(pBt)).FbtsFlags)&int32(BTS_FAST_SECURE) != 0 {
				/* If the following if() condition is not true, the db is corrupted.
				 ** The call to dropCell() below will detect this.  */
				iOff = int32(int64(apDiv[i])) - int32(int64((*TMemPage)(unsafe.Pointer(pParent)).FaData))
				if iOff+(**(**[5]int32)(__ccgo_up(bp + 32)))[i] <= libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize) {
					libc.Xmemcpy(tls, aOvflSpace+uintptr(iOff), apDiv[i], libc.Uint64FromInt32((**(**[5]int32)(__ccgo_up(bp + 32)))[i]))
					apDiv[i] = aOvflSpace + uintptr(int64(apDiv[i])-int64((*TMemPage)(unsafe.Pointer(pParent)).FaData))
				}
			}
			_dropCell(tls, pParent, i+nxDiv-libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FnOverflow), (**(**[5]int32)(__ccgo_up(bp + 32)))[i], bp)
		}
	}
	/* Make nMaxCells a multiple of 4 in order to preserve 8-byte
	 ** alignment */
	nMaxCells = (nMaxCells + int32(3)) & ^libc.Int32FromInt32(3)
	/*
	 ** Allocate space for memory structures
	 */
	szScratch = uint64(libc.Uint64FromInt32(nMaxCells)*uint64(8) + libc.Uint64FromInt32(nMaxCells)*uint64(2) + uint64((*TBtShared)(unsafe.Pointer(pBt)).FpageSize)) /* aSpace1 */
	(**(**TCellArray)(__ccgo_up(bp + 72))).FapCell = _sqlite3DbMallocRaw(tls, uintptr(0), szScratch)
	if (**(**TCellArray)(__ccgo_up(bp + 72))).FapCell == uintptr(0) {
		**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
		goto balance_cleanup
	}
	(**(**TCellArray)(__ccgo_up(bp + 72))).FszCell = (**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(nMaxCells)*8
	aSpace1 = (**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(nMaxCells)*2
	/*
	 ** Load pointers to all cells on sibling pages and the divider cells
	 ** into the local b.apCell[] array.  Make copies of the divider cells
	 ** into space obtained from aSpace1[]. The divider cells have already
	 ** been removed from pParent.
	 **
	 ** If the siblings are on leaf pages, then the child pointers of the
	 ** divider cells are stripped from the cells before they are copied
	 ** into aSpace1[].  In this way, all cells in b.apCell[] are without
	 ** child pointers.  If siblings are not leaves, then all cell in
	 ** b.apCell[] include child pointers.  Either way, all cells in b.apCell[]
	 ** are alike.
	 **
	 ** leafCorrection:  4 if pPage is a leaf.  0 if pPage is not a leaf.
	 **       leafData:  1 if pPage holds key+data and pParent holds only keys.
	 */
	(**(**TCellArray)(__ccgo_up(bp + 72))).FpRef = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[0]
	leafCorrection = libc.Uint16FromInt32(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer((**(**TCellArray)(__ccgo_up(bp + 72))).FpRef)).Fleaf) * int32(4))
	leafData = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer((**(**TCellArray)(__ccgo_up(bp + 72))).FpRef)).FintKeyLeaf)
	i = 0
	for {
		if !(i < nOld) {
			break
		}
		pOld = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i]
		limit = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pOld)).FnCell)
		aData = (*TMemPage)(unsafe.Pointer(pOld)).FaData
		maskPage = (*TMemPage)(unsafe.Pointer(pOld)).FmaskPage
		piCell = aData + uintptr((*TMemPage)(unsafe.Pointer(pOld)).FcellOffset)
		/* Verify that all sibling pages are of the same "type" (table-leaf,
		 ** table-interior, index-leaf, or index-interior).
		 */
		if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(pOld)).FaData))) != libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer((**(**[3]uintptr)(__ccgo_up(bp + 8)))[0])).FaData))) {
			**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81667))
			goto balance_cleanup
		}
		/* Load b.apCell[] with pointers to all cells in pOld.  If pOld
		 ** contains overflow cells, include them in the b.apCell[] array
		 ** in the correct spot.
		 **
		 ** Note that when there are multiple overflow cells, it is always the
		 ** case that they are sequential and adjacent.  This invariant arises
		 ** because multiple overflows can only occurs when inserting divider
		 ** cells into a parent on a prior balance, and divider cells are always
		 ** adjacent and are inserted in order.  There is an assert() tagged
		 ** with "NOTE 1" in the overflow cell insertion loop to prove this
		 ** invariant.
		 **
		 ** This must be done in advance.  Once the balance starts, the cell
		 ** offset section of the btree page will be overwritten and we will no
		 ** long be able to find the cells if a pointer to each cell is not saved
		 ** first.
		 */
		libc.Xmemset(tls, (**(**TCellArray)(__ccgo_up(bp + 72))).FszCell+uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2, 0, uint64(2)*libc.Uint64FromInt32(limit+libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pOld)).FnOverflow)))
		if libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pOld)).FnOverflow) > 0 {
			if limit < libc.Int32FromUint16(**(**Tu16)(__ccgo_up(pOld + 28))) {
				**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81691))
				goto balance_cleanup
			}
			limit = libc.Int32FromUint16(**(**Tu16)(__ccgo_up(pOld + 28)))
			j = 0
			for {
				if !(j < limit) {
					break
				}
				**(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*8)) = aData + uintptr(libc.Int32FromUint16(maskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up(piCell))))
				piCell = piCell + uintptr(2)
				(**(**TCellArray)(__ccgo_up(bp + 72))).FnCell = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell + 1
				goto _3
			_3:
				;
				j = j + 1
			}
			k = 0
			for {
				if !(k < libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pOld)).FnOverflow)) {
					break
				}
				/* NOTE 1 */
				**(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*8)) = **(**uintptr)(__ccgo_up(pOld + 40 + uintptr(k)*8))
				(**(**TCellArray)(__ccgo_up(bp + 72))).FnCell = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell + 1
				goto _4
			_4:
				;
				k = k + 1
			}
		}
		piEnd = aData + uintptr((*TMemPage)(unsafe.Pointer(pOld)).FcellOffset) + uintptr(int32(2)*libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pOld)).FnCell))
		for piCell < piEnd {
			**(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*8)) = aData + uintptr(libc.Int32FromUint16(maskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up(piCell))))
			piCell = piCell + uintptr(2)
			(**(**TCellArray)(__ccgo_up(bp + 72))).FnCell = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell + 1
		}
		cntOld[i] = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
		if i < nOld-int32(1) && !(leafData != 0) {
			sz = libc.Uint16FromInt32((**(**[5]int32)(__ccgo_up(bp + 32)))[i])
			**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2)) = sz
			pTemp = aSpace1 + uintptr(iSpace1)
			iSpace1 = iSpace1 + libc.Int32FromUint16(sz)
			libc.Xmemcpy(tls, pTemp, apDiv[i], uint64(sz))
			**(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*8)) = pTemp + uintptr(leafCorrection)
			**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2)) = libc.Uint16FromInt32(libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2))) - libc.Int32FromUint16(leafCorrection))
			if !((*TMemPage)(unsafe.Pointer(pOld)).Fleaf != 0) {
				/* The right pointer of the child page pOld becomes the left
				 ** pointer of the divider cell */
				libc.Xmemcpy(tls, **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*8)), (*TMemPage)(unsafe.Pointer(pOld)).FaData+8, uint64(4))
			} else {
				for libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2))) < int32(4) {
					/* Do not allow any cells smaller than 4 bytes. If a smaller cell
					 ** does exist, pad it with 0x00 bytes. */
					v1 = iSpace1
					iSpace1 = iSpace1 + 1
					**(**Tu8)(__ccgo_up(aSpace1 + uintptr(v1))) = uint8(0x00)
					**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2)) = **(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr((**(**TCellArray)(__ccgo_up(bp + 72))).FnCell)*2)) + 1
				}
			}
			(**(**TCellArray)(__ccgo_up(bp + 72))).FnCell = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell + 1
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	/*
	 ** Figure out the number of pages needed to hold all b.nCell cells.
	 ** Store this number in "k".  Also compute szNew[] which is the total
	 ** size of all cells on the i-th page and cntNew[] which is the index
	 ** in b.apCell[] of the cell that divides page i from page i+1.
	 ** cntNew[k] should equal b.nCell.
	 **
	 ** Values computed by this block:
	 **
	 **           k: The total number of sibling pages
	 **    szNew[i]: Spaced used on the i-th sibling page.
	 **   cntNew[i]: Index in b.apCell[] and b.szCell[] for the first cell to
	 **              the right of the i-th sibling page.
	 ** usableSpace: Number of bytes of space available on each sibling.
	 **
	 */
	usableSpace = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32(12) + uint32(leafCorrection))
	v1 = libc.Int32FromInt32(0)
	k = v1
	i = v1
	for {
		if !(i < nOld) {
			break
		}
		p = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i]
		**(**uintptr)(__ccgo_up(bp + 72 + 32 + uintptr(k)*8)) = (*TMemPage)(unsafe.Pointer(p)).FaDataEnd
		**(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(k)*4)) = cntOld[i]
		if k != 0 && **(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(k)*4)) == **(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(k-int32(1))*4)) {
			k = k - 1 /* Omit b.ixNx[] entry for child pages with no cells */
		}
		if !(leafData != 0) {
			k = k + 1
			**(**uintptr)(__ccgo_up(bp + 72 + 32 + uintptr(k)*8)) = (*TMemPage)(unsafe.Pointer(pParent)).FaDataEnd
			**(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(k)*4)) = cntOld[i] + int32(1)
		}
		(**(**[5]int32)(__ccgo_up(bp + 32)))[i] = usableSpace - (*TMemPage)(unsafe.Pointer(p)).FnFree
		j = 0
		for {
			if !(j < libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(p)).FnOverflow)) {
				break
			}
			**(**int32)(__ccgo_up(bp + 32 + uintptr(i)*4)) += int32(2) + libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(p)).FxCellSize})))(tls, p, **(**uintptr)(__ccgo_up(p + 40 + uintptr(j)*8))))
			goto _8
		_8:
			;
			j = j + 1
		}
		cntNew[i] = cntOld[i]
		goto _6
	_6:
		;
		i = i + 1
		k = k + 1
	}
	k = nOld
	i = 0
	for {
		if !(i < k) {
			break
		}
		for (**(**[5]int32)(__ccgo_up(bp + 32)))[i] > usableSpace {
			if i+int32(1) >= k {
				k = i + int32(2)
				if k > libc.Int32FromInt32(NB)+libc.Int32FromInt32(2) {
					**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81792))
					goto balance_cleanup
				}
				(**(**[5]int32)(__ccgo_up(bp + 32)))[k-int32(1)] = 0
				cntNew[k-int32(1)] = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
			}
			sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]-int32(1)))
			**(**int32)(__ccgo_up(bp + 32 + uintptr(i)*4)) -= sz1
			if !(leafData != 0) {
				if cntNew[i] < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
					sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]))
				} else {
					sz1 = 0
				}
			}
			**(**int32)(__ccgo_up(bp + 32 + uintptr(i+int32(1))*4)) += sz1
			cntNew[i] = cntNew[i] - 1
		}
		for cntNew[i] < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
			sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]))
			if (**(**[5]int32)(__ccgo_up(bp + 32)))[i]+sz1 > usableSpace {
				break
			}
			**(**int32)(__ccgo_up(bp + 32 + uintptr(i)*4)) += sz1
			cntNew[i] = cntNew[i] + 1
			if !(leafData != 0) {
				if cntNew[i] < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
					sz1 = int32(2) + libc.Int32FromUint16(_cachedCellSize(tls, bp+72, cntNew[i]))
				} else {
					sz1 = 0
				}
			}
			**(**int32)(__ccgo_up(bp + 32 + uintptr(i+int32(1))*4)) -= sz1
		}
		if cntNew[i] >= (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell {
			k = i + int32(1)
		} else {
			if i > 0 {
				v1 = cntNew[i-int32(1)]
			} else {
				v1 = 0
			}
			if cntNew[i] <= v1 {
				**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81825))
				goto balance_cleanup
			}
		}
		goto _9
	_9:
		;
		i = i + 1
	}
	/*
	 ** The packing computed by the previous block is biased toward the siblings
	 ** on the left side (siblings with smaller keys). The left siblings are
	 ** always nearly full, while the right-most sibling might be nearly empty.
	 ** The next block of code attempts to adjust the packing of siblings to
	 ** get a better balance.
	 **
	 ** This adjustment is more than an optimization.  The packing above might
	 ** be so out of balance as to be illegal.  For example, the right-most
	 ** sibling might be completely empty.  This adjustment is not optional.
	 */
	i = k - int32(1)
	for {
		if !(i > 0) {
			break
		}
		szRight = (**(**[5]int32)(__ccgo_up(bp + 32)))[i]         /* Size of sibling on the right */
		szLeft = (**(**[5]int32)(__ccgo_up(bp + 32)))[i-int32(1)] /* Index of first cell to the left of right sibling */
		r = cntNew[i-int32(1)] - int32(1)
		d = r + int32(1) - leafData
		_cachedCellSize(tls, bp+72, d)
		for cond := true; cond; cond = r >= 0 {
			szR = libc.Int32FromUint16(_cachedCellSize(tls, bp+72, r))
			szD = libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(d)*2)))
			if v14 = szRight != 0; v14 {
				if v13 = bBulk != 0; !v13 {
					if i == k-int32(1) {
						v1 = 0
					} else {
						v1 = int32(2)
					}
				}
			}
			if v14 && (v13 || szRight+szD+int32(2) > szLeft-(szR+v1)) {
				break
			}
			szRight = szRight + (szD + int32(2))
			szLeft = szLeft - (szR + int32(2))
			cntNew[i-int32(1)] = r
			r = r - 1
			d = d - 1
		}
		(**(**[5]int32)(__ccgo_up(bp + 32)))[i] = szRight
		(**(**[5]int32)(__ccgo_up(bp + 32)))[i-int32(1)] = szLeft
		if i > int32(1) {
			v1 = cntNew[i-int32(2)]
		} else {
			v1 = 0
		}
		if cntNew[i-int32(1)] <= v1 {
			**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81869))
			goto balance_cleanup
		}
		goto _11
	_11:
		;
		i = i - 1
	}
	/* Sanity check:  For a non-corrupt database file one of the following
	 ** must be true:
	 **    (1) We found one or more cells (cntNew[0])>0), or
	 **    (2) pPage is a virtual root page.  A virtual root page is when
	 **        the real root page is page 1 and we are the only child of
	 **        that page.
	 */
	/*
	 ** Allocate k new pages.  Reuse old pages where possible.
	 */
	pageFlags = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer((**(**[3]uintptr)(__ccgo_up(bp + 8)))[0])).FaData)))
	i = 0
	for {
		if !(i < k) {
			break
		}
		if i < nOld {
			v17 = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i]
			apNew[i] = v17
			**(**uintptr)(__ccgo_up(bp + 176)) = v17
			(**(**[3]uintptr)(__ccgo_up(bp + 8)))[i] = uintptr(0)
			**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 176)))).FpDbPage)
			nNew = nNew + 1
			if _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 176)))).FpDbPage) != int32(1)+libc.BoolInt32(i == iParentIdx-nxDiv) && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
				**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(81902))
			}
			if **(**int32)(__ccgo_up(bp)) != 0 {
				goto balance_cleanup
			}
		} else {
			if bBulk != 0 {
				v18 = uint32(1)
			} else {
				v18 = **(**TPgno)(__ccgo_up(bp + 52))
			}
			**(**int32)(__ccgo_up(bp)) = _allocateBtreePage(tls, pBt, bp+176, bp+52, v18, uint8(0))
			if **(**int32)(__ccgo_up(bp)) != 0 {
				goto balance_cleanup
			}
			_zeroPage(tls, **(**uintptr)(__ccgo_up(bp + 176)), pageFlags)
			apNew[i] = **(**uintptr)(__ccgo_up(bp + 176))
			nNew = nNew + 1
			cntOld[i] = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
			/* Set the pointer-map entry for the new sibling page. */
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				_ptrmapPut(tls, pBt, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 176)))).Fpgno, uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pParent)).Fpgno, bp)
				if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
					goto balance_cleanup
				}
			}
		}
		goto _16
	_16:
		;
		i = i + 1
	}
	/*
	 ** Reassign page numbers so that the new pages are in ascending order.
	 ** This helps to keep entries in the disk file in order so that a scan
	 ** of the table is closer to a linear scan through the file. That in turn
	 ** helps the operating system to deliver pages from the disk more rapidly.
	 **
	 ** An O(N*N) sort algorithm is used, but since N is never more than NB+2
	 ** (5), that is not a performance concern.
	 **
	 ** When NB==3, this one optimization makes the database about 25% faster
	 ** for large insertions and deletions.
	 */
	i = 0
	for {
		if !(i < nNew) {
			break
		}
		aPgno[i] = (*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno
		goto _19
	_19:
		;
		i = i + 1
	}
	i = 0
	for {
		if !(i < nNew-int32(1)) {
			break
		}
		iB = i
		j = i + int32(1)
		for {
			if !(j < nNew) {
				break
			}
			if (*TMemPage)(unsafe.Pointer(apNew[j])).Fpgno < (*TMemPage)(unsafe.Pointer(apNew[iB])).Fpgno {
				iB = j
			}
			goto _21
		_21:
			;
			j = j + 1
		}
		/* If apNew[i] has a page number that is bigger than any of the
		 ** subsequence apNew[i] entries, then swap apNew[i] with the subsequent
		 ** entry that has the smallest page number (which we know to be
		 ** entry apNew[iB]).
		 */
		if iB != i {
			pgnoA = (*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno
			pgnoB = (*TMemPage)(unsafe.Pointer(apNew[iB])).Fpgno
			pgnoTemp = libc.Uint32FromInt32(_sqlite3PendingByte)/(*TBtShared)(unsafe.Pointer(pBt)).FpageSize + uint32(1)
			fgA = (*TDbPage)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(apNew[i])).FpDbPage)).Fflags
			fgB = (*TDbPage)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(apNew[iB])).FpDbPage)).Fflags
			_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer(apNew[i])).FpDbPage, pgnoTemp, fgB)
			_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer(apNew[iB])).FpDbPage, pgnoA, fgA)
			_sqlite3PagerRekey(tls, (*TMemPage)(unsafe.Pointer(apNew[i])).FpDbPage, pgnoB, fgB)
			(*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno = pgnoB
			(*TMemPage)(unsafe.Pointer(apNew[iB])).Fpgno = pgnoA
		}
		goto _20
	_20:
		;
		i = i + 1
	}
	_sqlite3Put4byte(tls, pRight, (*TMemPage)(unsafe.Pointer(apNew[nNew-int32(1)])).Fpgno)
	/* If the sibling pages are not leaves, ensure that the right-child pointer
	 ** of the right-most new sibling page is set to the value that was
	 ** originally in the same field of the right-most old sibling page. */
	if pageFlags&int32(PTF_LEAF) == 0 && nOld != nNew {
		if nNew > nOld {
			pOld1 = apNew[nOld-int32(1)]
		} else {
			pOld1 = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[nOld-int32(1)]
		}
		libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(apNew[nNew-int32(1)])).FaData+8, (*TMemPage)(unsafe.Pointer(pOld1)).FaData+8, uint64(4))
	}
	/* Make any required updates to pointer map entries associated with
	 ** cells stored on sibling pages following the balance operation. Pointer
	 ** map entries associated with divider cells are set by the insertCell()
	 ** routine. The associated pointer map entries are:
	 **
	 **   a) if the cell contains a reference to an overflow chain, the
	 **      entry associated with the first page in the overflow chain, and
	 **
	 **   b) if the sibling pages are not leaves, the child page associated
	 **      with the cell.
	 **
	 ** If the sibling pages are not leaves, then the pointer map entry
	 ** associated with the right-child of each sibling may also need to be
	 ** updated. This happens below, after the sibling pages have been
	 ** populated, not here.
	 */
	if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		v17 = apNew[0]
		pOld2 = v17
		pNew1 = v17
		cntOldNext = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pNew1)).FnCell) + libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pNew1)).FnOverflow)
		iNew = 0
		iOld = 0
		i = 0
		for {
			if !(i < (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell) {
				break
			}
			pCell = **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(i)*8))
			for i == cntOldNext {
				iOld = iOld + 1
				if iOld < nNew {
					v17 = apNew[iOld]
				} else {
					v17 = (**(**[3]uintptr)(__ccgo_up(bp + 8)))[iOld]
				}
				pOld2 = v17
				cntOldNext = cntOldNext + (libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pOld2)).FnCell) + libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pOld2)).FnOverflow) + libc.BoolInt32(!(leafData != 0)))
			}
			if i == cntNew[iNew] {
				iNew = iNew + 1
				v1 = iNew
				pNew1 = apNew[v1]
				if !(leafData != 0) {
					goto _23
				}
			}
			/* Cell pCell is destined for new sibling page pNew. Originally, it
			 ** was either part of sibling page iOld (possibly an overflow cell),
			 ** or else the divider cell to the left of sibling page iOld. So,
			 ** if sibling page iOld had the same page number as pNew, and if
			 ** pCell really was a part of sibling page iOld (not a divider or
			 ** overflow cell), we can skip updating the pointer map entries.  */
			if iOld >= nNew || (*TMemPage)(unsafe.Pointer(pNew1)).Fpgno != aPgno[iOld] || !(uint64(pCell) >= uint64((*TMemPage)(unsafe.Pointer(pOld2)).FaData) && uint64(pCell) < uint64((*TMemPage)(unsafe.Pointer(pOld2)).FaDataEnd)) {
				if !(leafCorrection != 0) {
					_ptrmapPut(tls, pBt, _sqlite3Get4byte(tls, pCell), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pNew1)).Fpgno, bp)
				}
				if libc.Int32FromUint16(_cachedCellSize(tls, bp+72, i)) > libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pNew1)).FminLocal) {
					_ptrmapPutOvflPtr(tls, pNew1, pOld2, pCell, bp)
				}
				if **(**int32)(__ccgo_up(bp)) != 0 {
					goto balance_cleanup
				}
			}
			goto _23
		_23:
			;
			i = i + 1
		}
	}
	/* Insert new divider cells into pParent. */
	i = 0
	for {
		if !(i < nNew-int32(1)) {
			break
		}
		pNew2 = apNew[i]
		j = cntNew[i]
		pCell1 = **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(j)*8))
		sz2 = libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(j)*2))) + libc.Int32FromUint16(leafCorrection)
		pTemp1 = aOvflSpace + uintptr(iOvflSpace)
		if !((*TMemPage)(unsafe.Pointer(pNew2)).Fleaf != 0) {
			libc.Xmemcpy(tls, (*TMemPage)(unsafe.Pointer(pNew2)).FaData+8, pCell1, uint64(4))
		} else {
			if leafData != 0 {
				j = j - 1
				(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pNew2)).FxParseCell})))(tls, pNew2, **(**uintptr)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FapCell + uintptr(j)*8)), bp+184)
				pCell1 = pTemp1
				sz2 = int32(4) + _sqlite3PutVarint(tls, pCell1+4, libc.Uint64FromInt64((**(**TCellInfo)(__ccgo_up(bp + 184))).FnKey))
				pTemp1 = uintptr(0)
			} else {
				pCell1 = pCell1 - uintptr(4)
				/* Obscure case for non-leaf-data trees: If the cell at pCell was
				 ** previously stored on a leaf node, and its reported size was 4
				 ** bytes, then it may actually be smaller than this
				 ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
				 ** any cell). But it is important to pass the correct size to
				 ** insertCell(), so reparse the cell now.
				 **
				 ** This can only happen for b-trees used to evaluate "IN (SELECT ...)"
				 ** and WITHOUT ROWID tables with exactly one column which is the
				 ** primary key.
				 */
				if libc.Int32FromUint16(**(**Tu16)(__ccgo_up((**(**TCellArray)(__ccgo_up(bp + 72))).FszCell + uintptr(j)*2))) == int32(4) {
					sz2 = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pParent)).FxCellSize})))(tls, pParent, pCell1))
				}
			}
		}
		iOvflSpace = iOvflSpace + sz2
		k = 0
		for {
			if !(**(**int32)(__ccgo_up(bp + 72 + 80 + uintptr(k)*4)) <= j) {
				break
			}
			goto _27
		_27:
			;
			k = k + 1
		}
		pSrcEnd = **(**uintptr)(__ccgo_up(bp + 72 + 32 + uintptr(k)*8))
		if uint64(pCell1) < uint64(pSrcEnd) && uint64(pCell1+uintptr(sz2)) > uint64(pSrcEnd) {
			**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(82108))
			goto balance_cleanup
		}
		**(**int32)(__ccgo_up(bp)) = _insertCell(tls, pParent, nxDiv+i, pCell1, sz2, pTemp1, (*TMemPage)(unsafe.Pointer(pNew2)).Fpgno)
		if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
			goto balance_cleanup
		}
		goto _26
	_26:
		;
		i = i + 1
	}
	/* Now update the actual sibling pages. The order in which they are updated
	 ** is important, as this code needs to avoid disrupting any page from which
	 ** cells may still to be read. In practice, this means:
	 **
	 **  (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
	 **      then it is not safe to update page apNew[iPg] until after
	 **      the left-hand sibling apNew[iPg-1] has been updated.
	 **
	 **  (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
	 **      then it is not safe to update page apNew[iPg] until after
	 **      the right-hand sibling apNew[iPg+1] has been updated.
	 **
	 ** If neither of the above apply, the page is safe to update.
	 **
	 ** The iPg value in the following loop starts at nNew-1 goes down
	 ** to 0, then back up to nNew-1 again, thus making two passes over
	 ** the pages.  On the initial downward pass, only condition (1) above
	 ** needs to be tested because (2) will always be true from the previous
	 ** step.  On the upward pass, both conditions are always true, so the
	 ** upwards pass simply processes pages that were missed on the downward
	 ** pass.
	 */
	i = int32(1) - nNew
	for {
		if !(i < nNew) {
			break
		}
		if i < 0 {
			v1 = -i
		} else {
			v1 = i
		}
		iPg = v1
		if (**(**[5]Tu8)(__ccgo_up(bp + 60)))[iPg] != 0 {
			goto _28
		} /* Skip pages already processed */
		if i >= 0 || cntOld[iPg-int32(1)] >= cntNew[iPg-int32(1)] {
			/* Verify condition (1):  If cells are moving left, update iPg
			 ** only after iPg-1 has already been updated. */
			/* Verify condition (2):  If cells are moving right, update iPg
			 ** only after iPg+1 has already been updated. */
			if iPg == 0 {
				v1 = libc.Int32FromInt32(0)
				iOld1 = v1
				iNew1 = v1
				nNewCell = cntNew[0]
			} else {
				if iPg < nOld {
					v1 = cntOld[iPg-int32(1)] + libc.BoolInt32(!(leafData != 0))
				} else {
					v1 = (**(**TCellArray)(__ccgo_up(bp + 72))).FnCell
				}
				iOld1 = v1
				iNew1 = cntNew[iPg-int32(1)] + libc.BoolInt32(!(leafData != 0))
				nNewCell = cntNew[iPg] - iNew1
			}
			**(**int32)(__ccgo_up(bp)) = _editPage(tls, apNew[iPg], iOld1, iNew1, nNewCell, bp+72)
			if **(**int32)(__ccgo_up(bp)) != 0 {
				goto balance_cleanup
			}
			(**(**[5]Tu8)(__ccgo_up(bp + 60)))[iPg] = (**(**[5]Tu8)(__ccgo_up(bp + 60)))[iPg] + 1
			(*TMemPage)(unsafe.Pointer(apNew[iPg])).FnFree = usableSpace - (**(**[5]int32)(__ccgo_up(bp + 32)))[iPg]
		}
		goto _28
	_28:
		;
		i = i + 1
	}
	/* All pages have been processed exactly once */
	if isRoot != 0 && libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell) == 0 && libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset) <= (*TMemPage)(unsafe.Pointer(apNew[0])).FnFree {
		/* The root page of the b-tree now contains no cells. The only sibling
		 ** page is the right-child of the parent. Copy the contents of the
		 ** child page into the parent, decreasing the overall height of the
		 ** b-tree structure by one. This is described as the "balance-shallower"
		 ** sub-algorithm in some documentation.
		 **
		 ** If this is an auto-vacuum database, the call to copyNodeContent()
		 ** sets all pointer-map entries corresponding to database image pages
		 ** for which the pointer is stored within the content being copied.
		 **
		 ** It is critical that the child page be defragmented before being
		 ** copied into the parent, because if the parent is page 1 then it will
		 ** by smaller than the child due to the database header, and so all the
		 ** free space needs to be up front.
		 */
		**(**int32)(__ccgo_up(bp)) = _defragmentPage(tls, apNew[0], -int32(1))
		_copyNodeContent(tls, apNew[0], pParent, bp)
		_freePage(tls, apNew[0], bp)
	} else {
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && !(leafCorrection != 0) {
			/* Fix the pointer map entries associated with the right-child of each
			 ** sibling page. All other pointer map entries have already been taken
			 ** care of.  */
			i = 0
			for {
				if !(i < nNew) {
					break
				}
				key = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(apNew[i])).FaData+8)
				_ptrmapPut(tls, pBt, key, uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(apNew[i])).Fpgno, bp)
				goto _32
			_32:
				;
				i = i + 1
			}
		}
	}
	/* Free any old pages that were not reused as new pages.
	 */
	i = nNew
	for {
		if !(i < nOld) {
			break
		}
		_freePage(tls, (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i], bp)
		goto _33
	_33:
		;
		i = i + 1
	}
	/*
	 ** Cleanup before returning.
	 */
	goto balance_cleanup
balance_cleanup:
	;
	_sqlite3DbFree(tls, uintptr(0), (**(**TCellArray)(__ccgo_up(bp + 72))).FapCell)
	i = 0
	for {
		if !(i < nOld) {
			break
		}
		_releasePage(tls, (**(**[3]uintptr)(__ccgo_up(bp + 8)))[i])
		goto _34
	_34:
		;
		i = i + 1
	}
	i = 0
	for {
		if !(i < nNew) {
			break
		}
		_releasePage(tls, apNew[i])
		goto _35
	_35:
		;
		i = i + 1
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** This version of balance() handles the common special case where
//	** a new entry is being inserted on the extreme right-end of the
//	** tree, in other words, when the new entry will become the largest
//	** entry in the tree.
//	**
//	** Instead of trying to balance the 3 right-most leaf pages, just add
//	** a new page to the right-hand side and put the one new entry in
//	** that page.  This leaves the right side of the tree somewhat
//	** unbalanced.  But odds are that we will be inserting new entries
//	** at the end soon afterwards so the nearly empty page will quickly
//	** fill up.  On average.
//	**
//	** pPage is the leaf page which is the right-most page in the tree.
//	** pParent is its parent.  pPage must have a single overflow entry
//	** which is also the right-most entry on the page.
//	**
//	** The pSpace buffer is used to store a temporary copy of the divider
//	** cell that will be inserted into pParent. Such a cell consists of a 4
//	** byte page number followed by a variable length integer. In other
//	** words, at most 13 bytes. Hence the pSpace buffer must be at
//	** least 13 bytes in size.
//	*/
func _balance_quick(tls *libc.TLS, pParent uintptr, pPage uintptr, pSpace uintptr) (r int32) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var pBt, pOut, pStop, v1, v3 uintptr
	var v2 Tu8
	var _ /* b at bp+32 */ TCellArray
	var _ /* pCell at bp+16 */ uintptr
	var _ /* pNew at bp+0 */ uintptr
	var _ /* pgnoNew at bp+12 */ TPgno
	var _ /* rc at bp+8 */ int32
	var _ /* szCell at bp+24 */ Tu16
	_, _, _, _, _, _ = pBt, pOut, pStop, v1, v2, v3
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt /* Page number of pNew */
	if libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) == 0 {
		return _sqlite3CorruptError(tls, int32(81243))
	} /* dbfuzz001.test */
	/* Allocate a new page. This page will become the right-sibling of
	 ** pPage. Make the parent page writable, so that the new divider cell
	 ** may be inserted. If both these operations are successful, proceed.
	 */
	**(**int32)(__ccgo_up(bp + 8)) = _allocateBtreePage(tls, pBt, bp, bp+12, uint32(0), uint8(0))
	if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
		pOut = pSpace + 4
		**(**uintptr)(__ccgo_up(bp + 16)) = **(**uintptr)(__ccgo_up(pPage + 40))
		**(**Tu16)(__ccgo_up(bp + 24)) = (*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, **(**uintptr)(__ccgo_up(bp + 16)))
		_zeroPage(tls, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromInt32(PTF_INTKEY)|libc.Int32FromInt32(PTF_LEAFDATA)|libc.Int32FromInt32(PTF_LEAF))
		(**(**TCellArray)(__ccgo_up(bp + 32))).FnCell = int32(1)
		(**(**TCellArray)(__ccgo_up(bp + 32))).FpRef = pPage
		(**(**TCellArray)(__ccgo_up(bp + 32))).FapCell = bp + 16
		(**(**TCellArray)(__ccgo_up(bp + 32))).FszCell = bp + 24
		**(**uintptr)(__ccgo_up(bp + 32 + 32)) = (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd
		**(**int32)(__ccgo_up(bp + 32 + 80)) = int32(2)
		**(**int32)(__ccgo_up(bp + 32 + 80 + uintptr(libc.Int32FromInt32(NB)*libc.Int32FromInt32(2)-libc.Int32FromInt32(1))*4)) = int32(0x7fffffff)
		**(**int32)(__ccgo_up(bp + 8)) = _rebuildPage(tls, bp+32, 0, int32(1), **(**uintptr)(__ccgo_up(bp)))
		if **(**int32)(__ccgo_up(bp + 8)) != 0 {
			_releasePage(tls, **(**uintptr)(__ccgo_up(bp)))
			return **(**int32)(__ccgo_up(bp + 8))
		}
		(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnFree = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize - uint32((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FcellOffset) - uint32(2) - uint32(**(**Tu16)(__ccgo_up(bp + 24))))
		/* If this is an auto-vacuum database, update the pointer map
		 ** with entries for the new page, and any pointer from the
		 ** cell on the page to an overflow page. If either of these
		 ** operations fails, the return code is set, but the contents
		 ** of the parent page are still manipulated by the code below.
		 ** That is Ok, at this point the parent page is guaranteed to
		 ** be marked as dirty. Returning an error code will cause a
		 ** rollback, undoing any changes made to the parent page.
		 */
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			_ptrmapPut(tls, pBt, **(**TPgno)(__ccgo_up(bp + 12)), uint8(PTRMAP_BTREE), (*TMemPage)(unsafe.Pointer(pParent)).Fpgno, bp+8)
			if libc.Int32FromUint16(**(**Tu16)(__ccgo_up(bp + 24))) > libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FminLocal) {
				_ptrmapPutOvflPtr(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 16)), bp+8)
			}
		}
		/* Create a divider cell to insert into pParent. The divider cell
		 ** consists of a 4-byte page number (the page number of pPage) and
		 ** a variable length key value (which must be the same value as the
		 ** largest key on pPage).
		 **
		 ** To find the largest key value on pPage, first find the right-most
		 ** cell on pPage. The first two fields of this cell are the
		 ** record-length (a variable length integer at most 32-bits in size)
		 ** and the key value (a variable length integer, may have any value).
		 ** The first of the while(...) loops below skips over the record-length
		 ** field. The second while(...) loop copies the key value from the
		 ** cell on pPage into the pSpace buffer.
		 */
		**(**uintptr)(__ccgo_up(bp + 16)) = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)-int32(1)))))))
		pStop = **(**uintptr)(__ccgo_up(bp + 16)) + 9
		for {
			v1 = **(**uintptr)(__ccgo_up(bp + 16))
			**(**uintptr)(__ccgo_up(bp + 16)) = **(**uintptr)(__ccgo_up(bp + 16)) + 1
			if !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v1)))&int32(0x80) != 0 && **(**uintptr)(__ccgo_up(bp + 16)) < pStop) {
				break
			}
		}
		pStop = **(**uintptr)(__ccgo_up(bp + 16)) + 9
		for {
			v1 = **(**uintptr)(__ccgo_up(bp + 16))
			**(**uintptr)(__ccgo_up(bp + 16)) = **(**uintptr)(__ccgo_up(bp + 16)) + 1
			v2 = **(**Tu8)(__ccgo_up(v1))
			v3 = pOut
			pOut = pOut + 1
			**(**Tu8)(__ccgo_up(v3)) = v2
			if !(libc.Int32FromUint8(v2)&int32(0x80) != 0 && **(**uintptr)(__ccgo_up(bp + 16)) < pStop) {
				break
			}
		}
		/* Insert the new divider cell into pParent. */
		if **(**int32)(__ccgo_up(bp + 8)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 8)) = _insertCell(tls, pParent, libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pParent)).FnCell), pSpace, int32(int64(pOut)-int64(pSpace)), uintptr(0), (*TMemPage)(unsafe.Pointer(pPage)).Fpgno)
		}
		/* Set the right-child pointer of pParent to point to the new page. */
		_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pParent)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pParent)).FhdrOffset)+int32(8)), **(**TPgno)(__ccgo_up(bp + 12)))
		/* Release the reference to the new page. */
		_releasePage(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	return **(**int32)(__ccgo_up(bp + 8))
}

// C documentation
//
//	/*
//	** Do additional sanity check after btreeInitPage() if
//	** PRAGMA cell_size_check=ON
//	*/
func _btreeCellSizeCheck(tls *libc.TLS, pPage uintptr) (r int32) {
	var cellOffset, i, iCellFirst, iCellLast, pc, sz, usableSize int32
	var data uintptr
	_, _, _, _, _, _, _, _ = cellOffset, data, i, iCellFirst, iCellLast, pc, sz, usableSize /* Start of cell content area */
	iCellFirst = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset) + int32(2)*libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	usableSize = libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
	iCellLast = usableSize - int32(4)
	data = (*TMemPage)(unsafe.Pointer(pPage)).FaData
	cellOffset = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FcellOffset)
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		iCellLast = iCellLast - 1
	}
	i = 0
	for {
		if !(i < libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)) {
			break
		}
		pc = libc.Int32FromUint16(**(**Tu16)(__ccgo_up(data + uintptr(cellOffset+i*int32(2)))))
		if pc < iCellFirst || pc > iCellLast {
			return _sqlite3CorruptError(tls, int32(75424))
		}
		sz = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, data+uintptr(pc)))
		if pc+sz > usableSize {
			return _sqlite3CorruptError(tls, int32(75429))
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return SQLITE_OK
}

func _btreeParseCell(tls *libc.TLS, pPage uintptr, iCell int32, pInfo uintptr) {
	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iCell))))), pInfo)
}

// C documentation
//
//	/*
//	** Step the cursor to the back to the previous entry in the database.
//	** Return values:
//	**
//	**     SQLITE_OK     success
//	**     SQLITE_DONE   the cursor is already on the first element of the table
//	**     otherwise     some kind of error occurred
//	**
//	** The main entry point is sqlite3BtreePrevious().  That routine is optimized
//	** for the common case of merely decrementing the cell counter BtCursor.aiIdx
//	** to the previous cell on the current page.  The (slower) btreePrevious()
//	** helper routine is called when it is necessary to move to a different page
//	** or to restore the cursor.
//	**
//	** If bit 0x01 of the F argument to sqlite3BtreePrevious(C,F) is 1, then
//	** the cursor corresponds to an SQL index and this routine could have been
//	** skipped if the SQL index had been a unique index.  The F argument is a
//	** hint to the implement.  The native SQLite btree implementation does not
//	** use this hint, but COMDB2 does.
//	*/
func _btreePrevious(tls *libc.TLS, pCur uintptr) (r int32) {
	var idx, rc, v1 int32
	var pPage uintptr
	_, _, _, _ = idx, pPage, rc, v1
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
			v1 = _btreeRestoreCursorPosition(tls, pCur)
		} else {
			v1 = SQLITE_OK
		}
		rc = v1
		if rc != SQLITE_OK {
			return rc
		}
		if int32(CURSOR_INVALID) == libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) {
			return int32(SQLITE_DONE)
		}
		if int32(CURSOR_SKIPNEXT) == libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_VALID)
			if (*TBtCursor)(unsafe.Pointer(pCur)).FskipNext < 0 {
				return SQLITE_OK
			}
		}
	}
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	if _sqlite3FaultSim(tls, int32(412)) != 0 {
		(*TMemPage)(unsafe.Pointer(pPage)).FisInit = uint8(0)
	}
	if !((*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0) {
		return _sqlite3CorruptError(tls, int32(79674))
	}
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		idx = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
		rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)))))))
		if rc != 0 {
			return rc
		}
		rc = _moveToRightmost(tls, pCur)
	} else {
		for libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix) == 0 {
			if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) == 0 {
				(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
				return int32(SQLITE_DONE)
			}
			_moveToParent(tls, pCur)
		}
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix = (*TBtCursor)(unsafe.Pointer(pCur)).Fix - 1
		pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		if (*TMemPage)(unsafe.Pointer(pPage)).FintKey != 0 && !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
			rc = _sqlite3BtreePrevious(tls, pCur, 0)
		} else {
			rc = SQLITE_OK
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Invoke the 'collation needed' callback to request a collation sequence
//	** in the encoding enc of name zName, length nName.
//	*/
func _callCollNeeded(tls *libc.TLS, db uintptr, enc int32, zName uintptr) {
	var pTmp, zExternal, zExternal1 uintptr
	_, _, _ = pTmp, zExternal, zExternal1
	if (*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded != 0 {
		zExternal = _sqlite3DbStrDup(tls, db, zName)
		if !(zExternal != 0) {
			return
		}
		(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpCollNeededArg, db, enc, zExternal)
		_sqlite3DbFree(tls, db, zExternal)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded16 != 0 {
		pTmp = _sqlite3ValueNew(tls, db)
		_sqlite3ValueSetStr(tls, pTmp, -int32(1), zName, uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
		zExternal1 = _sqlite3ValueText(tls, pTmp, uint8(SQLITE_UTF16BE))
		if zExternal1 != 0 {
			(*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxCollNeeded16})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpCollNeededArg, db, libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc), zExternal1)
		}
		_sqlite3ValueFree(tls, pTmp)
	}
}

// C documentation
//
//	/*
//	** Check to see if the FROM clause term pFrom has table-valued function
//	** arguments.  If it does, leave an error message in pParse and return
//	** non-zero, since pFrom is not allowed to be a table-valued function.
//	*/
func _cannotBeFunction(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x10000000>>28) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21036, libc.VaList(bp+8, (*TSrcItem)(unsafe.Pointer(pFrom)).FzName))
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Do various sanity checks on a single page of a tree.  Return
//	** the tree depth.  Root pages return 0.  Parents of root pages
//	** return 1, and so forth.
//	**
//	** These checks are done:
//	**
//	**      1.  Make sure that cells and freeblocks do not overlap
//	**          but combine to completely cover the page.
//	**      2.  Make sure integer cell keys are in order.
//	**      3.  Check the integrity of overflow pages.
//	**      4.  Recursively call checkTreePage on all children.
//	**      5.  Verify that the depth of all children is the same.
//	*/
func _checkTreePage(tls *libc.TLS, pCheck uintptr, iPage TPgno, piMinKey uintptr, _maxKey Ti64) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	*(*Ti64)(unsafe.Pointer(bp)) = _maxKey
	var cellStart, d2, depth, doCoverageCheck, hdr, i, j, keyCanBeEqual, nCell, nFrag, pgno, rc, saved_v1, saved_v2, size1, v1 int32
	var contentOffset, nPage, pc, prev, size, usableSize Tu32
	var data, heap, pBt, pCell, pCellIdx, saved_zPfx uintptr
	var pgnoOvfl TPgno
	var savedIsInit Tu8
	var _ /* info at bp+24 */ TCellInfo
	var _ /* pPage at bp+8 */ uintptr
	var _ /* x at bp+16 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cellStart, contentOffset, d2, data, depth, doCoverageCheck, hdr, heap, i, j, keyCanBeEqual, nCell, nFrag, nPage, pBt, pCell, pCellIdx, pc, pgno, pgnoOvfl, prev, rc, savedIsInit, saved_v1, saved_v2, saved_zPfx, size, size1, usableSize, v1
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Result code from subroutine call */
	depth = -int32(1)                             /* Number of cells */
	doCoverageCheck = int32(1)                    /* True if cell coverage checking should be done */
	keyCanBeEqual = int32(1)                      /* Offset to the start of the cell content area */
	heap = uintptr(0)
	prev = uint32(0) /* Next and previous entry on the min-heap */
	saved_zPfx = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx
	saved_v1 = libc.Int32FromUint32((*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1)
	saved_v2 = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2
	savedIsInit = uint8(0)
	/* Check that the page exists
	 */
	_checkProgress(tls, pCheck)
	if (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr == 0 {
		goto end_of_check
	}
	pBt = (*TIntegrityCk)(unsafe.Pointer(pCheck)).FpBt
	usableSize = (*TBtShared)(unsafe.Pointer(pBt)).FusableSize
	if iPage == uint32(0) {
		return 0
	}
	if _checkRef(tls, pCheck, iPage) != 0 {
		return 0
	}
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4602
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = iPage
	v1 = _btreeGetPage(tls, pBt, iPage, bp+8, 0)
	rc = v1
	if v1 != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4620, libc.VaList(bp+56, rc))
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).Frc = int32(SQLITE_NOMEM)
		}
		goto end_of_check
	}
	/* Clear MemPage.isInit to make sure the corruption detection code in
	 ** btreeInitPage() is executed.  */
	savedIsInit = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit
	(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit = uint8(0)
	v1 = _btreeInitPage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	rc = v1
	if v1 != 0 {
		/* The only possible error from InitPage */
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4658, libc.VaList(bp+56, rc))
		goto end_of_check
	}
	v1 = _btreeComputeFreeSpace(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	rc = v1
	if v1 != 0 {
		_checkAppendMsg(tls, pCheck, __ccgo_ts+4696, libc.VaList(bp+56, rc))
		goto end_of_check
	}
	data = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FaData
	hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FhdrOffset)
	/* Set up for cell analysis */
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4718
	contentOffset = libc.Uint32FromInt32((libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(5)))))<<libc.Int32FromInt32(8)|libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(5)) + 1)))-libc.Int32FromInt32(1))&libc.Int32FromInt32(0xffff) + libc.Int32FromInt32(1))
	/* Enforced by btreeInitPage() */
	/* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
	 ** number of cells on the page. */
	nCell = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(3)))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(3)) + 1)))
	if (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0 || libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FintKey) == 0 {
		**(**Ti64)(__ccgo_up(pCheck + 120)) += int64(nCell)
	}
	/* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
	 ** immediately follows the b-tree page header. */
	cellStart = hdr + int32(12) - int32(4)*libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf)
	pCellIdx = data + uintptr(cellStart+int32(2)*(nCell-int32(1)))
	if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
		/* Analyze the right-child page of internal pages */
		pgno = libc.Int32FromUint32(_sqlite3Get4byte(tls, data+uintptr(hdr+int32(8))))
		if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = __ccgo_ts + 4744
			_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(pgno), uint8(PTRMAP_BTREE), iPage)
		}
		depth = _checkTreePage(tls, pCheck, libc.Uint32FromInt32(pgno), bp, **(**Ti64)(__ccgo_up(bp)))
		keyCanBeEqual = 0
	} else {
		/* For leaf pages, the coverage check will occur in the same loop
		 ** as the other cell checks, so initialize the heap.  */
		heap = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fheap
		**(**Tu32)(__ccgo_up(heap)) = uint32(0)
	}
	/* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
	 ** integer offsets to the cell contents. */
	i = nCell - int32(1)
	for {
		if !(i >= 0 && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
			break
		}
		/* Check cell size */
		(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = i
		pc = uint32(**(**Tu16)(__ccgo_up(pCellIdx)))
		pCellIdx = pCellIdx - uintptr(2)
		if pc < contentOffset || pc > usableSize-uint32(4) {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4774, libc.VaList(bp+56, pc, contentOffset, usableSize-uint32(4)))
			doCoverageCheck = 0
			goto _4
		}
		pCell = data + uintptr(pc)
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FxParseCell})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), pCell, bp+24)
		if pc+uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize) > usableSize {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4804, 0)
			doCoverageCheck = 0
			goto _4
		}
		/* Check for integer primary key out of range */
		if (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FintKey != 0 {
			if keyCanBeEqual != 0 {
				v1 = libc.BoolInt32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey > **(**Ti64)(__ccgo_up(bp)))
			} else {
				v1 = libc.BoolInt32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey >= **(**Ti64)(__ccgo_up(bp)))
			}
			if v1 != 0 {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4828, libc.VaList(bp+56, (**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey))
			}
			**(**Ti64)(__ccgo_up(bp)) = (**(**TCellInfo)(__ccgo_up(bp + 24))).FnKey
			keyCanBeEqual = 0 /* Only the first key on the page may ==maxKey */
		}
		/* Check the content overflow list */
		if (**(**TCellInfo)(__ccgo_up(bp + 24))).FnPayload > uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnLocal) { /* First page of the overflow chain */
			nPage = ((**(**TCellInfo)(__ccgo_up(bp + 24))).FnPayload - uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnLocal) + usableSize - uint32(5)) / (usableSize - uint32(4))
			pgnoOvfl = _sqlite3Get4byte(tls, pCell+uintptr(libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize)-int32(4)))
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, pgnoOvfl, uint8(PTRMAP_OVERFLOW1), iPage)
			}
			_checkList(tls, pCheck, 0, pgnoOvfl, nPage)
		}
		if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
			/* Check sanity of left child page for internal pages */
			pgno = libc.Int32FromUint32(_sqlite3Get4byte(tls, pCell))
			if (*TBtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				_checkPtrmap(tls, pCheck, libc.Uint32FromInt32(pgno), uint8(PTRMAP_BTREE), iPage)
			}
			d2 = _checkTreePage(tls, pCheck, libc.Uint32FromInt32(pgno), bp, **(**Ti64)(__ccgo_up(bp)))
			keyCanBeEqual = 0
			if d2 != depth {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4852, 0)
				depth = d2
			}
		} else {
			/* Populate the coverage-checking heap for leaf pages */
			_btreeHeapInsert(tls, heap, pc<<libc.Int32FromInt32(16)|(pc+uint32((**(**TCellInfo)(__ccgo_up(bp + 24))).FnSize)-uint32(1)))
		}
		goto _4
	_4:
		;
		i = i - 1
	}
	**(**Ti64)(__ccgo_up(piMinKey)) = **(**Ti64)(__ccgo_up(bp))
	/* Check for complete coverage of the page
	 */
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = uintptr(0)
	if doCoverageCheck != 0 && (*TIntegrityCk)(unsafe.Pointer(pCheck)).FmxErr > 0 {
		/* For leaf pages, the min-heap has already been initialized and the
		 ** cells have already been inserted.  But for internal pages, that has
		 ** not yet been done, so do it now */
		if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).Fleaf != 0) {
			heap = (*TIntegrityCk)(unsafe.Pointer(pCheck)).Fheap
			**(**Tu32)(__ccgo_up(heap)) = uint32(0)
			i = nCell - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				pc = uint32(**(**Tu16)(__ccgo_up(data + uintptr(cellStart+i*int32(2)))))
				size = uint32((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FxCellSize})))(tls, **(**uintptr)(__ccgo_up(bp + 8)), data+uintptr(pc)))
				_btreeHeapInsert(tls, heap, pc<<libc.Int32FromInt32(16)|(pc+size-uint32(1)))
				goto _6
			_6:
				;
				i = i - 1
			}
		}
		/* Add the freeblocks to the min-heap
		 **
		 ** EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
		 ** is the offset of the first freeblock, or zero if there are no
		 ** freeblocks on the page.
		 */
		i = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(1)))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(1)) + 1)))
		for i > 0 {
			/* Enforced by btreeComputeFreeSpace() */
			size1 = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i+int32(2)))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i+int32(2)) + 1)))
			/* due to btreeComputeFreeSpace() */
			_btreeHeapInsert(tls, heap, libc.Uint32FromInt32(i)<<libc.Int32FromInt32(16)|libc.Uint32FromInt32(i+size1-libc.Int32FromInt32(1)))
			/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
			 ** big-endian integer which is the offset in the b-tree page of the next
			 ** freeblock in the chain, or zero if the freeblock is the last on the
			 ** chain. */
			j = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i))))<<int32(8) | libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(i) + 1)))
			/* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
			 ** increasing offset. */
			/* Enforced by btreeComputeFreeSpace() */
			/* Enforced by btreeComputeFreeSpace() */
			i = j
		}
		/* Analyze the min-heap looking for overlap between cells and/or
		 ** freeblocks, and counting the number of untracked bytes in nFrag.
		 **
		 ** Each min-heap entry is of the form:    (start_address<<16)|end_address.
		 ** There is an implied first entry the covers the page header, the cell
		 ** pointer index, and the gap between the cell pointer index and the start
		 ** of cell content.
		 **
		 ** The loop below pulls entries from the min-heap in order and compares
		 ** the start_address against the previous end_address.  If there is an
		 ** overlap, that means bytes are used multiple times.  If there is a gap,
		 ** that gap is added to the fragmentation count.
		 */
		nFrag = 0
		prev = contentOffset - uint32(1) /* Implied first min-heap entry */
		for _btreeHeapPull(tls, heap, bp+16) != 0 {
			if prev&uint32(0xffff) >= **(**Tu32)(__ccgo_up(bp + 16))>>libc.Int32FromInt32(16) {
				_checkAppendMsg(tls, pCheck, __ccgo_ts+4877, libc.VaList(bp+56, **(**Tu32)(__ccgo_up(bp + 16))>>int32(16), iPage))
				break
			} else {
				nFrag = libc.Int32FromUint32(uint32(nFrag) + (**(**Tu32)(__ccgo_up(bp + 16))>>libc.Int32FromInt32(16) - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
				prev = **(**Tu32)(__ccgo_up(bp + 16))
			}
		}
		nFrag = libc.Int32FromUint32(uint32(nFrag) + (usableSize - prev&libc.Uint32FromInt32(0xffff) - libc.Uint32FromInt32(1)))
		/* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
		 ** is stored in the fifth field of the b-tree page header.
		 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
		 ** number of fragmented free bytes within the cell content area.
		 */
		if **(**Tu32)(__ccgo_up(heap)) == uint32(0) && nFrag != libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7))))) {
			_checkAppendMsg(tls, pCheck, __ccgo_ts+4914, libc.VaList(bp+56, nFrag, libc.Int32FromUint8(**(**Tu8)(__ccgo_up(data + uintptr(hdr+int32(7))))), iPage))
		}
	}
	goto end_of_check
end_of_check:
	;
	if !(doCoverageCheck != 0) {
		(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisInit = savedIsInit
	}
	_releasePage(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = saved_zPfx
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = libc.Uint32FromInt32(saved_v1)
	(*TIntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = saved_v2
	return depth + int32(1)
}

// C documentation
//
//	/*
//	** Erase the given database page and all its children.  Return
//	** the page to the freelist.
//	*/
func _clearDatabasePage(tls *libc.TLS, pBt uintptr, pgno TPgno, freePageFlag int32, pnChange uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var hdr, i, v2 int32
	var pCell uintptr
	var _ /* info at bp+16 */ TCellInfo
	var _ /* pPage at bp+0 */ uintptr
	var _ /* rc at bp+8 */ int32
	_, _, _, _ = hdr, i, pCell, v2
	if pgno > _btreePagecount(tls, pBt) {
		return _sqlite3CorruptError(tls, int32(83452))
	}
	**(**int32)(__ccgo_up(bp + 8)) = _getAndInitPage(tls, pBt, pgno, bp, 0)
	if **(**int32)(__ccgo_up(bp + 8)) != 0 {
		return **(**int32)(__ccgo_up(bp + 8))
	}
	if libc.Int32FromUint8((*TBtShared)(unsafe.Pointer(pBt)).FopenFlags)&int32(BTREE_SINGLE) == 0 && _sqlite3PagerPageRefcount(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpDbPage) != int32(1)+libc.BoolInt32(pgno == uint32(1)) {
		**(**int32)(__ccgo_up(bp + 8)) = _sqlite3CorruptError(tls, int32(83459))
		goto cleardatabasepage_out
	}
	hdr = libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FhdrOffset)
	i = 0
	for {
		if !(i < libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnCell)) {
			break
		}
		pCell = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaCellIdx + uintptr(int32(2)*i)))))
		if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fleaf != 0) {
			**(**int32)(__ccgo_up(bp + 8)) = _clearDatabasePage(tls, pBt, _sqlite3Get4byte(tls, pCell), int32(1), pnChange)
			if **(**int32)(__ccgo_up(bp + 8)) != 0 {
				goto cleardatabasepage_out
			}
		}
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FxParseCell})))(tls, **(**uintptr)(__ccgo_up(bp)), pCell, bp+16)
		if uint32((**(**TCellInfo)(__ccgo_up(bp + 16))).FnLocal) != (**(**TCellInfo)(__ccgo_up(bp + 16))).FnPayload {
			**(**int32)(__ccgo_up(bp + 8)) = _clearCellOverflow(tls, **(**uintptr)(__ccgo_up(bp)), pCell, bp+16)
		} else {
			**(**int32)(__ccgo_up(bp + 8)) = SQLITE_OK
		}
		if **(**int32)(__ccgo_up(bp + 8)) != 0 {
			goto cleardatabasepage_out
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if !((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).Fleaf != 0) {
		**(**int32)(__ccgo_up(bp + 8)) = _clearDatabasePage(tls, pBt, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData+uintptr(hdr+int32(8))), int32(1), pnChange)
		if **(**int32)(__ccgo_up(bp + 8)) != 0 {
			goto cleardatabasepage_out
		}
		if (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FintKey != 0 {
			pnChange = uintptr(0)
		}
	}
	if pnChange != 0 {
		**(**Ti64)(__ccgo_up(pnChange)) += libc.Int64FromUint16((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnCell)
	}
	if freePageFlag != 0 {
		_freePage(tls, **(**uintptr)(__ccgo_up(bp)), bp+8)
	} else {
		v2 = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpDbPage)
		**(**int32)(__ccgo_up(bp + 8)) = v2
		if v2 == 0 {
			_zeroPage(tls, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaData + uintptr(hdr))))|int32(PTF_LEAF))
		}
	}
	goto cleardatabasepage_out
cleardatabasepage_out:
	;
	_releasePage(tls, **(**uintptr)(__ccgo_up(bp)))
	return **(**int32)(__ccgo_up(bp + 8))
}

// C documentation
//
//	/*
//	** Cursor iCur is open on an intkey b-tree (a table). Register iRowid contains
//	** a rowid value just read from cursor iIdxCur, open on index pIdx. This
//	** function generates code to do a deferred seek of cursor iCur to the
//	** rowid stored in register iRowid.
//	**
//	** Normally, this is just:
//	**
//	**   OP_DeferredSeek $iCur $iRowid
//	**
//	** Which causes a seek on $iCur to the row with rowid $iRowid.
//	**
//	** However, if the scan currently being coded is a branch of an OR-loop and
//	** the statement currently being coded is a SELECT, then additional information
//	** is added that might allow OP_Column to omit the seek and instead do its
//	** lookup on the index, thus avoiding an expensive seek operation.  To
//	** enable this optimization, the P3 of OP_DeferredSeek is set to iIdxCur
//	** and P4 is set to an array of integers containing one entry for each column
//	** in the table.  For each table column, if the column is the i'th
//	** column of the index, then the corresponding array entry is set to (i+1).
//	** If the column does not appear in the index at all, the array entry is set
//	** to 0.  The OP_Column opcode can check this array to see if the column it
//	** wants is in the index and if it is, it will substitute the index cursor
//	** and column number and continue with those new values, rather than seeking
//	** the table cursor.
//	*/
func _codeDeferredSeek(tls *libc.TLS, pWInfo uintptr, pIdx uintptr, iCur int32, iIdxCur int32) {
	var ai, pParse, pTab, v, v1 uintptr
	var i, x1, x2 int32
	var v2 bool
	_, _, _, _, _, _, _, _, _ = ai, i, pParse, pTab, v, x1, x2, v1, v2
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse /* Parse context */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe           /* Vdbe to generate code within */
	libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 7, 0x80)
	_sqlite3VdbeAddOp3(tls, v, int32(OP_DeferredSeek), iIdxCur, 0, iCur)
	if v2 = libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_OR_SUBCLAUSE)|libc.Int32FromInt32(WHERE_RIGHT_JOIN)) != 0; v2 {
		if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
		} else {
			v1 = pParse
		}
	}
	if v2 && (*TParse)(unsafe.Pointer(v1)).FwriteMask == uint32(0) {
		pTab = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
		ai = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(4)*libc.Uint64FromInt32(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+libc.Int32FromInt32(1))))
		if ai != 0 {
			**(**Tu32)(__ccgo_up(ai)) = libc.Uint32FromInt16((*TTable)(unsafe.Pointer(pTab)).FnCol)
			i = 0
			for {
				if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)-int32(1)) {
					break
				}
				x1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
				x2 = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(x1)))
				if x1 >= 0 {
					**(**Tu32)(__ccgo_up(ai + uintptr(x2+int32(1))*4)) = libc.Uint32FromInt32(i + int32(1))
				}
				goto _3
			_3:
				;
				i = i + 1
			}
			_sqlite3VdbeChangeP4(tls, v, -int32(1), ai, -int32(15))
		}
	}
}

// C documentation
//
//	/*
//	** Generate code for the RETURNING trigger.  Unlike other triggers
//	** that invoke a subprogram in the bytecode, the code for RETURNING
//	** is generated in-line.
//	*/
func _codeReturningTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, regIn int32) {
	bp := tls.Alloc(272)
	defer tls.Free(272)
	var db, pCol, pFrom, pNew, pReturning, v, v2 uintptr
	var i, nCol, reg, v1 int32
	var _ /* sNC at bp+208 */ TNameContext
	var _ /* sSelect at bp+0 */ TSelect
	var _ /* uSrc at bp+120 */ struct {
		FfromSpace   [0][88]Tu8
		FsSrc        TSrcList
		F__ccgo_pad2 [80]byte
	}
	_, _, _, _, _, _, _, _, _, _, _ = db, i, nCol, pCol, pFrom, pNew, pReturning, reg, v, v1, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0) {
		/* This RETURNING trigger must be for a different statement as
		 ** this statement lacks a RETURNING clause. */
		return
	}
	pReturning = (*(*struct {
		FpReturning uintptr
	})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning
	if pTrigger != pReturning+16 {
		/* This RETURNING trigger is for a different statement */
		return
	}
	libc.Xmemset(tls, bp, 0, uint64(120))
	libc.Xmemset(tls, bp+120, 0, uint64(88))
	pFrom = bp + 120
	(**(**TSelect)(__ccgo_up(bp))).FpEList = _sqlite3ExprListDup(tls, db, (*TReturning)(unsafe.Pointer(pReturning)).FpReturnEL, 0)
	(**(**TSelect)(__ccgo_up(bp))).FpSrc = pFrom
	(*TSrcList)(unsafe.Pointer(pFrom)).FnSrc = int32(1)
	(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FpSTab = pTab
	(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FzName = (*TTable)(unsafe.Pointer(pTab)).FzName /* tag-20240424-1 */
	(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FiCursor = -int32(1)
	_sqlite3SelectPrep(tls, pParse, bp, uintptr(0))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		_sqlite3GenerateColumnNames(tls, pParse, bp)
	}
	_sqlite3ExprListDelete(tls, db, (**(**TSelect)(__ccgo_up(bp))).FpEList)
	pNew = _sqlite3ExpandReturning(tls, pParse, (*TReturning)(unsafe.Pointer(pReturning)).FpReturnEL, pTab)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		libc.Xmemset(tls, bp+208, 0, uint64(56))
		if (*TReturning)(unsafe.Pointer(pReturning)).FnRetCol == 0 {
			(*TReturning)(unsafe.Pointer(pReturning)).FnRetCol = (*TExprList)(unsafe.Pointer(pNew)).FnExpr
			v2 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v2))
			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
			(*TReturning)(unsafe.Pointer(pReturning)).FiRetCur = v1
		}
		(**(**TNameContext)(__ccgo_up(bp + 208))).FpParse = pParse
		*(*int32)(unsafe.Pointer(bp + 208 + 16)) = regIn
		(**(**TNameContext)(__ccgo_up(bp + 208))).FncFlags = int32(NC_UBaseReg)
		(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pTrigger)).Fop
		(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = pTab
		if _sqlite3ResolveExprListNames(tls, bp+208, pNew) == SQLITE_OK && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
			nCol = (*TExprList)(unsafe.Pointer(pNew)).FnExpr
			reg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			_sqlite3ProcessReturningSubqueries(tls, pNew, pTab)
			**(**int32)(__ccgo_up(pParse + 60)) += nCol + int32(2)
			(*TReturning)(unsafe.Pointer(pReturning)).FiRetReg = reg
			i = 0
			for {
				if !(i < nCol) {
					break
				}
				pCol = (*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr(i)*32))).FpExpr
				/* Due to !db->mallocFailed ~9 lines above */
				_sqlite3ExprCodeFactorable(tls, pParse, pCol, reg+i)
				if libc.Int32FromUint8(_sqlite3ExprAffinity(tls, pCol)) == int32(SQLITE_AFF_REAL) {
					_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), reg+i)
				}
				goto _3
			_3:
				;
				i = i + 1
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), reg, i, reg+i)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur, reg+i+int32(1))
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur, reg+i, reg+i+int32(1))
		}
	}
	_sqlite3ExprListDelete(tls, db, pNew)
	(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = uintptr(0)
}

// C documentation
//
//	/*
//	** Return true if column iCol of table pTab seem like it might be a
//	** good column to use as part of a query-time index.
//	**
//	** Current algorithm (subject to improvement!):
//	**
//	**   1.   If iCol is already the left-most column of some other index,
//	**        then return false.
//	**
//	**   2.   If iCol is part of an existing index that has an aiRowLogEst of
//	**        more than 20, then return false.
//	**
//	**   3.   If no disqualifying conditions above are found, return true.
//	**
//	** 2025-01-03: I experimented with a new rule that returns false if the
//	** the datatype of the column is "BOOLEAN". This did not improve
//	** performance on any queries at hand, but it did burn CPU cycles, so the
//	** idea was not committed.
//	*/
func _columnIsGoodIndexCandidate(tls *libc.TLS, pTab uintptr, iCol int32) (r int32) {
	var j int32
	var pIdx uintptr
	_, _ = j, pIdx
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != uintptr(0)) {
			break
		}
		j = 0
		for {
			if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
				break
			}
			if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) == iCol {
				if j == 0 {
					return 0
				}
				if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x100>>8)) != 0 && int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst + uintptr(j+int32(1))*2))) > int32(20) {
					return 0
				}
				break
			}
			goto _2
		_2:
			;
			j = j + 1
		}
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Convert the N-th element of pStmt->pColName[] into a string using
//	** xFunc() then return that string.  If N is out of range, return 0.
//	**
//	** There are up to 5 names for each column.  useType determines which
//	** name is returned.  Here are the names:
//	**
//	**    0      The column name as it should be displayed for output
//	**    1      The datatype name for the column
//	**    2      The name of the database that the column derives from
//	**    3      The name of the table that the column derives from
//	**    4      The name of the table column that the result column derives from
//	**
//	** If the result is not a simple column reference (if it is an expression
//	** or a constant) then useTypes 2, 3, and 4 return NULL.
//	*/
func _columnName(tls *libc.TLS, pStmt uintptr, N int32, useUtf16 int32, useType int32) (r uintptr) {
	var db, p, ret uintptr
	var i, n, v1 int32
	var prior_mallocFailed Tu8
	_, _, _, _, _, _, _ = db, i, n, p, prior_mallocFailed, ret, v1
	if N < 0 {
		return uintptr(0)
	}
	ret = uintptr(0)
	p = pStmt
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)) != 0 {
		if useType > 0 {
			goto columnName_end
		}
		if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)) == int32(1) {
			v1 = int32(8)
		} else {
			v1 = int32(4)
		}
		n = v1
		if N >= n {
			goto columnName_end
		}
		if useUtf16 != 0 {
			i = libc.Int32FromUint8(_iExplainColNames16[N+int32(8)*int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12))-int32(8)])
			ret = uintptr(unsafe.Pointer(&_azExplainColNames16data)) + uintptr(i)*2
		} else {
			ret = _azExplainColNames8[N+int32(8)*int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12))-int32(8)]
		}
		goto columnName_end
	}
	n = libc.Int32FromUint16((*TVdbe)(unsafe.Pointer(p)).FnResColumn)
	if N < n {
		prior_mallocFailed = (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed
		N = N + useType*n
		if useUtf16 != 0 {
			ret = Xsqlite3_value_text16(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName+uintptr(N)*56)
		} else {
			ret = Xsqlite3_value_text(tls, (*TVdbe)(unsafe.Pointer(p)).FaColName+uintptr(N)*56)
		}
		/* A malloc may have failed inside of the _text() call. If this
		 ** is the case, clear the mallocFailed flag and return NULL.
		 */
		if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) > libc.Int32FromUint8(prior_mallocFailed) {
			_sqlite3OomClear(tls, db)
			ret = uintptr(0)
		}
	}
	goto columnName_end
columnName_end:
	;
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return ret
}

// C documentation
//
//	/*
//	** Return a pointer to a string containing the 'declaration type' of the
//	** expression pExpr. The string may be treated as static by the caller.
//	**
//	** The declaration type is the exact datatype definition extracted from the
//	** original CREATE TABLE statement if the expression is a column. The
//	** declaration type for a ROWID field is INTEGER. Exactly when an expression
//	** is considered a column can be complex in the presence of subqueries. The
//	** result-set expression in all of the following SELECT statements is
//	** considered a column by this function.
//	**
//	**   SELECT col FROM tbl;
//	**   SELECT (SELECT col FROM tbl;
//	**   SELECT (SELECT col FROM tbl);
//	**   SELECT abc FROM (SELECT col AS abc FROM tbl);
//	**
//	** The declaration type for any expression other than a column is NULL.
//	**
//	** This routine has either 3 or 6 parameters depending on whether or not
//	** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.
//	*/
func _columnTypeImpl(tls *libc.TLS, pNC uintptr, pExpr uintptr, pzOrigDb uintptr, pzOrigTab uintptr, pzOrigCol uintptr) (r uintptr) {
	bp := tls.Alloc(144)
	defer tls.Free(144)
	var iCol, iDb, j int32
	var p, p1, pS, pS1, pTab, pTabList, zType uintptr
	var _ /* sNC at bp+24 */ TNameContext
	var _ /* sNC at bp+80 */ TNameContext
	var _ /* zOrigCol at bp+16 */ uintptr
	var _ /* zOrigDb at bp+0 */ uintptr
	var _ /* zOrigTab at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = iCol, iDb, j, p, p1, pS, pS1, pTab, pTabList, zType
	zType = uintptr(0)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
	**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
	switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	case int32(TK_COLUMN):
		/* The expression is a column. Locate the table the column is being
		 ** extracted from in NameContext.pSrcList. This table may be real
		 ** database table or a subquery.
		 */
		pTab = uintptr(0)                                      /* Table structure column is extracted from */
		pS = uintptr(0)                                        /* Select the column is extracted from */
		iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) /* Index of column in pTab */
		for pNC != 0 && !(pTab != 0) {
			pTabList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
			j = 0
			for {
				if !(j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).FiCursor != (*TExpr)(unsafe.Pointer(pExpr)).FiTable) {
					break
				}
				goto _1
			_1:
				;
				j = j + 1
			}
			if j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc {
				pTab = (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).FpSTab
				if int32(*(*uint32)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80 + 24 + 4))&0x20000000>>29) != 0 {
					pS = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80 + 72)))).FpSelect
				} else {
					pS = uintptr(0)
				}
			} else {
				pNC = (*TNameContext)(unsafe.Pointer(pNC)).FpNext
			}
		}
		if pTab == uintptr(0) {
			/* At one time, code such as "SELECT new.x" within a trigger would
			 ** cause this condition to run.  Since then, we have restructured how
			 ** trigger code is generated and so this condition is no longer
			 ** possible. However, it can still be true for statements like
			 ** the following:
			 **
			 **   CREATE TABLE t1(col INTEGER);
			 **   SELECT (SELECT t1.col) FROM FROM t1;
			 **
			 ** when columnType() is called on the expression "t1.col" in the
			 ** sub-select. In this case, set the column type to NULL, even
			 ** though it should really be "INTEGER".
			 **
			 ** This is not a problem, as the column type of "t1.col" is never
			 ** used. When columnType() is called on the expression
			 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
			 ** branch below.  */
			break
		}
		if pS != 0 {
			/* The "table" is actually a sub-select or a view in the FROM clause
			 ** of the SELECT statement. Return the declaration type and origin
			 ** data for the result-set column of the sub-select.
			 */
			if iCol < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS)).FpEList)).FnExpr && libc.Bool(libc.Bool(!(libc.Int32FromInt32(ViewCanHaveRowid) != 0)) || iCol >= 0) {
				p = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS)).FpEList + 8 + uintptr(iCol)*32))).FpExpr
				(**(**TNameContext)(__ccgo_up(bp + 24))).FpSrcList = (*TSelect)(unsafe.Pointer(pS)).FpSrc
				(**(**TNameContext)(__ccgo_up(bp + 24))).FpNext = pNC
				(**(**TNameContext)(__ccgo_up(bp + 24))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
				zType = _columnTypeImpl(tls, bp+24, p, bp, bp+8, bp+16)
			}
		} else {
			/* A real table or a CTE table */
			if iCol < 0 {
				iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
			}
			if iCol < 0 {
				zType = __ccgo_ts + 1178
				**(**uintptr)(__ccgo_up(bp + 16)) = __ccgo_ts + 17967
			} else {
				**(**uintptr)(__ccgo_up(bp + 16)) = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
				zType = _sqlite3ColumnType(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*16, uintptr(0))
			}
			**(**uintptr)(__ccgo_up(bp + 8)) = (*TTable)(unsafe.Pointer(pTab)).FzName
			if (*TNameContext)(unsafe.Pointer(pNC)).FpParse != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema != 0 {
				iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
				**(**uintptr)(__ccgo_up(bp)) = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TNameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb)).FaDb + uintptr(iDb)*32))).FzDbSName
			}
		}
	case int32(TK_SELECT):
		pS1 = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		p1 = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pS1)).FpEList + 8))).FpExpr
		(**(**TNameContext)(__ccgo_up(bp + 80))).FpSrcList = (*TSelect)(unsafe.Pointer(pS1)).FpSrc
		(**(**TNameContext)(__ccgo_up(bp + 80))).FpNext = pNC
		(**(**TNameContext)(__ccgo_up(bp + 80))).FpParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
		zType = _columnTypeImpl(tls, bp+80, p1, bp, bp+8, bp+16)
		break
	}
	if pzOrigDb != 0 {
		**(**uintptr)(__ccgo_up(pzOrigDb)) = **(**uintptr)(__ccgo_up(bp))
		**(**uintptr)(__ccgo_up(pzOrigTab)) = **(**uintptr)(__ccgo_up(bp + 8))
		**(**uintptr)(__ccgo_up(pzOrigCol)) = **(**uintptr)(__ccgo_up(bp + 16))
	}
	return zType
}

// C documentation
//
//	/*
//	** Compute the Hour, Minute, and Seconds from the julian day number.
//	*/
func _computeHMS(tls *libc.TLS, p uintptr) {
	var day_min, day_ms int32
	_, _ = day_min, day_ms /* milliseconds, minutes into the day */
	if (*TDateTime)(unsafe.Pointer(p)).FvalidHMS != 0 {
		return
	}
	_computeJD(tls, p)
	day_ms = int32(((*TDateTime)(unsafe.Pointer(p)).FiJD + libc.Int64FromInt32(43200000)) % libc.Int64FromInt32(86400000))
	(*TDateTime)(unsafe.Pointer(p)).Fs = float64(day_ms%libc.Int32FromInt32(60000)) / float64(1000)
	day_min = day_ms / int32(60000)
	(*TDateTime)(unsafe.Pointer(p)).Fm = day_min % int32(60)
	(*TDateTime)(unsafe.Pointer(p)).Fh = day_min / int32(60)
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
}

// C documentation
//
//	/*
//	** Convert from YYYY-MM-DD HH:MM:SS to julian day.  We always assume
//	** that the YYYY-MM-DD is according to the Gregorian calendar.
//	**
//	** Reference:  Meeus page 61
//	*/
func _computeJD(tls *libc.TLS, p uintptr) {
	var A, B, D, M, X1, X2, Y int32
	_, _, _, _, _, _, _ = A, B, D, M, X1, X2, Y
	if (*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0 {
		return
	}
	if (*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0 {
		Y = (*TDateTime)(unsafe.Pointer(p)).FY
		M = (*TDateTime)(unsafe.Pointer(p)).FM
		D = (*TDateTime)(unsafe.Pointer(p)).FD
	} else {
		Y = int32(2000) /* If no YMD specified, assume 2000-Jan-01 */
		M = int32(1)
		D = int32(1)
	}
	if Y < -int32(4713) || Y > int32(9999) || int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x80>>7)) != 0 {
		_datetimeError(tls, p)
		return
	}
	if M <= int32(2) {
		Y = Y - 1
		M = M + int32(12)
	}
	A = (Y + int32(4800)) / int32(100)
	B = int32(38) - A + A/int32(4)
	X1 = int32(36525) * (Y + int32(4716)) / int32(100)
	X2 = int32(306001) * (M + int32(1)) / int32(10000)
	(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(float64((float64(X1+X2+D+B) - libc.Float64FromFloat64(1524.5)) * libc.Float64FromInt32(86400000)))
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
	if (*TDateTime)(unsafe.Pointer(p)).FvalidHMS != 0 {
		**(**Tsqlite3_int64)(__ccgo_up(p)) += int64((*TDateTime)(unsafe.Pointer(p)).Fh*int32(3600000)+(*TDateTime)(unsafe.Pointer(p)).Fm*int32(60000)) + int64(float64((*TDateTime)(unsafe.Pointer(p)).Fs*libc.Float64FromInt32(1000))+libc.Float64FromFloat64(0.5))
		if (*TDateTime)(unsafe.Pointer(p)).Ftz != 0 {
			**(**Tsqlite3_int64)(__ccgo_up(p)) -= int64((*TDateTime)(unsafe.Pointer(p)).Ftz * int32(60000))
			(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(0)
			(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(0)
			(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
		}
	}
}

// C documentation
//
//	/*
//	** Compute the maximum number of paths in the solver algorithm, for
//	** queries that have three or more terms in the FROM clause.  Queries with
//	** two or fewer FROM clause terms are handled by the caller.
//	**
//	** Query planning is NP-hard.  We must limit the number of paths at
//	** each step of the solver search algorithm to avoid exponential behavior.
//	**
//	** The value returned is a tuning parameter.  Currently the value is:
//	**
//	**     18    for star queries
//	**     12    otherwise
//	**
//	** For the purposes of this heuristic, a star-query is defined as a query
//	** with a central "fact" table that is joined against multiple
//	** "dimension" tables, subject to the following constraints:
//	**
//	**   (aa)  Only a five-way or larger join is considered for this
//	**         optimization.  If there are fewer than four terms in the FROM
//	**         clause, this heuristic does not apply.
//	**
//	**   (bb)  The join between the fact table and the dimension tables must
//	**         be an INNER join.  CROSS and OUTER JOINs do not qualify.
//	**
//	**   (cc)  A table must have 3 or more dimension tables in order to be
//	**         considered a fact table. (Was 4 prior to 2026-02-10.)
//	**
//	**   (dd)  A table that is a self-join cannot be a dimension table.
//	**         Dimension tables are joined against fact tables.
//	**
//	** SIDE EFFECT:  (and really the whole point of this subroutine)
//	**
//	** If pWInfo describes a star-query, then the cost for SCANs of dimension
//	** WhereLoops is increased to be slightly larger than the cost of a SCAN
//	** in the fact table.  Only SCAN costs are increased.  SEARCH costs are
//	** unchanged. This heuristic helps keep fact tables in outer loops. Without
//	** this heuristic, paths with fact tables in outer loops tend to get pruned
//	** by the mxChoice limit on the number of paths, resulting in poor query
//	** plans.  See the starschema1.test test module for examples of queries
//	** that need this heuristic to find good query plans.
//	**
//	** This heuristic can be completely disabled, so that no query is
//	** considered a star-query, using SQLITE_TESTCTRL_OPTIMIZATION to
//	** disable the SQLITE_StarQuery optimization.  In the CLI, the command
//	** to do that is:  ".testctrl opt -starquery".
//	**
//	** HISTORICAL NOTES:
//	**
//	** This optimization was first added on 2024-05-09 by check-in 38db9b5c83d.
//	** The original optimization reduced the cost and output size estimate for
//	** fact tables to help them move to outer loops.  But months later (as people
//	** started upgrading) performance regression reports started caming in,
//	** including:
//	**
//	**    forum post b18ef983e68d06d1 (2024-12-21)
//	**    forum post 0025389d0860af82 (2025-01-14)
//	**    forum post d87570a145599033 (2025-01-17)
//	**
//	** To address these, the criteria for a star-query was tightened to exclude
//	** cases where the fact and dimensions are separated by an outer join, and
//	** the affect of star-schema detection was changed to increase the rRun cost
//	** on just full table scans of dimension tables, rather than reducing costs
//	** in the all access methods of the fact table.
//	*/
func _computeMxChoice(tls *libc.TLS, pWInfo uintptr) (r int32) {
	var aFromTabs, pFactTab, pStart, pWLoop uintptr
	var iFromIdx, nDep, nLoop, v5 int32
	var m, mSeen, mSelfJoin TBitmask
	var mxRun TLogEst
	_, _, _, _, _, _, _, _, _, _, _, _ = aFromTabs, iFromIdx, m, mSeen, mSelfJoin, mxRun, nDep, nLoop, pFactTab, pStart, pWLoop, v5
	nLoop = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)                                                                                                                                                                                                                       /* For looping over WhereLoops */
	if nLoop >= int32(4) && !(int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 68))&0x8>>3)) != 0) && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_StarQuery)) == uint32(0) { /* Bitmask for candidate fact-table */
		mSelfJoin = uint64(0)                                                  /* Where to start searching for dimension-tables */
		libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 3, 0x8) /* Only do this computation once */
		/* Look for fact tables with three or more dimensions where the
		 ** dimension tables are not separately from the fact tables by an outer
		 ** or cross join.  Adjust cost weights if found.
		 */
		aFromTabs = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
		pStart = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
		iFromIdx = 0
		m = libc.Uint64FromInt32(1)
		for {
			if !(iFromIdx < nLoop) {
				break
			}
			nDep = 0          /* Maximum SCAN cost of a fact table */
			mSeen = uint64(0) /* The candidate fact table */
			pFactTab = aFromTabs + uintptr(iFromIdx)*80
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pFactTab)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
				/* If the candidate fact-table is the right table of an outer join
				 ** restrict the search for dimension-tables to be tables to the right
				 ** of the fact-table.  Constraint (bb) */
				if iFromIdx+int32(3) > nLoop {
					break /* ^-- Impossible to reach nDep>=2 - Constraint (cc) */
				}
				for pStart != 0 && libc.Int32FromUint8((*TWhereLoop)(unsafe.Pointer(pStart)).FiTab) <= iFromIdx {
					pStart = (*TWhereLoop)(unsafe.Pointer(pStart)).FpNextLoop
				}
			}
			pWLoop = pStart
			for {
				if !(pWLoop != 0) {
					break
				}
				if libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(aFromTabs + uintptr((*TWhereLoop)(unsafe.Pointer(pWLoop)).FiTab)*80))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
					break /* Constraint (bb) */
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).Fprereq&m != uint64(0) && (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&mSeen == uint64(0) && (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&mSelfJoin == uint64(0) {
					if (**(**TSrcItem)(__ccgo_up(aFromTabs + uintptr((*TWhereLoop)(unsafe.Pointer(pWLoop)).FiTab)*80))).FpSTab == (*TSrcItem)(unsafe.Pointer(pFactTab)).FpSTab {
						mSelfJoin = mSelfJoin | m
					} else {
						nDep = nDep + 1
						mSeen = mSeen | (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
					}
				}
				goto _2
			_2:
				;
				pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
			}
			if nDep <= int32(2) {
				goto _1 /* Constraint (cc) */
			}
			/* If we reach this point, it means that pFactTab is a fact table
			 ** with four or more dimensions connected by inner joins.  Proceed
			 ** to make cost adjustments. */
			libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 2, 0x4)
			/* Compute the maximum cost of any WhereLoop for the
			 ** fact table plus one epsilon */
			mxRun = int16(-libc.Int32FromInt32(32768))
			pWLoop = pStart
			for {
				if !(pWLoop != 0) {
					break
				}
				if libc.Int32FromUint8((*TWhereLoop)(unsafe.Pointer(pWLoop)).FiTab) < iFromIdx {
					goto _3
				}
				if libc.Int32FromUint8((*TWhereLoop)(unsafe.Pointer(pWLoop)).FiTab) > iFromIdx {
					break
				}
				if int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun) > int32(mxRun) {
					mxRun = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun
				}
				goto _3
			_3:
				;
				pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
			}
			if int32(mxRun) < int32(LOGEST_MAX) {
				mxRun = mxRun + 1
			}
			/* Increase the cost of table scans for dimension tables to be
			 ** slightly more than the maximum cost of the fact table */
			pWLoop = pStart
			for {
				if !(pWLoop != 0) {
					break
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&mSeen == uint64(0) {
					goto _4
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FnLTerm != 0 {
					goto _4
				}
				if int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun) < int32(mxRun) {
					(*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun = mxRun
				}
				goto _4
			_4:
				;
				pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
			}
			goto _1
		_1:
			;
			iFromIdx = iFromIdx + 1
			m = m << uint64(1)
		}
	}
	if int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 68))&0x4>>2)) != 0 {
		v5 = int32(18)
	} else {
		v5 = int32(12)
	}
	return v5
}

// C documentation
//
//	/*
//	** Generate code to construct the Index object for an automatic index
//	** and to set up the WhereLevel object pLevel so that the code generator
//	** makes use of the automatic index.
//	*/
func _constructAutomaticIndex(tls *libc.TLS, pParse uintptr, pWC uintptr, notReady TBitmask, pLevel uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var addrCounter, addrInit, addrTop, i, iCol, iCol1, iContinue, mxBitCol, n, nKeyCol, regBase, regRecord, regYield, v3 int32
	var cMask, cMask1, extraCols, idxCols TBitmask
	var pColl, pExpr, pIdx, pLoop, pPartial, pSrc, pSubq, pTabList, pTable, pTerm, pWCEnd, pX, v, v10 uintptr
	var sentWarning, useBloomFilter Tu8
	var v2 uint64
	var v4 Tu16
	var _ /* zNotUsed at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrCounter, addrInit, addrTop, cMask, cMask1, extraCols, i, iCol, iCol1, iContinue, idxCols, mxBitCol, n, nKeyCol, pColl, pExpr, pIdx, pLoop, pPartial, pSrc, pSubq, pTabList, pTable, pTerm, pWCEnd, pX, regBase, regRecord, regYield, sentWarning, useBloomFilter, v, v10, v2, v3, v4 /* Bitmap of additional columns */
	sentWarning = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                /* True if a warning has been issued */
	useBloomFilter = uint8(0)                                                                                                                                                                                                                                                                                                                                                                             /* True to also add a Bloom filter */
	pPartial = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                 /* Partial Index Expression */
	iContinue = 0                                                                                                                                                                                                                                                                                                                                                                                         /* The FROM clause term to get the next index */
	addrCounter = 0                                                                                                                                                                                                                                                                                                                                                                                       /* Array of registers where record is assembled */
	/* Generate code to skip over the creation and initialization of the
	 ** transient index on 2nd and subsequent iterations of the loop. */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	addrInit = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
	/* Count the number of columns that will be added to the index
	 ** and used to match WHERE clause constraints */
	nKeyCol = 0
	pTabList = (*TWhereInfo)(unsafe.Pointer((*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpTabList
	pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
	pTable = (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab
	pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*56
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	idxCols = uint64(0)
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(pTerm < pWCEnd) {
			break
		}
		pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		/* Make the automatic index a partial index if there are terms in the
		 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
		 ** rows of the target table (pSrc) that can be used. */
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VIRTUAL) == 0 && _sqlite3ExprIsSingleTableConstraint(tls, pExpr, pTabList, libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom), 0) != 0 {
			pPartial = _sqlite3ExprAnd(tls, pParse, pPartial, _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0))
		}
		if _termCanDriveIndex(tls, pTerm, pSrc, notReady) != 0 {
			iCol = (*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pTerm + 32))).FleftColumn
			if iCol >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
				v2 = libc.Uint64FromInt32(1) << (libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1))
			} else {
				v2 = libc.Uint64FromInt32(1) << iCol
			}
			cMask = v2
			if !(sentWarning != 0) {
				Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_WARNING)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), __ccgo_ts+23988, libc.VaList(bp+16, (*TTable)(unsafe.Pointer(pTable)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTable)).FaCol + uintptr(iCol)*16))).FzCnName))
				sentWarning = uint8(1)
			}
			if idxCols&cMask == uint64(0) {
				if _whereLoopResize(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pLoop, nKeyCol+int32(1)) != 0 {
					goto end_auto_index_create
				}
				v3 = nKeyCol
				nKeyCol = nKeyCol + 1
				**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v3)*8)) = pTerm
				idxCols = idxCols | cMask
			}
		}
		goto _1
	_1:
		;
		pTerm += 56
	}
	v4 = libc.Uint16FromInt32(nKeyCol)
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = v4
	(*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pLoop + 24))).FnEq = v4
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_EQ) | libc.Int32FromInt32(WHERE_IDX_ONLY) | libc.Int32FromInt32(WHERE_INDEXED) | libc.Int32FromInt32(WHERE_AUTO_INDEX))
	/* Count the number of additional columns needed to create a
	 ** covering index.  A "covering index" is an index that contains all
	 ** columns that are needed by the query.  With a covering index, the
	 ** original table never needs to be accessed.  Automatic indices must
	 ** be a covering index because the index will not be updated if the
	 ** original table changes and the index and table cannot both be used
	 ** if they go out of sync.
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VIEW) {
		extraCols = libc.Uint64FromInt32(-libc.Int32FromInt32(1)) & ^idxCols
	} else {
		extraCols = (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed & (^idxCols | libc.Uint64FromInt32(1)<<(libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1)))
	}
	if !((*TTable)(unsafe.Pointer(pTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
		/* For WITHOUT ROWID tables, ensure that all PRIMARY KEY columns are
		 ** either in the idxCols mask or in the extraCols mask */
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTable)).FnCol)) {
				break
			}
			if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTable)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_PRIMKEY) == 0 {
				goto _5
			}
			if i >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
				extraCols = extraCols | libc.Uint64FromInt32(1)<<(libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1))
				break
			}
			if idxCols&(libc.Uint64FromInt32(1)<<i) != 0 {
				goto _5
			}
			extraCols = extraCols | libc.Uint64FromInt32(1)<<i
			goto _5
		_5:
			;
			i = i + 1
		}
	}
	if libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) < int32((*TTable)(unsafe.Pointer(pTable)).FnCol) {
		v3 = libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1)
	} else {
		v3 = int32((*TTable)(unsafe.Pointer(pTable)).FnCol)
	}
	mxBitCol = v3
	i = 0
	for {
		if !(i < mxBitCol) {
			break
		}
		if extraCols&(libc.Uint64FromInt32(1)<<i) != 0 {
			nKeyCol = nKeyCol + 1
		}
		goto _7
	_7:
		;
		i = i + 1
	}
	if (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(libc.Uint64FromInt32(1)<<(libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1))) != 0 {
		nKeyCol = nKeyCol + (int32((*TTable)(unsafe.Pointer(pTable)).FnCol) - libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) + int32(1))
	}
	/* Construct the Index object to describe this index */
	/* ^-- This guarantees that the number of index columns will fit in the u16 */
	pIdx = _sqlite3AllocateIndexObject(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nKeyCol+libc.BoolInt32((*TTable)(unsafe.Pointer(pTable)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)), 0, bp)
	if pIdx == uintptr(0) {
		goto end_auto_index_create
	}
	(*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pLoop + 24))).FpIndex = pIdx
	(*TIndex)(unsafe.Pointer(pIdx)).FzName = __ccgo_ts + 24014
	(*TIndex)(unsafe.Pointer(pIdx)).FpTable = pTable
	n = 0
	idxCols = uint64(0)
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	for {
		if !(pTerm < pWCEnd) {
			break
		}
		if _termCanDriveIndex(tls, pTerm, pSrc, notReady) != 0 {
			iCol1 = (*(*struct {
				FleftColumn int32
				FiField     int32
			})(unsafe.Pointer(pTerm + 32))).FleftColumn
			if iCol1 >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
				v2 = libc.Uint64FromInt32(1) << (libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1))
			} else {
				v2 = libc.Uint64FromInt32(1) << iCol1
			}
			cMask1 = v2
			if idxCols&cMask1 == uint64(0) {
				pX = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
				idxCols = idxCols | cMask1
				**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16((*(*struct {
					FleftColumn int32
					FiField     int32
				})(unsafe.Pointer(pTerm + 32))).FleftColumn)
				pColl = _sqlite3ExprCompareCollSeq(tls, pParse, pX)
				/* TH3 collate01.800 */
				if pColl != 0 {
					v10 = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
				} else {
					v10 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
				}
				**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = v10
				n = n + 1
				if (*TExpr)(unsafe.Pointer(pX)).FpLeft != uintptr(0) && libc.Int32FromUint8(_sqlite3ExprAffinity(tls, (*TExpr)(unsafe.Pointer(pX)).FpLeft)) != int32(SQLITE_AFF_TEXT) {
					/* TUNING: only use a Bloom filter on an automatic index
					 ** if one or more key columns has the ability to hold numeric
					 ** values, since strings all have the same hash in the Bloom
					 ** filter implementation and hence a Bloom filter on a text column
					 ** is not usually helpful. */
					useBloomFilter = uint8(1)
				}
			}
		}
		goto _8
	_8:
		;
		pTerm += 56
	}
	/* Add additional columns needed to make the automatic index into
	 ** a covering index */
	i = 0
	for {
		if !(i < mxBitCol) {
			break
		}
		if extraCols&(libc.Uint64FromInt32(1)<<i) != 0 {
			**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(i)
			**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
			n = n + 1
		}
		goto _11
	_11:
		;
		i = i + 1
	}
	if (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(libc.Uint64FromInt32(1)<<(libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1))) != 0 {
		i = libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1)
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTable)).FnCol)) {
				break
			}
			**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(i)
			**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
			n = n + 1
			goto _12
		_12:
			;
			i = i + 1
		}
	}
	if (*TTable)(unsafe.Pointer(pTable)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(-libc.Int32FromInt32(1))
		**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
	}
	/* Create the automatic index */
	v10 = pParse + 56
	v3 = *(*int32)(unsafe.Pointer(v10))
	*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = v3
	_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenAutoindex), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, nKeyCol+int32(1))
	_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) && useBloomFilter != 0 {
		_sqlite3WhereExplainBloomFilter(tls, pParse, (*TWhereClause)(unsafe.Pointer(pWC)).FpWInfo, pLevel)
		v10 = pParse + 60
		*(*int32)(unsafe.Pointer(v10)) = *(*int32)(unsafe.Pointer(v10)) + 1
		v3 = *(*int32)(unsafe.Pointer(v10))
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter = v3
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(10000), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter)
	}
	/* Fill the automatic index with content */
	if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000000>>25) != 0 {
		pSubq = *(*uintptr)(unsafe.Pointer(pSrc + 72))
		regYield = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
		addrCounter = _sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, 0)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
		addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), regYield)
	} else {
		addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt)
	}
	if pPartial != 0 {
		iContinue = _sqlite3VdbeMakeLabel(tls, pParse)
		_sqlite3ExprIfFalse(tls, pParse, pPartial, iContinue, int32(SQLITE_JUMPIFNULL))
		**(**Tu32)(__ccgo_up(pLoop + 48)) |= uint32(WHERE_PARTIALIDX)
	}
	regRecord = _sqlite3GetTempReg(tls, pParse)
	regBase = _sqlite3GenerateIndexKey(tls, pParse, pIdx, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, regRecord, 0, uintptr(0), uintptr(0), 0)
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0 {
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0, regBase, libc.Int32FromUint16((*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pLoop + 24))).FnEq))
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, regRecord)
	_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
	if pPartial != 0 {
		_sqlite3VdbeResolveLabel(tls, v, iContinue)
	}
	if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000000>>25) != 0 {
		_sqlite3VdbeChangeP2(tls, v, addrCounter, regBase+n)
		_translateColumnToCopy(tls, pParse, addrTop, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 72)))).FregResult, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
		_sqlite3VdbeGoto(tls, v, addrTop)
		libc.SetBitFieldPtr32Uint32(pSrc+24+4, libc.Uint32FromInt32(0), 25, 0x2000000)
		_sqlite3VdbeJumpHere(tls, v, addrTop)
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, addrTop+int32(1))
		_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_STMTSTATUS_AUTOINDEX))
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
			_sqlite3VdbeJumpHere(tls, v, addrTop)
		}
	}
	_sqlite3ReleaseTempReg(tls, pParse, regRecord)
	/* Jump here when skipping the initialization */
	_sqlite3VdbeJumpHere(tls, v, addrInit)
	goto end_auto_index_create
end_auto_index_create:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPartial)
}

// C documentation
//
//	/*
//	** This routine runs at the end of parsing a CREATE TABLE statement that
//	** has a WITHOUT ROWID clause.  The job of this routine is to convert both
//	** internal schema data structures and the generated VDBE code so that they
//	** are appropriate for a WITHOUT ROWID table instead of a rowid table.
//	** Changes include:
//	**
//	**     (1)  Set all columns of the PRIMARY KEY schema object to be NOT NULL.
//	**     (2)  Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
//	**          into BTREE_BLOBKEY.
//	**     (3)  Bypass the creation of the sqlite_schema table entry
//	**          for the PRIMARY KEY as the primary key index is now
//	**          identified by the sqlite_schema table entry of the table itself.
//	**     (4)  Set the Index.tnum of the PRIMARY KEY Index object in the
//	**          schema to the rootpage from the main table.
//	**     (5)  Add all table columns to the PRIMARY KEY Index object
//	**          so that the PRIMARY KEY is a covering index.  The surplus
//	**          columns are part of KeyInfo.nAllField and are not used for
//	**          sorting or lookup or uniqueness checks.
//	**     (6)  Replace the rowid tail on all automatically generated UNIQUE
//	**          indices with the PRIMARY KEY columns.
//	**
//	** For virtual tables, only (1) is performed.
//	*/
func _convertToWithoutRowidTable(tls *libc.TLS, pParse uintptr, pTab uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pIdx, pList, pPk, v, zColl, v12 uintptr
	var i, j, n, nExtra, nPk, v3 int32
	var v5 Tu16
	var _ /* ipkToken at bp+0 */ TToken
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, j, n, nExtra, nPk, pIdx, pList, pPk, v, zColl, v12, v3, v5
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* Mark every PRIMARY KEY column as NOT NULL (except for imposter tables)
	 */
	if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x60>>5)) != 0) {
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16 + 8))&0xf0>>4)) == OE_None {
				libc.SetBitFieldPtr8Uint32((*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16+8, libc.Uint32FromInt32(OE_Abort), 4, 0xf0)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_HasNotNull)
	}
	/* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
	 ** into BTREE_BLOBKEY.
	 */
	if (*(*struct {
		FaddrCrTab      int32
		FregRowid       int32
		FregRoot        int32
		FconstraintName TToken
	})(unsafe.Pointer(pParse + 256))).FaddrCrTab != 0 {
		_sqlite3VdbeChangeP3(tls, v, (*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FaddrCrTab, int32(BTREE_BLOBKEY))
	}
	/* Locate the PRIMARY KEY index.  Or, if this table was originally
	 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
	 */
	if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
		_sqlite3TokenInit(tls, bp, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TTable)(unsafe.Pointer(pTab)).FiPKey)*16))).FzCnName)
		pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp, 0))
		if pList == uintptr(0) {
			**(**Tu32)(__ccgo_up(pTab + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(TF_WithoutRowid))
			return
		}
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenRemap(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr, pTab+52)
		}
		(*(*TExprList_item)(unsafe.Pointer(pList + 8))).Ffg.FsortFlags = (*TParse)(unsafe.Pointer(pParse)).FiPkSortOrder
		(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
		_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), pList, libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FkeyConf), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_PRIMARYKEY))
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			**(**Tu32)(__ccgo_up(pTab + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(TF_WithoutRowid))
			return
		}
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
	} else {
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		/*
		 ** Remove all redundant columns from the PRIMARY KEY.  For example, change
		 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
		 ** code assumes the PRIMARY KEY contains no repeated columns.
		 */
		v3 = libc.Int32FromInt32(1)
		j = v3
		i = v3
		for {
			if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			if _isDupColumn(tls, pPk, j, pPk, i) != 0 {
				(*TIndex)(unsafe.Pointer(pPk)).FnColumn = (*TIndex)(unsafe.Pointer(pPk)).FnColumn - 1
			} else {
				**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8)) = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8))
				**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j))) = **(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(i)))
				v3 = j
				j = j + 1
				**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(v3)*2)) = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		(*TIndex)(unsafe.Pointer(pPk)).FnKeyCol = libc.Uint16FromInt32(j)
	}
	libc.SetBitFieldPtr16Uint32(pPk+100, libc.Uint32FromInt32(1), 10, 0x400)
	if !(int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x60>>5)) != 0) {
		libc.SetBitFieldPtr16Uint32(pPk+100, libc.Uint32FromInt32(1), 12, 0x1000)
	}
	v5 = (*TIndex)(unsafe.Pointer(pPk)).FnKeyCol
	(*TIndex)(unsafe.Pointer(pPk)).FnColumn = v5
	nPk = libc.Int32FromUint16(v5)
	/* Bypass the creation of the PRIMARY KEY btree and the sqlite_schema
	 ** table entry. This is only required if currently generating VDBE
	 ** code for a CREATE TABLE (not when parsing one as part of reading
	 ** a database schema).  */
	if v != 0 && (*TIndex)(unsafe.Pointer(pPk)).Ftnum > uint32(0) {
		_sqlite3VdbeChangeOpcode(tls, v, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pPk)).Ftnum), uint8(OP_Goto))
	}
	/* The root page of the PRIMARY KEY is the table root page */
	(*TIndex)(unsafe.Pointer(pPk)).Ftnum = (*TTable)(unsafe.Pointer(pTab)).Ftnum
	/* Update the in-memory representation of all UNIQUE indices by converting
	 ** the final rowid column into one or more columns of the PRIMARY KEY.
	 */
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			goto _6
		}
		v3 = libc.Int32FromInt32(0)
		n = v3
		i = v3
		for {
			if !(i < nPk) {
				break
			}
			if !(_isDupColumn(tls, pIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), pPk, i) != 0) {
				n = n + 1
			}
			goto _7
		_7:
			;
			i = i + 1
		}
		if n == 0 {
			/* This index is a superset of the primary key */
			(*TIndex)(unsafe.Pointer(pIdx)).FnColumn = (*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol
			goto _6
		}
		if _resizeIndexObject(tls, pParse, pIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)+n) != 0 {
			return
		}
		i = 0
		j = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		for {
			if !(i < nPk) {
				break
			}
			if !(_isDupColumn(tls, pIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol), pPk, i) != 0) {
				**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)) = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))
				**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*8)) = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8))
				if **(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(i))) != 0 {
					/* See ticket https://sqlite.org/src/info/bba7b69f9849b5bf */
					libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(1), 6, 0x40)
				}
				j = j + 1
			}
			goto _9
		_9:
			;
			i = i + 1
		}
		goto _6
	_6:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	/* Add all table columns to the PRIMARY KEY index
	 */
	nExtra = 0
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if !(_hasColumn(tls, (*TIndex)(unsafe.Pointer(pPk)).FaiColumn, nPk, i) != 0) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
			nExtra = nExtra + 1
		}
		goto _10
	_10:
		;
		i = i + 1
	}
	if _resizeIndexObject(tls, pParse, pPk, nPk+nExtra) != 0 {
		return
	}
	i = 0
	j = nPk
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if !(_hasColumn(tls, (*TIndex)(unsafe.Pointer(pPk)).FaiColumn, j, i) != 0) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
			zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16)
			**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)) = int16(i)
			if zColl != 0 {
				v12 = zColl
			} else {
				v12 = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
			}
			**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8)) = v12
			j = j + 1
		}
		goto _11
	_11:
		;
		i = i + 1
	}
	_recomputeColumnsNotIndexed(tls, pPk)
}

// C documentation
//
//	/*
//	** Attempt to transform a query of the form
//	**
//	**    SELECT count(*) FROM (SELECT x FROM t1 UNION ALL SELECT y FROM t2)
//	**
//	** Into this:
//	**
//	**    SELECT (SELECT count(*) FROM t1)+(SELECT count(*) FROM t2)
//	**
//	** The transformation only works if all of the following are true:
//	**
//	**   *  The subquery is a UNION ALL of two or more terms
//	**   *  The subquery does not have a LIMIT clause
//	**   *  There is no WHERE or GROUP BY or HAVING clauses on the subqueries
//	**   *  The outer query is a simple count(*) with no WHERE clause or other
//	**      extraneous syntax.
//	**   *  None of the subqueries are DISTINCT (forumpost/a860f5fb2e 2025-03-10)
//	**
//	** Return TRUE if the optimization is undertaken.
//	*/
func _countOfViewOptimization(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	var db, pCount, pExpr, pFrom, pPrior, pSub, pTerm, v1 uintptr
	_, _, _, _, _, _, _, _ = db, pCount, pExpr, pFrom, pPrior, pSub, pTerm, v1
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
		return 0
	} /* This is an aggregate */
	if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr != int32(1) {
		return 0
	} /* Single result column */
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != 0 {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(p)).FpHaving != 0 {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(p)).FpGroupBy != 0 {
		return 0
	}
	if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
		return 0
	}
	pExpr = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8))).FpExpr
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_AGG_FUNCTION) {
		return 0
	} /* Result is an aggregate */
	if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), __ccgo_ts+17120) != 0 {
		return 0
	} /* Is count() */
	if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != uintptr(0) {
		return 0
	} /* Must be count(*) */
	if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc != int32(1) {
		return 0
	} /* One table in FROM  */
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		return 0
	} /* Not a window function */
	pFrom = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x20000000>>29) == 0 {
		return 0
	} /* FROM is a subquery */
	pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
	if (*TSelect)(unsafe.Pointer(pSub)).FpPrior == uintptr(0) {
		return 0
	} /* Must be a compound */
	if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_CopyCte) != 0 {
		return 0
	} /* Not a CTE */
	for cond := true; cond; cond = pSub != 0 {
		if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSub)).Fop) != int32(TK_ALL) && (*TSelect)(unsafe.Pointer(pSub)).FpPrior != 0 {
			return 0
		} /* Must be UNION ALL */
		if (*TSelect)(unsafe.Pointer(pSub)).FpWhere != 0 {
			return 0
		} /* No WHERE clause */
		if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
			return 0
		} /* No LIMIT clause */
		if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Aggregate)|libc.Int32FromInt32(SF_Distinct)) != 0 {
			return 0 /* Not an aggregate nor DISTINCT */
		}
		/* Due to the previous */
		pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior /* Repeat over compound */
	}
	/* If we reach this point then it is OK to perform the transformation */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pCount = pExpr
	pExpr = uintptr(0)
	pSub = _sqlite3SubqueryDetach(tls, db, pFrom)
	_sqlite3SrcListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpSrc)
	(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt64(80)))
	for pSub != 0 {
		pPrior = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
		(*TSelect)(unsafe.Pointer(pSub)).FpPrior = uintptr(0)
		(*TSelect)(unsafe.Pointer(pSub)).FpNext = uintptr(0)
		**(**Tu32)(__ccgo_up(pSub + 4)) |= uint32(SF_Aggregate)
		**(**Tu32)(__ccgo_up(pSub + 4)) &= ^libc.Uint32FromInt32(SF_Compound)
		(*TSelect)(unsafe.Pointer(pSub)).FnSelectRow = 0
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(pSub)).FpEList)
		if pPrior != 0 {
			v1 = _sqlite3ExprDup(tls, db, pCount, 0)
		} else {
			v1 = pCount
		}
		pTerm = v1
		(*TSelect)(unsafe.Pointer(pSub)).FpEList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), pTerm)
		pTerm = _sqlite3PExpr(tls, pParse, int32(TK_SELECT), uintptr(0), uintptr(0))
		_sqlite3PExprAddSelect(tls, pParse, pTerm, pSub)
		if pExpr == uintptr(0) {
			pExpr = pTerm
		} else {
			pExpr = _sqlite3PExpr(tls, pParse, int32(TK_PLUS), pTerm, pExpr)
		}
		pSub = pPrior
	}
	(*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8))).FpExpr = pExpr
	**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Aggregate)
	return int32(1)
}

// C documentation
//
//	/*
//	** Create a new collating function for database "db".  The name is zName
//	** and the encoding is enc.
//	*/
func _createCollation(tls *libc.TLS, db uintptr, zName uintptr, enc Tu8, pCtx uintptr, __ccgo_fp_xCompare uintptr, __ccgo_fp_xDel uintptr) (r int32) {
	var aColl, p, pColl uintptr
	var enc2, j int32
	_, _, _, _, _ = aColl, enc2, j, p, pColl
	/* If SQLITE_UTF16 is specified as the encoding type, transform this
	 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
	 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
	 */
	enc2 = libc.Int32FromUint8(enc)
	if enc2 == int32(SQLITE_UTF16) || enc2 == int32(SQLITE_UTF16_ALIGNED) {
		enc2 = int32(SQLITE_UTF16BE)
	}
	if enc2 < int32(SQLITE_UTF8) || enc2 > int32(SQLITE_UTF16BE) {
		return _sqlite3MisuseError(tls, int32(190273))
	}
	/* Check if this call is removing or replacing an existing collation
	 ** sequence. If so, and there are active VMs, return busy. If there
	 ** are no active VMs, invalidate any pre-compiled statements.
	 */
	pColl = _sqlite3FindCollSeq(tls, db, libc.Uint8FromInt32(enc2), zName, 0)
	if pColl != 0 && (*TCollSeq)(unsafe.Pointer(pColl)).FxCmp != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+26050, 0)
			return int32(SQLITE_BUSY)
		}
		_sqlite3ExpirePreparedStatements(tls, db, 0)
		/* If collation sequence pColl was created directly by a call to
		 ** sqlite3_create_collation, and not generated by synthCollSeq(),
		 ** then any copies made by synthCollSeq() need to be invalidated.
		 ** Also, collation destructor - CollSeq.xDel() - function may need
		 ** to be called.
		 */
		if libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) & ^libc.Int32FromInt32(SQLITE_UTF16_ALIGNED) == enc2 {
			aColl = _sqlite3HashFind(tls, db+648, zName)
			j = 0
			for {
				if !(j < int32(3)) {
					break
				}
				p = aColl + uintptr(j)*40
				if libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(p)).Fenc) == libc.Int32FromUint8((*TCollSeq)(unsafe.Pointer(pColl)).Fenc) {
					if (*TCollSeq)(unsafe.Pointer(p)).FxDel != 0 {
						(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TCollSeq)(unsafe.Pointer(p)).FxDel})))(tls, (*TCollSeq)(unsafe.Pointer(p)).FpUser)
					}
					(*TCollSeq)(unsafe.Pointer(p)).FxCmp = uintptr(0)
				}
				goto _1
			_1:
				;
				j = j + 1
			}
		}
	}
	pColl = _sqlite3FindCollSeq(tls, db, libc.Uint8FromInt32(enc2), zName, int32(1))
	if pColl == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp = __ccgo_fp_xCompare
	(*TCollSeq)(unsafe.Pointer(pColl)).FpUser = pCtx
	(*TCollSeq)(unsafe.Pointer(pColl)).FxDel = __ccgo_fp_xDel
	(*TCollSeq)(unsafe.Pointer(pColl)).Fenc = libc.Uint8FromInt32(enc2 | libc.Int32FromUint8(enc)&libc.Int32FromInt32(SQLITE_UTF16_ALIGNED))
	_sqlite3Error(tls, db, SQLITE_OK)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Put the DateTime object into its error state.
//	*/
func _datetimeError(tls *libc.TLS, p uintptr) {
	libc.Xmemset(tls, p, 0, uint64(48))
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 6, 0x40)
}

// C documentation
//
//	/*
//	**    datetime( TIMESTRING, MOD, MOD, ...)
//	**
//	** Return YYYY-MM-DD HH:MM:SS
//	*/
func _datetimeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var Y, n, s int32
	var _ /* x at bp+0 */ TDateTime
	var _ /* zBuf at bp+48 */ [32]uint8
	_, _, _ = Y, n, s
	if _isDate(tls, context, argc, argv, bp) == 0 {
		_computeYMD_HMS(tls, bp)
		Y = (**(**TDateTime)(__ccgo_up(bp))).FY
		if Y < 0 {
			Y = -Y
		}
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(1)] = libc.Uint8FromInt32(int32('0') + Y/int32(1000)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(2)] = libc.Uint8FromInt32(int32('0') + Y/int32(100)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(3)] = libc.Uint8FromInt32(int32('0') + Y/int32(10)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(4)] = libc.Uint8FromInt32(int32('0') + Y%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(5)] = uint8('-')
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(6)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).FM/int32(10)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(7)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).FM%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(8)] = uint8('-')
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(9)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).FD/int32(10)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(10)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).FD%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(11)] = uint8(' ')
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(12)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fh/int32(10)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(13)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fh%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(14)] = uint8(':')
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(15)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fm/int32(10)%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(16)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fm%int32(10))
		(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(17)] = uint8(':')
		if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x20>>5)) != 0 {
			s = int32(float64(libc.Float64FromFloat64(1000)*(**(**TDateTime)(__ccgo_up(bp))).Fs) + libc.Float64FromFloat64(0.5))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(18)] = libc.Uint8FromInt32(int32('0') + s/int32(10000)%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(19)] = libc.Uint8FromInt32(int32('0') + s/int32(1000)%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(20)] = uint8('.')
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(21)] = libc.Uint8FromInt32(int32('0') + s/int32(100)%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(22)] = libc.Uint8FromInt32(int32('0') + s/int32(10)%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(23)] = libc.Uint8FromInt32(int32('0') + s%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(24)] = uint8(0)
			n = int32(24)
		} else {
			s = int32((**(**TDateTime)(__ccgo_up(bp))).Fs)
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(18)] = libc.Uint8FromInt32(int32('0') + s/int32(10)%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(19)] = libc.Uint8FromInt32(int32('0') + s%int32(10))
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[int32(20)] = uint8(0)
			n = int32(20)
		}
		if (**(**TDateTime)(__ccgo_up(bp))).FY < 0 {
			(**(**[32]uint8)(__ccgo_up(bp + 48)))[0] = uint8('-')
			Xsqlite3_result_text(tls, context, bp+48, n, uintptr(-libc.Int32FromInt32(1)))
		} else {
			Xsqlite3_result_text(tls, context, bp+48+1, n-int32(1), uintptr(-libc.Int32FromInt32(1)))
		}
	}
}

// C documentation
//
//	/*
//	** The first argument points to a nul-terminated string containing a
//	** list of space separated integers. Read the first nOut of these into
//	** the array aOut[].
//	*/
func _decodeIntArray(tls *libc.TLS, zIntArray uintptr, nOut int32, aOut uintptr, aLog uintptr, pIndex uintptr) {
	var c, i, sz, v2 int32
	var v TtRowcnt
	var z uintptr
	_, _, _, _, _, _ = c, i, sz, v, z, v2
	z = zIntArray
	if z == uintptr(0) {
		z = __ccgo_ts + 1704
	}
	i = 0
	for {
		if !(**(**uint8)(__ccgo_up(z)) != 0 && i < nOut) {
			break
		}
		v = uint64(0)
		for {
			v2 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(z)))
			c = v2
			if !(v2 >= int32('0') && c <= int32('9')) {
				break
			}
			v = v*uint64(10) + libc.Uint64FromInt32(c) - uint64('0')
			z = z + 1
		}
		if aOut != 0 {
			**(**TtRowcnt)(__ccgo_up(aOut + uintptr(i)*8)) = v
		}
		if aLog != 0 {
			**(**TLogEst)(__ccgo_up(aLog + uintptr(i)*2)) = _sqlite3LogEst(tls, v)
		}
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z))) == int32(' ') {
			z = z + 1
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if pIndex != 0 {
		libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 13, 0x2000)
		libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 9, 0x200)
		for **(**uint8)(__ccgo_up(z)) != 0 {
			if Xsqlite3_strglob(tls, __ccgo_ts+13056, z) == 0 {
				libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 13, 0x2000)
			} else {
				if Xsqlite3_strglob(tls, __ccgo_ts+13067, z) == 0 {
					sz = _sqlite3Atoi(tls, z+uintptr(3))
					if sz < int32(2) {
						sz = int32(2)
					}
					(*TIndex)(unsafe.Pointer(pIndex)).FszIdxRow = _sqlite3LogEst(tls, libc.Uint64FromInt32(sz))
				} else {
					if Xsqlite3_strglob(tls, __ccgo_ts+13077, z) == 0 {
						libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 9, 0x200)
					}
				}
			}
			for libc.Int32FromUint8(**(**uint8)(__ccgo_up(z))) != 0 && libc.Int32FromUint8(**(**uint8)(__ccgo_up(z))) != int32(' ') {
				z = z + 1
			}
			for libc.Int32FromUint8(**(**uint8)(__ccgo_up(z))) == int32(' ') {
				z = z + 1
			}
		}
	}
}

// C documentation
//
//	/*
//	** Check to see if a subquery contains result-set columns that are
//	** never used.  If it does, change the value of those result-set columns
//	** to NULL so that they do not cause unnecessary work to compute.
//	**
//	** Return the number of column that were changed to NULL.
//	*/
func _disableUnusedSubqueryResultColumns(tls *libc.TLS, pItem uintptr) (r int32) {
	var colUsed, m TBitmask
	var iCol Tu16
	var j, nChng, nCol, v3 int32
	var pList, pSub, pTab, pX, pY uintptr
	var v5 uint64
	_, _, _, _, _, _, _, _, _, _, _, _, _ = colUsed, iCol, j, m, nChng, nCol, pList, pSub, pTab, pX, pY, v3, v5 /* Column number */
	nChng = 0                                                                                                   /* Columns that may not be NULLed out */
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8000000>>27) != 0 || int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x400000>>22) != 0 {
		return 0
	}
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
	pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
	pX = pSub
	for {
		if !(pX != 0) {
			break
		}
		if (*TSelect)(unsafe.Pointer(pX)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) != uint32(0) {
			return 0
		}
		if (*TSelect)(unsafe.Pointer(pX)).FpPrior != 0 && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pX)).Fop) != int32(TK_ALL) {
			/* This optimization does not work for compound subqueries that
			 ** use UNION, INTERSECT, or EXCEPT.  Only UNION ALL is allowed. */
			return 0
		}
		if (*TSelect)(unsafe.Pointer(pX)).FpWin != 0 {
			/* This optimization does not work for subqueries that use window
			 ** functions. */
			return 0
		}
		goto _1
	_1:
		;
		pX = (*TSelect)(unsafe.Pointer(pX)).FpPrior
	}
	colUsed = (*TSrcItem)(unsafe.Pointer(pItem)).FcolUsed
	if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
		pList = (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy
		j = 0
		for {
			if !(j < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			iCol = *(*Tu16)(unsafe.Pointer(pList + 8 + uintptr(j)*32 + 24))
			if libc.Int32FromUint16(iCol) > 0 {
				iCol = iCol - 1
				if libc.Int32FromUint16(iCol) >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
					v3 = libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1)
				} else {
					v3 = libc.Int32FromUint16(iCol)
				}
				colUsed = colUsed | libc.Uint64FromInt32(1)<<v3
			}
			goto _2
		_2:
			;
			j = j + 1
		}
	}
	nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	j = 0
	for {
		if !(j < nCol) {
			break
		}
		if j < libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
			v5 = libc.Uint64FromInt32(1) << j
		} else {
			v5 = libc.Uint64FromInt32(1) << (libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) - libc.Int32FromInt32(1))
		}
		m = v5
		if m&colUsed != uint64(0) {
			goto _4
		}
		pX = pSub
		for {
			if !(pX != 0) {
				break
			}
			pY = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pX)).FpEList + 8 + uintptr(j)*32))).FpExpr
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pY)).Fop) == int32(TK_NULL) {
				goto _6
			}
			(*TExpr)(unsafe.Pointer(pY)).Fop = uint8(TK_NULL)
			**(**Tu32)(__ccgo_up(pY + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_Skip) | libc.Int32FromInt32(EP_Unlikely))
			**(**Tu32)(__ccgo_up(pX + 4)) |= uint32(SF_PushDown)
			nChng = nChng + 1
			goto _6
		_6:
			;
			pX = (*TSelect)(unsafe.Pointer(pX)).FpPrior
		}
		goto _4
	_4:
		;
		j = j + 1
	}
	return nChng
}

// C documentation
//
//	/*
//	** Argument pWhere is the WHERE clause belonging to SELECT statement p. This
//	** function attempts to transform expressions of the form:
//	**
//	**     EXISTS (SELECT ...)
//	**
//	** into joins. For example, given
//	**
//	**    CREATE TABLE sailors(sid INTEGER PRIMARY KEY, name TEXT);
//	**    CREATE TABLE reserves(sid INT, day DATE, PRIMARY KEY(sid, day));
//	**
//	**    SELECT name FROM sailors AS S WHERE EXISTS (
//	**      SELECT * FROM reserves AS R WHERE S.sid = R.sid AND R.day = '2022-10-25'
//	**    );
//	**
//	** the SELECT statement may be transformed as follows:
//	**
//	**    SELECT name FROM sailors AS S, reserves AS R
//	**      WHERE S.sid = R.sid AND R.day = '2022-10-25';
//	**
//	** **Approximately**.  Really, we have to ensure that the FROM-clause term
//	** that was formerly inside the EXISTS is only executed once.  This is handled
//	** by setting the SrcItem.fg.fromExists flag, which then causes code in
//	** the where.c file to exit the corresponding loop after the first successful
//	** match (if any).
//	*/
func _existsToJoin(tls *libc.TLS, pParse uintptr, p uintptr, pWhere uintptr) {
	var aCsrMap, db, pRight, pSub, pSubWhere uintptr
	_, _, _, _, _ = aCsrMap, db, pRight, pSub, pSubWhere
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 && pWhere != uintptr(0) && !((*TExpr)(unsafe.Pointer(pWhere)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != libc.Uint32FromInt32(0)) && (*TSelect)(unsafe.Pointer(p)).FpSrc != uintptr(0) && (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc < libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) && ((*TSelect)(unsafe.Pointer(p)).FpLimit == uintptr(0) || (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpLimit)).FpRight == uintptr(0)) {
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pWhere)).Fop) == int32(TK_AND) {
			pRight = (*TExpr)(unsafe.Pointer(pWhere)).FpRight
			_existsToJoin(tls, pParse, p, (*TExpr)(unsafe.Pointer(pWhere)).FpLeft)
			_existsToJoin(tls, pParse, p, pRight)
		} else {
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pWhere)).Fop) == int32(TK_EXISTS) {
				pSub = *(*uintptr)(unsafe.Pointer(pWhere + 32))
				pSubWhere = (*TSelect)(unsafe.Pointer(pSub)).FpWhere
				if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpSrc)).FnSrc == int32(1) && (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_Aggregate) == uint32(0) && !(int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpSrc + 8 + 24 + 4))&0x20000000>>29) != 0) && (*TSelect)(unsafe.Pointer(pSub)).FpLimit == uintptr(0) && (*TSelect)(unsafe.Pointer(pSub)).FpPrior == uintptr(0) {
					/* Before combining the sub-select with the parent, renumber the
					 ** cursor used by the subselect. This is because the EXISTS expression
					 ** might be a copy of another EXISTS expression from somewhere
					 ** else in the tree, and in this case it is important that it use
					 ** a unique cursor number.  */
					db = (*TParse)(unsafe.Pointer(pParse)).Fdb
					aCsrMap = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt32((*TParse)(unsafe.Pointer(pParse)).FnTab+libc.Int32FromInt32(2))*uint64(4)))
					if aCsrMap == uintptr(0) {
						return
					}
					**(**int32)(__ccgo_up(aCsrMap)) = (*TParse)(unsafe.Pointer(pParse)).FnTab + int32(1)
					_renumberCursors(tls, pParse, pSub, -int32(1), aCsrMap)
					_sqlite3DbFree(tls, db, aCsrMap)
					libc.Xmemset(tls, pWhere, 0, uint64(72))
					(*TExpr)(unsafe.Pointer(pWhere)).Fop = uint8(TK_INTEGER)
					*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pWhere)).Fu)) = int32(1)
					**(**Tu32)(__ccgo_up(pWhere + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue))
					libc.SetBitFieldPtr32Uint32((*TSelect)(unsafe.Pointer(pSub)).FpSrc+8+24+4, libc.Uint32FromInt32(1), 13, 0x2000)
					(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3SrcListAppendList(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpSrc, (*TSelect)(unsafe.Pointer(pSub)).FpSrc)
					if pSubWhere != 0 {
						(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3PExpr(tls, pParse, int32(TK_AND), (*TSelect)(unsafe.Pointer(p)).FpWhere, pSubWhere)
						(*TSelect)(unsafe.Pointer(pSub)).FpWhere = uintptr(0)
					}
					(*TSelect)(unsafe.Pointer(pSub)).FpSrc = uintptr(0)
					_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3SelectDeleteGeneric), pSub)
				}
			}
		}
	}
}

// C documentation
//
//	/*
//	** Add a single OP_Explain instruction to the VDBE to explain a simple
//	** count(*) query ("SELECT count(*) FROM pTab").
//	*/
func _explainSimpleCount(tls *libc.TLS, pParse uintptr, pTab uintptr, pIdx uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bCover int32
	var v1, v2 uintptr
	_, _, _ = bCover, v1, v2
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fexplain) == int32(2) {
		bCover = libc.BoolInt32(pIdx != uintptr(0) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))))
		if bCover != 0 {
			v1 = __ccgo_ts + 21529
		} else {
			v1 = __ccgo_ts + 1704
		}
		if bCover != 0 {
			v2 = (*TIndex)(unsafe.Pointer(pIdx)).FzName
		} else {
			v2 = __ccgo_ts + 1704
		}
		_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+21552, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, v1, v2))
	}
}

// C documentation
//
//	/*
//	** Recursively walk the expressions of a SELECT statement and generate
//	** a bitmask indicating which tables are used in that expression
//	** tree.
//	*/
func _exprSelectUsage(tls *libc.TLS, pMaskSet uintptr, pS uintptr) (r TBitmask) {
	var i int32
	var mask TBitmask
	var pSrc uintptr
	_, _, _ = i, mask, pSrc
	mask = uint64(0)
	for pS != 0 {
		pSrc = (*TSelect)(unsafe.Pointer(pS)).FpSrc
		mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpEList)
		mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpGroupBy)
		mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpOrderBy)
		mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpWhere)
		mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpHaving)
		if pSrc != uintptr(0) {
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x20000000>>29) != 0 {
					mask = mask | _exprSelectUsage(tls, pMaskSet, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 72)))).FpSelect)
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x100000>>20) == 0 {
					mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 64)))
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x10000000>>28) != 0 {
					mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 48)))
				}
				goto _1
			_1:
				;
				i = i + 1
			}
		}
		pS = (*TSelect)(unsafe.Pointer(pS)).FpPrior
	}
	return mask
}

// C documentation
//
//	/*
//	** Select callback used by sqlite3FixAAAA() routines.
//	*/
func _fixSelectCb(tls *libc.TLS, p uintptr, pSelect uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pFix, pItem, pList uintptr
	var i, iDb int32
	_, _, _, _, _, _ = db, i, iDb, pFix, pItem, pList
	pFix = *(*uintptr)(unsafe.Pointer(p + 40))
	db = (*TParse)(unsafe.Pointer((*TDbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb
	iDb = _sqlite3FindDbName(tls, db, (*TDbFixer)(unsafe.Pointer(pFix)).FzDb)
	pList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	if pList == uintptr(0) {
		return WRC_Continue
	}
	i = 0
	pItem = pList + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
			break
		}
		if libc.Int32FromUint8((*TDbFixer)(unsafe.Pointer(pFix)).FbTemp) == 0 && int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) == 0 {
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8000>>15) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
				if iDb != _sqlite3FindDbName(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72))) {
					_sqlite3ErrorMsg(tls, (*TDbFixer)(unsafe.Pointer(pFix)).FpParse, __ccgo_ts+13567, libc.VaList(bp+8, (*TDbFixer)(unsafe.Pointer(pFix)).FzType, (*TDbFixer)(unsafe.Pointer(pFix)).FpName, *(*uintptr)(unsafe.Pointer(pItem + 72))))
					return int32(WRC_Abort)
				}
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 21, 0x200000)
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 14, 0x4000)
			}
			*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*TDbFixer)(unsafe.Pointer(pFix)).FpSchema
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 23, 0x800000)
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 15, 0x8000)
		}
		if int32(*(*uint32)(unsafe.Pointer(pList + 8 + uintptr(i)*80 + 24 + 4))&0x100000>>20) == 0 && _sqlite3WalkExpr(tls, pFix+8, *(*uintptr)(unsafe.Pointer(pList + 8 + uintptr(i)*80 + 64))) != 0 {
			return int32(WRC_Abort)
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 80
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FpWith != 0 {
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpWith)).FnCte) {
				break
			}
			if _sqlite3WalkSelect(tls, p, (*(*TCte)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpWith + 16 + uintptr(i)*48))).FpSelect) != 0 {
				return int32(WRC_Abort)
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This function is called when an UPDATE or DELETE operation is being
//	** compiled on table pTab, which is the parent table of foreign-key pFKey.
//	** If the current operation is an UPDATE, then the pChanges parameter is
//	** passed a pointer to the list of columns being modified. If it is a
//	** DELETE, pChanges is passed a NULL pointer.
//	**
//	** It returns a pointer to a Trigger structure containing a trigger
//	** equivalent to the ON UPDATE or ON DELETE action specified by pFKey.
//	** If the action is "NO ACTION" then a NULL pointer is returned (these actions
//	** require no special handling by the triggers sub-system, code for them is
//	** created by fkScanChildren()).
//	**
//	** For example, if pFKey is the foreign key and pTab is table "p" in
//	** the following schema:
//	**
//	**   CREATE TABLE p(pk PRIMARY KEY);
//	**   CREATE TABLE c(ck REFERENCES p ON DELETE CASCADE);
//	**
//	** then the returned trigger structure is equivalent to:
//	**
//	**   CREATE TRIGGER ... DELETE ON p BEGIN
//	**     DELETE FROM c WHERE ck = old.pk;
//	**   END;
//	**
//	** The returned pointer is cached as part of the foreign key object. It
//	** is eventually freed along with the rest of the foreign key object by
//	** sqlite3FkDelete().
//	*/
func _fkActionTrigger(tls *libc.TLS, pParse uintptr, pTab uintptr, pFKey uintptr, pChanges uintptr) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var action, i, iAction, iFromCol, nFrom, v2 int32
	var db, pCol, pDflt, pEq, pItem, pItem1, pList, pNew, pRaise, pSelect, pSrc, pStep, pTrigger, pWhen, pWhere, zFrom, v4 uintptr
	var _ /* aiCol at bp+8 */ uintptr
	var _ /* pIdx at bp+0 */ uintptr
	var _ /* tFromCol at bp+48 */ TToken
	var _ /* tNew at bp+32 */ TToken
	var _ /* tOld at bp+16 */ TToken
	var _ /* tToCol at bp+64 */ TToken
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = action, db, i, iAction, iFromCol, nFrom, pCol, pDflt, pEq, pItem, pItem1, pList, pNew, pRaise, pSelect, pSrc, pStep, pTrigger, pWhen, pWhere, zFrom, v2, v4
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb       /* Trigger definition to return */
	iAction = libc.BoolInt32(pChanges != uintptr(0)) /* 1 for UPDATE, 0 for DELETE */
	action = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pFKey + 45 + uintptr(iAction))))
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008))<<libc.Int32FromInt32(32)) != 0 {
		action = OE_None
	}
	if action == int32(OE_Restrict) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
		return uintptr(0)
	}
	pTrigger = **(**uintptr)(__ccgo_up(pFKey + 48 + uintptr(iAction)*8))
	if action != OE_None && !(pTrigger != 0) { /* Length in bytes of zFrom */
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0)     /* Parent key index for this FK */
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* child table cols -> parent key cols */
		pStep = uintptr(0)                            /* First (only) step of trigger program */
		pWhere = uintptr(0)                           /* WHERE clause of trigger step */
		pList = uintptr(0)                            /* Changes list if ON UPDATE CASCADE */
		pSelect = uintptr(0)                          /* Iterator variable */
		pWhen = uintptr(0)                            /* WHEN clause for the trigger */
		if _sqlite3FkLocateIndex(tls, pParse, pTab, pFKey, bp, bp+8) != 0 {
			return uintptr(0)
		}
		i = 0
		for {
			if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
				break
			}
			**(**TToken)(__ccgo_up(bp + 16)) = TToken{
				Fz: __ccgo_ts + 6831,
				Fn: uint32(3),
			} /* Literal "old" token */
			**(**TToken)(__ccgo_up(bp + 32)) = TToken{
				Fz: __ccgo_ts + 6827,
				Fn: uint32(3),
			} /* tFromCol = OLD.tToCol */
			if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
				v2 = **(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 8)) + uintptr(i)*4))
			} else {
				v2 = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).FiFrom
			}
			iFromCol = v2
			if **(**uintptr)(__ccgo_up(bp)) != 0 {
				v2 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaiColumn + uintptr(i)*2)))
			} else {
				v2 = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
			}
			_sqlite3TokenInit(tls, bp+64, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(v2)*16))).FzCnName)
			_sqlite3TokenInit(tls, bp+48, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*16))).FzCnName)
			/* Create the expression "OLD.zToCol = zFromCol". It is important
			 ** that the "OLD.zToCol" term is on the LHS of the = operator, so
			 ** that the affinity and collation sequence associated with the
			 ** parent table are used for the comparison. */
			pEq = _sqlite3PExpr(tls, pParse, int32(TK_EQ), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0)), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+48, 0))
			pWhere = _sqlite3ExprAnd(tls, pParse, pWhere, pEq)
			/* For ON UPDATE, construct the next term of the WHEN clause.
			 ** The final WHEN clause will be like this:
			 **
			 **    WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
			 */
			if pChanges != 0 {
				pEq = _sqlite3PExpr(tls, pParse, int32(TK_IS), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+16, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0)), _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0)))
				pWhen = _sqlite3ExprAnd(tls, pParse, pWhen, pEq)
			}
			if action != int32(OE_Restrict) && (action != int32(OE_Cascade) || pChanges != 0) {
				if action == int32(OE_Cascade) {
					pNew = _sqlite3PExpr(tls, pParse, int32(TK_DOT), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+32, 0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+64, 0))
				} else {
					if action == int32(OE_SetDflt) {
						pCol = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*16
						if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
							pDflt = uintptr(0)
						} else {
							pDflt = _sqlite3ColumnExpr(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, pCol)
						}
						if pDflt != 0 {
							pNew = _sqlite3ExprDup(tls, db, pDflt, 0)
						} else {
							pNew = _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0)
						}
					} else {
						pNew = _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0)
					}
				}
				pList = _sqlite3ExprListAppend(tls, pParse, pList, pNew)
				_sqlite3ExprListSetName(tls, pParse, pList, bp+48, 0)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 8)))
		zFrom = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName
		nFrom = _sqlite3Strlen30(tls, zFrom)
		if action == int32(OE_Restrict) {
			pRaise = _sqlite3Expr(tls, db, int32(TK_STRING), __ccgo_ts+5396)
			pRaise = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), pRaise, uintptr(0))
			if pRaise != 0 {
				(*TExpr)(unsafe.Pointer(pRaise)).FaffExpr = uint8(OE_Abort)
			}
			pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
			if pSrc != 0 {
				pItem = pSrc + 8
				(*TSrcItem)(unsafe.Pointer(pItem)).FzName = _sqlite3DbStrDup(tls, db, zFrom)
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 15, 0x8000)
				*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*TTable)(unsafe.Pointer(pTab)).FpSchema
			}
			pSelect = _sqlite3SelectNew(tls, pParse, _sqlite3ExprListAppend(tls, pParse, uintptr(0), pRaise), pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
			pWhere = uintptr(0)
		}
		/* Disable lookaside memory allocation */
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		pTrigger = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt64(72)+libc.Uint64FromInt64(88)))
		if pTrigger != 0 {
			v4 = pTrigger + 1*72
			(*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list = v4
			pStep = v4
			(*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
			if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
				pItem1 = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8
				(*TSrcItem)(unsafe.Pointer(pItem1)).FzName = _sqlite3DbStrNDup(tls, db, zFrom, libc.Uint64FromInt32(nFrom))
				*(*uintptr)(unsafe.Pointer(pItem1 + 72)) = (*TTable)(unsafe.Pointer(pTab)).FpSchema
				libc.SetBitFieldPtr32Uint32(pItem1+24+4, libc.Uint32FromInt32(1), 15, 0x8000)
			}
			(*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere = _sqlite3ExprDup(tls, db, pWhere, int32(EXPRDUP_REDUCE))
			(*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList = _sqlite3ExprListDup(tls, db, pList, int32(EXPRDUP_REDUCE))
			(*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect = _sqlite3SelectDup(tls, db, pSelect, int32(EXPRDUP_REDUCE))
			if pWhen != 0 {
				pWhen = _sqlite3PExpr(tls, pParse, int32(TK_NOT), pWhen, uintptr(0))
				(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = _sqlite3ExprDup(tls, db, pWhen, int32(EXPRDUP_REDUCE))
			}
		}
		/* Re-enable the lookaside buffer, if it was disabled earlier. */
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable - 1
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v2 = 0
		} else {
			v2 = libc.Int32FromUint16((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = libc.Uint16FromInt32(v2)
		_sqlite3ExprDelete(tls, db, pWhere)
		_sqlite3ExprDelete(tls, db, pWhen)
		_sqlite3ExprListDelete(tls, db, pList)
		_sqlite3SelectDelete(tls, db, pSelect)
		if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == int32(1) {
			_fkTriggerDelete(tls, db, pTrigger)
			return uintptr(0)
		}
		switch action {
		case int32(OE_Restrict):
			(*TTriggerStep)(unsafe.Pointer(pStep)).Fop = uint8(TK_SELECT)
		case int32(OE_Cascade):
			if !(pChanges != 0) {
				(*TTriggerStep)(unsafe.Pointer(pStep)).Fop = uint8(TK_DELETE)
				break
			}
			fallthrough
		default:
			(*TTriggerStep)(unsafe.Pointer(pStep)).Fop = uint8(TK_UPDATE)
		}
		(*TTriggerStep)(unsafe.Pointer(pStep)).FpTrig = pTrigger
		(*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
		(*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
		**(**uintptr)(__ccgo_up(pFKey + 48 + uintptr(iAction)*8)) = pTrigger
		if pChanges != 0 {
			v2 = int32(TK_UPDATE)
		} else {
			v2 = int32(TK_DELETE)
		}
		(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = libc.Uint8FromInt32(v2)
	}
	return pTrigger
}

// C documentation
//
//	/*
//	** This routine attempts to flatten subqueries as a performance optimization.
//	** This routine returns 1 if it makes changes and 0 if no flattening occurs.
//	**
//	** To understand the concept of flattening, consider the following
//	** query:
//	**
//	**     SELECT a FROM (SELECT x+y AS a FROM t1 WHERE z<100) WHERE a>5
//	**
//	** The default way of implementing this query is to execute the
//	** subquery first and store the results in a temporary table, then
//	** run the outer query on that temporary table.  This requires two
//	** passes over the data.  Furthermore, because the temporary table
//	** has no indices, the WHERE clause on the outer query cannot be
//	** optimized.
//	**
//	** This routine attempts to rewrite queries such as the above into
//	** a single flat select, like this:
//	**
//	**     SELECT x+y AS a FROM t1 WHERE z<100 AND a>5
//	**
//	** The code generated for this simplification gives the same result
//	** but only has to scan the data once.  And because indices might
//	** exist on the table t1, a complete scan of the data might be
//	** avoided.
//	**
//	** Flattening is subject to the following constraints:
//	**
//	**  (**)  We no longer attempt to flatten aggregate subqueries. Was:
//	**        The subquery and the outer query cannot both be aggregates.
//	**
//	**  (**)  We no longer attempt to flatten aggregate subqueries. Was:
//	**        (2) If the subquery is an aggregate then
//	**        (2a) the outer query must not be a join and
//	**        (2b) the outer query must not use subqueries
//	**             other than the one FROM-clause subquery that is a candidate
//	**             for flattening.  (This is due to ticket [2f7170d73bf9abf80]
//	**             from 2015-02-09.)
//	**
//	**   (3)  If the subquery is the right operand of a LEFT JOIN then
//	**        (3a) the subquery may not be a join
//	**        (**) Was (3b): "the FROM clause of the subquery may not contain
//	**             a virtual table"
//	**        (**) Was: "The outer query may not have a GROUP BY." This case
//	**             is now managed correctly
//	**        (3d) the outer query may not be DISTINCT.
//	**        See also (26) for restrictions on RIGHT JOIN.
//	**
//	**   (4)  The subquery can not be DISTINCT.
//	**
//	**  (**)  At one point restrictions (4) and (5) defined a subset of DISTINCT
//	**        sub-queries that were excluded from this optimization. Restriction
//	**        (4) has since been expanded to exclude all DISTINCT subqueries.
//	**
//	**  (**)  We no longer attempt to flatten aggregate subqueries.  Was:
//	**        If the subquery is aggregate, the outer query may not be DISTINCT.
//	**
//	**   (7)  The subquery must have a FROM clause.  TODO:  For subqueries without
//	**        A FROM clause, consider adding a FROM clause with the special
//	**        table sqlite_once that consists of a single row containing a
//	**        single NULL.
//	**
//	**   (8)  If the subquery uses LIMIT then the outer query may not be a join.
//	**
//	**   (9)  If the subquery uses LIMIT then the outer query may not be aggregate.
//	**
//	**  (**)  Restriction (10) was removed from the code on 2005-02-05 but we
//	**        accidentally carried the comment forward until 2014-09-15.  Original
//	**        constraint: "If the subquery is aggregate then the outer query
//	**        may not use LIMIT."
//	**
//	**  (11)  The subquery and the outer query may not both have ORDER BY clauses.
//	**
//	**  (**)  Not implemented.  Subsumed into restriction (3).  Was previously
//	**        a separate restriction deriving from ticket #350.
//	**
//	**  (13)  The subquery and outer query may not both use LIMIT.
//	**
//	**  (14)  The subquery may not use OFFSET.
//	**
//	**  (15)  If the outer query is part of a compound select, then the
//	**        subquery may not use LIMIT.
//	**        (See ticket #2339 and ticket [02a8e81d44]).
//	**
//	**  (16)  If the outer query is aggregate, then the subquery may not
//	**        use ORDER BY.  (Ticket #2942)  This used to not matter
//	**        until we introduced the group_concat() function.
//	**
//	**  (17)  If the subquery is a compound select, then
//	**        (17a) all compound operators must be a UNION ALL, and
//	**        (17b) no terms within the subquery compound may be aggregate
//	**              or DISTINCT, and
//	**        (17c) every term within the subquery compound must have a FROM clause
//	**        (17d) the outer query may not be
//	**              (17d1) aggregate, or
//	**              (17d2) DISTINCT
//	**        (17e) the subquery may not contain window functions, and
//	**        (17f) the subquery must not be the RHS of a LEFT JOIN.
//	**        (17g) either the subquery is the first element of the outer
//	**              query or there are no RIGHT or FULL JOINs in any arm
//	**              of the subquery.  (This is a duplicate of condition (27b).)
//	**        (17h) The corresponding result set expressions in all arms of the
//	**              compound must have the same affinity.
//	**
//	**        The parent and sub-query may contain WHERE clauses. Subject to
//	**        rules (11), (13) and (14), they may also contain ORDER BY,
//	**        LIMIT and OFFSET clauses.  The subquery cannot use any compound
//	**        operator other than UNION ALL because all the other compound
//	**        operators have an implied DISTINCT which is disallowed by
//	**        restriction (4).
//	**
//	**        Also, each component of the sub-query must return the same number
//	**        of result columns. This is actually a requirement for any compound
//	**        SELECT statement, but all the code here does is make sure that no
//	**        such (illegal) sub-query is flattened. The caller will detect the
//	**        syntax error and return a detailed message.
//	**
//	**  (18)  If the sub-query is a compound select, then all terms of the
//	**        ORDER BY clause of the parent must be copies of a term returned
//	**        by the parent query.
//	**
//	**  (19)  If the subquery uses LIMIT then the outer query may not
//	**        have a WHERE clause.
//	**
//	**  (20)  If the sub-query is a compound select, then it must not use
//	**        an ORDER BY clause.  Ticket #3773.  We could relax this constraint
//	**        somewhat by saying that the terms of the ORDER BY clause must
//	**        appear as unmodified result columns in the outer query.  But we
//	**        have other optimizations in mind to deal with that case.
//	**
//	**  (21)  If the subquery uses LIMIT then the outer query may not be
//	**        DISTINCT.  (See ticket [752e1646fc]).
//	**
//	**  (22)  The subquery may not be a recursive CTE.
//	**
//	**  (23)  If the outer query is a recursive CTE, then the sub-query may not be
//	**        a compound query.  This restriction is because transforming the
//	**        parent to a compound query confuses the code that handles
//	**        recursive queries in multiSelect().
//	**
//	**  (**)  We no longer attempt to flatten aggregate subqueries.  Was:
//	**        The subquery may not be an aggregate that uses the built-in min() or
//	**        or max() functions.  (Without this restriction, a query like:
//	**        "SELECT x FROM (SELECT max(y), x FROM t1)" would not necessarily
//	**        return the value X for which Y was maximal.)
//	**
//	**  (25)  If either the subquery or the parent query contains a window
//	**        function in the select list or ORDER BY clause, flattening
//	**        is not attempted.
//	**
//	**  (26)  The subquery may not be the right operand of a RIGHT JOIN.
//	**        See also (3) for restrictions on LEFT JOIN.
//	**
//	**  (27)  The subquery may not contain a FULL or RIGHT JOIN unless it
//	**        is the first element of the parent query.  Two subcases:
//	**        (27a) the subquery is not a compound query.
//	**        (27b) the subquery is a compound query and the RIGHT JOIN occurs
//	**              in any arm of the compound query.  (See also (17g).)
//	**
//	**  (28)  The subquery is not a MATERIALIZED CTE.  (This is handled
//	**        in the caller before ever reaching this routine.)
//	**
//	**
//	** In this routine, the "p" parameter is a pointer to the outer query.
//	** The subquery is p->pSrc->a[iFrom].  isAgg is true if the outer query
//	** uses aggregates.
//	**
//	** If flattening is not attempted, this routine is a no-op and returns 0.
//	** If flattening is attempted this routine returns 1.
//	**
//	** All of the expression analysis must occur on both the outer query and
//	** the subquery before this routine runs.
//	*/
func _flattenSubquery(tls *libc.TLS, pParse uintptr, p uintptr, iFrom int32, isAgg int32) (r int32) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var aCsrMap, db, pItem, pItemTab, pLimit, pNew, pOrderBy, pOrderBy1, pParent, pPrior, pSrc, pSub, pSub1, pSubSrc, pSubitem, pTabToDel, pToplevel, pWhere, zSavedAuthContext, v5 uintptr
	var i, iNewParent, iParent, ii, isOuterJoin, nSubSrc, v4 int32
	var jointype Tu8
	var _ /* w at bp+0 */ TWalker
	var _ /* x at bp+48 */ TSubstContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCsrMap, db, i, iNewParent, iParent, ii, isOuterJoin, jointype, nSubSrc, pItem, pItemTab, pLimit, pNew, pOrderBy, pOrderBy1, pParent, pPrior, pSrc, pSub, pSub1, pSubSrc, pSubitem, pTabToDel, pToplevel, pWhere, zSavedAuthContext, v4, v5
	zSavedAuthContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext /* VDBE cursor number of the pSub result set temp table */
	iNewParent = -int32(1)                                              /* Replacement table for iParent */
	isOuterJoin = 0                                                     /* The subquery */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                          /* Walker to persist agginfo data */
	aCsrMap = uintptr(0)
	/* Check to see if flattening is permitted.  Return 0 if not.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_QueryFlattener)) != uint32(0) {
		return 0
	}
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
	pSubitem = pSrc + 8 + uintptr(iFrom)*80
	iParent = (*TSrcItem)(unsafe.Pointer(pSubitem)).FiCursor
	pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSubitem + 72)))).FpSelect
	if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 || (*TSelect)(unsafe.Pointer(pSub)).FpWin != 0 {
		return 0
	} /* Restriction (25) */
	pSubSrc = (*TSelect)(unsafe.Pointer(pSub)).FpSrc
	/* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
	 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
	 ** because they could be computed at compile-time.  But when LIMIT and OFFSET
	 ** became arbitrary expressions, we were forced to add restrictions (13)
	 ** and (14). */
	if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 {
		return 0
	} /* Restriction (13) */
	if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpLimit)).FpRight != 0 {
		return 0
	} /* Restriction (14) */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Compound) != uint32(0) && (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
		return 0 /* Restriction (15) */
	}
	if (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc == 0 {
		return 0
	} /* Restriction (7)  */
	if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_Distinct) != 0 {
		return 0
	} /* Restriction (4)  */
	if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && ((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc > int32(1) || isAgg != 0) {
		return 0 /* Restrictions (8)(9) */
	}
	if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 && (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
		return 0 /* Restriction (11) */
	}
	if isAgg != 0 && (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
		return 0
	} /* Restriction (16) */
	if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TSelect)(unsafe.Pointer(p)).FpWhere != 0 {
		return 0
	} /* Restriction (19) */
	if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) {
		return 0 /* Restriction (21) */
	}
	if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Recursive)) != 0 {
		return 0 /* Restrictions (22) */
	}
	/*
	 ** If the subquery is the right operand of a LEFT JOIN, then the
	 ** subquery may not be a join itself (3a). Example of why this is not
	 ** allowed:
	 **
	 **         t1 LEFT OUTER JOIN (t2 JOIN t3)
	 **
	 ** If we flatten the above, we would get
	 **
	 **         (t1 LEFT OUTER JOIN t2) JOIN t3
	 **
	 ** which is not at all the same thing.
	 **
	 ** See also tickets #306, #350, and #3300.
	 */
	if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
		if (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc > int32(1) || (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
			return 0
		}
		isOuterJoin = int32(1)
	}
	/* True by restriction (7) */
	if iFrom > 0 && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSubSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
		return 0 /* Restriction (27a) */
	}
	/* Condition (28) is blocked by the caller */
	/* Restriction (17): If the sub-query is a compound SELECT, then it must
	 ** use only the UNION ALL operator. And none of the simple select queries
	 ** that make up the compound SELECT are allowed to be aggregate or distinct
	 ** queries.
	 */
	if (*TSelect)(unsafe.Pointer(pSub)).FpPrior != 0 {
		if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
			return 0 /* Restriction (20) */
		}
		if isAgg != 0 || (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0) || isOuterJoin > 0 {
			return 0 /* (17d1), (17d2), or (17f) */
		}
		pSub1 = pSub
		for {
			if !(pSub1 != 0) {
				break
			}
			if (*TSelect)(unsafe.Pointer(pSub1)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) != uint32(0) || (*TSelect)(unsafe.Pointer(pSub1)).FpPrior != 0 && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSub1)).Fop) != int32(TK_ALL) || (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub1)).FpSrc)).FnSrc < int32(1) || (*TSelect)(unsafe.Pointer(pSub1)).FpWin != 0 {
				return 0
			}
			if iFrom > 0 && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub1)).FpSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
				/* Without this restriction, the JT_LTORJ flag would end up being
				 ** omitted on left-hand tables of the right join that is being
				 ** flattened. */
				return 0 /* Restrictions (17g), (27b) */
			}
			goto _1
		_1:
			;
			pSub1 = (*TSelect)(unsafe.Pointer(pSub1)).FpPrior
		}
		/* Restriction (18). */
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
			ii = 0
			for {
				if !(ii < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy)).FnExpr) {
					break
				}
				if libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy + 8 + uintptr(ii)*32 + 24))) == 0 {
					return 0
				}
				goto _2
			_2:
				;
				ii = ii + 1
			}
		}
		/* Restriction (23) */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Recursive) != 0 {
			return 0
		}
		/* Restriction (17h) */
		if _compoundHasDifferentAffinities(tls, pSub) != 0 {
			return 0
		}
		if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc > int32(1) {
			if (*TParse)(unsafe.Pointer(pParse)).FnSelect > int32(500) {
				return 0
			}
			if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FlttnUnionAll)) != uint32(0) {
				return 0
			}
			aCsrMap = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(int64((*TParse)(unsafe.Pointer(pParse)).FnTab)+libc.Int64FromInt32(1))*uint64(4))
			if aCsrMap != 0 {
				**(**int32)(__ccgo_up(aCsrMap)) = (*TParse)(unsafe.Pointer(pParse)).FnTab
			}
		}
	}
	/***** If we reach this point, flattening is permitted. *****/
	/* Authorize the subquery */
	(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pSubitem)).FzName
	_sqlite3AuthCheck(tls, pParse, int32(SQLITE_SELECT), uintptr(0), uintptr(0), uintptr(0))
	(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext
	/* Delete the transient structures associated with the subquery */
	if int32(*(*uint32)(unsafe.Pointer(pSubitem + 24 + 4))&0x20000000>>29) != 0 {
		pSub1 = _sqlite3SubqueryDetach(tls, db, pSubitem)
	} else {
		pSub1 = uintptr(0)
	}
	_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzName)
	_sqlite3DbFree(tls, db, (*TSrcItem)(unsafe.Pointer(pSubitem)).FzAlias)
	(*TSrcItem)(unsafe.Pointer(pSubitem)).FzName = uintptr(0)
	(*TSrcItem)(unsafe.Pointer(pSubitem)).FzAlias = uintptr(0)
	/* If the sub-query is a compound SELECT statement, then (by restrictions
	 ** 17 and 18 above) it must be a UNION ALL and the parent query must
	 ** be of the form:
	 **
	 **     SELECT <expr-list> FROM (<sub-query>) <where-clause>
	 **
	 ** followed by any ORDER BY, LIMIT and/or OFFSET clauses. This block
	 ** creates N-1 copies of the parent query without any ORDER BY, LIMIT or
	 ** OFFSET clauses and joins them to the left-hand-side of the original
	 ** using UNION ALL operators. In this case N is the number of simple
	 ** select statements in the compound sub-query.
	 **
	 ** Example:
	 **
	 **     SELECT a+1 FROM (
	 **        SELECT x FROM tab
	 **        UNION ALL
	 **        SELECT y FROM tab
	 **        UNION ALL
	 **        SELECT abs(z*2) FROM tab2
	 **     ) WHERE a!=5 ORDER BY 1
	 **
	 ** Transformed into:
	 **
	 **     SELECT x+1 FROM tab WHERE x+1!=5
	 **     UNION ALL
	 **     SELECT y+1 FROM tab WHERE y+1!=5
	 **     UNION ALL
	 **     SELECT abs(z*2)+1 FROM tab2 WHERE abs(z*2)+1!=5
	 **     ORDER BY 1
	 **
	 ** We call this the "compound-subquery flattening".
	 */
	pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
	for {
		if !(pSub != 0) {
			break
		}
		pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
		pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
		pPrior = (*TSelect)(unsafe.Pointer(p)).FpPrior
		pItemTab = (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab
		(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab = uintptr(0)
		(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		(*TSelect)(unsafe.Pointer(p)).FpPrior = uintptr(0)
		(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
		pNew = _sqlite3SelectDup(tls, db, p, 0)
		(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit
		(*TSelect)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
		(*TSelect)(unsafe.Pointer(p)).Fop = uint8(TK_ALL)
		(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab = pItemTab
		if pNew == uintptr(0) {
			(*TSelect)(unsafe.Pointer(p)).FpPrior = pPrior
		} else {
			v5 = pParse + 132
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v4 = *(*int32)(unsafe.Pointer(v5))
			(*TSelect)(unsafe.Pointer(pNew)).FselId = libc.Uint32FromInt32(v4)
			if aCsrMap != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
				_renumberCursors(tls, pParse, pNew, iFrom, aCsrMap)
			}
			(*TSelect)(unsafe.Pointer(pNew)).FpPrior = pPrior
			if pPrior != 0 {
				(*TSelect)(unsafe.Pointer(pPrior)).FpNext = pNew
			}
			(*TSelect)(unsafe.Pointer(pNew)).FpNext = p
			(*TSelect)(unsafe.Pointer(p)).FpPrior = pNew
		}
		goto _3
	_3:
		;
		pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
	}
	_sqlite3DbFree(tls, db, aCsrMap)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3SrcItemAttachSubquery(tls, pParse, pSubitem, pSub1, 0)
		return int32(1)
	}
	/* Defer deleting the Table object associated with the
	 ** subquery until code generation is
	 ** complete, since there may still exist Expr.pTab entries that
	 ** refer to the subquery even after flattening.  Ticket #3346.
	 **
	 ** pSubitem->pSTab is always non-NULL by test restrictions and tests above.
	 */
	if (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab != uintptr(0) {
		pTabToDel = (*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab
		if (*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef == uint32(1) {
			if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
				v5 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
			} else {
				v5 = pParse
			}
			pToplevel = v5
			_sqlite3ParserAddCleanup(tls, pToplevel, __ccgo_fp(_sqlite3DeleteTableGeneric), pTabToDel)
		} else {
			(*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef = (*TTable)(unsafe.Pointer(pTabToDel)).FnTabRef - 1
		}
		(*TSrcItem)(unsafe.Pointer(pSubitem)).FpSTab = uintptr(0)
	}
	/* The following loop runs once for each term in a compound-subquery
	 ** flattening (as described above).  If we are doing a different kind
	 ** of flattening - a flattening other than a compound-subquery flattening -
	 ** then this loop only runs once.
	 **
	 ** This loop moves all of the FROM elements of the subquery into the
	 ** the FROM clause of the outer query.  Before doing this, remember
	 ** the cursor number for the original outer query FROM element in
	 ** iParent.  The iParent cursor will never be used.  Subsequent code
	 ** will scan expressions looking for iParent references and replace
	 ** those references with expressions that resolve to the subquery FROM
	 ** elements we are now copying in.
	 */
	pSub = pSub1
	pParent = p
	for {
		if !(pParent != 0) {
			break
		}
		jointype = (*TSrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype
		pSubSrc = (*TSelect)(unsafe.Pointer(pSub)).FpSrc     /* FROM clause of subquery */
		nSubSrc = (*TSrcList)(unsafe.Pointer(pSubSrc)).FnSrc /* Number of terms in subquery FROM clause */
		pSrc = (*TSelect)(unsafe.Pointer(pParent)).FpSrc     /* FROM clause of the outer query */
		/* The subquery uses a single slot of the FROM clause of the outer
		 ** query.  If the subquery has more than one element in its FROM clause,
		 ** then expand the outer query to make space for it to hold all elements
		 ** of the subquery.
		 **
		 ** Example:
		 **
		 **    SELECT * FROM tabA, (SELECT * FROM sub1, sub2), tabB;
		 **
		 ** The outer query has 3 slots in its FROM clause.  One slot of the
		 ** outer query (the middle slot) is used by the subquery.  The next
		 ** block of code will expand the outer query FROM clause to 4 slots.
		 ** The middle slot is expanded to two slots in order to make space
		 ** for the two elements in the FROM clause of the subquery.
		 */
		if nSubSrc > int32(1) {
			pSrc = _sqlite3SrcListEnlarge(tls, pParse, pSrc, nSubSrc-int32(1), iFrom+int32(1))
			if pSrc == uintptr(0) {
				break
			}
			(*TSelect)(unsafe.Pointer(pParent)).FpSrc = pSrc
			pSubitem = pSrc + 8 + uintptr(iFrom)*80
		}
		/* Transfer the FROM clause terms from the subquery into the
		 ** outer query.
		 */
		iNewParent = (*(*TSrcItem)(unsafe.Pointer(pSubSrc + 8))).FiCursor
		i = 0
		for {
			if !(i < nSubSrc) {
				break
			}
			pItem = pSrc + 8 + uintptr(i+iFrom)*80
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x100000>>20) != 0 {
				_sqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 64)))
			}
			**(**TSrcItem)(__ccgo_up(pItem)) = *(*TSrcItem)(unsafe.Pointer(pSubSrc + 8 + uintptr(i)*80))
			v5 = pItem + 24
			*(*Tu8)(unsafe.Pointer(v5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v5))) | libc.Int32FromUint8(jointype)&libc.Int32FromInt32(JT_LTORJ))
			libc.Xmemset(tls, pSubSrc+8+uintptr(i)*80, 0, uint64(80))
			goto _8
		_8:
			;
			i = i + 1
		}
		v5 = pSubitem + 24
		*(*Tu8)(unsafe.Pointer(v5)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v5))) | libc.Int32FromUint8(jointype))
		/* Begin substituting subquery result set expressions for
		 ** references to the iParent in the outer query.
		 **
		 ** Example:
		 **
		 **   SELECT a+5, b*10 FROM (SELECT x*3 AS a, y+10 AS b FROM t1) WHERE a>b;
		 **   \                     \_____________ subquery __________/          /
		 **    \_____________________ outer query ______________________________/
		 **
		 ** We look at every expression in the outer query and every place we see
		 ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
			/* At this point, any non-zero iOrderByCol values indicate that the
			 ** ORDER BY column expression is identical to the iOrderByCol'th
			 ** expression returned by SELECT statement pSub. Since these values
			 ** do not necessarily correspond to columns in SELECT statement pParent,
			 ** zero them before transferring the ORDER BY clause.
			 **
			 ** Not doing this may cause an error if a subsequent call to this
			 ** function attempts to flatten a compound sub-query into pParent.
			 ** See ticket [d11a6e908f].
			 */
			pOrderBy1 = (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy
			i = 0
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pOrderBy1)).FnExpr) {
					break
				}
				*(*Tu16)(unsafe.Pointer(pOrderBy1 + 8 + uintptr(i)*32 + 24)) = uint16(0)
				goto _11
			_11:
				;
				i = i + 1
			}
			(*TSelect)(unsafe.Pointer(pParent)).FpOrderBy = pOrderBy1
			(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
		}
		pWhere = (*TSelect)(unsafe.Pointer(pSub)).FpWhere
		(*TSelect)(unsafe.Pointer(pSub)).FpWhere = uintptr(0)
		if isOuterJoin > 0 {
			_sqlite3SetJoinExpr(tls, pWhere, iNewParent, uint32(EP_OuterON))
		}
		if pWhere != 0 {
			if (*TSelect)(unsafe.Pointer(pParent)).FpWhere != 0 {
				(*TSelect)(unsafe.Pointer(pParent)).FpWhere = _sqlite3PExpr(tls, pParse, int32(TK_AND), pWhere, (*TSelect)(unsafe.Pointer(pParent)).FpWhere)
			} else {
				(*TSelect)(unsafe.Pointer(pParent)).FpWhere = pWhere
			}
		}
		if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FpParse = pParse
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FiTable = iParent
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FiNewTable = iNewParent
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FisOuterJoin = isOuterJoin
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FnSelDepth = 0
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FpEList = (*TSelect)(unsafe.Pointer(pSub)).FpEList
			(**(**TSubstContext)(__ccgo_up(bp + 48))).FpCList = _findLeftmostExprlist(tls, pSub)
			_substSelect(tls, bp+48, pParent, 0)
		}
		/* The flattened query is a compound if either the inner or the
		 ** outer query is a compound. */
		**(**Tu32)(__ccgo_up(pParent + 4)) |= (*TSelect)(unsafe.Pointer(pSub)).FselFlags & uint32(SF_Compound)
		/* restriction (17b) */
		/*
		 ** SELECT ... FROM (SELECT ... LIMIT a OFFSET b) LIMIT x OFFSET y;
		 **
		 ** One is tempted to try to add a and b to combine the limits.  But this
		 ** does not work if either limit is negative.
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FpLimit != 0 {
			(*TSelect)(unsafe.Pointer(pParent)).FpLimit = (*TSelect)(unsafe.Pointer(pSub)).FpLimit
			(*TSelect)(unsafe.Pointer(pSub)).FpLimit = uintptr(0)
		}
		/* Recompute the SrcItem.colUsed masks for the flattened
		 ** tables. */
		i = 0
		for {
			if !(i < nSubSrc) {
				break
			}
			_recomputeColumnsUsed(tls, pParent, pSrc+8+uintptr(i+iFrom)*80)
			goto _12
		_12:
			;
			i = i + 1
		}
		goto _7
	_7:
		;
		pParent = (*TSelect)(unsafe.Pointer(pParent)).FpPrior
		pSub = (*TSelect)(unsafe.Pointer(pSub)).FpPrior
	}
	/* Finally, delete what is left of the subquery and return success.
	 */
	_sqlite3AggInfoPersistWalkerInit(tls, bp, pParse)
	_sqlite3WalkSelect(tls, bp, pSub1)
	_sqlite3SelectDelete(tls, db, pSub1)
	return int32(1)
}

func _freeCursorWithCache(tls *libc.TLS, p uintptr, pCx uintptr) {
	var pCache uintptr
	_ = pCache
	pCache = (*TVdbeCursor)(unsafe.Pointer(pCx)).FpCache
	libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(0), 3, 0x8)
	(*TVdbeCursor)(unsafe.Pointer(pCx)).FpCache = uintptr(0)
	if (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue != 0 {
		_sqlite3RCStrUnref(tls, (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue)
		(*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue = uintptr(0)
	}
	_sqlite3DbFree(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, pCache)
	_sqlite3VdbeFreeCursorNN(tls, p, pCx)
}

// C documentation
//
//	/*
//	** Return TRUE (non-zero) if the i-th entry in the pTabList SrcList can
//	** be implemented as a co-routine.  The i-th entry is guaranteed to be
//	** a subquery.
//	**
//	** The subquery is implemented as a co-routine if all of the following are
//	** true:
//	**
//	**    (1)  The subquery will likely be implemented in the outer loop of
//	**         the query.  This will be the case if any one of the following
//	**         conditions hold:
//	**         (a)  The subquery is the only term in the FROM clause
//	**         (b)  The subquery is the left-most term and a CROSS JOIN or similar
//	**              requires it to be the outer loop
//	**         (c)  All of the following are true:
//	**                (i) The subquery is the left-most subquery in the FROM clause
//	**               (ii) There is nothing that would prevent the subquery from
//	**                    being used as the outer loop if the sqlite3WhereBegin()
//	**                    routine nominates it to that position.
//	**              (iii) The query is not a UPDATE ... FROM
//	**    (2)  The subquery is not a CTE that should be materialized because
//	**         (a) the AS MATERIALIZED keyword is used, or
//	**         (b) the CTE is used multiple times and does not have the
//	**             NOT MATERIALIZED keyword
//	**    (3)  The subquery is not part of a left operand for a RIGHT JOIN
//	**    (4)  The SQLITE_Coroutine optimization disable flag is not set
//	**    (5)  The subquery is not self-joined
//	*/
func _fromClauseTermCanBeCoroutine(tls *libc.TLS, pParse uintptr, pTabList uintptr, i int32, selFlags int32) (r int32) {
	var pCteUse, pItem uintptr
	_, _ = pCteUse, pItem
	pItem = pTabList + 8 + uintptr(i)*80
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x400000>>22) != 0 {
		pCteUse = *(*uintptr)(unsafe.Pointer(pItem + 56))
		if libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d) == M10d_Yes {
			return 0
		} /* (2a) */
		if (*TCteUse)(unsafe.Pointer(pCteUse)).FnUse >= int32(2) && libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d) != int32(M10d_No) {
			return 0
		} /* (2b) */
	}
	if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
		return 0
	} /* (3)  */
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Coroutines)) != uint32(0) {
		return 0
	} /* (4)  */
	if _isSelfJoinView(tls, pTabList, pItem, i+int32(1), (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) != uintptr(0) {
		return 0 /* (5) */
	}
	if i == 0 {
		if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc == int32(1) {
			return int32(1)
		} /* (1a) */
		if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + 1*80))).Ffg.Fjointype)&int32(JT_CROSS) != 0 {
			return int32(1)
		} /* (1b) */
		if selFlags&int32(SF_UpdateFrom) != 0 {
			return 0
		} /* (1c-iii) */
		return int32(1)
	}
	if selFlags&int32(SF_UpdateFrom) != 0 {
		return 0
	} /* (1c-iii) */
	for int32(1) != 0 {
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
			return 0
		} /* (1c-ii) */
		if i == 0 {
			break
		}
		i = i - 1
		pItem -= 80
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
			return 0
		} /* (1c-i) */
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** This routine generates VDBE code to compute the content of a WITH RECURSIVE
//	** query of the form:
//	**
//	**   <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
//	**                         \___________/             \_______________/
//	**                           p->pPrior                      p
//	**
//	**
//	** There is exactly one reference to the recursive-table in the FROM clause
//	** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
//	**
//	** The setup-query runs once to generate an initial set of rows that go
//	** into a Queue table.  Rows are extracted from the Queue table one by
//	** one.  Each row extracted from Queue is output to pDest.  Then the single
//	** extracted row (now in the iCurrent table) becomes the content of the
//	** recursive-table for a recursive-query run.  The output of the recursive-query
//	** is added back into the Queue table.  Then another row is extracted from Queue
//	** and the iteration continues until the Queue table is empty.
//	**
//	** If the compound query operator is UNION then no duplicate rows are ever
//	** inserted into the Queue table.  The iDistinct table keeps a copy of all rows
//	** that have ever been inserted into Queue and causes duplicates to be
//	** discarded.  If the operator is UNION ALL, then duplicates are allowed.
//	**
//	** If the query has an ORDER BY, then entries in the Queue table are kept in
//	** ORDER BY order and the first entry is extracted for each cycle.  Without
//	** an ORDER BY, the Queue table is just a FIFO.
//	**
//	** If a LIMIT clause is provided, then the iteration stops after LIMIT rows
//	** have been output to pDest.  A LIMIT of zero means to output no rows and a
//	** negative LIMIT means to output all rows.  If there is also an OFFSET clause
//	** with a positive value, then the first OFFSET outputs are discarded rather
//	** than being sent to pDest.  The LIMIT count does not begin until after OFFSET
//	** rows have been skipped.
//	*/
func _generateWithRecursiveQuery(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var addrBreak, addrCont, addrTop, eDest, i, iCurrent, iDistinct, iQueue, nCol, rc, regCurrent, regLimit, regOffset, v1 int32
	var apColl, pFirstRec, pKeyInfo, pKeyInfo1, pLimit, pOrderBy, pSetup, pSrc, v, v4 uintptr
	var _ /* destQueue at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrBreak, addrCont, addrTop, apColl, eDest, i, iCurrent, iDistinct, iQueue, nCol, pFirstRec, pKeyInfo, pKeyInfo1, pLimit, pOrderBy, pSetup, pSrc, rc, regCurrent, regLimit, regOffset, v, v1, v4
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc                                        /* The FROM clause of the recursive query */
	nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr /* Number of columns in the recursive table */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                                      /* CONTINUE and BREAK addresses */
	iCurrent = 0                                                                      /* The Queue table */
	iDistinct = 0                                                                     /* To ensure unique results if UNION */
	eDest = int32(SRT_Fifo)                                                           /* Registers used by LIMIT and OFFSET */
	if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20697, 0)
		return
	}
	/* Obtain authorization to do a recursive query */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_RECURSIVE), uintptr(0), uintptr(0), uintptr(0)) != 0 {
		return
	}
	/* Process the LIMIT and OFFSET clauses, if they exist */
	addrBreak = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(320) /* 4 billion rows */
	_computeLimitRegisters(tls, pParse, p, addrBreak)
	pLimit = (*TSelect)(unsafe.Pointer(p)).FpLimit
	regLimit = (*TSelect)(unsafe.Pointer(p)).FiLimit
	regOffset = (*TSelect)(unsafe.Pointer(p)).FiOffset
	(*TSelect)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	v1 = libc.Int32FromInt32(0)
	(*TSelect)(unsafe.Pointer(p)).FiOffset = v1
	(*TSelect)(unsafe.Pointer(p)).FiLimit = v1
	pOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	/* Locate the cursor number of the Current table */
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x1000000>>24) != 0 {
			iCurrent = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80))).FiCursor
			break
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	/* Allocate cursors numbers for Queue and Distinct.  The cursor number for
	 ** the Distinct table must be exactly one greater than Queue in order
	 ** for the SRT_DistFifo and SRT_DistQueue destinations to work. */
	v4 = pParse + 56
	v1 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	iQueue = v1
	if libc.Int32FromUint8((*TSelect)(unsafe.Pointer(p)).Fop) == int32(TK_UNION) {
		if pOrderBy != 0 {
			v1 = int32(SRT_DistQueue)
		} else {
			v1 = int32(SRT_DistFifo)
		}
		eDest = v1
		v4 = pParse + 56
		v1 = *(*int32)(unsafe.Pointer(v4))
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		iDistinct = v1
	} else {
		if pOrderBy != 0 {
			v1 = int32(SRT_Queue)
		} else {
			v1 = int32(SRT_Fifo)
		}
		eDest = v1
	}
	_sqlite3SelectDestInit(tls, bp, eDest, iQueue)
	/* Allocate cursors for Current, Queue, and Distinct. */
	v4 = pParse + 60
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	v1 = *(*int32)(unsafe.Pointer(v4))
	regCurrent = v1
	_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), iCurrent, regCurrent, nCol)
	if pOrderBy != 0 {
		pKeyInfo = _multiSelectByMergeKeyInfo(tls, pParse, p, int32(1))
		_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(2), 0, pKeyInfo, -int32(9))
		(**(**TSelectDest)(__ccgo_up(bp))).FpOrderBy = pOrderBy
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iQueue, nCol)
	}
	if iDistinct != 0 { /* For looping through pKeyInfo->aColl[] */
		nCol = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
		pKeyInfo1 = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nCol, int32(1))
		if pKeyInfo1 != 0 {
			i = 0
			apColl = pKeyInfo1 + 32
			for {
				if !(i < nCol) {
					break
				}
				**(**uintptr)(__ccgo_up(apColl)) = _multiSelectCollSeq(tls, pParse, p, i)
				if uintptr(0) == **(**uintptr)(__ccgo_up(apColl)) {
					**(**uintptr)(__ccgo_up(apColl)) = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
				}
				goto _11
			_11:
				;
				i = i + 1
				apColl += 8
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), iDistinct, nCol, 0, pKeyInfo1, -int32(9))
		} else {
		}
	}
	/* Detach the ORDER BY clause from the compound SELECT */
	(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
	/* Figure out how many elements of the compound SELECT are part of the
	 ** recursive query.  Make sure no recursive elements use aggregate
	 ** functions.  Mark the recursive elements as UNION ALL even if they
	 ** are really UNION because the distinctness will be enforced by the
	 ** iDistinct table.  pFirstRec is left pointing to the left-most
	 ** recursive term of the CTE.
	 */
	pFirstRec = p
	for {
		if !(pFirstRec != uintptr(0)) {
			break
		}
		if (*TSelect)(unsafe.Pointer(pFirstRec)).FselFlags&uint32(SF_Aggregate) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20746, 0)
			goto end_of_recursive_query
		}
		(*TSelect)(unsafe.Pointer(pFirstRec)).Fop = uint8(TK_ALL)
		if (*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior)).FselFlags&uint32(SF_Recursive) == uint32(0) {
			break
		}
		goto _12
	_12:
		;
		pFirstRec = (*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior
	}
	/* Store the results of the setup-query in Queue. */
	pSetup = (*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior
	(*TSelect)(unsafe.Pointer(pSetup)).FpNext = uintptr(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20788, 0)
	rc = _sqlite3Select(tls, pParse, pSetup, bp)
	(*TSelect)(unsafe.Pointer(pSetup)).FpNext = p
	if rc != 0 {
		goto end_of_recursive_query
	}
	/* Find the next row in the Queue and output that row */
	addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iQueue, addrBreak)
	/* Transfer the next row in Queue over to Current */
	_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iCurrent) /* To reset column cache */
	if pOrderBy != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iQueue, (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr+int32(1), regCurrent)
	} else {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iQueue, regCurrent)
	}
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Delete), iQueue)
	/* Output the single row in Current */
	addrCont = _sqlite3VdbeMakeLabel(tls, pParse)
	_codeOffset(tls, v, regOffset, addrCont)
	_selectInnerLoop(tls, pParse, p, iCurrent, uintptr(0), uintptr(0), pDest, addrCont, addrBreak)
	if regLimit != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), regLimit, addrBreak)
	}
	_sqlite3VdbeResolveLabel(tls, v, addrCont)
	/* Execute the recursive SELECT taking the single row in Current as
	 ** the value for the recursive-table. Store the results in the Queue.
	 */
	(*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior = uintptr(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+20794, 0)
	_sqlite3Select(tls, pParse, p, bp)
	(*TSelect)(unsafe.Pointer(pFirstRec)).FpPrior = pSetup
	/* Keep running the loop until the Queue is empty */
	_sqlite3VdbeGoto(tls, v, addrTop)
	_sqlite3VdbeResolveLabel(tls, v, addrBreak)
	goto end_of_recursive_query
end_of_recursive_query:
	;
	_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
	(*TSelect)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
	(*TSelect)(unsafe.Pointer(p)).FpLimit = pLimit
	return
}

// C documentation
//
//	/*
//	** Check the N SrcItem objects to the right of pBase.  (N might be zero!)
//	** If any of those SrcItem objects have a USING clause containing zName
//	** then return true.
//	**
//	** If N is zero, or none of the N SrcItem objects to the right of pBase
//	** contains a USING clause, or if none of the USING clauses contain zName,
//	** then return false.
//	*/
func _inAnyUsingClause(tls *libc.TLS, zName uintptr, pBase uintptr, N int32) (r int32) {
	for N > 0 {
		N = N - 1
		pBase += 80
		if int32(*(*uint32)(unsafe.Pointer(pBase + 24 + 4))&0x100000>>20) == 0 {
			continue
		}
		if *(*uintptr)(unsafe.Pointer(pBase + 64)) == uintptr(0) {
			continue
		}
		if _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pBase + 64)), zName) >= 0 {
			return int32(1)
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Compare the "idx"-th cell on the page pPage against the key
//	** pointing to by pIdxKey using xRecordCompare.  Return negative or
//	** zero if the cell is less than or equal pIdxKey.  Return positive
//	** if unknown.
//	**
//	**    Return value negative:     Cell at pCur[idx] less than pIdxKey
//	**
//	**    Return value is zero:      Cell at pCur[idx] equals pIdxKey
//	**
//	**    Return value positive:     Nothing is known about the relationship
//	**                               of the cell at pCur[idx] and pIdxKey.
//	**
//	** This routine is part of an optimization.  It is always safe to return
//	** a positive value as that will cause the optimization to be skipped.
//	*/
func _indexCellCompare(tls *libc.TLS, pPage uintptr, idx int32, pIdxKey uintptr, __ccgo_fp_xRecordCompare TRecordCompare) (r int32) {
	var c, nCell, v1 int32
	var pCell uintptr
	var v2 bool
	_, _, _, _, _ = c, nCell, pCell, v1, v2 /* Size of the pCell cell in bytes */
	pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)))))
	nCell = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell)))
	if nCell <= libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).Fmax1bytePayload) {
		/* This branch runs if the record-size field of the cell is a
		 ** single byte varint and the record fits entirely on the main
		 ** b-tree page.  */
		if pCell+uintptr(nCell) >= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
			return int32(99)
		}
		c = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xRecordCompare})))(tls, nCell, pCell+1, pIdxKey)
	} else {
		if v2 = !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell + 1)))&libc.Int32FromInt32(0x80) != 0); v2 {
			v1 = nCell&libc.Int32FromInt32(0x7f)<<libc.Int32FromInt32(7) + libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell + 1)))
			nCell = v1
		}
		if v2 && v1 <= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			/* The record-size field is a 2 byte varint and the record
			 ** fits entirely on the main b-tree page.  */
			if pCell+uintptr(nCell) >= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
				return int32(99)
			}
			c = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xRecordCompare})))(tls, nCell, pCell+2, pIdxKey)
		} else {
			/* If the record extends into overflow pages, do not attempt
			 ** the optimization. */
			c = int32(99)
		}
	}
	return c
}

// C documentation
//
//	/*
//	** Return TRUE if the iCol-th column of index pIdx is NOT NULL
//	*/
func _indexColumnNotNull(tls *libc.TLS, pIdx uintptr, iCol int32) (r int32) {
	var j int32
	_ = j
	j = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2)))
	if j >= 0 {
		return int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(j)*16 + 8)) & 0xf0 >> 4))
	} else {
		if j == -int32(1) {
			return int32(1)
		} else {
			return 0 /* Assume an indexed expression can always yield a NULL */
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Return True if it is possible that pIndex might be useful in
//	** implementing the ORDER BY clause in pBuilder.
//	**
//	** Return False if pBuilder does not contain an ORDER BY clause or
//	** if there is no way for pIndex to be useful in implementing that
//	** ORDER BY clause.
//	*/
func _indexMightHelpWithOrderBy(tls *libc.TLS, pBuilder uintptr, pIndex uintptr, iCursor int32) (r int32) {
	var aColExpr, pExpr, pOB, v1 uintptr
	var ii, jj int32
	_, _, _, _, _, _ = aColExpr, ii, jj, pExpr, pOB, v1
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x2000>>13)) != 0 {
		return 0
	}
	v1 = (*TWhereInfo)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpOrderBy
	pOB = v1
	if v1 == uintptr(0) {
		return 0
	}
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pOB)).FnExpr) {
			break
		}
		pExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pOB + 8 + uintptr(ii)*32))).FpExpr)
		if pExpr == uintptr(0) {
			goto _2
		}
		if (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_COLUMN)) && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == iCursor {
			if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) < 0 {
				return int32(1)
			}
			jj = 0
			for {
				if !(jj < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol)) {
					break
				}
				if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) == int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(jj)*2))) {
					return int32(1)
				}
				goto _3
			_3:
				;
				jj = jj + 1
			}
		} else {
			v1 = (*TIndex)(unsafe.Pointer(pIndex)).FaColExpr
			aColExpr = v1
			if v1 != uintptr(0) {
				jj = 0
				for {
					if !(jj < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol)) {
						break
					}
					if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(jj)*2))) != -int32(2) {
						goto _5
					}
					if _sqlite3ExprCompareSkip(tls, pExpr, (*(*TExprList_item)(unsafe.Pointer(aColExpr + 8 + uintptr(jj)*32))).FpExpr, iCursor) == 0 {
						return int32(1)
					}
					goto _5
				_5:
					;
					jj = jj + 1
				}
			}
		}
		goto _2
	_2:
		;
		ii = ii + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** pX is the RHS of an IN operator.  If pX is a SELECT statement
//	** that can be simplified to a direct table access, then return
//	** a pointer to the SELECT statement.  If pX is not a SELECT statement,
//	** or if the SELECT statement needs to be materialized into a transient
//	** table, then return NULL.
//	*/
func _isCandidateForInOpt(tls *libc.TLS, pX uintptr) (r uintptr) {
	var i int32
	var p, pEList, pRes, pSrc, pTab uintptr
	_, _, _, _, _, _ = i, p, pEList, pRes, pSrc, pTab
	if !((*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(EP_xIsSelect) != libc.Uint32FromInt32(0)) {
		return uintptr(0)
	} /* Not a subquery */
	if (*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_VarSelect)) != uint32(0) {
		return uintptr(0)
	} /* Correlated subq */
	p = *(*uintptr)(unsafe.Pointer(pX + 32))
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		return uintptr(0)
	} /* Not a compound SELECT */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) != 0 {
		return uintptr(0) /* No DISTINCT keyword and no aggregate functions */
	}
	/* Has no GROUP BY clause */
	if (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 {
		return uintptr(0)
	} /* Has no LIMIT clause */
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != 0 {
		return uintptr(0)
	} /* Has no WHERE clause */
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
	if (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc != int32(1) {
		return uintptr(0)
	} /* Single term in FROM clause */
	if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + 24 + 4))&0x20000000>>29) != 0 {
		return uintptr(0)
	} /* FROM is not a subquery or view */
	pTab = (*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).FpSTab
	/* FROM clause is not a view */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		return uintptr(0)
	} /* FROM clause not a virtual table */
	pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
	/* All SELECT results must be columns. */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		pRes = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FpExpr
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRes)).Fop) != int32(TK_COLUMN) {
			return uintptr(0)
		}
		/* Not a correlated subquery */
		goto _1
	_1:
		;
		i = i + 1
	}
	return p
}

// C documentation
//
//	/*
//	** Process time function arguments.  argv[0] is a date-time stamp.
//	** argv[1] and following are modifiers.  Parse them all and write
//	** the resulting time into the DateTime structure p.  Return 0
//	** on success and 1 if there are any errors.
//	**
//	** If there are zero parameters (if even argv[0] is undefined)
//	** then assume a default value of "now" for argv[0].
//	*/
func _isDate(tls *libc.TLS, context uintptr, argc int32, argv uintptr, p uintptr) (r int32) {
	var eType, i, n, v1 int32
	var z uintptr
	_, _, _, _, _ = eType, i, n, z, v1
	libc.Xmemset(tls, p, 0, uint64(48))
	if argc == 0 {
		if !(_sqlite3NotPureFunc(tls, context) != 0) {
			return int32(1)
		}
		return _setDateTimeToCurrent(tls, context, p)
	}
	v1 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv)))
	eType = v1
	if v1 == int32(SQLITE_FLOAT) || eType == int32(SQLITE_INTEGER) {
		_setRawDateNumber(tls, p, Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv))))
	} else {
		z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
		if !(z != 0) || _parseDateOrTime(tls, context, z, p) != 0 {
			return int32(1)
		}
	}
	i = int32(1)
	for {
		if !(i < argc) {
			break
		}
		z = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
		n = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*8)))
		if z == uintptr(0) || _parseModifier(tls, context, z, n, p, i) != 0 {
			return int32(1)
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	_computeJD(tls, p)
	if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x40>>6)) != 0 || !(_validJulianDay(tls, (*TDateTime)(unsafe.Pointer(p)).FiJD) != 0) {
		return int32(1)
	}
	if argc == int32(1) && (*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0 && (*TDateTime)(unsafe.Pointer(p)).FD > int32(28) {
		/* Make sure a YYYY-MM-DD is normalized.
		 ** Example: 2023-02-31 -> 2023-03-03 */
		(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(0)
	}
	return 0
}

/*
** The following routines implement the various date and time functions
** of SQLite.
 */

// C documentation
//
//	/*
//	** Check to see if the pThis entry of pTabList is a self-join of another view.
//	** Search FROM-clause entries in the range of iFirst..iEnd, including iFirst
//	** but stopping before iEnd.
//	**
//	** If pThis is a self-join, then return the SrcItem for the first other
//	** instance of that view found.  If pThis is not a self-join then return 0.
//	*/
func _isSelfJoinView(tls *libc.TLS, pTabList uintptr, pThis uintptr, iFirst int32, iEnd int32) (r uintptr) {
	var pItem, pS1, pSel uintptr
	var v1 int32
	_, _, _, _ = pItem, pS1, pSel, v1
	pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pThis + 72)))).FpSelect
	if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_PushDown) != 0 {
		return uintptr(0)
	}
	for iFirst < iEnd {
		v1 = iFirst
		iFirst = iFirst + 1
		pItem = pTabList + 8 + uintptr(v1)*80
		if !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0) {
			continue
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x2000000>>25) != 0 {
			continue
		}
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzName == uintptr(0) {
			continue
		}
		if (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FpSchema != (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pThis)).FpSTab)).FpSchema {
			continue
		}
		if Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TSrcItem)(unsafe.Pointer(pThis)).FzName) != 0 {
			continue
		}
		pS1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
		if (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FpSchema == uintptr(0) && (*TSelect)(unsafe.Pointer(pSel)).FselId != (*TSelect)(unsafe.Pointer(pS1)).FselId {
			/* The query flattener left two different CTE tables with identical
			 ** names in the same FROM clause. */
			continue
		}
		if (*TSelect)(unsafe.Pointer(pS1)).FselFlags&uint32(SF_PushDown) != 0 {
			/* The view was modified by some other optimization such as
			 ** pushDownWhereTerms() */
			continue
		}
		return pItem
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** The select statement passed as the first argument is an aggregate query.
//	** The second argument is the associated aggregate-info object. This
//	** function tests if the SELECT is of the form:
//	**
//	**   SELECT count(*) FROM <tbl>
//	**
//	** where table is a database table, not a sub-select or view. If the query
//	** does match this pattern, then a pointer to the Table object representing
//	** <tbl> is returned. Otherwise, NULL is returned.
//	**
//	** This routine checks to see if it is safe to use the count optimization.
//	** A correct answer is still obtained (though perhaps more slowly) if
//	** this routine returns NULL when it could have returned a table pointer.
//	** But returning the pointer when NULL should have been returned can
//	** result in incorrect answers and/or crashes.  So, when in doubt, return NULL.
//	*/
func _isSimpleCount(tls *libc.TLS, p uintptr, pAggInfo uintptr) (r uintptr) {
	var pExpr, pTab uintptr
	_, _ = pExpr, pTab
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != 0 || (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr != int32(1) || (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc != int32(1) || int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 24 + 4))&0x20000000>>29) != 0 || (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc != int32(1) || (*TSelect)(unsafe.Pointer(p)).FpHaving != 0 {
		return uintptr(0)
	}
	pTab = (*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSTab
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		return uintptr(0)
	}
	pExpr = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8))).FpExpr
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_AGG_FUNCTION) {
		return uintptr(0)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo != pAggInfo {
		return uintptr(0)
	}
	if (*TFuncDef)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_COUNT) == uint32(0) {
		return uintptr(0)
	}
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Distinct)|libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
		return uintptr(0)
	}
	return pTab
}

// C documentation
//
//	/*
//	** Load the content from either the sqlite_stat4
//	** into the relevant Index.aSample[] arrays.
//	**
//	** Arguments zSql1 and zSql2 must point to SQL statements that return
//	** data equivalent to the following:
//	**
//	**    zSql1: SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx
//	**    zSql2: SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4
//	**
//	** where %Q is replaced with the database name before the SQL is executed.
//	*/
func _loadStatTbl(tls *libc.TLS, db uintptr, zSql1 uintptr, zSql2 uintptr, zDb uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, nByte Ti64
	var nCol, nIdxCol, nSample, rc int32
	var pIdx, pIdx1, pPrevIdx, pPtr, pSample, pSpace, zIndex, zIndex1, zSql uintptr
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, nByte, nCol, nIdxCol, nSample, pIdx, pIdx1, pPrevIdx, pPtr, pSample, pSpace, rc, zIndex, zIndex1, zSql /* Result codes from subroutines */
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)                                                                                                               /* Text of the SQL statement */
	pPrevIdx = uintptr(0)                                                                                                                                   /* A slot in pIdx->aSample[] */
	zSql = _sqlite3MPrintf(tls, db, zSql1, libc.VaList(bp+16, zDb))
	if !(zSql != 0) {
		return int32(SQLITE_NOMEM)
	}
	rc = Xsqlite3_prepare(tls, db, zSql, -int32(1), bp, uintptr(0))
	_sqlite3DbFree(tls, db, zSql)
	if rc != 0 {
		return rc
	}
	for Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) {
		nIdxCol = int32(1) /* Available memory as a u8 for easier manipulation */
		zIndex = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
		if zIndex == uintptr(0) {
			continue
		}
		nSample = Xsqlite3_column_int(tls, **(**uintptr)(__ccgo_up(bp)), int32(1))
		pIdx = _findIndexOrPrimaryKey(tls, db, zIndex, zDb)
		if pIdx == uintptr(0) {
			continue
		}
		if (*TIndex)(unsafe.Pointer(pIdx)).FaSample != uintptr(0) {
			/* The same index appears in sqlite_stat4 under multiple names */
			continue
		}
		if !((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
			nIdxCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			nIdxCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		}
		(*TIndex)(unsafe.Pointer(pIdx)).FnSampleCol = nIdxCol
		(*TIndex)(unsafe.Pointer(pIdx)).FmxSample = nSample
		nByte = (libc.Int64FromInt64(40)*int64(nSample) + libc.Int64FromInt32(7)) & int64(^libc.Int32FromInt32(7))
		nByte = nByte + libc.Int64FromInt64(8)*int64(nIdxCol)*int64(3)*int64(nSample)
		nByte = nByte + int64(nIdxCol)*libc.Int64FromInt64(8) /* Space for Index.aAvgEq[] */
		(*TIndex)(unsafe.Pointer(pIdx)).FaSample = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(nByte))
		if (*TIndex)(unsafe.Pointer(pIdx)).FaSample == uintptr(0) {
			Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
			return int32(SQLITE_NOMEM)
		}
		pPtr = (*TIndex)(unsafe.Pointer(pIdx)).FaSample
		pPtr = pPtr + uintptr((int64(nSample)*libc.Int64FromInt64(40)+libc.Int64FromInt32(7))&int64(^libc.Int32FromInt32(7)))
		pSpace = pPtr
		(*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq = pSpace
		pSpace = pSpace + uintptr(nIdxCol)*8
		**(**Tu32)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FpTable + 48)) |= uint32(TF_HasStat4)
		i = 0
		for {
			if !(i < int64(nSample)) {
				break
			}
			(**(**TIndexSample)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40))).FanEq = pSpace
			pSpace = pSpace + uintptr(nIdxCol)*8
			(**(**TIndexSample)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40))).FanLt = pSpace
			pSpace = pSpace + uintptr(nIdxCol)*8
			(**(**TIndexSample)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40))).FanDLt = pSpace
			pSpace = pSpace + uintptr(nIdxCol)*8
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc != 0 {
		return rc
	}
	zSql = _sqlite3MPrintf(tls, db, zSql2, libc.VaList(bp+16, zDb))
	if !(zSql != 0) {
		return int32(SQLITE_NOMEM)
	}
	rc = Xsqlite3_prepare(tls, db, zSql, -int32(1), bp, uintptr(0))
	_sqlite3DbFree(tls, db, zSql)
	if rc != 0 {
		return rc
	}
	for Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) == int32(SQLITE_ROW) { /* Pointer to the index object */
		nCol = int32(1) /* Number of columns in index */
		zIndex1 = Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), 0)
		if zIndex1 == uintptr(0) {
			continue
		}
		pIdx1 = _findIndexOrPrimaryKey(tls, db, zIndex1, zDb)
		if pIdx1 == uintptr(0) {
			continue
		}
		if (*TIndex)(unsafe.Pointer(pIdx1)).FnSample >= (*TIndex)(unsafe.Pointer(pIdx1)).FmxSample {
			/* Too many slots used because the same index appears in
			 ** sqlite_stat4 using multiple names */
			continue
		}
		/* This next condition is true if data has already been loaded from
		 ** the sqlite_stat4 table. */
		nCol = (*TIndex)(unsafe.Pointer(pIdx1)).FnSampleCol
		if pIdx1 != pPrevIdx {
			_initAvgEq(tls, pPrevIdx)
			pPrevIdx = pIdx1
		}
		pSample = (*TIndex)(unsafe.Pointer(pIdx1)).FaSample + uintptr((*TIndex)(unsafe.Pointer(pIdx1)).FnSample)*40
		_decodeIntArray(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(1)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanEq, uintptr(0), uintptr(0))
		_decodeIntArray(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(2)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanLt, uintptr(0), uintptr(0))
		_decodeIntArray(tls, Xsqlite3_column_text(tls, **(**uintptr)(__ccgo_up(bp)), int32(3)), nCol, (*TIndexSample)(unsafe.Pointer(pSample)).FanDLt, uintptr(0), uintptr(0))
		/* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
		 ** This is in case the sample record is corrupted. In that case, the
		 ** sqlite3VdbeRecordCompare() may read up to two varints past the
		 ** end of the allocated buffer before it realizes it is dealing with
		 ** a corrupt record.  Or it might try to read a large integer from the
		 ** buffer.  In any case, eight 0x00 bytes prevents this from causing
		 ** a buffer overread.  */
		(*TIndexSample)(unsafe.Pointer(pSample)).Fn = Xsqlite3_column_bytes(tls, **(**uintptr)(__ccgo_up(bp)), int32(4))
		(*TIndexSample)(unsafe.Pointer(pSample)).Fp = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt32((*TIndexSample)(unsafe.Pointer(pSample)).Fn+int32(8)))
		if (*TIndexSample)(unsafe.Pointer(pSample)).Fp == uintptr(0) {
			Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
			return int32(SQLITE_NOMEM)
		}
		if (*TIndexSample)(unsafe.Pointer(pSample)).Fn != 0 {
			libc.Xmemcpy(tls, (*TIndexSample)(unsafe.Pointer(pSample)).Fp, Xsqlite3_column_blob(tls, **(**uintptr)(__ccgo_up(bp)), int32(4)), libc.Uint64FromInt32((*TIndexSample)(unsafe.Pointer(pSample)).Fn))
		}
		(*TIndex)(unsafe.Pointer(pIdx1)).FnSample = (*TIndex)(unsafe.Pointer(pIdx1)).FnSample + 1
	}
	rc = Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc == SQLITE_OK {
		_initAvgEq(tls, pPrevIdx)
	}
	return rc
}

// C documentation
//
//	/*
//	** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
//	** that name in the set of source tables in pSrcList and make the pExpr
//	** expression node refer back to that source column.  The following changes
//	** are made to pExpr:
//	**
//	**    pExpr->iDb           Set the index in db->aDb[] of the database X
//	**                         (even if X is implied).
//	**    pExpr->iTable        Set to the cursor number for the table obtained
//	**                         from pSrcList.
//	**    pExpr->y.pTab        Points to the Table structure of X.Y (even if
//	**                         X and/or Y are implied.)
//	**    pExpr->iColumn       Set to the column number within the table.
//	**    pExpr->op            Set to TK_COLUMN.
//	**    pExpr->pLeft         Any expression this points to is deleted
//	**    pExpr->pRight        Any expression this points to is deleted.
//	**
//	** The zDb variable is the name of the database (the "X").  This value may be
//	** NULL meaning that name is of the form Y.Z or Z.  Any available database
//	** can be used.  The zTable variable is the name of the table (the "Y").  This
//	** value can be NULL if zDb is also NULL.  If zTable is NULL it
//	** means that the form of the name is Z and that columns from any table
//	** can be used.
//	**
//	** If the name cannot be resolved unambiguously, leave an error message
//	** in pParse and return WRC_Abort.  Return WRC_Prune on success.
//	*/
func _lookupName(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, pRight uintptr, pNC uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var cnt, cntTab, eNewExprOp, hit, i, iCol, j, nSubquery, op, v4 int32
	var db, pEList, pItem, pMatch, pOrig, pSchema, pSel, pSrcList, pTab, pTopNC, pUpsert, zAs, zCol, zErr, v8 uintptr
	var v5 uint32
	var _ /* bRowid at bp+8 */ int32
	var _ /* pFJMatch at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = cnt, cntTab, db, eNewExprOp, hit, i, iCol, j, nSubquery, op, pEList, pItem, pMatch, pOrig, pSchema, pSel, pSrcList, pTab, pTopNC, pUpsert, zAs, zCol, zErr, v4, v5, v8 /* Loop counters */
	cnt = 0                                                                                                                                                                                                                                               /* Number of matching column names */
	cntTab = 0                                                                                                                                                                                                                                            /* Number of potential "rowid" matches */
	nSubquery = 0                                                                                                                                                                                                                                         /* How many levels of subquery */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                                                                                                                                                                                            /* Use for looping over pSrcList items */
	pMatch = uintptr(0)                                                                                                                                                                                                                                   /* The matching pSrcList item */
	pTopNC = pNC                                                                                                                                                                                                                                          /* First namecontext in the list */
	pSchema = uintptr(0)                                                                                                                                                                                                                                  /* Schema of the expression */
	eNewExprOp = int32(TK_COLUMN)                                                                                                                                                                                                                         /* New value for pExpr->op on success */
	pTab = uintptr(0)                                                                                                                                                                                                                                     /* Table holding the row */
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)                                                                                                                                                                                                             /* Matches for FULL JOIN .. USING */
	zCol = *(*uintptr)(unsafe.Pointer(pRight + 8))
	/* the name context cannot be NULL. */
	/* The Z in X.Y.Z cannot be NULL */
	/* Initialize the node to no-match */
	(*TExpr)(unsafe.Pointer(pExpr)).FiTable = -int32(1)
	/* Translate the schema name in zDb into a pointer to the corresponding
	 ** schema.  If not found, pSchema will remain NULL and nothing will match
	 ** resulting in an appropriate error message toward the end of this routine
	 */
	if zDb != 0 {
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_PartIdx)|libc.Int32FromInt32(NC_IsCheck)) != 0 {
			/* Silently ignore database qualifiers inside CHECK constraints and
			 ** partial indices.  Do not raise errors because that might break
			 ** legacy and because it does not hurt anything to just ignore the
			 ** database name. */
			zDb = uintptr(0)
		} else {
			i = 0
			for {
				if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
					break
				}
				if _sqlite3StrICmp(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FzDbSName, zDb) == 0 {
					pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpSchema
					break
				}
				goto _1
			_1:
				;
				i = i + 1
			}
			if i == (*Tsqlite3)(unsafe.Pointer(db)).FnDb && _sqlite3StrICmp(tls, __ccgo_ts+6820, zDb) == 0 {
				/* This branch is taken when the main database has been renamed
				 ** using SQLITE_DBCONFIG_MAINDBNAME. */
				pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema
				zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FzDbSName
			}
		}
	}
	/* Start at the inner-most context and move outward until a match is found */
	for cond := true; cond; cond = pNC != 0 {
		pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
		if pSrcList != 0 {
			i = 0
			pItem = pSrcList + 8
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
					break
				}
				pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
				if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000>>17) != 0 {
					/* In this case, pItem is a subquery that has been formed from a
					 ** parenthesized subset of the FROM clause terms.  Example:
					 **   .... FROM t1 LEFT JOIN (t2 RIGHT JOIN t3 USING(x)) USING(y) ...
					 **                          \_________________________/
					 **             This pItem -------------^
					 */
					hit = 0
					pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
					pEList = (*TSelect)(unsafe.Pointer(pSel)).FpEList
					j = 0
					for {
						if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
							break
						}
						**(**int32)(__ccgo_up(bp + 8)) = 0 /* True if possible rowid match */
						if !(_sqlite3MatchEName(tls, pEList+8+uintptr(j)*32, zCol, zTab, zDb, bp+8) != 0) {
							goto _3
						}
						if **(**int32)(__ccgo_up(bp + 8)) == 0 {
							if cnt > 0 {
								if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x100000>>20) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 64)), zCol) < 0 || pMatch == pItem {
									/* Two or more tables have the same column name which is
									 ** not joined by USING. Or, a single table has two columns
									 ** that match a USING term (if pMatch==pItem). These are both
									 ** "ambiguous column name" errors. Signal as much by clearing
									 ** pFJMatch and letting cnt go above 1. */
									_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
									**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
								} else {
									if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
										/* An INNER or LEFT JOIN.  Use the left-most table */
										goto _3
									} else {
										if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) == 0 {
											/* A RIGHT JOIN.  Use the right-most table */
											cnt = 0
											_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
											**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
										} else {
											/* For a FULL JOIN, we must construct a coalesce() func */
											_extendFJMatch(tls, pParse, bp, pMatch, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
										}
									}
								}
							}
							cnt = cnt + 1
							hit = int32(1)
						} else {
							if cnt > 0 {
								/* This is a potential rowid match, but there has already been
								 ** a real match found. So this can be ignored.  */
								goto _3
							}
						}
						cntTab = cntTab + 1
						pMatch = pItem
						(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(j)
						libc.SetBitFieldPtr16Uint32(pEList+8+uintptr(j)*32+16+4, libc.Uint32FromInt32(1), 9, 0x200)
						/* rowid cannot be part of a USING clause - assert() this. */
						if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*32 + 16 + 4))&0x100>>8)) != 0 {
							break
						}
						goto _3
					_3:
						;
						j = j + 1
					}
					if hit != 0 || zTab == uintptr(0) {
						goto _2
					}
				}
				if zTab != 0 {
					if zDb != 0 {
						if (*TTable)(unsafe.Pointer(pTab)).FpSchema != pSchema {
							goto _2
						}
						if pSchema == uintptr(0) && libc.Xstrcmp(tls, zDb, __ccgo_ts+6825) != 0 {
							goto _2
						}
					}
					if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != uintptr(0) {
						if _sqlite3StrICmp(tls, zTab, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias) != 0 {
							goto _2
						}
					} else {
						if _sqlite3StrICmp(tls, zTab, (*TTable)(unsafe.Pointer(pTab)).FzName) != 0 {
							if (*TTable)(unsafe.Pointer(pTab)).Ftnum != uint32(1) {
								goto _2
							}
							if !(_isValidSchemaTableName(tls, zTab, pTab, zDb) != 0) {
								goto _2
							}
						}
					}
					if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
						_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr+64)
					}
				}
				j = _sqlite3ColumnIndex(tls, pTab, zCol)
				if j >= 0 {
					if cnt > 0 {
						if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x100000>>20) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 64)), zCol) < 0 {
							/* Two or more tables have the same column name which is
							 ** not joined by USING.  This is an error.  Signal as much
							 ** by clearing pFJMatch and letting cnt go above 1. */
							_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
							**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
						} else {
							if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
								/* An INNER or LEFT JOIN.  Use the left-most table */
								goto _2
							} else {
								if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) == 0 {
									/* A RIGHT JOIN.  Use the right-most table */
									cnt = 0
									_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
									**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
								} else {
									/* For a FULL JOIN, we must construct a coalesce() func */
									_extendFJMatch(tls, pParse, bp, pMatch, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
								}
							}
						}
					}
					cnt = cnt + 1
					pMatch = pItem
					/* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
					if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
						v4 = -int32(1)
					} else {
						v4 = int32(int16(j))
					}
					(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(v4)
					if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000>>17) != 0 {
						_sqlite3SrcItemColumnUsed(tls, pItem, j)
					}
				}
				if 0 == cnt && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) {
					/* pTab is a potential ROWID match.  Keep track of it and match
					 ** the ROWID later if that seems appropriate.  (Search for "cntTab"
					 ** to find related code.)  Only allow a ROWID match if there is
					 ** a single ROWID match candidate.
					 */
					/* The (much more common) non-SQLITE_ALLOW_ROWID_IN_VIEW case is
					 ** simpler since we require exactly one candidate, which will
					 ** always be a non-VIEW
					 */
					cntTab = cntTab + 1
					pMatch = pItem
				}
				goto _2
			_2:
				;
				i = i + 1
				pItem += 80
			}
			if pMatch != 0 {
				(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pMatch)).FiCursor
				*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*TSrcItem)(unsafe.Pointer(pMatch)).FpSTab
				if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pMatch)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
					**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
				}
				pSchema = (*TTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpSchema
			}
		} /* if( pSrcList ) */
		/* If we have not already resolved the name, then maybe
		 ** it is a new.* or old.* trigger argument reference.  Or
		 ** maybe it is an excluded.* from an upsert.  Or maybe it is
		 ** a reference in the RETURNING clause to a table being modified.
		 */
		if cnt == 0 && zDb == uintptr(0) {
			pTab = uintptr(0)
			if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != uintptr(0) {
				op = libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeTriggerOp)
				if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0 {
					if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_UBaseReg) != 0 && (zTab == uintptr(0) || _sqlite3StrICmp(tls, zTab, (*TTable)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab)).FzName) == 0 || _isValidSchemaTableName(tls, zTab, (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab, uintptr(0)) != 0) {
						(*TExpr)(unsafe.Pointer(pExpr)).FiTable = libc.BoolInt32(op != int32(TK_DELETE))
						pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
					}
				} else {
					if op != int32(TK_DELETE) && zTab != 0 && _sqlite3StrICmp(tls, __ccgo_ts+6827, zTab) == 0 {
						(*TExpr)(unsafe.Pointer(pExpr)).FiTable = int32(1)
						pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
					} else {
						if op != int32(TK_INSERT) && zTab != 0 && _sqlite3StrICmp(tls, __ccgo_ts+6831, zTab) == 0 {
							(*TExpr)(unsafe.Pointer(pExpr)).FiTable = 0
							pTab = (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab
						}
					}
				}
			}
			if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_UUpsert) != 0 && zTab != uintptr(0) {
				pUpsert = *(*uintptr)(unsafe.Pointer(pNC + 16))
				if pUpsert != 0 && _sqlite3StrICmp(tls, __ccgo_ts+6835, zTab) == 0 {
					pTab = (*(*TSrcItem)(unsafe.Pointer((*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc + 8))).FpSTab
					(*TExpr)(unsafe.Pointer(pExpr)).FiTable = int32(EXCLUDED_TABLE_NUMBER)
				}
			}
			if pTab != 0 {
				pSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
				cntTab = cntTab + 1
				iCol = _sqlite3ColumnIndex(tls, pTab, zCol)
				if iCol >= 0 {
					if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) == iCol {
						iCol = -int32(1)
					}
				} else {
					if _sqlite3IsRowid(tls, zCol) != 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) {
						iCol = -int32(1)
					} else {
						iCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
					}
				}
				if iCol < int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
					cnt = cnt + 1
					pMatch = uintptr(0)
					if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == int32(EXCLUDED_TABLE_NUMBER) {
						if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
							(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(iCol)
							*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
							eNewExprOp = int32(TK_COLUMN)
						} else {
							(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TUpsert)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNC + 16)))).FregData + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
							eNewExprOp = int32(TK_REGISTER)
						}
					} else {
						*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
						if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0 {
							eNewExprOp = int32(TK_REGISTER)
							(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = uint8(TK_COLUMN)
							(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(iCol)
							(*TExpr)(unsafe.Pointer(pExpr)).FiTable = *(*int32)(unsafe.Pointer(&(*TNameContext)(unsafe.Pointer(pNC)).FuNC)) + (int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))*(*TExpr)(unsafe.Pointer(pExpr)).FiTable + int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iCol))) + int32(1)
						} else {
							(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(iCol)
							eNewExprOp = int32(TK_TRIGGER)
							if iCol < 0 {
								(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
							} else {
								if (*TExpr)(unsafe.Pointer(pExpr)).FiTable == 0 {
									if iCol >= int32(32) {
										v5 = uint32(0xffffffff)
									} else {
										v5 = libc.Uint32FromInt32(1) << iCol
									}
									**(**Tu32)(__ccgo_up(pParse + 248)) |= v5
								} else {
									if iCol >= int32(32) {
										v5 = uint32(0xffffffff)
									} else {
										v5 = libc.Uint32FromInt32(1) << iCol
									}
									**(**Tu32)(__ccgo_up(pParse + 252)) |= v5
								}
							}
						}
					}
				}
			}
		}
		/*
		 ** Perhaps the name is a reference to the ROWID
		 */
		if cnt == 0 && cntTab >= int32(1) && pMatch != 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_GenCol)) == 0 && _sqlite3IsRowid(tls, zCol) != 0 && ((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pMatch)).FpSTab)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) || int32(*(*uint32)(unsafe.Pointer(pMatch + 24 + 4))&0x20000>>17) != 0) {
			cnt = cntTab
			if int32(*(*uint32)(unsafe.Pointer(pMatch + 24 + 4))&0x20000>>17) == 0 {
				(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = int16(-int32(1))
			}
			(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
		}
		/*
		 ** If the input is of the form Z (not Y.Z or X.Y.Z) then the name Z
		 ** might refer to an result-set alias.  This happens, for example, when
		 ** we are resolving names in the WHERE clause of the following command:
		 **
		 **     SELECT a+b AS x FROM table WHERE x<10;
		 **
		 ** In cases like this, replace pExpr with a copy of the expression that
		 ** forms the result set entry ("a+b" in the example) and return immediately.
		 ** Note that the expression in the result set should have already been
		 ** resolved by the time the WHERE clause is resolved.
		 **
		 ** The ability to use an output result-set column in the WHERE, GROUP BY,
		 ** or HAVING clauses, or as part of a larger expression in the ORDER BY
		 ** clause is not standard SQL.  This is a (goofy) SQLite extension, that
		 ** is supported for backwards compatibility only. Hence, we issue a warning
		 ** on sqlite3_log() whenever the capability is used.
		 */
		if cnt == 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_UEList) != 0 && zTab == uintptr(0) {
			pEList = *(*uintptr)(unsafe.Pointer(pNC + 16))
			j = 0
			for {
				if !(j < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
					break
				}
				zAs = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*32))).FzEName
				if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*32 + 16 + 4))&0xc000>>14)) == ENAME_NAME && Xsqlite3_stricmp(tls, zAs, zCol) == 0 {
					pOrig = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*32))).FpExpr
					if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowAgg) == 0 && (*TExpr)(unsafe.Pointer(pOrig)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6844, libc.VaList(bp+24, zAs))
						return int32(WRC_Abort)
					}
					if (*TExpr)(unsafe.Pointer(pOrig)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Win)) != uint32(0) && ((*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowWin) == 0 || pNC != pTopNC) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6875, libc.VaList(bp+24, zAs))
						return int32(WRC_Abort)
					}
					if _sqlite3ExprVectorSize(tls, pOrig) != int32(1) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6912, 0)
						return int32(WRC_Abort)
					}
					_resolveAlias(tls, pParse, pEList, j, pExpr, nSubquery)
					cnt = int32(1)
					pMatch = uintptr(0)
					if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
						_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr)
					}
					goto lookupname_end
				}
				goto _7
			_7:
				;
				j = j + 1
			}
		}
		/* Advance to the next name context.  The loop will exit when either
		 ** we have a match (cnt>0) or when we run out of name contexts.
		 */
		if cnt != 0 {
			break
		}
		pNC = (*TNameContext)(unsafe.Pointer(pNC)).FpNext
		nSubquery = nSubquery + 1
	}
	/*
	 ** If X and Y are NULL (in other words if only the column name Z is
	 ** supplied) and the value of Z is enclosed in double-quotes, then
	 ** Z is a string literal if it doesn't match any column names.  In that
	 ** case, we need to return right away and not make any changes to
	 ** pExpr.
	 **
	 ** Because no reference was made to outer contexts, the pNC->nRef
	 ** fields are not changed in any context.
	 */
	if cnt == 0 && zTab == uintptr(0) {
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_DblQuoted)) != uint32(0) && _areDoubleQuotedStringsEnabled(tls, db, pTopNC) != 0 {
			/* If a double-quoted identifier does not match any known column name,
			 ** then treat it as a string.
			 **
			 ** This hack was added in the early days of SQLite in a misguided attempt
			 ** to be compatible with MySQL 3.x, which used double-quotes for strings.
			 ** I now sorely regret putting in this hack. The effect of this hack is
			 ** that misspelled identifier names are silently converted into strings
			 ** rather than causing an error, to the frustration of countless
			 ** programmers. To all those frustrated programmers, my apologies.
			 **
			 ** Someday, I hope to get rid of this hack. Unfortunately there is
			 ** a huge amount of legacy SQL that uses it. So for now, we just
			 ** issue a warning.
			 */
			Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+6930, libc.VaList(bp+24, zCol))
			(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_STRING)
			libc.Xmemset(tls, pExpr+64, 0, uint64(8))
			return int32(WRC_Prune)
		}
		if _sqlite3ExprIdToTrueFalse(tls, pExpr) != 0 {
			return int32(WRC_Prune)
		}
	}
	/*
	 ** cnt==0 means there was not match.
	 ** cnt>1 means there were two or more matches.
	 **
	 ** cnt==0 is always an error.  cnt>1 is often an error, but might
	 ** be multiple matches for a NATURAL LEFT JOIN or a LEFT JOIN USING.
	 */
	if cnt != int32(1) {
		if **(**uintptr)(__ccgo_up(bp)) != 0 {
			if (*TExprList)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnExpr == cnt-int32(1) {
				if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf)) != uint32(0) {
					**(**Tu32)(__ccgo_up(pExpr + 4)) &= ^libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf))
				} else {
					_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
					(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
					_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
					(*TExpr)(unsafe.Pointer(pExpr)).FpRight = uintptr(0)
				}
				_extendFJMatch(tls, pParse, bp, pMatch, (*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_FUNCTION)
				*(*uintptr)(unsafe.Pointer(pExpr + 8)) = __ccgo_ts + 6965
				*(*uintptr)(unsafe.Pointer(pExpr + 32)) = **(**uintptr)(__ccgo_up(bp))
				(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_DEFER)
				cnt = int32(1)
				goto lookupname_end
			} else {
				_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp)))
				**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
			}
		}
		if cnt == 0 {
			v8 = __ccgo_ts + 6974
		} else {
			v8 = __ccgo_ts + 6989
		}
		zErr = v8
		if zDb != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7011, libc.VaList(bp+24, zErr, zDb, zTab, zCol))
		} else {
			if zTab != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7024, libc.VaList(bp+24, zErr, zTab, zCol))
			} else {
				if cnt == 0 && (*TExpr)(unsafe.Pointer(pRight)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_DblQuoted)) != uint32(0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7034, libc.VaList(bp+24, zErr, zCol))
				} else {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7095, libc.VaList(bp+24, zErr, zCol))
				}
			}
		}
		_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
		(*TNameContext)(unsafe.Pointer(pTopNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pTopNC)).FnNcErr + 1
		eNewExprOp = int32(TK_NULL)
	}
	/* Remove all substructure from pExpr */
	if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_TokenOnly)|libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)) {
		_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
		_sqlite3ExprDelete(tls, db, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		(*TExpr)(unsafe.Pointer(pExpr)).FpRight = uintptr(0)
		**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf))
	}
	/* If a column from a table in pSrcList is referenced, then record
	 ** this fact in the pSrcList.a[].colUsed bitmask.  Column 0 causes
	 ** bit 0 to be set.  Column 1 sets bit 1.  And so forth.  Bit 63 is
	 ** set if the 63rd or any subsequent column is used.
	 **
	 ** The colUsed mask is an optimization used to help determine if an
	 ** index is a covering index.  The correct answer is still obtained
	 ** if the mask contains extra set bits.  However, it is important to
	 ** avoid setting bits beyond the maximum column number of the table.
	 ** (See ticket [b92e5e8ec2cdbaa1]).
	 **
	 ** If a generated column is referenced, set bits for every column
	 ** of the table.
	 */
	if pMatch != 0 {
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 {
			**(**TBitmask)(__ccgo_up(pMatch + 40)) |= _sqlite3ExprColUsed(tls, pExpr)
		} else {
			libc.SetBitFieldPtr32Uint32(pMatch+24+4, libc.Uint32FromInt32(1), 16, 0x10000)
		}
	}
	(*TExpr)(unsafe.Pointer(pExpr)).Fop = libc.Uint8FromInt32(eNewExprOp)
	goto lookupname_end
lookupname_end:
	;
	if cnt == int32(1) {
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FxAuth != 0 && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_TRIGGER)) {
			_sqlite3AuthRead(tls, pParse, pExpr, pSchema, (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList)
		}
		/* Increment the nRef value on all name contexts from TopNC up to
		 ** the point where the name matched. */
		for {
			(*TNameContext)(unsafe.Pointer(pTopNC)).FnRef = (*TNameContext)(unsafe.Pointer(pTopNC)).FnRef + 1
			if pTopNC == pNC {
				break
			}
			pTopNC = (*TNameContext)(unsafe.Pointer(pTopNC)).FpNext
			goto _9
		_9:
		}
		return int32(WRC_Prune)
	} else {
		return int32(WRC_Abort)
	}
	return r
}

// C documentation
//
//	/*
//	** Somewhere on pPage is a pointer to page iFrom.  Modify this pointer so
//	** that it points to iTo. Parameter eType describes the type of pointer to
//	** be modified, as  follows:
//	**
//	** PTRMAP_BTREE:     pPage is a btree-page. The pointer points at a child
//	**                   page of pPage.
//	**
//	** PTRMAP_OVERFLOW1: pPage is a btree-page. The pointer points at an overflow
//	**                   page pointed to by one of the cells on pPage.
//	**
//	** PTRMAP_OVERFLOW2: pPage is an overflow-page. The pointer points at the next
//	**                   overflow page in the list.
//	*/
func _modifyPagePointer(tls *libc.TLS, pPage uintptr, iFrom TPgno, iTo TPgno, eType Tu8) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, nCell, rc, v1 int32
	var pCell uintptr
	var _ /* info at bp+0 */ TCellInfo
	_, _, _, _, _ = i, nCell, pCell, rc, v1
	if libc.Int32FromUint8(eType) == int32(PTRMAP_OVERFLOW2) {
		/* The pointer is always the first 4 bytes of the page in this case.  */
		if _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData) != iFrom {
			return _sqlite3CorruptError(tls, int32(77112))
		}
		_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData, iTo)
	} else {
		if (*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0 {
			v1 = SQLITE_OK
		} else {
			v1 = _btreeInitPage(tls, pPage)
		}
		rc = v1
		if rc != 0 {
			return rc
		}
		nCell = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
		i = 0
		for {
			if !(i < nCell) {
				break
			}
			pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*i)))))
			if libc.Int32FromUint8(eType) == int32(PTRMAP_OVERFLOW1) {
				(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, pCell, bp)
				if uint32((**(**TCellInfo)(__ccgo_up(bp))).FnLocal) < (**(**TCellInfo)(__ccgo_up(bp))).FnPayload {
					if pCell+uintptr((**(**TCellInfo)(__ccgo_up(bp))).FnSize) > (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
						return _sqlite3CorruptError(tls, int32(77131))
					}
					if iFrom == _sqlite3Get4byte(tls, pCell+uintptr((**(**TCellInfo)(__ccgo_up(bp))).FnSize)-uintptr(4)) {
						_sqlite3Put4byte(tls, pCell+uintptr((**(**TCellInfo)(__ccgo_up(bp))).FnSize)-uintptr(4), iTo)
						break
					}
				}
			} else {
				if pCell+uintptr(4) > (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TBtShared)(unsafe.Pointer((*TMemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
					return _sqlite3CorruptError(tls, int32(77140))
				}
				if _sqlite3Get4byte(tls, pCell) == iFrom {
					_sqlite3Put4byte(tls, pCell, iTo)
					break
				}
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		if i == nCell {
			if libc.Int32FromUint8(eType) != int32(PTRMAP_BTREE) || _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))) != iFrom {
				return _sqlite3CorruptError(tls, int32(77152))
			}
			_sqlite3Put4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)), iTo)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Move the cursor down to the left-most leaf entry beneath the
//	** entry to which it is currently pointing.
//	**
//	** The left-most leaf is the one with the smallest key - the first
//	** in ascending order.
//	*/
func _moveToLeftmost(tls *libc.TLS, pCur uintptr) (r int32) {
	var pPage, v1 uintptr
	var pgno TPgno
	var rc int32
	var v2 bool
	_, _, _, _, _ = pPage, pgno, rc, v1, v2
	rc = SQLITE_OK
	for {
		if v2 = rc == SQLITE_OK; v2 {
			v1 = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
			pPage = v1
		}
		if !(v2 && !((*TMemPage)(unsafe.Pointer(v1)).Fleaf != 0)) {
			break
		}
		pgno = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)))))))
		rc = _moveToChild(tls, pCur, pgno)
	}
	return rc
}

// C documentation
//
//	/*
//	** Attempt to parse the given string into a julian day number.  Return
//	** the number of errors.
//	**
//	** The following are acceptable forms for the input string:
//	**
//	**      YYYY-MM-DD HH:MM:SS.FFF  +/-HH:MM
//	**      DDDD.DD
//	**      now
//	**
//	** In the first form, the +/-HH:MM is always optional.  The fractional
//	** seconds extension (the ".FFF") is optional.  The seconds portion
//	** (":SS.FFF") is option.  The year and date can be omitted as long
//	** as there is a time string.  The time string can be omitted as long
//	** as there is a year and date.
//	*/
func _parseDateOrTime(tls *libc.TLS, context uintptr, zDate uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* r at bp+0 */ float64
	if _parseYyyyMmDd(tls, zDate, p) == 0 {
		return 0
	} else {
		if _parseHhMmSs(tls, zDate, p) == 0 {
			return 0
		} else {
			if _sqlite3StrICmp(tls, zDate, __ccgo_ts+1228) == 0 && _sqlite3NotPureFunc(tls, context) != 0 {
				return _setDateTimeToCurrent(tls, context, p)
			} else {
				if _sqlite3AtoF(tls, zDate, bp) > 0 {
					_setRawDateNumber(tls, p, **(**float64)(__ccgo_up(bp)))
					return 0
				} else {
					if (_sqlite3StrICmp(tls, zDate, __ccgo_ts+1232) == 0 || _sqlite3StrICmp(tls, zDate, __ccgo_ts+1239) == 0) && _sqlite3NotPureFunc(tls, context) != 0 {
						libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 5, 0x20)
						return _setDateTimeToCurrent(tls, context, p)
					}
				}
			}
		}
	}
	return int32(1)
}

/* The julian day number for 9999-12-31 23:59:59.999 is 5373484.4999999.
** Multiplying this by 86400000 gives 464269060799999 as the maximum value
** for DateTime.iJD.
**
** But some older compilers (ex: gcc 4.2.1 on older Macs) cannot deal with
** such a large integer literal, so we have to encode it.
 */

// C documentation
//
//	/*
//	** Parse times of the form HH:MM or HH:MM:SS or HH:MM:SS.FFFF.
//	** The HH, MM, and SS must each be exactly 2 digits.  The
//	** fractional seconds FFFF can be one or more digits.
//	**
//	** Return 1 if there is a parsing error and 0 on success.
//	*/
func _parseHhMmSs(tls *libc.TLS, zDate uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var ms, rScale float64
	var _ /* h at bp+0 */ int32
	var _ /* m at bp+4 */ int32
	var _ /* s at bp+8 */ int32
	_, _ = ms, rScale
	ms = float64(0)
	if _getDigits(tls, zDate, __ccgo_ts+1204, libc.VaList(bp+24, bp, bp+4)) != int32(2) {
		return int32(1)
	}
	zDate = zDate + uintptr(5)
	if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zDate))) == int32(':') {
		zDate = zDate + 1
		if _getDigits(tls, zDate, __ccgo_ts+1212, libc.VaList(bp+24, bp+8)) != int32(1) {
			return int32(1)
		}
		zDate = zDate + uintptr(2)
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zDate))) == int32('.') && libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(zDate + 1)))])&int32(0x04) != 0 {
			rScale = float64(1)
			zDate = zDate + 1
			for libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(zDate)))])&int32(0x04) != 0 {
				ms = float64(ms*float64(10)) + float64(**(**uint8)(__ccgo_up(zDate))) - libc.Float64FromUint8('0')
				rScale = rScale * float64(10)
				zDate = zDate + 1
			}
			ms = ms / rScale
			/* Truncate to avoid problems with sub-milliseconds
			 ** rounding. https://sqlite.org/forum/forumpost/766a2c9231 */
			if ms > float64(0.999) {
				ms = float64(0.999)
			}
		}
	} else {
		**(**int32)(__ccgo_up(bp + 8)) = 0
	}
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
	(*TDateTime)(unsafe.Pointer(p)).Fh = **(**int32)(__ccgo_up(bp))
	(*TDateTime)(unsafe.Pointer(p)).Fm = **(**int32)(__ccgo_up(bp + 4))
	(*TDateTime)(unsafe.Pointer(p)).Fs = float64(**(**int32)(__ccgo_up(bp + 8))) + ms
	if _parseTimezone(tls, zDate, p) != 0 {
		return int32(1)
	}
	return 0
}

// C documentation
//
//	/*
//	** Process a modifier to a date-time stamp.  The modifiers are
//	** as follows:
//	**
//	**     NNN days
//	**     NNN hours
//	**     NNN minutes
//	**     NNN.NNNN seconds
//	**     NNN months
//	**     NNN years
//	**     +/-YYYY-MM-DD HH:MM:SS.SSS
//	**     ceiling
//	**     floor
//	**     start of month
//	**     start of year
//	**     start of week
//	**     start of day
//	**     weekday N
//	**     unixepoch
//	**     auto
//	**     localtime
//	**     utc
//	**     subsec
//	**     subsecond
//	**
//	** Return 0 on success and 1 if there is any kind of error. If the error
//	** is in a system call (i.e. localtime()), then an error message is written
//	** to context pCtx. If the error is an unrecognized modifier, no error is
//	** written to pCtx.
//	*/
func _parseModifier(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, p uintptr, idx int32) (r int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var Z, day Tsqlite3_int64
	var cnt, i, rc, rx, x, y, v1 int32
	var db, z2, zCopy uintptr
	var iErr, iGuess, iOrigJD, v2 Ti64
	var rRounder, v11 float64
	var z0 uint8
	var v4 bool
	var _ /* D at bp+64 */ int32
	var _ /* M at bp+60 */ int32
	var _ /* Y at bp+56 */ int32
	var _ /* h at bp+68 */ int32
	var _ /* m at bp+72 */ int32
	var _ /* new at bp+8 */ TDateTime
	var _ /* r at bp+0 */ float64
	var _ /* tx at bp+80 */ TDateTime
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = Z, cnt, day, db, i, iErr, iGuess, iOrigJD, rRounder, rc, rx, x, y, z0, z2, zCopy, v1, v11, v2, v4
	rc = int32(1)
	switch libc.Int32FromUint8(_sqlite3UpperToLower[uint8(**(**uint8)(__ccgo_up(z)))]) {
	case int32('a'):
		/*
		 **    auto
		 **
		 ** If rawS is available, then interpret as a julian day number, or
		 ** a unix timestamp, depending on its magnitude.
		 */
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1272) == 0 {
			if idx > int32(1) {
				return int32(1)
			} /* IMP: R-33611-57934 */
			_autoAdjustDate(tls, p)
			rc = 0
		}
	case int32('c'):
		/*
		 **    ceiling
		 **
		 ** Resolve day-of-month overflow by rolling forward into the next
		 ** month.  As this is the default action, this modifier is really
		 ** a no-op that is only included for symmetry.  See "floor".
		 */
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1277) == 0 {
			_computeJD(tls, p)
			_clearYMD_HMS_TZ(tls, p)
			rc = 0
			(*TDateTime)(unsafe.Pointer(p)).FnFloor = uint8(0)
		}
	case int32('f'):
		/*
		 **    floor
		 **
		 ** Resolve day-of-month overflow by rolling back to the end of the
		 ** previous month.
		 */
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1285) == 0 {
			_computeJD(tls, p)
			**(**Tsqlite3_int64)(__ccgo_up(p)) -= int64(libc.Int32FromUint8((*TDateTime)(unsafe.Pointer(p)).FnFloor) * int32(86400000))
			_clearYMD_HMS_TZ(tls, p)
			rc = 0
		}
	case int32('j'):
		/*
		 **    julianday
		 **
		 ** Always interpret the prior number as a julian-day value.  If this
		 ** is not the first modifier, or if the prior argument is not a numeric
		 ** value in the allowed range of julian day numbers understood by
		 ** SQLite (0..5373484.5) then the result will be NULL.
		 */
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1291) == 0 {
			if idx > int32(1) {
				return int32(1)
			} /* IMP: R-31176-64601 */
			if (*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0 && int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x80>>7)) != 0 {
				rc = 0
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
			}
		}
	case int32('l'):
		/*    localtime
		 **
		 ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
		 ** show local time.
		 */
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1301) == 0 && _sqlite3NotPureFunc(tls, pCtx) != 0 {
			if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x8>>3)) != 0 {
				v1 = SQLITE_OK
			} else {
				v1 = _toLocaltime(tls, p, pCtx)
			}
			rc = v1
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 4, 0x10)
			libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 3, 0x8)
		}
	case int32('u'):
		/*
		 **    unixepoch
		 **
		 ** Treat the current value of p->s as the number of
		 ** seconds since 1970.  Convert to a real julian day number.
		 */
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1311) == 0 && int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x80>>7)) != 0 {
			if idx > int32(1) {
				return int32(1)
			} /* IMP: R-49255-55373 */
			**(**float64)(__ccgo_up(bp)) = float64((*TDateTime)(unsafe.Pointer(p)).Fs*float64(1000)) + float64(2.1086676e+14)
			if **(**float64)(__ccgo_up(bp)) >= float64(0) && **(**float64)(__ccgo_up(bp)) < float64(4.642690608e+14) {
				_clearYMD_HMS_TZ(tls, p)
				(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(**(**float64)(__ccgo_up(bp)) + libc.Float64FromFloat64(0.5))
				(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
				rc = 0
			}
		} else {
			if Xsqlite3_stricmp(tls, z, __ccgo_ts+1321) == 0 && _sqlite3NotPureFunc(tls, pCtx) != 0 {
				if int32(uint32(*(*uint8)(unsafe.Pointer(p + 44))&0x10>>4)) == 0 { /* Guess at the corresponding utc time */
					cnt = 0 /* Guess is off by this much */
					_computeJD(tls, p)
					v2 = (*TDateTime)(unsafe.Pointer(p)).FiJD
					iOrigJD = v2
					iGuess = v2
					iErr = 0
					for {
						libc.Xmemset(tls, bp+8, 0, uint64(48))
						iGuess = iGuess - iErr
						(**(**TDateTime)(__ccgo_up(bp + 8))).FiJD = iGuess
						(**(**TDateTime)(__ccgo_up(bp + 8))).FvalidJD = uint8(1)
						rc = _toLocaltime(tls, bp+8, pCtx)
						if rc != 0 {
							return rc
						}
						_computeJD(tls, bp+8)
						iErr = (**(**TDateTime)(__ccgo_up(bp + 8))).FiJD - iOrigJD
						goto _5
					_5:
						;
						if v4 = iErr != 0; v4 {
							v1 = cnt
							cnt = cnt + 1
						}
						if !(v4 && v1 < int32(3)) {
							break
						}
					}
					libc.Xmemset(tls, p, 0, uint64(48))
					(*TDateTime)(unsafe.Pointer(p)).FiJD = iGuess
					(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
					libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
					libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
				}
				rc = SQLITE_OK
			}
		}
	case int32('w'):
		/*
		 **    weekday N
		 **
		 ** Move the date to the same time on the next occurrence of
		 ** weekday N where 0==Sunday, 1==Monday, and so forth.  If the
		 ** date is already on the appropriate weekday, this is a no-op.
		 */
		if v4 = Xsqlite3_strnicmp(tls, z, __ccgo_ts+1325, int32(8)) == 0 && _sqlite3AtoF(tls, z+8, bp) > 0 && **(**float64)(__ccgo_up(bp)) >= float64(0) && **(**float64)(__ccgo_up(bp)) < float64(7); v4 {
			v1 = int32(**(**float64)(__ccgo_up(bp)))
			n = v1
		}
		if v4 && float64(v1) == **(**float64)(__ccgo_up(bp)) {
			_computeYMD_HMS(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
			(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
			_computeJD(tls, p)
			Z = ((*TDateTime)(unsafe.Pointer(p)).FiJD + int64(129600000)) / int64(86400000) % int64(7)
			if Z > int64(n) {
				Z = Z - int64(7)
			}
			**(**Tsqlite3_int64)(__ccgo_up(p)) += (int64(n) - Z) * int64(86400000)
			_clearYMD_HMS_TZ(tls, p)
			rc = 0
		}
	case int32('s'):
		/*
		 **    start of TTTTT
		 **
		 ** Move the date backwards to the beginning of the current day,
		 ** or month or year.
		 **
		 **    subsecond
		 **    subsec
		 **
		 ** Show subsecond precision in the output of datetime() and
		 ** unixepoch() and strftime('%s').
		 */
		if Xsqlite3_strnicmp(tls, z, __ccgo_ts+1334, int32(9)) != 0 {
			if Xsqlite3_stricmp(tls, z, __ccgo_ts+1232) == 0 || Xsqlite3_stricmp(tls, z, __ccgo_ts+1239) == 0 {
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 5, 0x20)
				rc = 0
			}
			break
		}
		if !((*TDateTime)(unsafe.Pointer(p)).FvalidJD != 0) && !((*TDateTime)(unsafe.Pointer(p)).FvalidYMD != 0) && !((*TDateTime)(unsafe.Pointer(p)).FvalidHMS != 0) {
			break
		}
		z = z + uintptr(9)
		_computeYMD(tls, p)
		(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
		v1 = libc.Int32FromInt32(0)
		(*TDateTime)(unsafe.Pointer(p)).Fm = v1
		(*TDateTime)(unsafe.Pointer(p)).Fh = v1
		(*TDateTime)(unsafe.Pointer(p)).Fs = float64(0)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
		(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
		(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
		if Xsqlite3_stricmp(tls, z, __ccgo_ts+1344) == 0 {
			(*TDateTime)(unsafe.Pointer(p)).FD = int32(1)
			rc = 0
		} else {
			if Xsqlite3_stricmp(tls, z, __ccgo_ts+1350) == 0 {
				(*TDateTime)(unsafe.Pointer(p)).FM = int32(1)
				(*TDateTime)(unsafe.Pointer(p)).FD = int32(1)
				rc = 0
			} else {
				if Xsqlite3_stricmp(tls, z, __ccgo_ts+1355) == 0 {
					rc = 0
				}
			}
		}
	case int32('+'):
		fallthrough
	case int32('-'):
		fallthrough
	case int32('0'):
		fallthrough
	case int32('1'):
		fallthrough
	case int32('2'):
		fallthrough
	case int32('3'):
		fallthrough
	case int32('4'):
		fallthrough
	case int32('5'):
		fallthrough
	case int32('6'):
		fallthrough
	case int32('7'):
		fallthrough
	case int32('8'):
		fallthrough
	case int32('9'):
		z2 = z
		db = Xsqlite3_context_db_handle(tls, pCtx)
		z0 = **(**uint8)(__ccgo_up(z))
		n = int32(1)
		for {
			if !(**(**uint8)(__ccgo_up(z + uintptr(n))) != 0) {
				break
			}
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(n)))) == int32(':') {
				break
			}
			if libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(z + uintptr(n))))])&int32(0x01) != 0 {
				break
			}
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(n)))) == int32('-') {
				if n == int32(5) && _getDigits(tls, z+1, __ccgo_ts+1359, libc.VaList(bp+136, bp+56)) == int32(1) {
					break
				}
				if n == int32(6) && _getDigits(tls, z+1, __ccgo_ts+1363, libc.VaList(bp+136, bp+56)) == int32(1) {
					break
				}
			}
			goto _9
		_9:
			;
			n = n + 1
		}
		zCopy = _sqlite3DbStrNDup(tls, db, z, libc.Uint64FromInt32(n))
		if zCopy == uintptr(0) {
			break
		}
		rx = libc.BoolInt32(_sqlite3AtoF(tls, zCopy, bp) <= 0)
		_sqlite3DbFree(tls, db, zCopy)
		if rx != 0 {
			break
		}
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(n)))) == int32('-') {
			/* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
			 ** specified number of years, months, and days.  MM is limited to
			 ** the range 0-11 and DD is limited to 0-30.
			 */
			if libc.Int32FromUint8(z0) != int32('+') && libc.Int32FromUint8(z0) != int32('-') {
				break
			} /* Must start with +/- */
			if n == int32(5) {
				if _getDigits(tls, z+1, __ccgo_ts+1367, libc.VaList(bp+136, bp+56, bp+60, bp+64)) != int32(3) {
					break
				}
			} else {
				if _getDigits(tls, z+1, __ccgo_ts+1379, libc.VaList(bp+136, bp+56, bp+60, bp+64)) != int32(3) {
					break
				}
				z = z + 1
			}
			if **(**int32)(__ccgo_up(bp + 60)) >= int32(12) {
				break
			} /* M range 0..11 */
			if **(**int32)(__ccgo_up(bp + 64)) >= int32(31) {
				break
			} /* D range 0..30 */
			_computeYMD_HMS(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
			if libc.Int32FromUint8(z0) == int32('-') {
				**(**int32)(__ccgo_up(p + 8)) -= **(**int32)(__ccgo_up(bp + 56))
				**(**int32)(__ccgo_up(p + 12)) -= **(**int32)(__ccgo_up(bp + 60))
				**(**int32)(__ccgo_up(bp + 64)) = -**(**int32)(__ccgo_up(bp + 64))
			} else {
				**(**int32)(__ccgo_up(p + 8)) += **(**int32)(__ccgo_up(bp + 56))
				**(**int32)(__ccgo_up(p + 12)) += **(**int32)(__ccgo_up(bp + 60))
			}
			if (*TDateTime)(unsafe.Pointer(p)).FM > 0 {
				v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(1)) / int32(12)
			} else {
				v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(12)) / int32(12)
			}
			x = v1
			**(**int32)(__ccgo_up(p + 8)) += x
			**(**int32)(__ccgo_up(p + 12)) -= x * int32(12)
			_computeFloor(tls, p)
			_computeJD(tls, p)
			(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(0)
			(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(0)
			**(**Tsqlite3_int64)(__ccgo_up(p)) += int64(**(**int32)(__ccgo_up(bp + 64))) * int64(86400000)
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + 11))) == 0 {
				rc = 0
				break
			}
			if libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(z + 11)))])&int32(0x01) != 0 && _getDigits(tls, z+12, __ccgo_ts+1204, libc.VaList(bp+136, bp+68, bp+72)) == int32(2) {
				z2 = z + 12
				n = int32(2)
			} else {
				break
			}
		}
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(z2 + uintptr(n)))) == int32(':') {
			if !(libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(z2)))])&libc.Int32FromInt32(0x04) != 0) {
				z2 = z2 + 1
			}
			libc.Xmemset(tls, bp+80, 0, uint64(48))
			if _parseHhMmSs(tls, z2, bp+80) != 0 {
				break
			}
			_computeJD(tls, bp+80)
			(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD -= int64(43200000)
			day = (**(**TDateTime)(__ccgo_up(bp + 80))).FiJD / int64(86400000)
			(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD -= day * int64(86400000)
			if libc.Int32FromUint8(z0) == int32('-') {
				(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD = -(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD
			}
			_computeJD(tls, p)
			_clearYMD_HMS_TZ(tls, p)
			**(**Tsqlite3_int64)(__ccgo_up(p)) += (**(**TDateTime)(__ccgo_up(bp + 80))).FiJD
			rc = 0
			break
		}
		/* If control reaches this point, it means the transformation is
		 ** one of the forms like "+NNN days".  */
		z = z + uintptr(n)
		for libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(z)))])&int32(0x01) != 0 {
			z = z + 1
		}
		n = _sqlite3Strlen30(tls, z)
		if n < int32(3) || n > int32(10) {
			break
		}
		if libc.Int32FromUint8(_sqlite3UpperToLower[uint8(**(**uint8)(__ccgo_up(z + uintptr(n-int32(1)))))]) == int32('s') {
			n = n - 1
		}
		_computeJD(tls, p)
		if **(**float64)(__ccgo_up(bp)) < libc.Float64FromInt32(0) {
			v11 = -libc.Float64FromFloat64(0.5)
		} else {
			v11 = +libc.Float64FromFloat64(0.5)
		}
		rRounder = v11
		(*TDateTime)(unsafe.Pointer(p)).FnFloor = uint8(0)
		i = 0
		for {
			if !(i < libc.Int32FromUint64(libc.Uint64FromInt64(96)/libc.Uint64FromInt64(16))) {
				break
			}
			if libc.Int32FromUint8(_aXformType[i].FnName) == n && Xsqlite3_strnicmp(tls, uintptr(unsafe.Pointer(&_aXformType))+uintptr(i)*16+1, z, n) == 0 && **(**float64)(__ccgo_up(bp)) > float64(-_aXformType[i].FrLimit) && **(**float64)(__ccgo_up(bp)) < float64(_aXformType[i].FrLimit) {
				switch i {
				case int32(4): /* Special processing to add months */
					_computeYMD_HMS(tls, p)
					**(**int32)(__ccgo_up(p + 12)) += int32(**(**float64)(__ccgo_up(bp)))
					if (*TDateTime)(unsafe.Pointer(p)).FM > 0 {
						v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(1)) / int32(12)
					} else {
						v1 = ((*TDateTime)(unsafe.Pointer(p)).FM - int32(12)) / int32(12)
					}
					x = v1
					**(**int32)(__ccgo_up(p + 8)) += x
					**(**int32)(__ccgo_up(p + 12)) -= x * int32(12)
					_computeFloor(tls, p)
					(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
					**(**float64)(__ccgo_up(bp)) = **(**float64)(__ccgo_up(bp)) - float64(int32(**(**float64)(__ccgo_up(bp))))
				case int32(5): /* Special processing to add years */
					y = int32(**(**float64)(__ccgo_up(bp)))
					_computeYMD_HMS(tls, p)
					**(**int32)(__ccgo_up(p + 8)) += y
					_computeFloor(tls, p)
					(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
					**(**float64)(__ccgo_up(bp)) = **(**float64)(__ccgo_up(bp)) - float64(int32(**(**float64)(__ccgo_up(bp))))
					break
				}
				_computeJD(tls, p)
				**(**Tsqlite3_int64)(__ccgo_up(p)) += int64(float64(float64(**(**float64)(__ccgo_up(bp))*libc.Float64FromFloat64(1000))*float64(_aXformType[i].FrXform)) + rRounder)
				rc = 0
				break
			}
			goto _12
		_12:
			;
			i = i + 1
		}
		_clearYMD_HMS_TZ(tls, p)
	default:
		break
	}
	return rc
}

// C documentation
//
//	/*
//	** Parse a timezone extension on the end of a date-time.
//	** The extension is of the form:
//	**
//	**        (+/-)HH:MM
//	**
//	** Or the "zulu" notation:
//	**
//	**        Z
//	**
//	** If the parse is successful, write the number of minutes
//	** of change in p->tz and return 0.  If a parser error occurs,
//	** return non-zero.
//	**
//	** A missing specifier is not considered an error.
//	*/
func _parseTimezone(tls *libc.TLS, zDate uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var c, sgn int32
	var _ /* nHr at bp+0 */ int32
	var _ /* nMn at bp+4 */ int32
	_, _ = c, sgn
	sgn = 0
	for libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(zDate)))])&int32(0x01) != 0 {
		zDate = zDate + 1
	}
	(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
	c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(zDate)))
	if c == int32('-') {
		sgn = -int32(1)
	} else {
		if c == int32('+') {
			sgn = +libc.Int32FromInt32(1)
		} else {
			if c == int32('Z') || c == int32('z') {
				zDate = zDate + 1
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
				libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
				goto zulu_time
			} else {
				return libc.BoolInt32(c != 0)
			}
		}
	}
	zDate = zDate + 1
	if _getDigits(tls, zDate, __ccgo_ts+1196, libc.VaList(bp+16, bp, bp+4)) != int32(2) {
		return int32(1)
	}
	zDate = zDate + uintptr(5)
	(*TDateTime)(unsafe.Pointer(p)).Ftz = sgn * (**(**int32)(__ccgo_up(bp + 4)) + **(**int32)(__ccgo_up(bp))*int32(60))
	if (*TDateTime)(unsafe.Pointer(p)).Ftz == 0 { /* Forum post 2025-09-17T10:12:14z */
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
	}
	goto zulu_time
zulu_time:
	;
	for libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(zDate)))])&int32(0x01) != 0 {
		zDate = zDate + 1
	}
	return libc.BoolInt32(libc.Int32FromUint8(**(**uint8)(__ccgo_up(zDate))) != 0)
}

func _readCoord(tls *libc.TLS, p uintptr, pCoord uintptr) {
	*(*Tu32)(unsafe.Pointer(pCoord)) = **(**Tu32)(__ccgo_up(p))
}

func _readInt64(tls *libc.TLS, p uintptr) (r Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* x at bp+0 */ Ti64
	libc.Xmemcpy(tls, bp, p, uint64(8))
	return **(**Ti64)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** For each name in the the expression-list pEList (i.e. each
//	** pEList->a[i].zName) that matches the string in zOld, extract the
//	** corresponding rename-token from Parse object pParse and add it
//	** to the RenameCtx pCtx.
//	*/
func _renameColumnElistNames(tls *libc.TLS, pParse uintptr, pCtx uintptr, pEList uintptr, zOld uintptr) {
	var i int32
	var zName uintptr
	_, _ = i, zName
	if pEList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			zName = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
			if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0xc000>>14)) == ENAME_NAME && zName != uintptr(0) && 0 == Xsqlite3_stricmp(tls, zName, zOld) {
				_renameTokenFind(tls, pParse, pCtx, zName)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
//	** it was read from the schema of database zDb. Return SQLITE_OK if
//	** successful. Otherwise, return an SQLite error code and leave an error
//	** message in the Parse object.
//	*/
func _renameResolveTrigger(tls *libc.TLS, pParse uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, p, pNew, pSel, pSrc, pStep, pUpsert, pUpsertSet uintptr
	var i, rc, v2 int32
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _ = db, i, p, pNew, pSel, pSrc, pStep, pUpsert, pUpsertSet, rc, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger
	rc = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint64(56))
	(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
	(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = _sqlite3FindTable(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).Ftable, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).FpTabSchema))*32))).FzDbSName)
	(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pNew)).Fop
	/* ALWAYS() because if the table of the trigger does not exist, the
	 ** error would have been hit before this point */
	if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
		rc = libc.BoolInt32(_sqlite3ViewGetColumnNames(tls, pParse, (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0)
	}
	/* Resolve symbols in WHEN clause */
	if rc == SQLITE_OK && (*TTrigger)(unsafe.Pointer(pNew)).FpWhen != 0 {
		rc = _sqlite3ResolveExprNames(tls, bp, (*TTrigger)(unsafe.Pointer(pNew)).FpWhen)
	}
	pStep = (*TTrigger)(unsafe.Pointer(pNew)).Fstep_list
	for {
		if !(rc == SQLITE_OK && pStep != 0) {
			break
		}
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect != 0 {
			_sqlite3SelectPrep(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, bp)
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				rc = (*TParse)(unsafe.Pointer(pParse)).Frc
			}
		}
		if rc == SQLITE_OK && (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
			pSrc = _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0)
			if pSrc != 0 {
				pSel = _sqlite3SelectNew(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
				if pSel == uintptr(0) {
					(*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList = uintptr(0)
					pSrc = uintptr(0)
					rc = int32(SQLITE_NOMEM)
				} else {
					/* pStep->pExprList contains an expression-list used for an UPDATE
					 ** statement. So the a[].zEName values are the RHS of the
					 ** "<col> = <expr>" clauses of the UPDATE statement. So, before
					 ** running SelectPrep(), change all the eEName values in
					 ** pStep->pExprList to ENAME_SPAN (from their current value of
					 ** ENAME_NAME). This is to prevent any ids in ON() clauses that are
					 ** part of pSrc from being incorrectly resolved against the
					 ** a[].zEName values as if they were column aliases.  */
					_renameSetENames(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, int32(ENAME_SPAN))
					_sqlite3SelectPrep(tls, pParse, pSel, uintptr(0))
					_renameSetENames(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, ENAME_NAME)
					if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
						v2 = int32(SQLITE_ERROR)
					} else {
						v2 = SQLITE_OK
					}
					rc = v2
					if (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList != 0 {
						(*TSelect)(unsafe.Pointer(pSel)).FpEList = uintptr(0)
					}
					(*TSelect)(unsafe.Pointer(pSel)).FpSrc = uintptr(0)
					_sqlite3SelectDelete(tls, db, pSel)
				}
				if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
					i = 0
					for {
						if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc)).FnSrc && rc == SQLITE_OK) {
							break
						}
						p = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8 + uintptr(i)*80
						if int32(*(*uint32)(unsafe.Pointer(p + 24 + 4))&0x20000000>>29) != 0 {
							_sqlite3SelectPrep(tls, pParse, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 72)))).FpSelect, uintptr(0))
						}
						goto _3
					_3:
						;
						i = i + 1
					}
				}
				if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					rc = int32(SQLITE_NOMEM)
				}
				(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = pSrc
				if rc == SQLITE_OK && (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere != 0 {
					rc = _sqlite3ResolveExprNames(tls, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere)
				}
				if rc == SQLITE_OK {
					rc = _sqlite3ResolveExprListNames(tls, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList)
				}
				if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 && rc == SQLITE_OK {
					pUpsert = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
					(*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc = pSrc
					*(*uintptr)(unsafe.Pointer(bp + 16)) = pUpsert
					(**(**TNameContext)(__ccgo_up(bp))).FncFlags = int32(NC_UUpsert)
					rc = _sqlite3ResolveExprListNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
					if rc == SQLITE_OK {
						pUpsertSet = (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet
						rc = _sqlite3ResolveExprListNames(tls, bp, pUpsertSet)
					}
					if rc == SQLITE_OK {
						rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
					}
					if rc == SQLITE_OK {
						rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
					}
					(**(**TNameContext)(__ccgo_up(bp))).FncFlags = 0
				}
				(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = uintptr(0)
				_sqlite3SrcListDelete(tls, db, pSrc)
			} else {
				rc = int32(SQLITE_NOMEM)
			}
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
	return rc
}

// C documentation
//
//	/*
//	** Set all pEList->a[].fg.eEName fields in the expression-list to val.
//	*/
func _renameSetENames(tls *libc.TLS, pEList uintptr, val int32) {
	var i int32
	_ = i
	if pEList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			libc.SetBitFieldPtr16Uint32(pEList+8+uintptr(i)*32+16+4, libc.Uint32FromInt32(val&libc.Int32FromInt32(0x3)), 14, 0xc000)
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** Generate code to verify that the schemas of database zDb and, if
//	** bTemp is not true, database "temp", can still be parsed. This is
//	** called at the end of the generation of an ALTER TABLE ... RENAME ...
//	** statement to ensure that the operation has not rendered any schema
//	** objects unusable.
//	*/
func _renameTestSchema(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32, zWhen uintptr, bNoDQS int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 10, 0x400)
	_sqlite3NestedParse(tls, pParse, __ccgo_ts+8675, libc.VaList(bp+8, zDb, zDb, bTemp, zWhen, bNoDQS))
	if bTemp == 0 {
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+8850, libc.VaList(bp+8, zDb, zWhen, bNoDQS))
	}
}

// C documentation
//
//	/*
//	** Walker callback used by sqlite3RenameExprUnmap().
//	*/
func _renameUnmapSelectCb(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var i int32
	var pList, pParse, pSrc uintptr
	_, _, _, _ = i, pList, pParse, pSrc
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return int32(WRC_Abort)
	}
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_View)|libc.Int32FromInt32(SF_CopyCte)) != 0 {
		return int32(WRC_Prune)
	}
	if (*TSelect)(unsafe.Pointer(p)).FpEList != 0 {
		pList = (*TSelect)(unsafe.Pointer(p)).FpEList
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			if (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FzEName != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0xc000>>14)) == ENAME_NAME {
				_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FzEName)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	if (*TSelect)(unsafe.Pointer(p)).FpSrc != 0 { /* Every Select as a SrcList, even if it is empty */
		pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
				break
			}
			_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80))).FzName)
			if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x100000>>20) == 0 {
				_sqlite3WalkExpr(tls, pWalker, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 64)))
			} else {
				_unmapColumnIdlistNames(tls, pParse, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 64)))
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	_renameWalkWith(tls, pWalker, p)
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Invoke sqlite3WalkExpr() or sqlite3WalkSelect() on all Select or Expr
//	** objects that are part of the trigger passed as the second argument.
//	*/
func _renameWalkTrigger(tls *libc.TLS, pWalker uintptr, pTrigger uintptr) {
	var i int32
	var pSrc, pStep, pUpsert uintptr
	_, _, _, _ = i, pSrc, pStep, pUpsert
	/* Find tokens to edit in WHEN clause */
	_sqlite3WalkExpr(tls, pWalker, (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen)
	/* Find tokens to edit in trigger steps */
	pStep = (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list
	for {
		if !(pStep != 0) {
			break
		}
		_sqlite3WalkSelect(tls, pWalker, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect)
		_sqlite3WalkExpr(tls, pWalker, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere)
		_sqlite3WalkExprList(tls, pWalker, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList)
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 {
			pUpsert = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
			_sqlite3WalkExprList(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
			_sqlite3WalkExprList(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet)
			_sqlite3WalkExpr(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
			_sqlite3WalkExpr(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
		}
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
			pSrc = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 24 + 4))&0x20000000>>29) != 0 {
					_sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*80 + 72)))).FpSelect)
				}
				goto _2
			_2:
				;
				i = i + 1
			}
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
}

// C documentation
//
//	/*
//	** Resize an Index object to hold N columns total.  Return SQLITE_OK
//	** on success and SQLITE_NOMEM on an OOM error.
//	*/
func _resizeIndexObject(tls *libc.TLS, pParse uintptr, pIdx uintptr, N int32) (r int32) {
	var db, zExtra uintptr
	var nByte Tu64
	_, _, _ = db, nByte, zExtra
	if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) >= N {
		return SQLITE_OK
	}
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	nByte = uint64(libc.Uint64FromInt64(8)+libc.Uint64FromInt64(2)+libc.Uint64FromInt64(2)+libc.Uint64FromInt32(1)) * libc.Uint64FromInt32(N)
	zExtra = _sqlite3DbMallocZero(tls, db, nByte)
	if zExtra == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FazColl, uint64(8)*uint64((*TIndex)(unsafe.Pointer(pIdx)).FnColumn))
	(*TIndex)(unsafe.Pointer(pIdx)).FazColl = zExtra
	zExtra = zExtra + uintptr(uint64(8)*libc.Uint64FromInt32(N))
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst, uint64(2)*libc.Uint64FromInt32(libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)+libc.Int32FromInt32(1)))
	(*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst = zExtra
	zExtra = zExtra + uintptr(uint64(2)*libc.Uint64FromInt32(N))
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaiColumn, uint64(2)*uint64((*TIndex)(unsafe.Pointer(pIdx)).FnColumn))
	(*TIndex)(unsafe.Pointer(pIdx)).FaiColumn = zExtra
	zExtra = zExtra + uintptr(uint64(2)*libc.Uint64FromInt32(N))
	libc.Xmemcpy(tls, zExtra, (*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder, uint64((*TIndex)(unsafe.Pointer(pIdx)).FnColumn))
	(*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder = zExtra
	(*TIndex)(unsafe.Pointer(pIdx)).FnColumn = libc.Uint16FromInt32(N) /* See tag-20250221-1 above for proof of safety */
	libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(1), 11, 0x800)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** pEList is a list of expressions which are really the result set of the
//	** a SELECT statement.  pE is a term in an ORDER BY or GROUP BY clause.
//	** This routine checks to see if pE is a simple identifier which corresponds
//	** to the AS-name of one of the terms of the expression list.  If it is,
//	** this routine return an integer between 1 and N where N is the number of
//	** elements in pEList, corresponding to the matching entry.  If there is
//	** no match, or if pE is not a simple identifier, then this routine
//	** return 0.
//	**
//	** pEList has been resolved.  pE has not.
//	*/
func _resolveAsName(tls *libc.TLS, pParse uintptr, pEList uintptr, pE uintptr) (r int32) {
	var i int32
	var zCol uintptr
	_, _ = i, zCol /* Loop counter */
	_ = pParse
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_ID) {
		zCol = *(*uintptr)(unsafe.Pointer(pE + 8))
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0xc000>>14)) == ENAME_NAME && Xsqlite3_stricmp(tls, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName, zCol) == 0 {
				return i + int32(1)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Analyze the ORDER BY clause in a compound SELECT statement.   Modify
//	** each term of the ORDER BY clause is a constant integer between 1
//	** and N where N is the number of columns in the compound SELECT.
//	**
//	** ORDER BY terms that are already an integer between 1 and N are
//	** unmodified.  ORDER BY terms that are integers outside the range of
//	** 1 through N generate an error.  ORDER BY terms that are expressions
//	** are matched against result set expressions of compound SELECT
//	** beginning with the left-most SELECT and working toward the right.
//	** At the first match, the ORDER BY expression is transformed into
//	** the integer column number.
//	**
//	** Return the number of errors seen.
//	*/
func _resolveCompoundOrderBy(tls *libc.TLS, pParse uintptr, pSelect uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pDup, pE, pEList, pItem, pNew, pOrderBy, pParent uintptr
	var i, moreToDo int32
	var _ /* iCol at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = db, i, moreToDo, pDup, pE, pEList, pItem, pNew, pOrderBy, pParent
	moreToDo = int32(1)
	pOrderBy = (*TSelect)(unsafe.Pointer(pSelect)).FpOrderBy
	if pOrderBy == uintptr(0) {
		return 0
	}
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7629, 0)
		return int32(1)
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		libc.SetBitFieldPtr16Uint32(pOrderBy+8+uintptr(i)*32+16+4, libc.Uint32FromInt32(0), 13, 0x2000)
		goto _1
	_1:
		;
		i = i + 1
	}
	(*TSelect)(unsafe.Pointer(pSelect)).FpNext = uintptr(0)
	for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		(*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpPrior)).FpNext = pSelect
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
	}
	for pSelect != 0 && moreToDo != 0 {
		moreToDo = 0
		pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
		i = 0
		pItem = pOrderBy + 8
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
				break
			}
			**(**int32)(__ccgo_up(bp)) = -int32(1)
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x2000>>13)) != 0 {
				goto _2
			}
			pE = _sqlite3ExprSkipCollateAndLikely(tls, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			if pE == uintptr(0) {
				goto _2
			}
			if _sqlite3ExprIsInteger(tls, pE, bp, uintptr(0)) != 0 {
				if **(**int32)(__ccgo_up(bp)) <= 0 || **(**int32)(__ccgo_up(bp)) > (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
					_resolveOutOfRangeError(tls, pParse, __ccgo_ts+7663, i+int32(1), (*TExprList)(unsafe.Pointer(pEList)).FnExpr, pE)
					return int32(1)
				}
			} else {
				**(**int32)(__ccgo_up(bp)) = _resolveAsName(tls, pParse, pEList, pE)
				if **(**int32)(__ccgo_up(bp)) == 0 {
					/* Now test if expression pE matches one of the values returned
					 ** by pSelect. In the usual case this is done by duplicating the
					 ** expression, resolving any symbols in it, and then comparing
					 ** it against each expression returned by the SELECT statement.
					 ** Once the comparisons are finished, the duplicate expression
					 ** is deleted.
					 **
					 ** If this is running as part of an ALTER TABLE operation and
					 ** the symbols resolve successfully, also resolve the symbols in the
					 ** actual expression. This allows the code in alter.c to modify
					 ** column references within the ORDER BY expression as required.  */
					pDup = _sqlite3ExprDup(tls, db, pE, 0)
					if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
						**(**int32)(__ccgo_up(bp)) = _resolveOrderByTermToExprList(tls, pParse, pSelect, pDup)
						if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && **(**int32)(__ccgo_up(bp)) > 0 {
							_resolveOrderByTermToExprList(tls, pParse, pSelect, pE)
						}
					}
					_sqlite3ExprDelete(tls, db, pDup)
				}
			}
			if **(**int32)(__ccgo_up(bp)) > 0 {
				/* Convert the ORDER BY term into an integer column number iCol,
				 ** taking care to preserve the COLLATE clause if it exists. */
				if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
					pNew = _sqlite3ExprInt32(tls, db, **(**int32)(__ccgo_up(bp)))
					if pNew == uintptr(0) {
						return int32(1)
					}
					if (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr == pE {
						(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pNew
					} else {
						pParent = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
						for libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pParent)).FpLeft)).Fop) == int32(TK_COLLATE) {
							pParent = (*TExpr)(unsafe.Pointer(pParent)).FpLeft
						}
						(*TExpr)(unsafe.Pointer(pParent)).FpLeft = pNew
					}
					_sqlite3ExprDelete(tls, db, pE)
					(*(*struct {
						FiOrderByCol Tu16
						FiAlias      Tu16
					})(unsafe.Pointer(pItem + 24))).FiOrderByCol = libc.Uint16FromInt32(**(**int32)(__ccgo_up(bp)))
				}
				libc.SetBitFieldPtr16Uint32(pItem+16+4, libc.Uint32FromInt32(1), 13, 0x2000)
			} else {
				moreToDo = int32(1)
			}
			goto _2
		_2:
			;
			i = i + 1
			pItem += 32
		}
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpNext
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			break
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32 + 16 + 4))&0x2000>>13)) == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7669, libc.VaList(bp+16, i+int32(1)))
			return int32(1)
		}
		goto _3
	_3:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** This routine is callback for sqlite3WalkExpr().
//	**
//	** Resolve symbolic names into TK_COLUMN operators for the current
//	** node in the expression tree.  Return 0 to continue the search down
//	** the tree or 2 to abort the tree walk.
//	**
//	** This routine also does error checking and name resolution for
//	** function names.  The operator for aggregate functions is changed
//	** to TK_AGG_FUNCTION.
//	*/
func _resolveExprStep(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var anRef [8]int32
	var auth, i, is_agg, n, nLeft, nRef, nRight, no_such_func, rc, savedAllowFlags, wrong_num_args, v5 int32
	var enc Tu8
	var p, pDef, pItem, pLeft, pList, pNC, pNC2, pParse, pRight, pRight1, pSel, pSrcList, pWin, zDb, zId, zTable, zType, v4 uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = anRef, auth, enc, i, is_agg, n, nLeft, nRef, nRight, no_such_func, p, pDef, pItem, pLeft, pList, pNC, pNC2, pParse, pRight, pRight1, pSel, pSrcList, pWin, rc, savedAllowFlags, wrong_num_args, zDb, zId, zTable, zType, v4, v5
	pNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	pParse = (*TNameContext)(unsafe.Pointer(pNC)).FpParse
	switch libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) {
	/* The special operator TK_ROW means use the rowid for the first
	 ** column in the FROM clause.  This is used by the LIMIT and ORDER BY
	 ** clause processing on UPDATE and DELETE statements, and by
	 ** UPDATE ... FROM statement processing.
	 */
	case int32(TK_ROW):
		pSrcList = (*TNameContext)(unsafe.Pointer(pNC)).FpSrcList
		pItem = pSrcList + 8
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_COLUMN)
		*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
		(*TExpr)(unsafe.Pointer(pExpr)).FiTable = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
		(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = (*TExpr)(unsafe.Pointer(pExpr)).FiColumn - 1
		(*TExpr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
		break
		/* An optimization:  Attempt to convert
		 **
		 **      "expr IS NOT NULL"  -->  "TRUE"
		 **      "expr IS NULL"      -->  "FALSE"
		 **
		 ** if we can prove that "expr" is never NULL.  Call this the
		 ** "NOT NULL strength reduction optimization".
		 **
		 ** If this optimization occurs, also restore the NameContext ref-counts
		 ** to the state they where in before the "column" LHS expression was
		 ** resolved.  This prevents "column" from being counted as having been
		 ** referenced, which might prevent a SELECT from being erroneously
		 ** marked as correlated.
		 **
		 ** 2024-03-28: Beware of aggregates.  A bare column of aggregated table
		 ** can still evaluate to NULL even though it is marked as NOT NULL.
		 ** Example:
		 **
		 **       CREATE TABLE t1(a INT NOT NULL);
		 **       SELECT a, a IS NULL, a IS NOT NULL, count(*) FROM t1;
		 **
		 ** The "a IS NULL" and "a IS NOT NULL" expressions cannot be optimized
		 ** here because at the time this case is hit, we do not yet know whether
		 ** or not t1 is being aggregated.  We have to assume the worst and omit
		 ** the optimization.  The only time it is safe to apply this optimization
		 ** is within the WHERE clause.
		 */
		fallthrough
	case int32(TK_NOTNULL):
		fallthrough
	case int32(TK_ISNULL):
		i = 0
		p = pNC
		for {
			if !(p != 0 && i < libc.Int32FromUint64(libc.Uint64FromInt64(32)/libc.Uint64FromInt64(4))) {
				break
			}
			anRef[i] = (*TNameContext)(unsafe.Pointer(p)).FnRef
			goto _1
		_1:
			;
			p = (*TNameContext)(unsafe.Pointer(p)).FpNext
			i = i + 1
		}
		_sqlite3WalkExpr(tls, pWalker, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			return int32(WRC_Prune)
		}
		if _sqlite3ExprCanBeNull(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft) != 0 {
			/* The expression can be NULL.  So the optimization does not apply */
			return int32(WRC_Prune)
		}
		i = 0
		p = pNC
		for {
			if !(p != 0) {
				break
			}
			if (*TNameContext)(unsafe.Pointer(p)).FncFlags&int32(NC_Where) == 0 {
				return int32(WRC_Prune) /* Not in a WHERE clause.  Unsafe to optimize. */
			}
			goto _2
		_2:
			;
			p = (*TNameContext)(unsafe.Pointer(p)).FpNext
			i = i + 1
		}
		*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fu)) = libc.BoolInt32(libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_NOTNULL))
		**(**Tu32)(__ccgo_up(pExpr + 4)) |= uint32(EP_IntValue)
		(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_INTEGER)
		i = 0
		p = pNC
		for {
			if !(p != 0 && i < libc.Int32FromUint64(libc.Uint64FromInt64(32)/libc.Uint64FromInt64(4))) {
				break
			}
			(*TNameContext)(unsafe.Pointer(p)).FnRef = anRef[i]
			goto _3
		_3:
			;
			p = (*TNameContext)(unsafe.Pointer(p)).FpNext
			i = i + 1
		}
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		(*TExpr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
		return int32(WRC_Prune)
		/* A column name:                    ID
		 ** Or table name and column name:    ID.ID
		 ** Or a database, table and column:  ID.ID.ID
		 **
		 ** The TK_ID and TK_OUT cases are combined so that there will only
		 ** be one call to lookupName().  Then the compiler will in-line
		 ** lookupName() for a size reduction and performance increase.
		 */
		fallthrough
	case int32(TK_ID):
		fallthrough
	case int32(TK_DOT):
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_ID) {
			zDb = uintptr(0)
			zTable = uintptr(0)
			pRight = pExpr
		} else {
			pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
			if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_GenCol)) != 0 {
				_notValidImpl(tls, pParse, pNC, __ccgo_ts+7204, uintptr(0), pExpr)
			}
			pRight = (*TExpr)(unsafe.Pointer(pExpr)).FpRight
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight)).Fop) == int32(TK_ID) {
				zDb = uintptr(0)
			} else {
				zDb = *(*uintptr)(unsafe.Pointer(pLeft + 8))
				pLeft = (*TExpr)(unsafe.Pointer(pRight)).FpLeft
				pRight = (*TExpr)(unsafe.Pointer(pRight)).FpRight
			}
			zTable = *(*uintptr)(unsafe.Pointer(pLeft + 8))
			if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
				_sqlite3RenameTokenRemap(tls, pParse, pExpr, pRight)
				_sqlite3RenameTokenRemap(tls, pParse, pExpr+64, pLeft)
			}
		}
		return _lookupName(tls, pParse, zDb, zTable, pRight, pNC, pExpr)
		/* Resolve function names
		 */
		fallthrough
	case int32(TK_FUNCTION): /* Number of arguments */
		no_such_func = 0                                                              /* True if no such function exists */
		wrong_num_args = 0                                                            /* True if wrong number of arguments */
		is_agg = 0                                                                    /* Information about the function */
		enc = (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc /* The database encoding */
		savedAllowFlags = (*TNameContext)(unsafe.Pointer(pNC)).FncFlags & (libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin))
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) && libc.Int32FromUint8((*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FeFrmType) != int32(TK_FILTER) {
			v4 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
		} else {
			v4 = uintptr(0)
		}
		pWin = v4
		pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		if pList != 0 {
			v5 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		} else {
			v5 = 0
		}
		n = v5
		zId = *(*uintptr)(unsafe.Pointer(pExpr + 8))
		pDef = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zId, n, enc, uint8(0))
		if pDef == uintptr(0) {
			pDef = _sqlite3FindFunction(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zId, -int32(2), enc, uint8(0))
			if pDef == uintptr(0) {
				no_such_func = int32(1)
			} else {
				wrong_num_args = int32(1)
			}
		} else {
			is_agg = libc.BoolInt32((*TFuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0))
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_UNLIKELY) != 0 {
				**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_Unlikely))
				if n == int32(2) {
					(*TExpr)(unsafe.Pointer(pExpr)).FiTable = _exprProbability(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + 1*32))).FpExpr)
					if (*TExpr)(unsafe.Pointer(pExpr)).FiTable < 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7221, libc.VaList(bp+8, pExpr))
						(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
					}
				} else {
					/* EVIDENCE-OF: R-61304-29449 The unlikely(X) function is
					 ** equivalent to likelihood(X, 0.0625).
					 ** EVIDENCE-OF: R-01283-11636 The unlikely(X) function is
					 ** short-hand for likelihood(X,0.0625).
					 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand
					 ** for likelihood(X,0.9375).
					 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent
					 ** to likelihood(X,0.9375). */
					/* TUNING: unlikely() probability is 0.0625.  likely() is 0.9375 */
					if libc.Int32FromUint8(**(**uint8)(__ccgo_up((*TFuncDef)(unsafe.Pointer(pDef)).FzName))) == int32('u') {
						v5 = int32(8388608)
					} else {
						v5 = int32(125829120)
					}
					(*TExpr)(unsafe.Pointer(pExpr)).FiTable = v5
				}
			}
			auth = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_FUNCTION), uintptr(0), (*TFuncDef)(unsafe.Pointer(pDef)).FzName, uintptr(0))
			if auth != SQLITE_OK {
				if auth == int32(SQLITE_DENY) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7285, libc.VaList(bp+8, pExpr))
					(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
				}
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_NULL)
				return int32(WRC_Prune)
			}
			/* If the function may call sqlite3_value_subtype(), then set the
			 ** EP_SubtArg flag on all of its argument expressions. This prevents
			 ** where.c from replacing the expression with a value read from an
			 ** index on the same expression, which will not have the correct
			 ** subtype. Also set the flag if the function expression itself is
			 ** an EP_SubtArg expression. In this case subtypes are required as
			 ** the function may return a value with a subtype back to its
			 ** caller using sqlite3_result_value().  */
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_SUBTYPE) != 0 || (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromUint32(EP_SubtArg) != uint32(0) {
				_resolveSetExprSubtypeArg(tls, pList)
			}
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_CONSTANT)|libc.Int32FromInt32(SQLITE_FUNC_SLOCHNG)) != 0 {
				/* For the purposes of the EP_ConstFunc flag, date and time
				 ** functions and other functions that change slowly are considered
				 ** constant because they are constant for the duration of one query.
				 ** This allows them to be factored out of inner loops. */
				**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_ConstFunc))
			}
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_CONSTANT) == uint32(0) {
				/* Clearly non-deterministic functions like random(), but also
				 ** date/time functions that use 'now', and other functions like
				 ** sqlite_version() that might change over time cannot be used
				 ** in an index or generated column.  Curiously, they can be used
				 ** in a CHECK constraint.  SQLServer, MySQL, and PostgreSQL all
				 ** allow this. */
				if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_PartIdx)|libc.Int32FromInt32(NC_GenCol)) != 0 {
					_notValidImpl(tls, pParse, pNC, __ccgo_ts+7321, uintptr(0), pExpr)
				}
			} else {
				/* Must fit in 8 bits */
				(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = libc.Uint8FromInt32((*TNameContext)(unsafe.Pointer(pNC)).FncFlags & int32(NC_SelfRef))
			}
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INTERNAL) != uint32(0) && libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&uint32(DBFLAG_InternalFunc) == uint32(0) {
				/* Internal-use-only functions are disallowed unless the
				 ** SQL is being compiled using sqlite3NestedParse() or
				 ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be
				 ** used to activate internal functions for testing purposes */
				no_such_func = int32(1)
				pDef = uintptr(0)
			} else {
				if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_DIRECT)|libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)) != uint32(0) && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
					if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_FromDDL) != 0 {
						**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_FromDDL))
					}
					_sqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
				}
			}
		}
		if 0 == libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME)) {
			if pDef != 0 && (*TFuncDef)(unsafe.Pointer(pDef)).FxValue == uintptr(0) && pWin != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7349, libc.VaList(bp+8, pExpr))
				(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
			} else {
				if is_agg != 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowAgg) == 0 || is_agg != 0 && (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_WINDOW) != 0 && !(pWin != 0) || is_agg != 0 && pWin != 0 && (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_AllowWin) == 0 {
					if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_WINDOW) != 0 || pWin != 0 {
						zType = __ccgo_ts + 7392
					} else {
						zType = __ccgo_ts + 7399
					}
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7409, libc.VaList(bp+8, zType, pExpr))
					(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
					is_agg = 0
				} else {
					if no_such_func != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7437, libc.VaList(bp+8, pExpr))
						(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
					} else {
						if wrong_num_args != 0 {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7459, libc.VaList(bp+8, pExpr))
							(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
						} else {
							if is_agg == 0 && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
								_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7503, libc.VaList(bp+8, pExpr))
								(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
							} else {
								if is_agg == 0 && (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
									_sqlite3ExprOrderByAggregateError(tls, pParse, pExpr)
									(*TNameContext)(unsafe.Pointer(pNC)).FnNcErr = (*TNameContext)(unsafe.Pointer(pNC)).FnNcErr + 1
								}
							}
						}
					}
				}
			}
			if is_agg != 0 {
				/* Window functions may not be arguments of aggregate functions.
				 ** Or arguments of other window functions. But aggregate functions
				 ** may be arguments for window functions.  */
				if !(pWin != 0) {
					v5 = int32(NC_AllowAgg)
				} else {
					v5 = 0
				}
				**(**int32)(__ccgo_up(pNC + 40)) &= ^(libc.Int32FromInt32(NC_AllowWin) | v5)
			}
		} else {
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) || (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
				is_agg = int32(1)
			}
		}
		_sqlite3WalkExprList(tls, pWalker, pList)
		if is_agg != 0 {
			if (*TExpr)(unsafe.Pointer(pExpr)).FpLeft != 0 {
				_sqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpLeft + 32)))
			}
			if pWin != 0 && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
				pSel = (*TNameContext)(unsafe.Pointer(pNC)).FpWinSelect
				if libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME)) == 0 {
					if pSel != 0 {
						v4 = (*TSelect)(unsafe.Pointer(pSel)).FpWinDefn
					} else {
						v4 = uintptr(0)
					}
					_sqlite3WindowUpdate(tls, pParse, v4, pWin, pDef)
					if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
						break
					}
				}
				_sqlite3WalkExprList(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpPartition)
				_sqlite3WalkExprList(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy)
				_sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(pWin)).FpFilter)
				_sqlite3WindowLink(tls, pSel, pWin)
				**(**int32)(__ccgo_up(pNC + 40)) |= int32(NC_HasWin)
			} else {
				/* For looping up thru outer contexts */
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_AGG_FUNCTION)
				(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = uint8(0)
				if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
					_sqlite3WalkExpr(tls, pWalker, (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpFilter)
				}
				pNC2 = pNC
				for pNC2 != 0 && _sqlite3ReferencesSrcList(tls, pParse, pExpr, (*TNameContext)(unsafe.Pointer(pNC2)).FpSrcList) == 0 {
					v4 = pExpr + 2
					*(*Tu8)(unsafe.Pointer(v4)) = Tu8(uint32(*(*Tu8)(unsafe.Pointer(v4))) + (libc.Uint32FromInt32(1) + (*TNameContext)(unsafe.Pointer(pNC2)).FnNestedSelect))
					pNC2 = (*TNameContext)(unsafe.Pointer(pNC2)).FpNext
				}
				if pNC2 != 0 && pDef != 0 {
					v4 = pExpr + 2
					*(*Tu8)(unsafe.Pointer(v4)) = Tu8(uint32(*(*Tu8)(unsafe.Pointer(v4))) + (*TNameContext)(unsafe.Pointer(pNC2)).FnNestedSelect)
					v4 = pNC2 + 40
					*(*int32)(unsafe.Pointer(v4)) = int32(uint32(*(*int32)(unsafe.Pointer(v4))) | (libc.Uint32FromInt32(NC_HasAgg) | ((*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags^libc.Uint32FromInt32(SQLITE_FUNC_ANYORDER))&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_MINMAX)|libc.Int32FromInt32(SQLITE_FUNC_ANYORDER))))
				}
			}
			**(**int32)(__ccgo_up(pNC + 40)) |= savedAllowFlags
		}
		/* FIX ME:  Compute pExpr->affinity based on the expected return
		 ** type of the function
		 */
		return int32(WRC_Prune)
	case int32(TK_EXISTS):
		fallthrough
	case int32(TK_SELECT):
		fallthrough
	case int32(TK_IN):
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			nRef = (*TNameContext)(unsafe.Pointer(pNC)).FnRef
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_EXISTS) {
				libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 11, 0x800)
			}
			if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&int32(NC_SelfRef) != 0 {
				_notValidImpl(tls, pParse, pNC, __ccgo_ts+7551, pExpr, pExpr)
			} else {
				_sqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
			}
			if nRef != (*TNameContext)(unsafe.Pointer(pNC)).FnRef {
				**(**Tu32)(__ccgo_up(pExpr + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_VarSelect))
				**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 4)) |= uint32(SF_Correlated)
			}
			**(**int32)(__ccgo_up(pNC + 40)) |= int32(NC_Subquery)
		}
	case int32(TK_VARIABLE):
		if (*TNameContext)(unsafe.Pointer(pNC)).FncFlags&(libc.Int32FromInt32(NC_IsCheck)|libc.Int32FromInt32(NC_PartIdx)|libc.Int32FromInt32(NC_IdxExpr)|libc.Int32FromInt32(NC_GenCol)) != 0 {
			_notValidImpl(tls, pParse, pNC, __ccgo_ts+7562, pExpr, pExpr)
		}
	case int32(TK_IS):
		fallthrough
	case int32(TK_ISNOT):
		pRight1 = _sqlite3ExprSkipCollateAndLikely(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		/* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
		 ** and "x IS NOT FALSE". */
		if pRight1 != 0 && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_ID) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_TRUEFALSE)) {
			rc = _resolveExprStep(tls, pWalker, pRight1)
			if rc == int32(WRC_Abort) {
				return int32(WRC_Abort)
			}
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight1)).Fop) == int32(TK_TRUEFALSE) {
				(*TExpr)(unsafe.Pointer(pExpr)).Fop2 = (*TExpr)(unsafe.Pointer(pExpr)).Fop
				(*TExpr)(unsafe.Pointer(pExpr)).Fop = uint8(TK_TRUTH)
				return WRC_Continue
			}
		}
		fallthrough
	case int32(TK_BETWEEN):
		fallthrough
	case int32(TK_EQ):
		fallthrough
	case int32(TK_NE):
		fallthrough
	case int32(TK_LT):
		fallthrough
	case int32(TK_LE):
		fallthrough
	case int32(TK_GT):
		fallthrough
	case int32(TK_GE):
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
			break
		}
		nLeft = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_BETWEEN) {
			nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8))).FpExpr)
			if nRight == nLeft {
				nRight = _sqlite3ExprVectorSize(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8 + 1*32))).FpExpr)
			}
		} else {
			nRight = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		}
		if nLeft != nRight {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6912, 0)
			_sqlite3RecordErrorOffsetOfExpr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		}
		break
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		v5 = int32(WRC_Abort)
	} else {
		v5 = WRC_Continue
	}
	return v5
}

// C documentation
//
//	/*
//	** This function checks if argument pFrom refers to a CTE declared by
//	** a WITH clause on the stack currently maintained by the parser (on the
//	** pParse->pWith linked list).  And if currently processing a CTE
//	** CTE expression, through routine checks to see if the reference is
//	** a recursive reference to the CTE.
//	**
//	** If pFrom matches a CTE according to either of these two above, pFrom->pSTab
//	** and other fields are populated accordingly.
//	**
//	** Return 0 if no match is found.
//	** Return 1 if a match is found.
//	** Return 2 if an error condition is detected.
//	*/
func _resolveFromTermToCte(tls *libc.TLS, pParse uintptr, pWalker uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var bMayRecursive, i, iRecTab, rc, v3 int32
	var db, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, v1 uintptr
	var _ /* pWith at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bMayRecursive, db, i, iRecTab, pCte, pCteUse, pEList, pItem, pLeft, pRecTerm, pSavedWith, pSel, pSrc, pTab, rc, v1, v3 /* The matching WITH */
	if (*TParse)(unsafe.Pointer(pParse)).FpWith == uintptr(0) {
		/* There are no WITH clauses in the stack.  No match is possible */
		return 0
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		/* Prior errors might have left pParse->pWith in a goofy state, so
		 ** go no further. */
		return 0
	}
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x8000>>15) == 0 && *(*uintptr)(unsafe.Pointer(pFrom + 72)) != uintptr(0) {
		/* The FROM term contains a schema qualifier (ex: main.t1) and so
		 ** it cannot possibly be a CTE reference. */
		return 0
	}
	if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x200000>>21) != 0 {
		/* The FROM term is specifically excluded from matching a CTE.
		 **   (1)  It is part of a trigger that used to have zDatabase but had
		 **        zDatabase removed by sqlite3FixTriggerStep().
		 **   (2)  This is the first term in the FROM clause of an UPDATE.
		 */
		return 0
	}
	pCte = _searchWith(tls, (*TParse)(unsafe.Pointer(pParse)).FpWith, pFrom, bp)
	if pCte != 0 {
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Initial value of pParse->pWith */
		iRecTab = -int32(1)
		/* If pCte->zCteErr is non-NULL at this point, then this is an illegal
		 ** recursive reference to CTE pCte. Leave an error in pParse and return
		 ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
		 ** In this case, proceed.  */
		if (*TCte)(unsafe.Pointer(pCte)).FzCteErr != 0 {
			_sqlite3ErrorMsg(tls, pParse, (*TCte)(unsafe.Pointer(pCte)).FzCteErr, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
			return int32(2)
		}
		if _cannotBeFunction(tls, pParse, pFrom) != 0 {
			return int32(2)
		}
		pTab = _sqlite3DbMallocZero(tls, db, uint64(120))
		if pTab == uintptr(0) {
			return int32(2)
		}
		pCteUse = (*TCte)(unsafe.Pointer(pCte)).FpUse
		if pCteUse == uintptr(0) {
			v1 = _sqlite3DbMallocZero(tls, db, uint64(20))
			pCteUse = v1
			(*TCte)(unsafe.Pointer(pCte)).FpUse = v1
			if pCteUse == uintptr(0) || _sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DbFree), pCteUse) == uintptr(0) {
				_sqlite3DbFree(tls, db, pTab)
				return int32(2)
			}
			(*TCteUse)(unsafe.Pointer(pCteUse)).FeM10d = (*TCte)(unsafe.Pointer(pCte)).FeM10d
		}
		(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = pTab
		(*TTable)(unsafe.Pointer(pTab)).FnTabRef = uint32(1)
		(*TTable)(unsafe.Pointer(pTab)).FzName = _sqlite3DbStrDup(tls, db, (*TCte)(unsafe.Pointer(pCte)).FzName)
		(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(-int32(1))
		(*TTable)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
		**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_Ephemeral) | libc.Int32FromInt32(TF_NoVisibleRowid))
		_sqlite3SrcItemAttachSubquery(tls, pParse, pFrom, (*TCte)(unsafe.Pointer(pCte)).FpSelect, int32(1))
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return int32(2)
		}
		pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
		**(**Tu32)(__ccgo_up(pSel + 4)) |= uint32(SF_CopyCte)
		if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x40000000>>30) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21059, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(pFrom + 48))))
			return int32(2)
		}
		libc.SetBitFieldPtr32Uint32(pFrom+24+4, libc.Uint32FromInt32(1), 22, 0x400000)
		*(*uintptr)(unsafe.Pointer(pFrom + 56)) = pCteUse
		(*TCteUse)(unsafe.Pointer(pCteUse)).FnUse = (*TCteUse)(unsafe.Pointer(pCteUse)).FnUse + 1
		/* Check if this is a recursive CTE. */
		pRecTerm = pSel
		bMayRecursive = libc.BoolInt32(libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_ALL) || libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) == int32(TK_UNION))
		for bMayRecursive != 0 && libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pRecTerm)).Fop) == libc.Int32FromUint8((*TSelect)(unsafe.Pointer(pSel)).Fop) {
			pSrc = (*TSelect)(unsafe.Pointer(pRecTerm)).FpSrc
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				pItem = pSrc + 8 + uintptr(i)*80
				if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != uintptr(0) && !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x4000>>14) != 0) && !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0) && (int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8000>>15) != 0 || *(*uintptr)(unsafe.Pointer(pItem + 72)) == uintptr(0)) && 0 == _sqlite3StrICmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TCte)(unsafe.Pointer(pCte)).FzName) {
					(*TSrcItem)(unsafe.Pointer(pItem)).FpSTab = pTab
					(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
					libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 24, 0x1000000)
					if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21079, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName))
						return int32(2)
					}
					**(**Tu32)(__ccgo_up(pRecTerm + 4)) |= uint32(SF_Recursive)
					if iRecTab < 0 {
						v1 = pParse + 56
						v3 = *(*int32)(unsafe.Pointer(v1))
						*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
						iRecTab = v3
					}
					(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = iRecTab
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			if (*TSelect)(unsafe.Pointer(pRecTerm)).FselFlags&uint32(SF_Recursive) == uint32(0) {
				break
			}
			pRecTerm = (*TSelect)(unsafe.Pointer(pRecTerm)).FpPrior
		}
		(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21122
		pSavedWith = (*TParse)(unsafe.Pointer(pParse)).FpWith
		(*TParse)(unsafe.Pointer(pParse)).FpWith = **(**uintptr)(__ccgo_up(bp))
		if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
			(*TSelect)(unsafe.Pointer(pRecTerm)).FpWith = (*TSelect)(unsafe.Pointer(pSel)).FpWith
			rc = _sqlite3WalkSelect(tls, pWalker, pRecTerm)
			(*TSelect)(unsafe.Pointer(pRecTerm)).FpWith = uintptr(0)
			if rc != 0 {
				(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return int32(2)
			}
		} else {
			if _sqlite3WalkSelect(tls, pWalker, pSel) != 0 {
				(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return int32(2)
			}
		}
		(*TParse)(unsafe.Pointer(pParse)).FpWith = **(**uintptr)(__ccgo_up(bp))
		pLeft = pSel
		for {
			if !((*TSelect)(unsafe.Pointer(pLeft)).FpPrior != 0) {
				break
			}
			goto _5
		_5:
			;
			pLeft = (*TSelect)(unsafe.Pointer(pLeft)).FpPrior
		}
		pEList = (*TSelect)(unsafe.Pointer(pLeft)).FpEList
		if (*TCte)(unsafe.Pointer(pCte)).FpCols != 0 {
			if pEList != 0 && (*TExprList)(unsafe.Pointer(pEList)).FnExpr != (*TExprList)(unsafe.Pointer((*TCte)(unsafe.Pointer(pCte)).FpCols)).FnExpr {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21145, libc.VaList(bp+16, (*TCte)(unsafe.Pointer(pCte)).FzName, (*TExprList)(unsafe.Pointer(pEList)).FnExpr, (*TExprList)(unsafe.Pointer((*TCte)(unsafe.Pointer(pCte)).FpCols)).FnExpr))
				(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return int32(2)
			}
			pEList = (*TCte)(unsafe.Pointer(pCte)).FpCols
		}
		_sqlite3ColumnsFromExprList(tls, pParse, pEList, pTab+54, pTab+8)
		if bMayRecursive != 0 {
			if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_Recursive) != 0 {
				(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21183
			} else {
				(*TCte)(unsafe.Pointer(pCte)).FzCteErr = __ccgo_ts + 21217
			}
			_sqlite3WalkSelect(tls, pWalker, pSel)
		}
		(*TCte)(unsafe.Pointer(pCte)).FzCteErr = uintptr(0)
		(*TParse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
		return int32(1) /* Success */
	}
	return 0 /* No match */
}

// C documentation
//
//	/*
//	** This routine is called after all opcodes have been inserted.  It loops
//	** through all the opcodes and fixes up some details.
//	**
//	** (1) For each jump instruction with a negative P2 value (a label)
//	**     resolve the P2 value to an actual address.
//	**
//	** (2) Compute the maximum number of arguments used by the xUpdate/xFilter
//	**     methods of any virtual table and store that value in *pMaxVtabArgs.
//	**
//	** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
//	**     indicate what the prepared statement actually does.
//	**
//	** (4) (discontinued)
//	**
//	** (5) Reclaim the memory allocated for storing labels.
//	**
//	** This routine will only function correctly if the mkopcodeh.tcl generator
//	** script numbers the opcodes correctly.  Changes to this routine must be
//	** coordinated with changes to mkopcodeh.tcl.
//	*/
func _resolveP2Values(tls *libc.TLS, p uintptr, pMaxVtabArgs uintptr) {
	var aLabel, pOp, pParse uintptr
	var n, nMaxVtabArgs int32
	_, _, _, _, _ = aLabel, n, nMaxVtabArgs, pOp, pParse
	nMaxVtabArgs = **(**int32)(__ccgo_up(pMaxVtabArgs))
	pParse = (*TVdbe)(unsafe.Pointer(p)).FpParse
	aLabel = (*TParse)(unsafe.Pointer(pParse)).FaLabel
	/* tag-20230419-1 */
	libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 9, 0x200)
	libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 8, 0x100)
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*24
	for int32(1) != 0 {
		/* Only JUMP opcodes and the short list of special opcodes in the switch
		 ** below need to be considered.  The mkopcodeh.tcl generator script groups
		 ** all these opcodes together near the front of the opcode list.  Skip
		 ** any opcode that does not need processing by virtual of the fact that
		 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
		 */
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) <= int32(SQLITE_MX_JUMP_OPCODE) {
			/* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
			 ** cases from this switch! */
			switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
			case int32(OP_Transaction):
				if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 {
					libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 9, 0x200)
				}
				fallthrough
			case int32(OP_AutoCommit):
				fallthrough
			case OP_Savepoint:
				libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 8, 0x100)
			case int32(OP_Checkpoint):
				fallthrough
			case int32(OP_Vacuum):
				fallthrough
			case int32(OP_JournalMode):
				libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 9, 0x200)
				libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 8, 0x100)
			case int32(OP_Init):
				goto resolve_p2_values_loop_exit
			case int32(OP_VUpdate):
				if (*TOp)(unsafe.Pointer(pOp)).Fp2 > nMaxVtabArgs {
					nMaxVtabArgs = (*TOp)(unsafe.Pointer(pOp)).Fp2
				}
			case int32(OP_VFilter):
				/* The instruction immediately prior to VFilter will be an
				 ** OP_Integer that sets the "argc" value for the VFilter.  See
				 ** the code where OP_VFilter is generated at tag-20250207a. */
				n = (**(**TOp)(__ccgo_up(pOp + uintptr(-libc.Int32FromInt32(1))*24))).Fp1
				if n > nMaxVtabArgs {
					nMaxVtabArgs = n
				}
				/* Fall through into the default case */
				fallthrough
			default:
				if (*TOp)(unsafe.Pointer(pOp)).Fp2 < 0 {
					/* The mkopcodeh.tcl script has so arranged things that the only
					 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
					 ** have non-negative values for P2. */
					/* True because of tag-20230419-1 */
					(*TOp)(unsafe.Pointer(pOp)).Fp2 = **(**int32)(__ccgo_up(aLabel + uintptr(^(*TOp)(unsafe.Pointer(pOp)).Fp2)*4))
				}
				/* OPFLG_JUMP opcodes never have P2==0, though OPFLG_JUMP0 opcodes
				 ** might */
				/* Jumps never go off the end of the bytecode array */
				break
			}
			/* The mkopcodeh.tcl script has so arranged things that the only
			 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
			 ** have non-negative values for P2. */
		}
		pOp -= 24
	}
	goto resolve_p2_values_loop_exit
resolve_p2_values_loop_exit:
	;
	if aLabel != 0 {
		_sqlite3DbNNFreeNN(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, (*TParse)(unsafe.Pointer(pParse)).FaLabel)
		(*TParse)(unsafe.Pointer(pParse)).FaLabel = uintptr(0)
	}
	(*TParse)(unsafe.Pointer(pParse)).FnLabel = 0
	**(**int32)(__ccgo_up(pMaxVtabArgs)) = nMaxVtabArgs
}

// C documentation
//
//	/*
//	** Resolve names in the SELECT statement p and all of its descendants.
//	*/
func _resolveSelectStep(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext uintptr
	var i, isCompound, nCompound, nRef, v1 int32
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, isCompound, nCompound, nRef, pGroupBy, pItem, pItem1, pItem2, pLeftmost, pOuterNC, pParse, pSub, pSub1, pWin, zSavedContext, v1 /* Database connection */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Resolved) != 0 {
		return int32(WRC_Prune)
	}
	pOuterNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Normally sqlite3SelectExpand() will be called first and will have
	 ** already expanded this SELECT.  However, if this is a subquery within
	 ** an expression, sqlite3ResolveExprNames() will be called without a
	 ** prior call to sqlite3SelectExpand().  When that happens, let
	 ** sqlite3SelectPrep() do all of the processing for this SELECT.
	 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
	 ** this routine in the correct order.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Expanded) == uint32(0) {
		_sqlite3SelectPrep(tls, pParse, p, pOuterNC)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			v1 = int32(WRC_Abort)
		} else {
			v1 = int32(WRC_Prune)
		}
		return v1
	}
	isCompound = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FpPrior != uintptr(0))
	nCompound = 0
	pLeftmost = p
	for p != 0 {
		**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Resolved)
		/* Resolve the expressions in the LIMIT and OFFSET clauses. These
		 ** are not allowed to refer to any names, so pass an empty NameContext.
		 */
		libc.Xmemset(tls, bp, 0, uint64(56))
		(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
		(**(**TNameContext)(__ccgo_up(bp))).FpWinSelect = p
		if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpLimit) != 0 {
			return int32(WRC_Abort)
		}
		/* If the SF_Converted flags is set, then this Select object was
		 ** was created by the convertCompoundSelectToSubquery() function.
		 ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
		 ** as if it were part of the sub-query, not the parent. This block
		 ** moves the pOrderBy down to the sub-query. It will be moved back
		 ** after the names have been resolved.  */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Converted) != 0 {
			pSub = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 72)))).FpSelect
			(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
			(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		}
		/* Recursively resolve names in all subqueries in the FROM clause
		 */
		if pOuterNC != 0 {
			(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect + 1
		}
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
				break
			}
			pItem = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80
			/* Test of tag-20240424-1*/
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 && (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect)).FselFlags&uint32(SF_Resolved) == uint32(0) {
				if pOuterNC != 0 {
					v1 = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef
				} else {
					v1 = 0
				}
				nRef = v1
				zSavedContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext
				if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
					(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pItem)).FzName
				}
				_sqlite3ResolveSelectNames(tls, pParse, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect, pOuterNC)
				(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedContext
				if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
					return int32(WRC_Abort)
				}
				/* If the number of references to the outer context changed when
				 ** expressions in the sub-select were resolved, the sub-select
				 ** is correlated. It is not required to check the refcount on any
				 ** but the innermost outer context object, as lookupName() increments
				 ** the refcount on all contexts between the current one and the
				 ** context containing the column when it resolves a name. */
				if pOuterNC != 0 {
					libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.BoolUint32((*TNameContext)(unsafe.Pointer(pOuterNC)).FnRef > nRef), 27, 0x8000000)
				}
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		if pOuterNC != 0 && (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect > uint32(0) {
			(*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect = (*TNameContext)(unsafe.Pointer(pOuterNC)).FnNestedSelect - 1
		}
		/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
		 ** resolve the result-set expression list.
		 */
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
		(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(p)).FpSrc
		(**(**TNameContext)(__ccgo_up(bp))).FpNext = pOuterNC
		/* Resolve names in the result set. */
		if _sqlite3ResolveExprListNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpEList) != 0 {
			return int32(WRC_Abort)
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowWin)
		/* If there are no aggregate functions in the result-set, and no GROUP BY
		 ** expression, do not allow aggregates in any of the other expressions.
		 */
		pGroupBy = (*TSelect)(unsafe.Pointer(p)).FpGroupBy
		if pGroupBy != 0 || (**(**TNameContext)(__ccgo_up(bp))).FncFlags&int32(NC_HasAgg) != 0 {
			**(**Tu32)(__ccgo_up(p + 4)) |= libc.Uint32FromInt32(int32(SF_Aggregate) | (**(**TNameContext)(__ccgo_up(bp))).FncFlags&(libc.Int32FromInt32(NC_MinMaxAgg)|libc.Int32FromInt32(NC_OrderAgg)))
		} else {
			(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowAgg)
		}
		/* Add the output column list to the name-context before parsing the
		 ** other expressions in the SELECT statement. This is so that
		 ** expressions in the WHERE clause (etc.) can refer to expressions by
		 ** aliases in the result set.
		 **
		 ** Minor point: If this is the case, then the expression will be
		 ** re-evaluated for each reference to it.
		 */
		*(*uintptr)(unsafe.Pointer(bp + 16)) = (*TSelect)(unsafe.Pointer(p)).FpEList
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= int32(NC_UEList)
		if (*TSelect)(unsafe.Pointer(p)).FpHaving != 0 {
			if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7761, 0)
				return int32(WRC_Abort)
			}
			if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving) != 0 {
				return int32(WRC_Abort)
			}
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= int32(NC_Where)
		if _sqlite3ResolveExprNames(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpWhere) != 0 {
			return int32(WRC_Abort)
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_Where)
		/* Resolve names in table-valued-function arguments */
		i = 0
		for {
			if !(i < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc)).FnSrc) {
				break
			}
			pItem1 = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*80
			if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x10000000>>28) != 0 && _sqlite3ResolveExprListNames(tls, bp, *(*uintptr)(unsafe.Pointer(pItem1 + 48))) != 0 {
				return int32(WRC_Abort)
			}
			goto _4
		_4:
			;
			i = i + 1
		}
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			pWin = (*TSelect)(unsafe.Pointer(p)).FpWinDefn
			for {
				if !(pWin != 0) {
					break
				}
				if _sqlite3ResolveExprListNames(tls, bp, (*TWindow)(unsafe.Pointer(pWin)).FpOrderBy) != 0 || _sqlite3ResolveExprListNames(tls, bp, (*TWindow)(unsafe.Pointer(pWin)).FpPartition) != 0 {
					return int32(WRC_Abort)
				}
				goto _5
			_5:
				;
				pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
			}
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags |= libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_AllowWin)
		/* If this is a converted compound query, move the ORDER BY clause from
		 ** the sub-query back to the parent query. At this point each term
		 ** within the ORDER BY clause has been transformed to an integer value.
		 ** These integers will be replaced by copies of the corresponding result
		 ** set expressions by the call to resolveOrderGroupBy() below.  */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Converted) != 0 {
			pSub1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 72)))).FpSelect
			(*TSelect)(unsafe.Pointer(p)).FpOrderBy = (*TSelect)(unsafe.Pointer(pSub1)).FpOrderBy
			(*TSelect)(unsafe.Pointer(pSub1)).FpOrderBy = uintptr(0)
		}
		/* Process the ORDER BY clause for singleton SELECT statements.
		 ** The ORDER BY clause for compounds SELECT statements is handled
		 ** below, after all of the result-sets for all of the elements of
		 ** the compound have been resolved.
		 **
		 ** If there is an ORDER BY clause on a term of a compound-select other
		 ** than the right-most term, then that is a syntax error.  But the error
		 ** is not detected until much later, and so we need to go ahead and
		 ** resolve those symbols on the incorrect ORDER BY for consistency.
		 */
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) && isCompound <= nCompound && _resolveOrderGroupBy(tls, bp, p, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, __ccgo_ts+7663) != 0 {
			return int32(WRC_Abort)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return int32(WRC_Abort)
		}
		(**(**TNameContext)(__ccgo_up(bp))).FncFlags &= ^libc.Int32FromInt32(NC_AllowWin)
		/* Resolve the GROUP BY clause.  At the same time, make sure
		 ** the GROUP BY clause does not contain aggregate functions.
		 */
		if pGroupBy != 0 {
			if _resolveOrderGroupBy(tls, bp, p, pGroupBy, __ccgo_ts+7800) != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return int32(WRC_Abort)
			}
			i = 0
			pItem2 = pGroupBy + 8
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
					break
				}
				if (*TExpr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pItem2)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Agg)) != uint32(0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7806, 0)
					return int32(WRC_Abort)
				}
				goto _6
			_6:
				;
				i = i + 1
				pItem2 += 32
			}
		}
		/* If this is part of a compound SELECT, check that it has the right
		 ** number of expressions in the select list. */
		if (*TSelect)(unsafe.Pointer(p)).FpNext != 0 && (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpNext)).FpEList)).FnExpr {
			_sqlite3SelectWrongNumTermsError(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpNext)
			return int32(WRC_Abort)
		}
		/* If the SELECT statement contains ON clauses that were moved into
		 ** the WHERE clause, go through and verify that none of the terms
		 ** in the ON clauses reference tables to the right of the ON clause. */
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_OnToWhere) != 0 {
			_sqlite3SelectCheckOnClauses(tls, pParse, p)
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return int32(WRC_Abort)
			}
		}
		/* Advance to the next term of the compound
		 */
		p = (*TSelect)(unsafe.Pointer(p)).FpPrior
		nCompound = nCompound + 1
	}
	/* Resolve the ORDER BY on a compound SELECT after all terms of
	 ** the compound have been resolved.
	 */
	if isCompound != 0 && _resolveCompoundOrderBy(tls, pParse, pLeftmost) != 0 {
		return int32(WRC_Abort)
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** Check the leaf RTree cell given by pCellData against constraint p.
//	** If this constraint is not satisfied, set *peWithin to NOT_WITHIN.
//	** If the constraint is satisfied, leave *peWithin unchanged.
//	**
//	** The constraint is of the form:  xN op $val
//	**
//	** The op is given by p->op.  The xN is p->iCoord-th coordinate in
//	** pCellData.  $val is given by p->u.rValue.
//	*/
func _rtreeLeafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var xN TRtreeDValue
	var v1 Tsqlite3_rtree_dbl
	var _ /* c at bp+0 */ TRtreeCoord
	_, _ = xN, v1 /* Coordinate value converted to a double */
	pCellData = pCellData + uintptr(int32(8)+(*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord*int32(4))
	/* Coordinate decoded */
	libc.Xmemcpy(tls, bp, pCellData, uint64(4))
	if eInt != 0 {
		v1 = float64(*(*int32)(unsafe.Pointer(bp)))
	} else {
		v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
	}
	xN = v1
	switch (*TRtreeConstraint)(unsafe.Pointer(p)).Fop {
	case int32(RTREE_TRUE):
		return /* Always satisfied */
	case int32(RTREE_FALSE):
	case int32(RTREE_LE):
		if xN <= *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	case int32(RTREE_LT):
		if xN < *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	case int32(RTREE_GE):
		if xN >= *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	case int32(RTREE_GT):
		if xN > *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	default:
		if xN == *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	}
	**(**int32)(__ccgo_up(peWithin)) = NOT_WITHIN
}

// C documentation
//
//	/*
//	** Check the internal RTree node given by pCellData against constraint p.
//	** If this constraint cannot be satisfied by any child within the node,
//	** set *peWithin to NOT_WITHIN.
//	*/
func _rtreeNonleafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var val, v1 Tsqlite3_rtree_dbl
	var _ /* c at bp+0 */ TRtreeCoord
	var _ /* c at bp+12 */ TRtreeCoord
	var _ /* c at bp+4 */ TRtreeCoord
	var _ /* c at bp+8 */ TRtreeCoord
	_, _ = val, v1 /* Coordinate value convert to a double */
	/* p->iCoord might point to either a lower or upper bound coordinate
	 ** in a coordinate pair.  But make pCellData point to the lower bound.
	 */
	pCellData = pCellData + uintptr(int32(8)+int32(4)*((*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord&int32(0xfe)))
	switch (*TRtreeConstraint)(unsafe.Pointer(p)).Fop {
	case int32(RTREE_TRUE):
		return /* Always satisfied */
	case int32(RTREE_FALSE):
	case int32(RTREE_EQ):
		/* Coordinate decoded */ libc.Xmemcpy(tls, bp, pCellData, uint64(4))
		if eInt != 0 {
			v1 = float64(*(*int32)(unsafe.Pointer(bp)))
		} else {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
		}
		val = v1
		/* val now holds the lower bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			pCellData = pCellData + uintptr(4)
			/* Coordinate decoded */ libc.Xmemcpy(tls, bp+4, pCellData, uint64(4))
			if eInt != 0 {
				v1 = float64(*(*int32)(unsafe.Pointer(bp + 4)))
			} else {
				v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 4)))
			}
			val = v1
			/* val now holds the upper bound of the coordinate pair */
			if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) <= val {
				return
			}
		}
	case int32(RTREE_LE):
		fallthrough
	case int32(RTREE_LT):
		/* Coordinate decoded */ libc.Xmemcpy(tls, bp+8, pCellData, uint64(4))
		if eInt != 0 {
			v1 = float64(*(*int32)(unsafe.Pointer(bp + 8)))
		} else {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 8)))
		}
		val = v1
		/* val now holds the lower bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			return
		}
	default:
		pCellData = pCellData + uintptr(4)
		/* Coordinate decoded */ libc.Xmemcpy(tls, bp+12, pCellData, uint64(4))
		if eInt != 0 {
			v1 = float64(*(*int32)(unsafe.Pointer(bp + 12)))
		} else {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 12)))
		}
		val = v1
		/* val now holds the upper bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) <= val {
			return
		}
		break
	}
	**(**int32)(__ccgo_up(peWithin)) = NOT_WITHIN
}

// C documentation
//
//	/*
//	** If any term of pSrc, or any SF_NestedFrom sub-query, is not the same
//	** as pSrcItem but has the same alias as p0, then return true.
//	** Otherwise return false.
//	*/
func _sameSrcAlias(tls *libc.TLS, p0 uintptr, pSrc uintptr) (r int32) {
	var i int32
	var p1 uintptr
	_, _ = i, p1
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		p1 = pSrc + 8 + uintptr(i)*80
		if p1 == p0 {
			goto _1
		}
		if (*TSrcItem)(unsafe.Pointer(p0)).FpSTab == (*TSrcItem)(unsafe.Pointer(p1)).FpSTab && 0 == Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(p0)).FzAlias, (*TSrcItem)(unsafe.Pointer(p1)).FzAlias) {
			return int32(1)
		}
		if int32(*(*uint32)(unsafe.Pointer(p1 + 24 + 4))&0x20000000>>29) != 0 && (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p1 + 72)))).FpSelect)).FselFlags&uint32(SF_NestedFrom) != uint32(0) && _sameSrcAlias(tls, p0, (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p1 + 72)))).FpSelect)).FpSrc) != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
//	** interface.
//	**
//	** For each FROM-clause subquery, add Column.zType, Column.zColl, and
//	** Column.affinity information to the Table structure that represents
//	** the result set of that subquery.
//	**
//	** The Table structure that represents the result set was constructed
//	** by selectExpander() but the type and collation and affinity information
//	** was omitted at that point because identifiers had not yet been resolved.
//	** This routine is called after identifier resolution.
//	*/
func _selectAddSubqueryTypeInfo(tls *libc.TLS, pWalker uintptr, p uintptr) {
	var i int32
	var pFrom, pParse, pSel, pTab, pTabList uintptr
	_, _, _, _, _, _ = i, pFrom, pParse, pSel, pTab, pTabList
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_HasTypeInfo) != 0 {
		return
	}
	**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_HasTypeInfo)
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	i = 0
	pFrom = pTabList + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) != uint32(0) && int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x20000000>>29) != 0 {
			/* A sub-query in the FROM clause of a SELECT */
			pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
			_sqlite3SubqueryColumnTypes(tls, pParse, pTab, pSel, uint8(SQLITE_AFF_NONE))
		}
		goto _1
	_1:
		;
		i = i + 1
		pFrom += 80
	}
}

// C documentation
//
//	/*
//	** This routine is a Walker callback for "expanding" a SELECT statement.
//	** "Expanding" means to do the following:
//	**
//	**    (1)  Make sure VDBE cursor numbers have been assigned to every
//	**         element of the FROM clause.
//	**
//	**    (2)  Fill in the pTabList->a[].pTab fields in the SrcList that
//	**         defines FROM clause.  When views appear in the FROM clause,
//	**         fill pTabList->a[].pSelect with a copy of the SELECT statement
//	**         that implements the view.  A copy is made of the view's SELECT
//	**         statement so that we can freely modify or delete that statement
//	**         without worrying about messing up the persistent representation
//	**         of the view.
//	**
//	**    (3)  Add terms to the WHERE clause to accommodate the NATURAL keyword
//	**         on joins and the ON and USING clause of joins.
//	**
//	**    (4)  Scan the list of columns in the result set (pEList) looking
//	**         for instances of the "*" operator or the TABLE.* operator.
//	**         If found, expand each "*" to be every column in every table
//	**         and TABLE.* to be every column in TABLE.
//	**
//	*/
func _selectExpander(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, db, pE, pEList, pExpr, pFrom, pLeft, pNestedFrom, pNew, pParse, pRight, pSel, pTab, pTab1, pTabList, pUsing, pX, pX1, zName, zSchemaName, zTName, zTabName, zUName, v2 uintptr
	var eCodeOrig Tu8
	var elistFlags Tu32
	var flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, rc, tableSeen, v1 int32
	var nCol Ti16
	var selFlags Tu16
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, db, eCodeOrig, elistFlags, flags, i, iDb, iErrOfst, ii, j, k, longNames, nAdd, nCol, pE, pEList, pExpr, pFrom, pLeft, pNestedFrom, pNew, pParse, pRight, pSel, pTab, pTab1, pTabList, pUsing, pX, pX1, rc, selFlags, tableSeen, zName, zSchemaName, zTName, zTabName, zUName, v1, v2
	pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	selFlags = uint16((*TSelect)(unsafe.Pointer(p)).FselFlags)
	elistFlags = uint32(0)
	**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Expanded)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return int32(WRC_Abort)
	}
	if libc.Int32FromUint16(selFlags)&int32(SF_Expanded) != 0 {
		return int32(WRC_Prune)
	}
	if (*TWalker)(unsafe.Pointer(pWalker)).FeCode != 0 {
		/* Renumber selId because it has been copied from a view */
		v2 = pParse + 132
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		v1 = *(*int32)(unsafe.Pointer(v2))
		(*TSelect)(unsafe.Pointer(p)).FselId = libc.Uint32FromInt32(v1)
	}
	pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
	if (*TParse)(unsafe.Pointer(pParse)).FpWith != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_View) != 0 {
		if (*TSelect)(unsafe.Pointer(p)).FpWith == uintptr(0) {
			(*TSelect)(unsafe.Pointer(p)).FpWith = _sqlite3DbMallocZero(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+16)+libc.Uint64FromInt32(libc.Int32FromInt32(1))*libc.Uint64FromInt64(48)))
			if (*TSelect)(unsafe.Pointer(p)).FpWith == uintptr(0) {
				return int32(WRC_Abort)
			}
		}
		(*TWith)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpWith)).FbView = int32(1)
	}
	_sqlite3WithPush(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWith, uint8(0))
	/* Make sure cursor numbers have been assigned to all entries in
	 ** the FROM clause of the SELECT statement.
	 */
	_sqlite3SrcListAssignCursors(tls, pParse, pTabList)
	/* Look up every table named in the FROM clause of the select.  If
	 ** an entry of the FROM clause is a subquery instead of a table or view,
	 ** then create a transient table structure to describe the subquery.
	 */
	i = 0
	pFrom = pTabList + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		if (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab != 0 {
			goto _3
		}
		if (*TSrcItem)(unsafe.Pointer(pFrom)).FzName == uintptr(0) {
			pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect
			/* A sub-query in the FROM clause of a SELECT */
			if _sqlite3WalkSelect(tls, pWalker, pSel) != 0 {
				return int32(WRC_Abort)
			}
			if _sqlite3ExpandSubquery(tls, pParse, pFrom) != 0 {
				return int32(WRC_Abort)
			}
		} else {
			v1 = _resolveFromTermToCte(tls, pParse, pWalker, pFrom)
			rc = v1
			if v1 != 0 {
				if rc > int32(1) {
					return int32(WRC_Abort)
				}
				pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
			} else {
				/* An ordinary table or view name in the FROM clause */
				v2 = _sqlite3LocateTableItem(tls, pParse, uint32(0), pFrom)
				pTab = v2
				(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = v2
				if pTab == uintptr(0) {
					return int32(WRC_Abort)
				}
				if (*TTable)(unsafe.Pointer(pTab)).FnTabRef >= uint32(0xffff) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21259, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
					(*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab = uintptr(0)
					return int32(WRC_Abort)
				}
				(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && _cannotBeFunction(tls, pParse, pFrom) != 0 {
					return int32(WRC_Abort)
				}
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
					eCodeOrig = uint8((*TWalker)(unsafe.Pointer(pWalker)).FeCode)
					if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
						return int32(WRC_Abort)
					}
					if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
						if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableView) == uint64(0) && (*TTable)(unsafe.Pointer(pTab)).FpSchema != (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21298, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
						}
						_sqlite3SrcItemAttachSubquery(tls, pParse, pFrom, (*(*struct {
							FpSelect uintptr
						})(unsafe.Pointer(&(*TTable)(unsafe.Pointer(pTab)).Fu))).FpSelect, int32(1))
					} else {
						if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) && (int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x800000>>23) != 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_FROM_DDL) != 0) && (*(*struct {
							FnArg  int32
							FazArg uintptr
							Fp     uintptr
						})(unsafe.Pointer(pTab + 64))).Fp != uintptr(0) && libc.Int32FromUint8((*TVTable)(unsafe.Pointer((*(*struct {
							FnArg  int32
							FazArg uintptr
							Fp     uintptr
						})(unsafe.Pointer(pTab + 64))).Fp)).FeVtabRisk) > libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16349, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
						}
					}
					nCol = (*TTable)(unsafe.Pointer(pTab)).FnCol
					(*TTable)(unsafe.Pointer(pTab)).FnCol = int16(-int32(1))
					(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1) /* Turn on Select.selId renumbering */
					if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x20000000>>29) != 0 {
						_sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect)
					}
					(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(eCodeOrig)
					(*TTable)(unsafe.Pointer(pTab)).FnCol = nCol
				}
			}
		}
		/* Locate the index named by the INDEXED BY clause, if any. */
		if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x40000000>>30) != 0 && _sqlite3IndexedByLookup(tls, pParse, pFrom) != 0 {
			return int32(WRC_Abort)
		}
		goto _3
	_3:
		;
		i = i + 1
		pFrom += 80
	}
	/* Process NATURAL keywords, and ON and USING clauses of joins.
	 */
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 || _sqlite3ProcessJoin(tls, pParse, p) != 0 {
		return int32(WRC_Abort)
	}
	/* For every "*" that occurs in the column list, insert the names of
	 ** all columns in all tables.  And for every TABLE.* insert the names
	 ** of all columns in TABLE.  The parser inserted a special expression
	 ** with the TK_ASTERISK operator for each "*" that it found in the column
	 ** list.  The following code just has to locate the TK_ASTERISK
	 ** expressions and expand each one to the list of all columns in
	 ** all tables.
	 **
	 ** The first loop just checks to see if there are any "*" operators
	 ** that need expanding.
	 */
	k = 0
	for {
		if !(k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		pE = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(k)*32))).FpExpr
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_ASTERISK) {
			break
		}
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight)).Fop) == int32(TK_ASTERISK) {
			break
		}
		elistFlags = elistFlags | (*TExpr)(unsafe.Pointer(pE)).Fflags
		goto _6
	_6:
		;
		k = k + 1
	}
	if k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr {
		/*
		 ** If we get here it means the result set contains one or more "*"
		 ** operators that need to be expanded.  Loop through each expression
		 ** in the result set and expand them one by one.
		 */
		a = pEList + 8
		pNew = uintptr(0)
		flags = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fflags)
		longNames = libc.BoolInt32(flags&int32(SQLITE_FullColNames) != 0 && flags&int32(SQLITE_ShortColNames) == 0)
		k = 0
		for {
			if !(k < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			pE = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr
			elistFlags = elistFlags | (*TExpr)(unsafe.Pointer(pE)).Fflags
			pRight = (*TExpr)(unsafe.Pointer(pE)).FpRight
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_ASTERISK) && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) != int32(TK_DOT) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRight)).Fop) != int32(TK_ASTERISK)) {
				/* This particular expression does not need to be expanded.
				 */
				pNew = _sqlite3ExprListAppend(tls, pParse, pNew, (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr)
				if pNew != 0 {
					(*(*TExprList_item)(unsafe.Pointer(pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32))).FzEName = (**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FzEName
					libc.SetBitFieldPtr16Uint32(pNew+8+uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32+16+4, libc.Uint32FromInt32(int32(uint32(*(*uint16)(unsafe.Pointer(a + uintptr(k)*32 + 16 + 4))&0xc000>>14))), 14, 0xc000)
					(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FzEName = uintptr(0)
				}
				(**(**TExprList_item)(__ccgo_up(a + uintptr(k)*32))).FpExpr = uintptr(0)
			} else {
				/* This expression is a "*" or a "TABLE.*" and needs to be
				 ** expanded. */
				tableSeen = 0 /* Set to 1 when TABLE matches */
				zTName = uintptr(0)
				if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pE)).Fop) == int32(TK_DOT) {
					zTName = *(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpLeft + 8))
					iErrOfst = *(*int32)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pE)).FpRight + 52))
				} else {
					iErrOfst = *(*int32)(unsafe.Pointer(pE + 52))
				}
				i = 0
				pFrom = pTabList + 8
				for {
					if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
						break
					} /* Number of cols including rowid */
					pTab1 = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab /* AS name for this data source */
					zSchemaName = uintptr(0)                          /* USING clause for pFrom[1] */
					v2 = (*TSrcItem)(unsafe.Pointer(pFrom)).FzAlias
					zTabName = v2
					if v2 == uintptr(0) {
						zTabName = (*TTable)(unsafe.Pointer(pTab1)).FzName
					}
					if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
						break
					}
					if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x20000>>17) != 0 {
						pNestedFrom = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pFrom + 72)))).FpSelect)).FpEList
					} else {
						if zTName != 0 && _sqlite3StrICmp(tls, zTName, zTabName) != 0 {
							goto _8
						}
						pNestedFrom = uintptr(0)
						iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab1)).FpSchema)
						if iDb >= 0 {
							v2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
						} else {
							v2 = __ccgo_ts + 6825
						}
						zSchemaName = v2
					}
					if i+int32(1) < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc && int32(*(*uint32)(unsafe.Pointer(pFrom + 1*80 + 24 + 4))&0x100000>>20) != 0 && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
						pUsing = *(*uintptr)(unsafe.Pointer(pFrom + 1*80 + 64))
						ii = 0
						for {
							if !(ii < (*TIdList)(unsafe.Pointer(pUsing)).FnId) {
								break
							}
							zUName = (*(*TIdList_item)(unsafe.Pointer(pUsing + 8 + uintptr(ii)*8))).FzName
							pRight = _sqlite3Expr(tls, db, int32(TK_ID), zUName)
							_sqlite3ExprSetErrorOffset(tls, pRight, iErrOfst)
							pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pRight)
							if pNew != 0 {
								pX = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
								(*TExprList_item)(unsafe.Pointer(pX)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21329, libc.VaList(bp+8, zUName))
								libc.SetBitFieldPtr16Uint32(pX+16+4, libc.Uint32FromInt32(ENAME_TAB), 14, 0xc000)
								libc.SetBitFieldPtr16Uint32(pX+16+4, libc.Uint32FromInt32(1), 8, 0x100)
							}
							goto _11
						_11:
							;
							ii = ii + 1
						}
					} else {
						pUsing = uintptr(0)
					}
					nAdd = int32((*TTable)(unsafe.Pointer(pTab1)).FnCol)
					if (*TTable)(unsafe.Pointer(pTab1)).FtabFlags&uint32(TF_NoVisibleRowid) == uint32(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 {
						nAdd = nAdd + 1
					}
					j = 0
					for {
						if !(j < nAdd) {
							break
						} /* Newly added ExprList term */
						if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
							zName = _sqlite3RowidAlias(tls, pTab1)
							if zName == uintptr(0) {
								goto _12
							}
						} else {
							zName = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FzCnName
							/* If pTab is actually an SF_NestedFrom sub-select, do not
							 ** expand any ENAME_ROWID columns.  */
							if pNestedFrom != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pNestedFrom + 8 + uintptr(j)*32 + 16 + 4))&0xc000>>14)) == int32(ENAME_ROWID) {
								goto _12
							}
							if zTName != 0 && pNestedFrom != 0 && _sqlite3MatchEName(tls, pNestedFrom+8+uintptr(j)*32, uintptr(0), zTName, uintptr(0), uintptr(0)) == 0 {
								goto _12
							}
							/* If a column is marked as 'hidden', omit it from the expanded
							 ** result-set list unless the SELECT has the SF_IncludeHidden
							 ** bit set.
							 */
							if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_IncludeHidden) == uint32(0) && libc.Int32FromUint16((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab1)).FaCol+uintptr(j)*16)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
								goto _12
							}
							if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 && zTName == uintptr(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) == 0 {
								goto _12
							}
						}
						tableSeen = int32(1)
						if i > 0 && zTName == uintptr(0) && libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) == 0 {
							if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x100000>>20) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 64)), zName) >= 0 {
								/* In a join with a USING clause, omit columns in the
								 ** using clause from the table on the right. */
								goto _12
							}
						}
						pRight = _sqlite3Expr(tls, db, int32(TK_ID), zName)
						if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1) && (libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pFrom)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 || libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 || !(_inAnyUsingClause(tls, zName, pFrom, (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc-i-int32(1)) != 0)) || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
							pLeft = _sqlite3Expr(tls, db, int32(TK_ID), zTabName)
							pExpr = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pRight)
							if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TExpr)(unsafe.Pointer(pE)).FpLeft != 0 {
								_sqlite3RenameTokenRemap(tls, pParse, pLeft, (*TExpr)(unsafe.Pointer(pE)).FpLeft)
							}
							if zSchemaName != 0 {
								pLeft = _sqlite3Expr(tls, db, int32(TK_ID), zSchemaName)
								pExpr = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pExpr)
							}
						} else {
							pExpr = pRight
						}
						_sqlite3ExprSetErrorOffset(tls, pExpr, iErrOfst)
						pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pExpr)
						if pNew == uintptr(0) {
							break /* OOM */
						}
						pX1 = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
						if libc.Int32FromUint16(selFlags)&int32(SF_NestedFrom) != 0 && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
							if pNestedFrom != 0 && libc.Bool(libc.Bool(!(libc.Int32FromInt32(ViewCanHaveRowid) != 0)) || j < (*TExprList)(unsafe.Pointer(pNestedFrom)).FnExpr) {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pNestedFrom + 8 + uintptr(j)*32))).FzEName)
							} else {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+21334, libc.VaList(bp+8, zSchemaName, zTabName, zName))
							}
							if j == int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) {
								v1 = int32(ENAME_ROWID)
							} else {
								v1 = int32(ENAME_TAB)
							}
							libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(v1), 14, 0xc000)
							if int32(*(*uint32)(unsafe.Pointer(pFrom + 24 + 4))&0x100000>>20) != 0 && _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 64)), zName) >= 0 || pUsing != 0 && _sqlite3IdListIndex(tls, pUsing, zName) >= 0 || j < int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_NOEXPAND) != 0 {
								libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(1), 7, 0x80)
							}
						} else {
							if longNames != 0 {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3MPrintf(tls, db, __ccgo_ts+13636, libc.VaList(bp+8, zTabName, zName))
								libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(ENAME_NAME), 14, 0xc000)
							} else {
								(*TExprList_item)(unsafe.Pointer(pX1)).FzEName = _sqlite3DbStrDup(tls, db, zName)
								libc.SetBitFieldPtr16Uint32(pX1+16+4, libc.Uint32FromInt32(ENAME_NAME), 14, 0xc000)
							}
						}
						goto _12
					_12:
						;
						j = j + 1
					}
					goto _8
				_8:
					;
					i = i + 1
					pFrom += 80
				}
				if !(tableSeen != 0) {
					if zTName != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21343, libc.VaList(bp+8, zTName))
					} else {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21361, 0)
					}
				}
			}
			goto _7
		_7:
			;
			k = k + 1
		}
		_sqlite3ExprListDelete(tls, db, pEList)
		(*TSelect)(unsafe.Pointer(p)).FpEList = pNew
	}
	if (*TSelect)(unsafe.Pointer(p)).FpEList != 0 {
		if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21381, 0)
			return int32(WRC_Abort)
		}
		if elistFlags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc)|libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
			**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_ComplexResult)
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Set the pointer-map entries for all children of page pPage. Also, if
//	** pPage contains cells that point to overflow pages, set the pointer
//	** map entries for the overflow pages as well.
//	*/
func _setChildPtrmaps(tls *libc.TLS, pPage uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var childPgno, childPgno1, pgno TPgno
	var i, nCell, v1 int32
	var pBt, pCell uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _ = childPgno, childPgno1, i, nCell, pBt, pCell, pgno, v1 /* Return code */
	pBt = (*TMemPage)(unsafe.Pointer(pPage)).FpBt
	pgno = (*TMemPage)(unsafe.Pointer(pPage)).Fpgno
	if (*TMemPage)(unsafe.Pointer(pPage)).FisInit != 0 {
		v1 = SQLITE_OK
	} else {
		v1 = _btreeInitPage(tls, pPage)
	}
	**(**int32)(__ccgo_up(bp)) = v1
	if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
		return **(**int32)(__ccgo_up(bp))
	}
	nCell = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
	i = 0
	for {
		if !(i < nCell) {
			break
		}
		pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*i)))))
		_ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp)
		if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
			childPgno = _sqlite3Get4byte(tls, pCell)
			_ptrmapPut(tls, pBt, childPgno, uint8(PTRMAP_BTREE), pgno, bp)
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		childPgno1 = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		_ptrmapPut(tls, pBt, childPgno1, uint8(PTRMAP_BTREE), pgno, bp)
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Set the time to the current time reported by the VFS.
//	**
//	** Return the number of errors.
//	*/
func _setDateTimeToCurrent(tls *libc.TLS, context uintptr, p uintptr) (r int32) {
	(*TDateTime)(unsafe.Pointer(p)).FiJD = _sqlite3StmtCurrentTime(tls, context)
	if (*TDateTime)(unsafe.Pointer(p)).FiJD > 0 {
		(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 4, 0x10)
		libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 3, 0x8)
		_clearYMD_HMS_TZ(tls, p)
		return 0
	} else {
		return int32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Input "r" is a numeric quantity which might be a julian day number,
//	** or the number of seconds since 1970.  If the value if r is within
//	** range of a julian day number, install it as such and set validJD.
//	** If the value is a valid unix timestamp, put it in p->s and set p->rawS.
//	*/
func _setRawDateNumber(tls *libc.TLS, p uintptr, r float64) {
	(*TDateTime)(unsafe.Pointer(p)).Fs = r
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 7, 0x80)
	if r >= float64(0) && r < float64(5.3734845e+06) {
		(*TDateTime)(unsafe.Pointer(p)).FiJD = int64(float64(r*libc.Float64FromFloat64(8.64e+07)) + libc.Float64FromFloat64(0.5))
		(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
	}
}

// C documentation
//
//	/*
//	** Add a new column to the table currently being constructed.
//	**
//	** The parser calls this routine once for each column declaration
//	** in a CREATE TABLE statement.  sqlite3StartTable() gets called
//	** first to get things going.  Then this routine is called for each
//	** column.
//	*/
func _sqlite3AddColumn(tls *libc.TLS, pParse uintptr, _sName TToken, _sType TToken) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	*(*TToken)(unsafe.Pointer(bp)) = _sName
	*(*TToken)(unsafe.Pointer(bp + 16)) = _sType
	var aNew, db, p, pCol, z, zType, v1 uintptr
	var affinity uint8
	var eType, h, szEst Tu8
	var i int32
	_, _, _, _, _, _, _, _, _, _, _, _ = aNew, affinity, db, eType, h, i, p, pCol, szEst, z, zType, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	eType = uint8(COLTYPE_CUSTOM)
	szEst = uint8(1)
	affinity = uint8(SQLITE_AFF_BLOB)
	v1 = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	p = v1
	if v1 == uintptr(0) {
		return
	}
	if int32((*TTable)(unsafe.Pointer(p)).FnCol)+int32(1) > **(**int32)(__ccgo_up(db + 136 + 2*4)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13960, libc.VaList(bp+40, (*TTable)(unsafe.Pointer(p)).FzName))
		return
	}
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		_sqlite3DequoteToken(tls, bp)
	}
	/* Because keywords GENERATE ALWAYS can be converted into identifiers
	 ** by the parser, we can sometimes end up with a typename that ends
	 ** with "generated always".  Check for this case and omit the surplus
	 ** text. */
	if (**(**TToken)(__ccgo_up(bp + 16))).Fn >= uint32(16) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 16))).Fz+uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-libc.Uint32FromInt32(6)), __ccgo_ts+13983, int32(6)) == 0 {
		(**(**TToken)(__ccgo_up(bp + 16))).Fn -= uint32(6)
		for (**(**TToken)(__ccgo_up(bp + 16))).Fn > uint32(0) && libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up((**(**TToken)(__ccgo_up(bp + 16))).Fz + uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-uint32(1)))))])&int32(0x01) != 0 {
			(**(**TToken)(__ccgo_up(bp + 16))).Fn = (**(**TToken)(__ccgo_up(bp + 16))).Fn - 1
		}
		if (**(**TToken)(__ccgo_up(bp + 16))).Fn >= uint32(9) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 16))).Fz+uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-libc.Uint32FromInt32(9)), __ccgo_ts+13990, int32(9)) == 0 {
			(**(**TToken)(__ccgo_up(bp + 16))).Fn -= uint32(9)
			for (**(**TToken)(__ccgo_up(bp + 16))).Fn > uint32(0) && libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up((**(**TToken)(__ccgo_up(bp + 16))).Fz + uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn-uint32(1)))))])&int32(0x01) != 0 {
				(**(**TToken)(__ccgo_up(bp + 16))).Fn = (**(**TToken)(__ccgo_up(bp + 16))).Fn - 1
			}
		}
	}
	/* Check for standard typenames.  For standard typenames we will
	 ** set the Column.eType field rather than storing the typename after
	 ** the column name, in order to save space. */
	if (**(**TToken)(__ccgo_up(bp + 16))).Fn >= uint32(3) {
		_sqlite3DequoteToken(tls, bp+16)
		i = 0
		for {
			if !(i < int32(SQLITE_N_STDTYPE)) {
				break
			}
			if (**(**TToken)(__ccgo_up(bp + 16))).Fn == uint32(_sqlite3StdTypeLen[i]) && Xsqlite3_strnicmp(tls, (**(**TToken)(__ccgo_up(bp + 16))).Fz, _sqlite3StdType[i], libc.Int32FromUint32((**(**TToken)(__ccgo_up(bp + 16))).Fn)) == 0 {
				(**(**TToken)(__ccgo_up(bp + 16))).Fn = uint32(0)
				eType = libc.Uint8FromInt32(i + int32(1))
				affinity = _sqlite3StdTypeAffinity[i]
				if libc.Int32FromUint8(affinity) <= int32(SQLITE_AFF_TEXT) {
					szEst = uint8(5)
				}
				break
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	z = _sqlite3DbMallocRaw(tls, db, libc.Uint64FromInt64(libc.Int64FromUint32((**(**TToken)(__ccgo_up(bp))).Fn)+int64(1)+libc.Int64FromUint32((**(**TToken)(__ccgo_up(bp + 16))).Fn)+libc.BoolInt64((**(**TToken)(__ccgo_up(bp + 16))).Fn > libc.Uint32FromInt32(0))))
	if z == uintptr(0) {
		return
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenMap(tls, pParse, z, bp)
	}
	libc.Xmemcpy(tls, z, (**(**TToken)(__ccgo_up(bp))).Fz, uint64((**(**TToken)(__ccgo_up(bp))).Fn))
	**(**uint8)(__ccgo_up(z + uintptr((**(**TToken)(__ccgo_up(bp))).Fn))) = uint8(0)
	_sqlite3Dequote(tls, z)
	if (*TTable)(unsafe.Pointer(p)).FnCol != 0 && _sqlite3ColumnIndex(tls, p, z) >= 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14000, libc.VaList(bp+40, z))
		_sqlite3DbFree(tls, db, z)
		return
	}
	aNew = _sqlite3DbRealloc(tls, db, (*TTable)(unsafe.Pointer(p)).FaCol, libc.Uint64FromInt64(int64((*TTable)(unsafe.Pointer(p)).FnCol)+libc.Int64FromInt32(1))*uint64(16))
	if aNew == uintptr(0) {
		_sqlite3DbFree(tls, db, z)
		return
	}
	(*TTable)(unsafe.Pointer(p)).FaCol = aNew
	pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr((*TTable)(unsafe.Pointer(p)).FnCol)*16
	libc.Xmemset(tls, pCol, 0, uint64(16))
	(*TColumn)(unsafe.Pointer(pCol)).FzCnName = z
	(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, z)
	if (**(**TToken)(__ccgo_up(bp + 16))).Fn == uint32(0) {
		/* If there is no type specified, columns have the default affinity
		 ** 'BLOB' with a default size of 4 bytes. */
		(*TColumn)(unsafe.Pointer(pCol)).Faffinity = affinity
		libc.SetBitFieldPtr8Uint32(pCol+8, uint32(eType), 0, 0xf)
		(*TColumn)(unsafe.Pointer(pCol)).FszEst = szEst
	} else {
		zType = z + uintptr(_sqlite3Strlen30(tls, z)) + uintptr(1)
		libc.Xmemcpy(tls, zType, (**(**TToken)(__ccgo_up(bp + 16))).Fz, uint64((**(**TToken)(__ccgo_up(bp + 16))).Fn))
		**(**uint8)(__ccgo_up(zType + uintptr((**(**TToken)(__ccgo_up(bp + 16))).Fn))) = uint8(0)
		_sqlite3Dequote(tls, zType)
		(*TColumn)(unsafe.Pointer(pCol)).Faffinity = _sqlite3AffinityType(tls, zType, pCol)
		v1 = pCol + 14
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(COLFLAG_HASTYPE))
	}
	if int32((*TTable)(unsafe.Pointer(p)).FnCol) <= int32(0xff) {
		h = uint8(uint64((*TColumn)(unsafe.Pointer(pCol)).FhName) % uint64(16))
		**(**Tu8)(__ccgo_up(p + 104 + uintptr(h))) = libc.Uint8FromInt16((*TTable)(unsafe.Pointer(p)).FnCol)
	}
	(*TTable)(unsafe.Pointer(p)).FnCol = (*TTable)(unsafe.Pointer(p)).FnCol + 1
	(*TTable)(unsafe.Pointer(p)).FnNVCol = (*TTable)(unsafe.Pointer(p)).FnNVCol + 1
	(*(*struct {
		FaddrCrTab      int32
		FregRowid       int32
		FregRoot        int32
		FconstraintName TToken
	})(unsafe.Pointer(pParse + 256))).FconstraintName.Fn = uint32(0)
}

// C documentation
//
//	/*
//	** This routine is called by the parser while in the middle of
//	** parsing a CREATE TABLE statement.  A "NOT NULL" constraint has
//	** been seen on a column.  This routine sets the notNull flag on
//	** the column currently under construction.
//	*/
func _sqlite3AddNotNull(tls *libc.TLS, pParse uintptr, onError int32) {
	var p, pCol, pIdx uintptr
	_, _, _ = p, pCol, pIdx
	p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if p == uintptr(0) || int32((*TTable)(unsafe.Pointer(p)).FnCol) < int32(1) {
		return
	}
	pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(p)).FnCol)-int32(1))*16
	libc.SetBitFieldPtr8Uint32(pCol+8, uint32(libc.Uint8FromInt32(onError)), 4, 0xf0)
	**(**Tu32)(__ccgo_up(p + 48)) |= uint32(TF_HasNotNull)
	/* Set the uniqNotNull flag on any UNIQUE or PK indexes already created
	 ** on this column.  */
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_UNIQUE) != 0 {
		pIdx = (*TTable)(unsafe.Pointer(p)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn))) == int32((*TTable)(unsafe.Pointer(p)).FnCol)-int32(1) {
				libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(1), 12, 0x1000)
			}
			goto _1
		_1:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	}
}

// C documentation
//
//	/*
//	** Designate the PRIMARY KEY for the table.  pList is a list of names
//	** of columns that form the primary key.  If pList is NULL, then the
//	** most recently added column of the table is the primary key.
//	**
//	** A table can have at most one primary key.  If the table already has
//	** a primary key (and this is the second primary key) then create an
//	** error.
//	**
//	** If the PRIMARY KEY is on a single column whose datatype is INTEGER,
//	** then we will try to use that column as the rowid.  Set the Table.iPKey
//	** field of the table under construction to be the index of the
//	** INTEGER PRIMARY KEY column.  Table.iPKey is set to -1 if there is
//	** no INTEGER PRIMARY KEY.
//	**
//	** If the key is not an INTEGER PRIMARY KEY, then create a unique
//	** index for the key.  No index is created for INTEGER PRIMARY KEYs.
//	*/
func _sqlite3AddPrimaryKey(tls *libc.TLS, pParse uintptr, pList uintptr, onError int32, autoInc int32, sortOrder int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iCol, nTerm int32
	var pCExpr, pCExpr1, pCol, pTab uintptr
	_, _, _, _, _, _, _ = i, iCol, nTerm, pCExpr, pCExpr1, pCol, pTab
	pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	pCol = uintptr(0)
	iCol = -int32(1)
	if pTab == uintptr(0) {
		goto primary_key_exit
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasPrimaryKey) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14164, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto primary_key_exit
	}
	**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_HasPrimaryKey)
	if pList == uintptr(0) {
		iCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol) - int32(1)
		pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
		_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
		nTerm = int32(1)
	} else {
		nTerm = (*TExprList)(unsafe.Pointer(pList)).FnExpr
		i = 0
		for {
			if !(i < nTerm) {
				break
			}
			pCExpr = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr)
			_sqlite3StringToId(tls, pCExpr)
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pCExpr)).Fop) == int32(TK_ID) {
				iCol = _sqlite3ColumnIndex(tls, pTab, *(*uintptr)(unsafe.Pointer(pCExpr + 8)))
				if iCol >= 0 {
					pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16
					_makeColumnPartOfPrimaryKey(tls, pParse, pCol)
				}
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	if nTerm == int32(1) && pCol != 0 && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) == int32(COLTYPE_INTEGER) && sortOrder != int32(SQLITE_SO_DESC) {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && pList != 0 {
			pCExpr1 = _sqlite3ExprSkipCollate(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8))).FpExpr)
			_sqlite3RenameTokenRemap(tls, pParse, pTab+52, pCExpr1)
		}
		(*TTable)(unsafe.Pointer(pTab)).FiPKey = int16(iCol)
		(*TTable)(unsafe.Pointer(pTab)).FkeyConf = libc.Uint8FromInt32(onError)
		**(**Tu32)(__ccgo_up(pTab + 48)) |= libc.Uint32FromInt32(autoInc * int32(TF_Autoincrement))
		if pList != 0 {
			(*TParse)(unsafe.Pointer(pParse)).FiPkSortOrder = (*(*TExprList_item)(unsafe.Pointer(pList + 8))).Ffg.FsortFlags
		}
		_sqlite3HasExplicitNulls(tls, pParse, pList)
	} else {
		if autoInc != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14205, 0)
		} else {
			_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), pList, onError, uintptr(0), uintptr(0), sortOrder, 0, uint8(SQLITE_IDXTYPE_PRIMARYKEY))
			pList = uintptr(0)
		}
	}
	goto primary_key_exit
primary_key_exit:
	;
	_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	return
}

// C documentation
//
//	/*
//	** Add the RETURNING clause to the parse currently underway.
//	**
//	** This routine creates a special TEMP trigger that will fire for each row
//	** of the DML statement.  That TEMP trigger contains a single SELECT
//	** statement with a result set that is the argument of the RETURNING clause.
//	** The trigger has the Trigger.bReturning flag and an opcode of
//	** TK_RETURNING instead of TK_SELECT, so that the trigger code generator
//	** knows to handle it specially.  The TEMP trigger is automatically
//	** removed at the end of the parse.
//	**
//	** When this routine is called, we do not yet know if the RETURNING clause
//	** is attached to a DELETE, INSERT, or UPDATE, so construct it as a
//	** RETURNING trigger instead.  It will then be converted into the appropriate
//	** type on the first call to sqlite3TriggersExist().
//	*/
func _sqlite3AddReturning(tls *libc.TLS, pParse uintptr, pList uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pHash, pRet uintptr
	_, _, _ = db, pHash, pRet
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13906, 0)
	} else {
	}
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 12, 0x1000)
	pRet = _sqlite3DbMallocZero(tls, db, uint64(232))
	if pRet == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pList)
		return
	}
	(*(*struct {
		FpReturning uintptr
	})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning = pRet
	(*TReturning)(unsafe.Pointer(pRet)).FpParse = pParse
	(*TReturning)(unsafe.Pointer(pRet)).FpReturnEL = pList
	_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DeleteReturning), pRet)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}
	Xsqlite3_snprintf(tls, int32(40), pRet+188, __ccgo_ts+13940, libc.VaList(bp+8, pParse))
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FzName = pRet + 188
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fop = uint8(TK_RETURNING)
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Ftr_tm = uint8(TRIGGER_AFTER)
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FbReturning = uint8(1)
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.FpTabSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema
	(*TReturning)(unsafe.Pointer(pRet)).FretTrig.Fstep_list = pRet + 88
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.Fop = uint8(TK_RETURNING)
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpTrig = pRet + 16
	(*TReturning)(unsafe.Pointer(pRet)).FretTStep.FpExprList = pList
	pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema + 56
	if _sqlite3HashInsert(tls, pHash, pRet+188, pRet+16) == pRet+16 {
		_sqlite3OomFault(tls, db)
	}
}

// C documentation
//
//	/*
//	** This function is called after an "ALTER TABLE ... ADD" statement
//	** has been parsed. Argument pColDef contains the text of the new
//	** column definition.
//	**
//	** The Table structure pParse->pNewTable was extended to include
//	** the new column during parsing.
//	*/
func _sqlite3AlterFinishAddColumn(tls *libc.TLS, pParse uintptr, pColDef uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pCol, pDflt, pNew, pTab, v, zCol, zDb, zEnd, zTab, v1 uintptr
	var iDb, r1, rc int32
	var _ /* pVal at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, iDb, pCol, pDflt, pNew, pTab, r1, rc, v, zCol, zDb, zEnd, zTab, v1 /* Temporary registers */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	pNew = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pNew)).FpSchema)
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	zTab = (*TTable)(unsafe.Pointer(pNew)).FzName + 16 /* Skip the "sqlite_altertab_" prefix on the name */
	pCol = (*TTable)(unsafe.Pointer(pNew)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pNew)).FnCol)-int32(1))*16
	pDflt = _sqlite3ColumnExpr(tls, pNew, pCol)
	pTab = _sqlite3FindTable(tls, db, zTab, zDb)
	/* Invoke the authorization callback. */
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), zDb, (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
		return
	}
	/* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
	 ** If there is a NOT NULL constraint, then the default value for the
	 ** column must not be NULL.
	 */
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10293, 0)
		return
	}
	if (*TTable)(unsafe.Pointer(pNew)).FpIndex != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+10325, 0)
		return
	}
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) == 0 {
		/* If the default value for the new column was specified with a
		 ** literal NULL, then set pDflt to 0. This simplifies checking
		 ** for an SQL NULL default below.
		 */
		if pDflt != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pDflt)).FpLeft)).Fop) == int32(TK_NULL) {
			pDflt = uintptr(0)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pNew + 64))).FpFKey != 0 && pDflt != 0 {
			_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10352)
		}
		if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) != 0 && !(pDflt != 0) {
			_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10411)
		}
		/* Ensure the default expression is something that sqlite3ValueFromExpr()
		 ** can handle (i.e. not CURRENT_TIME etc.)
		 */
		if pDflt != 0 {
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
			rc = _sqlite3ValueFromExpr(tls, db, pDflt, uint8(SQLITE_UTF8), uint8(SQLITE_AFF_BLOB), bp)
			if rc != SQLITE_OK {
				return
			}
			if !(**(**uintptr)(__ccgo_up(bp)) != 0) {
				_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10464)
			}
			_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(bp)))
		}
	} else {
		if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_STORED) != 0 {
			_sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, __ccgo_ts+10510)
		}
	}
	/* Modify the CREATE TABLE statement. */
	zCol = _sqlite3DbStrNDup(tls, db, (*TToken)(unsafe.Pointer(pColDef)).Fz, uint64((*TToken)(unsafe.Pointer(pColDef)).Fn))
	if zCol != 0 {
		zEnd = zCol + uintptr((*TToken)(unsafe.Pointer(pColDef)).Fn-uint32(1))
		for zEnd > zCol && (libc.Int32FromUint8(**(**uint8)(__ccgo_up(zEnd))) == int32(';') || libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(zEnd)))])&int32(0x01) != 0) {
			v1 = zEnd
			zEnd = zEnd - 1
			**(**uint8)(__ccgo_up(v1)) = uint8('\000')
		}
		/* substr() operations on characters, but addColOffset is in bytes. So we
		 ** have to use printf() to translate between these units: */
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+10537, libc.VaList(bp+16, zDb, (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pNew + 64))).FaddColOffset, zCol, (*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(pNew + 64))).FaddColOffset, zTab))
		_sqlite3DbFree(tls, db, zCol)
	}
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		/* Make sure the schema version is at least 3.  But do not upgrade
		 ** from less than 3 to 4, as that will corrupt any preexisting DESC
		 ** index.
		 */
		r1 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_ReadCookie), iDb, r1, int32(BTREE_FILE_FORMAT))
		_sqlite3VdbeUsesBtree(tls, v, iDb)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), r1, -int32(2))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), r1, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_FILE_FORMAT), int32(3))
		_sqlite3ReleaseTempReg(tls, pParse, r1)
		/* Reload the table definition */
		_renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterAdd))
		/* Verify that constraints are still satisfied */
		if (*TTable)(unsafe.Pointer(pNew)).FpCheck != uintptr(0) || int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) != 0 && libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 || (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Strict) != uint32(0) {
			_sqlite3NestedParse(tls, pParse, __ccgo_ts+10683, libc.VaList(bp+16, zTab, zDb))
		}
	}
}

// C documentation
//
//	/*
//	** Load the content of the sqlite_stat1 and sqlite_stat4 tables. The
//	** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
//	** arrays. The contents of sqlite_stat4 are used to populate the
//	** Index.aSample[] arrays.
//	**
//	** If the sqlite_stat1 table is not present in the database, SQLITE_ERROR
//	** is returned. In this case, even if SQLITE_ENABLE_STAT4 was defined
//	** during compilation and the sqlite_stat4 table is present, no data is
//	** read from it.
//	**
//	** If SQLITE_ENABLE_STAT4 was defined during compilation and the
//	** sqlite_stat4 table is not present in the database, SQLITE_ERROR is
//	** returned. However, in this case, data is read from the sqlite_stat1
//	** table (if it is present) before returning.
//	**
//	** If an OOM error occurs, this function always sets db->mallocFailed.
//	** This means if the caller does not care about other errors, the return
//	** code may be ignored.
//	*/
func _sqlite3AnalysisLoad(tls *libc.TLS, db uintptr, iDb int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, pIdx, pIdx1, pIdx2, pSchema, pStat1, pTab, zSql, v3 uintptr
	var rc, v5 int32
	var _ /* sInfo at bp+0 */ TanalysisInfo
	_, _, _, _, _, _, _, _, _, _, _ = i, pIdx, pIdx1, pIdx2, pSchema, pStat1, pTab, rc, zSql, v3, v5
	rc = SQLITE_OK
	pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	/* Clear any prior statistics */
	i = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(i)).Fdata
		**(**Tu32)(__ccgo_up(pTab + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(TF_HasStat1))
		goto _1
	_1:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx = (*THashElem)(unsafe.Pointer(i)).Fdata
		libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(0), 8, 0x100)
		_sqlite3DeleteIndexSamples(tls, db, pIdx)
		(*TIndex)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
		goto _2
	_2:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	/* Load new statistics out of the sqlite_stat1 table */
	(**(**TanalysisInfo)(__ccgo_up(bp))).Fdb = db
	(**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	v3 = _sqlite3FindTable(tls, db, __ccgo_ts+12837, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase)
	pStat1 = v3
	if v3 != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pStat1)).FeTabType) == TABTYP_NORM {
		zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+13210, libc.VaList(bp+24, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase))
		if zSql == uintptr(0) {
			rc = int32(SQLITE_NOMEM)
		} else {
			rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_analysisLoader), bp, uintptr(0))
			_sqlite3DbFree(tls, db, zSql)
		}
	}
	/* Set appropriate defaults on all indexes not in the sqlite_stat1 table */
	i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx1 = (*THashElem)(unsafe.Pointer(i)).Fdata
		if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0x100>>8)) != 0) {
			_sqlite3DefaultRowEst(tls, pIdx1)
		}
		goto _4
	_4:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	/* Load the statistics from the sqlite_stat4 table. */
	if rc == SQLITE_OK {
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
		rc = _loadStat4(tls, db, (**(**TanalysisInfo)(__ccgo_up(bp))).FzDatabase)
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable - 1
		if (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			v5 = 0
		} else {
			v5 = libc.Int32FromUint16((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
		}
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = libc.Uint16FromInt32(v5)
	}
	i = (*THash)(unsafe.Pointer(pSchema + 32)).Ffirst
	for {
		if !(i != 0) {
			break
		}
		pIdx2 = (*THashElem)(unsafe.Pointer(i)).Fdata
		Xsqlite3_free(tls, (*TIndex)(unsafe.Pointer(pIdx2)).FaiRowEst)
		(*TIndex)(unsafe.Pointer(pIdx2)).FaiRowEst = uintptr(0)
		goto _6
	_6:
		;
		i = (*THashElem)(unsafe.Pointer(i)).Fnext
	}
	if rc == int32(SQLITE_NOMEM) {
		_sqlite3OomFault(tls, db)
	}
	return rc
}

/************** End of analyze.c *********************************************/
/************** Begin file attach.c ******************************************/
/*
** 2003 April 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** This is called by the parser when it sees a CREATE TRIGGER statement
//	** up to the point of the BEGIN before the trigger actions.  A Trigger
//	** structure is generated based on the information available and stored
//	** in pParse->pNewTrigger.  After the trigger actions have been parsed, the
//	** sqlite3FinishTrigger() function is called to complete the trigger
//	** construction process.
//	*/
func _sqlite3BeginTrigger(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, tr_tm int32, op int32, pColumns uintptr, pTableName uintptr, pWhen uintptr, isTemp int32, noErr int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var code, iDb, iTabDb, v4 int32
	var db, pTab, pTrigger, zDb, zDbTrig, zName, v1 uintptr
	var _ /* pName at bp+0 */ uintptr
	var _ /* sFix at bp+8 */ TDbFixer
	_, _, _, _, _, _, _, _, _, _, _ = code, db, iDb, iTabDb, pTab, pTrigger, zDb, zDbTrig, zName, v1, v4
	pTrigger = uintptr(0)                      /* Table that the trigger fires off of */
	zName = uintptr(0)                         /* Name of the trigger */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* State vector for the DB fixer */
	/* pName1->z might be NULL, but not pName1 itself */
	if isTemp != 0 {
		/* If TEMP was specified, then the trigger name may not be qualified. */
		if (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21840, 0)
			goto trigger_cleanup
		}
		iDb = int32(1)
		**(**uintptr)(__ccgo_up(bp)) = pName1
	} else {
		/* Figure out the db that the trigger will be created in */
		iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
		if iDb < 0 {
			goto trigger_cleanup
		}
	}
	if !(pTableName != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto trigger_cleanup
	}
	/* A long-standing parser bug is that this syntax was allowed:
	 **
	 **    CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
	 **                                                 ^^^^^^^^
	 **
	 ** To maintain backwards compatibility, ignore the database
	 ** name on pTableName if we are reparsing out of the schema table
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && iDb != int32(1) {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pTableName + 8 + 72)))
		*(*uintptr)(unsafe.Pointer(pTableName + 8 + 72)) = uintptr(0)
	}
	/* If the trigger name was unqualified, and the table is a temp table,
	 ** then set iDb to 1 to create the trigger in the temporary database.
	 ** If sqlite3SrcListLookup() returns 0, indicating the table does not
	 ** exist, the error is caught by the block below.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema == (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
		iDb = int32(1)
	}
	/* Ensure the table name matches database name and that the table exists */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto trigger_cleanup
	}
	_sqlite3FixInit(tls, bp+8, pParse, iDb, __ccgo_ts+21886, **(**uintptr)(__ccgo_up(bp)))
	if _sqlite3FixSrcList(tls, bp+8, pTableName) != 0 {
		goto trigger_cleanup
	}
	pTab = _sqlite3SrcListLookup(tls, pParse, pTableName)
	if !(pTab != 0) {
		/* The table does not exist. */
		goto trigger_orphan_error
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21894, 0)
		goto trigger_orphan_error
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Shadow) != uint32(0) && _sqlite3ReadOnlyShadowTables(tls, db) != 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21935, 0)
		goto trigger_orphan_error
	}
	/* Check that the trigger name is not reserved and that no trigger of the
	 ** specified name exists */
	zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
	if zName == uintptr(0) {
		goto trigger_cleanup
	}
	if _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+21886, (*TTable)(unsafe.Pointer(pTab)).FzName) != 0 {
		goto trigger_cleanup
	}
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		if _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema+56, zName) != 0 {
			if !(noErr != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21975, libc.VaList(bp+112, **(**uintptr)(__ccgo_up(bp))))
			} else {
				_sqlite3CodeVerifySchema(tls, pParse, iDb)
			}
			goto trigger_cleanup
		}
	}
	/* NB: The SQLITE_ALLOW_TRIGGERS_ON_SYSTEM_TABLES compile-time option is
	 ** experimental and unsupported. Do not use it unless understand the
	 ** implications and you cannot get by without this capability. */
	/* Do not create a trigger on a system table */
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+6760, int32(7)) == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22001, 0)
		goto trigger_cleanup
	}
	/* INSTEAD of triggers are only for views and views only support INSTEAD
	 ** of triggers.
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) && tr_tm != int32(TK_INSTEAD) {
		if tr_tm == int32(TK_BEFORE) {
			v1 = __ccgo_ts + 22039
		} else {
			v1 = __ccgo_ts + 22046
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22052, libc.VaList(bp+112, v1, pTableName+8))
		goto trigger_orphan_error
	}
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) && tr_tm == int32(TK_INSTEAD) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22089, libc.VaList(bp+112, pTableName+8))
		goto trigger_orphan_error
	}
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		iTabDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		code = int32(SQLITE_CREATE_TRIGGER)
		zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iTabDb)*32))).FzDbSName
		if isTemp != 0 {
			v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FzDbSName
		} else {
			v1 = zDb
		}
		zDbTrig = v1
		if iTabDb == int32(1) || isTemp != 0 {
			code = int32(SQLITE_CREATE_TEMP_TRIGGER)
		}
		if _sqlite3AuthCheck(tls, pParse, code, zName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDbTrig) != 0 {
			goto trigger_cleanup
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iTabDb == int32(1) {
			v1 = __ccgo_ts + 6768
		} else {
			v1 = __ccgo_ts + 6288
		}
		if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v1, uintptr(0), zDb) != 0 {
			goto trigger_cleanup
		}
	}
	/* INSTEAD OF triggers can only appear on views and BEFORE triggers
	 ** cannot appear on views.  So we might as well translate every
	 ** INSTEAD OF trigger into a BEFORE trigger.  It simplifies code
	 ** elsewhere.
	 */
	if tr_tm == int32(TK_INSTEAD) {
		tr_tm = int32(TK_BEFORE)
	}
	/* Build the Trigger object */
	pTrigger = _sqlite3DbMallocZero(tls, db, uint64(72))
	if pTrigger == uintptr(0) {
		goto trigger_cleanup
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).FzName = zName
	zName = uintptr(0)
	(*TTrigger)(unsafe.Pointer(pTrigger)).Ftable = _sqlite3DbStrDup(tls, db, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzName)
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*TTable)(unsafe.Pointer(pTab)).FpSchema
	(*TTrigger)(unsafe.Pointer(pTrigger)).Fop = libc.Uint8FromInt32(op)
	if tr_tm == int32(TK_BEFORE) {
		v4 = int32(TRIGGER_BEFORE)
	} else {
		v4 = int32(TRIGGER_AFTER)
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).Ftr_tm = libc.Uint8FromInt32(v4)
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenRemap(tls, pParse, (*TTrigger)(unsafe.Pointer(pTrigger)).Ftable, (*(*TSrcItem)(unsafe.Pointer(pTableName + 8))).FzName)
		(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = pWhen
		pWhen = uintptr(0)
	} else {
		(*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen = _sqlite3ExprDup(tls, db, pWhen, int32(EXPRDUP_REDUCE))
	}
	(*TTrigger)(unsafe.Pointer(pTrigger)).FpColumns = pColumns
	pColumns = uintptr(0)
	(*TParse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrigger
	goto trigger_cleanup
trigger_cleanup:
	;
	_sqlite3DbFree(tls, db, zName)
	_sqlite3SrcListDelete(tls, db, pTableName)
	_sqlite3IdListDelete(tls, db, pColumns)
	_sqlite3ExprDelete(tls, db, pWhen)
	if !((*TParse)(unsafe.Pointer(pParse)).FpNewTrigger != 0) {
		_sqlite3DeleteTrigger(tls, db, pTrigger)
	} else {
	}
	return
	goto trigger_orphan_error
trigger_orphan_error:
	;
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) == int32(1) {
		/* Ticket #3810.
		 ** Normally, whenever a table is dropped, all associated triggers are
		 ** dropped too.  But if a TEMP trigger is created on a non-TEMP table
		 ** and the table is dropped by a different database connection, the
		 ** trigger is not visible to the database connection that does the
		 ** drop so the trigger cannot be dropped.  This results in an
		 ** "orphaned trigger" - a trigger whose associated table is missing.
		 **
		 ** 2020-11-05 see also https://sqlite.org/forum/forumpost/157dc791df
		 */
		libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(1), 7, 0x80)
	}
	goto trigger_cleanup
}

// C documentation
//
//	/*
//	** The first argument, pCur, is a cursor opened on some b-tree. Count the
//	** number of entries in the b-tree and write the result to *pnEntry.
//	**
//	** SQLITE_OK is returned if the operation is successfully executed.
//	** Otherwise, if an error is encountered (i.e. an IO error or database
//	** corruption) an SQLite error code is returned.
//	*/
func _sqlite3BtreeCount(tls *libc.TLS, db uintptr, pCur uintptr, pnEntry uintptr) (r int32) {
	var iIdx, rc int32
	var nEntry Ti64
	var pPage uintptr
	_, _, _, _ = iIdx, nEntry, pPage, rc
	nEntry = 0 /* Return code */
	rc = _moveToRoot(tls, pCur)
	if rc == int32(SQLITE_EMPTY) {
		**(**Ti64)(__ccgo_up(pnEntry)) = 0
		return SQLITE_OK
	}
	/* Unless an error occurs, the following loop runs one iteration for each
	 ** page in the B-Tree structure (not including overflow pages).
	 */
	for rc == SQLITE_OK && !(libc.AtomicLoadNInt32(db+432, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0) { /* Current page of the b-tree */
		/* If this is a leaf page or the tree is not an int-key tree, then
		 ** this page contains countable entries. Increment the entry counter
		 ** accordingly.
		 */
		pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 || !((*TMemPage)(unsafe.Pointer(pPage)).FintKey != 0) {
			nEntry = nEntry + libc.Int64FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell)
		}
		/* pPage is a leaf node. This loop navigates the cursor so that it
		 ** points to the first interior cell that it points to the parent of
		 ** the next page in the tree that has not yet been visited. The
		 ** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
		 ** of the page, or to the number of cells in the page if the next page
		 ** to visit is the right-child of its parent.
		 **
		 ** If all pages in the tree have been visited, return SQLITE_OK to the
		 ** caller.
		 */
		if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
			for cond := true; cond; cond = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix) >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell) {
				if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) == 0 {
					/* All pages of the b-tree have been visited. Return successfully. */
					**(**Ti64)(__ccgo_up(pnEntry)) = nEntry
					return _moveToRoot(tls, pCur)
				}
				_moveToParent(tls, pCur)
			}
			(*TBtCursor)(unsafe.Pointer(pCur)).Fix = (*TBtCursor)(unsafe.Pointer(pCur)).Fix + 1
			pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		}
		/* Descend to the child node of the cell that the cursor currently
		 ** points at. This is the right-child if (iIdx==pPage->nCell).
		 */
		iIdx = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
		if iIdx == libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8))))
		} else {
			rc = _moveToChild(tls, pCur, _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iIdx)))))))
		}
	}
	/* An error has occurred. Return an error code. */
	return rc
}

// C documentation
//
//	/*
//	** Delete the entry that the cursor is pointing to.
//	**
//	** If the BTREE_SAVEPOSITION bit of the flags parameter is zero, then
//	** the cursor is left pointing at an arbitrary location after the delete.
//	** But if that bit is set, then the cursor is left in a state such that
//	** the next call to BtreeNext() or BtreePrev() moves it to the same row
//	** as it would have been on if the call to BtreeDelete() had been omitted.
//	**
//	** The BTREE_AUXDELETE bit of flags indicates that is one of several deletes
//	** associated with a single table entry and its indexes.  Only one of those
//	** deletes is considered the "primary" delete.  The primary delete occurs
//	** on a cursor that is not a BTREE_FORDELETE cursor.  All but one delete
//	** operation on non-FORDELETE cursors is tagged with the AUXDELETE flag.
//	** The BTREE_AUXDELETE bit is a hint that is not used by this implementation,
//	** but which might be used by alternative storage engines.
//	*/
func _sqlite3BtreeDelete(tls *libc.TLS, pCur uintptr, flags Tu8) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bPreserve Tu8
	var iCellDepth, iCellIdx, nCell int32
	var n TPgno
	var p, pBt, pCell, pLeaf, pPage, pTmp, v2 uintptr
	var v1 Ti8
	var _ /* info at bp+8 */ TCellInfo
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _ = bPreserve, iCellDepth, iCellIdx, n, nCell, p, pBt, pCell, pLeaf, pPage, pTmp, v1, v2
	p = (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt /* Keep cursor valid.  2 for CURSOR_SKIPNEXT */
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
			**(**int32)(__ccgo_up(bp)) = _btreeRestoreCursorPosition(tls, pCur)
			if **(**int32)(__ccgo_up(bp)) != 0 || libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
				return **(**int32)(__ccgo_up(bp))
			}
		} else {
			return _sqlite3CorruptError(tls, int32(83091))
		}
	}
	iCellDepth = int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)
	iCellIdx = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	if libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) <= iCellIdx {
		return _sqlite3CorruptError(tls, int32(83100))
	}
	pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*iCellIdx)))))
	if (*TMemPage)(unsafe.Pointer(pPage)).FnFree < 0 && _btreeComputeFreeSpace(tls, pPage) != 0 {
		return _sqlite3CorruptError(tls, int32(83104))
	}
	if pCell < (*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx+uintptr((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
		return _sqlite3CorruptError(tls, int32(83107))
	}
	/* If the BTREE_SAVEPOSITION bit is on, then the cursor position must
	 ** be preserved following this delete operation. If the current delete
	 ** will cause a b-tree rebalance, then this is done by saving the cursor
	 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
	 ** returning.
	 **
	 ** If the current delete will not cause a rebalance, then the cursor
	 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
	 ** before or after the deleted entry.
	 **
	 ** The bPreserve value records which path is required:
	 **
	 **    bPreserve==0         Not necessary to save the cursor position
	 **    bPreserve==1         Use CURSOR_REQUIRESEEK to save the cursor position
	 **    bPreserve==2         Cursor won't move.  Set CURSOR_SKIPNEXT.
	 */
	bPreserve = libc.BoolUint8(libc.Int32FromUint8(flags)&int32(BTREE_SAVEPOSITION) != 0)
	if bPreserve != 0 {
		if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) || (*TMemPage)(unsafe.Pointer(pPage)).FnFree+libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxCellSize})))(tls, pPage, pCell))+int32(2) > libc.Int32FromUint32((*TBtShared)(unsafe.Pointer(pBt)).FusableSize*libc.Uint32FromInt32(2)/libc.Uint32FromInt32(3)) || libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) == int32(1) {
			/* A b-tree rebalance will be required after deleting this entry.
			 ** Save the cursor key.  */
			**(**int32)(__ccgo_up(bp)) = _saveCursorKey(tls, pCur)
			if **(**int32)(__ccgo_up(bp)) != 0 {
				return **(**int32)(__ccgo_up(bp))
			}
		} else {
			bPreserve = uint8(2)
		}
	}
	/* If the page containing the entry to delete is not a leaf page, move
	 ** the cursor to the largest entry in the tree that is smaller than
	 ** the entry being deleted. This cell will replace the cell being deleted
	 ** from the internal node. The 'previous' entry is used for this instead
	 ** of the 'next' entry, as the previous entry is always a part of the
	 ** sub-tree headed by the child page of the cell being deleted. This makes
	 ** balancing the tree following the delete operation easier.  */
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		**(**int32)(__ccgo_up(bp)) = _sqlite3BtreePrevious(tls, pCur, 0)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			return **(**int32)(__ccgo_up(bp))
		}
	}
	/* Save the positions of any other cursors open on this table before
	 ** making any modifications.  */
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_Multiple) != 0 {
		**(**int32)(__ccgo_up(bp)) = _saveAllCursors(tls, pBt, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			return **(**int32)(__ccgo_up(bp))
		}
	}
	/* If this is a delete operation to remove a row from a table b-tree,
	 ** invalidate any incrblob cursors open on the row being deleted.  */
	if (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0) && (*TBtree)(unsafe.Pointer(p)).FhasIncrblobCur != 0 {
		_invalidateIncrblobCursors(tls, p, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey, 0)
	}
	/* Make the page containing the entry to be deleted writable. Then free any
	 ** overflow pages associated with the entry and finally remove the cell
	 ** itself from within the page.  */
	**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
	if **(**int32)(__ccgo_up(bp)) != 0 {
		return **(**int32)(__ccgo_up(bp))
	}
	(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, pCell, bp+8)
	if uint32((**(**TCellInfo)(__ccgo_up(bp + 8))).FnLocal) != (**(**TCellInfo)(__ccgo_up(bp + 8))).FnPayload {
		**(**int32)(__ccgo_up(bp)) = _clearCellOverflow(tls, pPage, pCell, bp+8)
	} else {
		**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	}
	_dropCell(tls, pPage, iCellIdx, libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 8))).FnSize), bp)
	if **(**int32)(__ccgo_up(bp)) != 0 {
		return **(**int32)(__ccgo_up(bp))
	}
	/* If the cell deleted was not located on a leaf page, then the cursor
	 ** is currently pointing to the largest entry in the sub-tree headed
	 ** by the child-page of the cell that was just deleted from an internal
	 ** node. The cell from the leaf node needs to be moved to the internal
	 ** node to replace the deleted cell.  */
	if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		pLeaf = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		if (*TMemPage)(unsafe.Pointer(pLeaf)).FnFree < 0 {
			**(**int32)(__ccgo_up(bp)) = _btreeComputeFreeSpace(tls, pLeaf)
			if **(**int32)(__ccgo_up(bp)) != 0 {
				return **(**int32)(__ccgo_up(bp))
			}
		}
		if iCellDepth < int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)-int32(1) {
			n = (*TMemPage)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pCur + 144 + uintptr(iCellDepth+int32(1))*8)))).Fpgno
		} else {
			n = (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fpgno
		}
		pCell = (*TMemPage)(unsafe.Pointer(pLeaf)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pLeaf)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pLeaf)).FaCellIdx + uintptr(int32(2)*(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pLeaf)).FnCell)-int32(1)))))))
		if pCell < (*TMemPage)(unsafe.Pointer(pLeaf)).FaData+4 {
			return _sqlite3CorruptError(tls, int32(83198))
		}
		nCell = libc.Int32FromUint16((*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pLeaf)).FxCellSize})))(tls, pLeaf, pCell))
		pTmp = (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace
		**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pLeaf)).FpDbPage)
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = _insertCell(tls, pPage, iCellIdx, pCell-uintptr(4), nCell+int32(4), pTmp, n)
		}
		_dropCell(tls, pLeaf, libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pLeaf)).FnCell)-int32(1), nCell, bp)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			return **(**int32)(__ccgo_up(bp))
		}
	}
	/* Balance the tree. If the entry deleted was located on a leaf page,
	 ** then the cursor still points to that page. In this case the first
	 ** call to balance() repairs the tree, and the if(...) condition is
	 ** never true.
	 **
	 ** Otherwise, if the entry deleted was on an internal node page, then
	 ** pCur is pointing to the leaf page from which a cell was removed to
	 ** replace the cell deleted from the internal node. This is slightly
	 ** tricky as the leaf node may be underfull, and the internal node may
	 ** be either under or overfull. In this case run the balancing algorithm
	 ** on the leaf node first. If the balance proceeds far enough up the
	 ** tree that we can be sure that any problem in the internal node has
	 ** been corrected, so be it. Otherwise, after balancing the leaf node,
	 ** walk the cursor up the tree to the internal node and balance it as
	 ** well.  */
	if (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnFree*int32(3) <= libc.Int32FromUint32((*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize)*int32(2) {
		/* Optimization: If the free space is less than 2/3rds of the page,
		 ** then balance() will always be a no-op.  No need to invoke it. */
		**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	} else {
		**(**int32)(__ccgo_up(bp)) = _balance(tls, pCur)
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > iCellDepth {
		_releasePageNotNull(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
		(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = (*TBtCursor)(unsafe.Pointer(pCur)).FiPage - 1
		for int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > iCellDepth {
			v2 = pCur + 84
			v1 = *(*Ti8)(unsafe.Pointer(v2))
			*(*Ti8)(unsafe.Pointer(v2)) = *(*Ti8)(unsafe.Pointer(v2)) - 1
			_releasePage(tls, **(**uintptr)(__ccgo_up(pCur + 144 + uintptr(v1)*8)))
		}
		(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = **(**uintptr)(__ccgo_up(pCur + 144 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*8))
		**(**int32)(__ccgo_up(bp)) = _balance(tls, pCur)
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		if libc.Int32FromUint8(bPreserve) > int32(1) {
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_SKIPNEXT)
			if iCellIdx >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
				(*TBtCursor)(unsafe.Pointer(pCur)).FskipNext = -int32(1)
				(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1))
			} else {
				(*TBtCursor)(unsafe.Pointer(pCur)).FskipNext = int32(1)
			}
		} else {
			**(**int32)(__ccgo_up(bp)) = _moveToRoot(tls, pCur)
			if bPreserve != 0 {
				_btreeReleaseAllCursorPages(tls, pCur)
				(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_REQUIRESEEK)
			}
			if **(**int32)(__ccgo_up(bp)) == int32(SQLITE_EMPTY) {
				**(**int32)(__ccgo_up(bp)) = SQLITE_OK
			}
		}
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/* Move the cursor so that it points to an entry in an index table
//	** near the key pIdxKey.   Return a success code.
//	**
//	** If an exact match is not found, then the cursor is always
//	** left pointing at a leaf page which would hold the entry if it
//	** were present.  The cursor might point to an entry that comes
//	** before or after the key.
//	**
//	** An integer is written into *pRes which is the result of
//	** comparing the key with the entry to which the cursor is
//	** pointing.  The meaning of the integer written into
//	** *pRes is as follows:
//	**
//	**     *pRes<0      The cursor is left pointing at an entry that
//	**                  is smaller than pIdxKey or if the table is empty
//	**                  and the cursor is therefore left point to nothing.
//	**
//	**     *pRes==0     The cursor is left pointing at an entry that
//	**                  exactly matches pIdxKey.
//	**
//	**     *pRes>0      The cursor is left pointing at an entry that
//	**                  is larger than pIdxKey.
//	**
//	** The pIdxKey->eqSeen field is set to 1 if there
//	** exists an entry in the table that exactly matches pIdxKey.
//	*/
func _sqlite3BtreeIndexMoveto(tls *libc.TLS, pCur uintptr, pIdxKey uintptr, pRes uintptr) (r int32) {
	var c, c1, idx, lwr, nCell, nOverrun, rc, upr, v1 int32
	var chldPg TPgno
	var pCell, pCellBody, pCellKey, pPage, v3 uintptr
	var xRecordCompare TRecordCompare
	var v10 Ti8
	var v2 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = c, c1, chldPg, idx, lwr, nCell, nOverrun, pCell, pCellBody, pCellKey, pPage, rc, upr, xRecordCompare, v1, v10, v2, v3
	xRecordCompare = _sqlite3VdbeFindCompare(tls, pIdxKey)
	(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode = uint8(0)
	/* Check to see if we can skip a lot of work.  Two cases:
	 **
	 **    (1) If the cursor is already pointing to the very last cell
	 **        in the table and the pIdxKey search key is greater than or
	 **        equal to that last cell, then no movement is required.
	 **
	 **    (2) If the cursor is on the last page of the table and the first
	 **        cell on that last page is less than or equal to the pIdxKey
	 **        search key, then we can start the search on the current page
	 **        without needing to go back to root.
	 */
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && (*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf != 0 && _cursorOnLastPage(tls, pCur) != 0 {
		if v2 = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix) == libc.Int32FromUint16((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell)-int32(1); v2 {
			v1 = _indexCellCompare(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage, libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix), pIdxKey, xRecordCompare)
			c = v1
		}
		if v2 && v1 <= 0 && libc.Int32FromUint8((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK {
			**(**int32)(__ccgo_up(pRes)) = c
			return SQLITE_OK /* Cursor already pointing at the correct spot */
		}
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) > 0 && _indexCellCompare(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage, 0, pIdxKey, xRecordCompare) <= 0 && libc.Int32FromUint8((*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK {
			v3 = pCur + 1
			*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) & ^(libc.Int32FromInt32(BTCF_ValidOvfl) | libc.Int32FromInt32(BTCF_AtLast)))
			if !((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FisInit != 0) {
				return _sqlite3CorruptError(tls, int32(79316))
			}
			goto bypass_moveto_root /* Start search on the current page */
		}
		(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode = uint8(SQLITE_OK)
	}
	rc = _moveToRoot(tls, pCur)
	if rc != 0 {
		if rc == int32(SQLITE_EMPTY) {
			**(**int32)(__ccgo_up(pRes)) = -int32(1)
			return SQLITE_OK
		}
		return rc
	}
	goto bypass_moveto_root
bypass_moveto_root:
	;
	for {
		pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage /* Pointer to current cell in pPage */
		/* pPage->nCell must be greater than zero. If this is the root-page
		 ** the cursor would have been INVALID above and this for(;;) loop
		 ** not run. If this is not the root-page, then the moveToChild() routine
		 ** would have already detected db corruption. Similarly, pPage must
		 ** be the right kind (index or table) of b-tree page. Otherwise
		 ** a moveToChild() or moveToRoot() call would have detected corruption.  */
		lwr = 0
		upr = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1)
		idx = upr >> int32(1) /* idx = (lwr+upr)/2; */
		for {                 /* Size of the pCell cell in bytes */
			pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)))))
			/* The maximum supported page-size is 65536 bytes. This means that
			 ** the maximum number of record bytes stored on an index B-Tree
			 ** page is less than 16384 bytes and may be stored as a 2-byte
			 ** varint. This information is used to attempt to avoid parsing
			 ** the entire cell by checking for the cases where the record is
			 ** stored entirely within the b-tree page by inspecting the first
			 ** 2 bytes of the cell.
			 */
			nCell = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell)))
			if nCell <= libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).Fmax1bytePayload) {
				/* This branch runs if the record-size field of the cell is a
				 ** single byte varint and the record fits entirely on the main
				 ** b-tree page.  */
				if pCell+uintptr(nCell) >= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
					rc = _sqlite3CorruptError(tls, int32(79375))
					goto moveto_index_finish
				}
				c1 = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})))(tls, nCell, pCell+1, pIdxKey)
			} else {
				if v2 = !(libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell + 1)))&libc.Int32FromInt32(0x80) != 0); v2 {
					v1 = nCell&libc.Int32FromInt32(0x7f)<<libc.Int32FromInt32(7) + libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pCell + 1)))
					nCell = v1
				}
				if v2 && v1 <= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) && pCell+uintptr(nCell) < (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
					/* The record-size field is a 2 byte varint and the record
					 ** fits entirely on the main b-tree page.  */
					c1 = (*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})))(tls, nCell, pCell+2, pIdxKey)
				} else {
					pCellBody = pCell - uintptr((*TMemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
					nOverrun = int32(18) /* Size of the overrun padding */
					(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, pCellBody, pCur+48)
					nCell = int32((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey)
					/* True if key size is 2^32 or more */
					/* Invalid key size:  0x80 0x80 0x00 */
					/* Invalid key size:  0x80 0x80 0x01 */
					/* Minimum legal index key size */
					if nCell < int32(2) || libc.Uint32FromInt32(nCell)/(*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize > (*TBtShared)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpBt)).FnPage {
						rc = _sqlite3CorruptError(tls, int32(79406))
						goto moveto_index_finish
					}
					pCellKey = _sqlite3Malloc(tls, libc.Uint64FromInt32(nCell)+libc.Uint64FromInt32(nOverrun))
					if pCellKey == uintptr(0) {
						rc = int32(SQLITE_NOMEM)
						goto moveto_index_finish
					}
					(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
					rc = _accessPayload(tls, pCur, uint32(0), libc.Uint32FromInt32(nCell), pCellKey, 0)
					libc.Xmemset(tls, pCellKey+uintptr(nCell), 0, libc.Uint64FromInt32(nOverrun)) /* Fix uninit warnings */
					v3 = pCur + 1
					*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) & ^libc.Int32FromInt32(BTCF_ValidOvfl))
					if rc != 0 {
						Xsqlite3_free(tls, pCellKey)
						goto moveto_index_finish
					}
					c1 = _sqlite3VdbeRecordCompare(tls, nCell, pCellKey, pIdxKey)
					Xsqlite3_free(tls, pCellKey)
				}
			}
			if c1 < 0 {
				lwr = idx + int32(1)
			} else {
				if c1 > 0 {
					upr = idx - int32(1)
				} else {
					**(**int32)(__ccgo_up(pRes)) = 0
					rc = SQLITE_OK
					(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
					if (*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode != 0 {
						rc = _sqlite3CorruptError(tls, int32(79438))
					}
					goto moveto_index_finish
				}
			}
			if lwr > upr {
				break
			}
			idx = (lwr + upr) >> int32(1) /* idx = (lwr+upr)/2 */
			goto _5
		_5:
		}
		if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
			(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
			**(**int32)(__ccgo_up(pRes)) = c1
			rc = SQLITE_OK
			goto moveto_index_finish
		}
		if lwr >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		} else {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*lwr))))))
		}
		/* This block is similar to an in-lined version of:
		 **
		 **    pCur->ix = (u16)lwr;
		 **    rc = moveToChild(pCur, chldPg);
		 **    if( rc ) break;
		 */
		(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
		v3 = pCur + 1
		*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
		if int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) >= libc.Int32FromInt32(BTCURSOR_MAX_DEPTH)-libc.Int32FromInt32(1) {
			return _sqlite3CorruptError(tls, int32(79469))
		}
		**(**Tu16)(__ccgo_up(pCur + 88 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*2)) = libc.Uint16FromInt32(lwr)
		**(**uintptr)(__ccgo_up(pCur + 144 + uintptr((*TBtCursor)(unsafe.Pointer(pCur)).FiPage)*8)) = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix = uint16(0)
		(*TBtCursor)(unsafe.Pointer(pCur)).FiPage = (*TBtCursor)(unsafe.Pointer(pCur)).FiPage + 1
		rc = _getAndInitPage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpBt, chldPg, pCur+136, libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
		if rc == SQLITE_OK && (libc.Int32FromUint16((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell) < int32(1) || libc.Int32FromUint8((*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FintKey) != libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurIntKey)) {
			_releasePage(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpPage)
			rc = _sqlite3CorruptError(tls, int32(79480))
		}
		if rc != 0 {
			v3 = pCur + 84
			*(*Ti8)(unsafe.Pointer(v3)) = *(*Ti8)(unsafe.Pointer(v3)) - 1
			v10 = *(*Ti8)(unsafe.Pointer(v3))
			(*TBtCursor)(unsafe.Pointer(pCur)).FpPage = **(**uintptr)(__ccgo_up(pCur + 144 + uintptr(v10)*8))
			break
		}
		/*
		 ***** End of in-lined moveToChild() call */
		goto _4
	_4:
	}
	goto moveto_index_finish
moveto_index_finish:
	;
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	return rc
}

// C documentation
//
//	/*
//	** Insert a new record into the BTree.  The content of the new record
//	** is described by the pX object.  The pCur cursor is used only to
//	** define what table the record should be inserted into, and is left
//	** pointing at a random location.
//	**
//	** For a table btree (used for rowid tables), only the pX.nKey value of
//	** the key is used. The pX.pKey value must be NULL.  The pX.nKey is the
//	** rowid or INTEGER PRIMARY KEY of the row.  The pX.nData,pData,nZero fields
//	** hold the content of the row.
//	**
//	** For an index btree (used for indexes and WITHOUT ROWID tables), the
//	** key is an arbitrary byte sequence stored in pX.pKey,nKey.  The
//	** pX.pData,nData,nZero fields must be zero.
//	**
//	** If the seekResult parameter is non-zero, then a successful call to
//	** sqlite3BtreeIndexMoveto() to seek cursor pCur to (pKey,nKey) has already
//	** been performed.  In other words, if seekResult!=0 then the cursor
//	** is currently pointing to a cell that will be adjacent to the cell
//	** to be inserted.  If seekResult<0 then pCur points to a cell that is
//	** smaller then (pKey,nKey).  If seekResult>0 then pCur points to a cell
//	** that is larger than (pKey,nKey).
//	**
//	** If seekResult==0, that means pCur is pointing at some unknown location.
//	** In that case, this routine must seek the cursor to the correct insertion
//	** point for (pKey,nKey) before doing the insertion.  For index btrees,
//	** if pX->nMem is non-zero, then pX->aMem contains pointers to the unpacked
//	** key values and pX->aMem can be used instead of pX->pKey to avoid having
//	** to decode the key.
//	*/
func _sqlite3BtreeInsert(tls *libc.TLS, pCur uintptr, pX uintptr, flags int32, seekResult int32) (r int32) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var idx int32
	var newCell, oldCell, p, pPage, v1 uintptr
	var ovfl TPgno
	var v2 Tu16
	var _ /* info at bp+104 */ TCellInfo
	var _ /* info at bp+128 */ TCellInfo
	var _ /* loc at bp+4 */ int32
	var _ /* r at bp+16 */ TUnpackedRecord
	var _ /* rc at bp+0 */ int32
	var _ /* szNew at bp+8 */ int32
	var _ /* x2 at bp+56 */ TBtreePayload
	_, _, _, _, _, _, _, _ = idx, newCell, oldCell, ovfl, p, pPage, v1, v2
	**(**int32)(__ccgo_up(bp + 4)) = seekResult /* -1: before desired location  +1: after */
	**(**int32)(__ccgo_up(bp + 8)) = 0
	p = (*TBtCursor)(unsafe.Pointer(pCur)).FpBtree
	newCell = uintptr(0)
	/* Save the positions of any other cursors open on this table.
	 **
	 ** In some cases, the call to btreeMoveto() below is a no-op. For
	 ** example, when inserting data into a table with auto-generated integer
	 ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
	 ** integer key to use. It then calls this function to actually insert the
	 ** data into the intkey B-Tree. In this case btreeMoveto() recognizes
	 ** that the cursor is already where it needs to be and returns without
	 ** doing any work. To avoid thwarting these optimizations, it is important
	 ** not to clear the cursor here.
	 */
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_Multiple) != 0 {
		**(**int32)(__ccgo_up(bp)) = _saveAllCursors(tls, (*TBtree)(unsafe.Pointer(p)).FpBt, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			return **(**int32)(__ccgo_up(bp))
		}
		if **(**int32)(__ccgo_up(bp + 4)) != 0 && int32((*TBtCursor)(unsafe.Pointer(pCur)).FiPage) < 0 {
			/* This can only happen if the schema is corrupt such that there is more
			 ** than one table or index with the same root page as used by the cursor.
			 ** Which can only happen if the SQLITE_NoSchemaError flag was set when
			 ** the schema was loaded. This cannot be asserted though, as a user might
			 ** set the flag, load the schema, and then unset the flag.  */
			return _sqlite3CorruptError(tls, int32(82673))
		}
	}
	/* Ensure that the cursor is not in the CURSOR_FAULT state and that it
	 ** points to a valid cell.
	 */
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) >= int32(CURSOR_REQUIRESEEK) {
		**(**int32)(__ccgo_up(bp)) = _moveToRoot(tls, pCur)
		if **(**int32)(__ccgo_up(bp)) != 0 && **(**int32)(__ccgo_up(bp)) != int32(SQLITE_EMPTY) {
			return **(**int32)(__ccgo_up(bp))
		}
	}
	/* Assert that the caller has been consistent. If this cursor was opened
	 ** expecting an index b-tree, then the caller should be inserting blob
	 ** keys with no associated data. If the cursor was opened expecting an
	 ** intkey table, the caller should be inserting integer keys with a
	 ** blob of associated data.  */
	if (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0) {
		/* If this is an insert into a table b-tree, invalidate any incrblob
		 ** cursors open on the row being replaced */
		if (*TBtree)(unsafe.Pointer(p)).FhasIncrblobCur != 0 {
			_invalidateIncrblobCursors(tls, p, (*TBtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, 0)
		}
		/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
		 ** to a row with the same key as the new entry being inserted.
		 */
		/* On the other hand, BTREE_SAVEPOSITION==0 does not imply
		 ** that the cursor is not pointing to a row to be overwritten.
		 ** So do a complete check.
		 */
		if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidNKey) != 0 && (*TBtreePayload)(unsafe.Pointer(pX)).FnKey == (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey {
			/* The cursor is pointing to the entry that is to be
			 ** overwritten */
			if libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize) != 0 && (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload == libc.Uint32FromInt32((*TBtreePayload)(unsafe.Pointer(pX)).FnData)+libc.Uint32FromInt32((*TBtreePayload)(unsafe.Pointer(pX)).FnZero) {
				/* New entry is the same size as the old.  Do an overwrite */
				return _btreeOverwriteCell(tls, pCur, pX)
			}
		} else {
			if **(**int32)(__ccgo_up(bp + 4)) == 0 {
				/* The cursor is *not* pointing to the cell to be overwritten, nor
				 ** to an adjacent cell.  Move the cursor so that it is pointing either
				 ** to the cell to be overwritten or an adjacent cell.
				 */
				**(**int32)(__ccgo_up(bp)) = _sqlite3BtreeTableMoveto(tls, pCur, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, libc.BoolInt32(flags&int32(BTREE_APPEND) != 0), bp+4)
				if **(**int32)(__ccgo_up(bp)) != 0 {
					return **(**int32)(__ccgo_up(bp))
				}
			}
		}
	} else {
		/* This is an index or a WITHOUT ROWID table */
		/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
		 ** to a row with the same key as the new entry being inserted.
		 */
		/* If the cursor is not already pointing either to the cell to be
		 ** overwritten, or if a new cell is being inserted, if the cursor is
		 ** not pointing to an immediately adjacent cell, then move the cursor
		 ** so that it does.
		 */
		if **(**int32)(__ccgo_up(bp + 4)) == 0 && flags&int32(BTREE_SAVEPOSITION) == 0 {
			if (*TBtreePayload)(unsafe.Pointer(pX)).FnMem != 0 {
				(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FpKeyInfo = (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo
				(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FaMem = (*TBtreePayload)(unsafe.Pointer(pX)).FaMem
				(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FnField = (*TBtreePayload)(unsafe.Pointer(pX)).FnMem
				(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).Fdefault_rc = 0
				(**(**TUnpackedRecord)(__ccgo_up(bp + 16))).FeqSeen = uint8(0)
				**(**int32)(__ccgo_up(bp)) = _sqlite3BtreeIndexMoveto(tls, pCur, bp+16, bp+4)
			} else {
				**(**int32)(__ccgo_up(bp)) = _btreeMoveto(tls, pCur, (*TBtreePayload)(unsafe.Pointer(pX)).FpKey, (*TBtreePayload)(unsafe.Pointer(pX)).FnKey, libc.BoolInt32(flags&int32(BTREE_APPEND) != 0), bp+4)
			}
			if **(**int32)(__ccgo_up(bp)) != 0 {
				return **(**int32)(__ccgo_up(bp))
			}
		}
		/* If the cursor is currently pointing to an entry to be overwritten
		 ** and the new content is the same as as the old, then use the
		 ** overwrite optimization.
		 */
		if **(**int32)(__ccgo_up(bp + 4)) == 0 {
			_getCellInfo(tls, pCur)
			if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == (*TBtreePayload)(unsafe.Pointer(pX)).FnKey {
				(**(**TBtreePayload)(__ccgo_up(bp + 56))).FpData = (*TBtreePayload)(unsafe.Pointer(pX)).FpKey
				(**(**TBtreePayload)(__ccgo_up(bp + 56))).FnData = int32((*TBtreePayload)(unsafe.Pointer(pX)).FnKey)
				(**(**TBtreePayload)(__ccgo_up(bp + 56))).FnZero = 0
				return _btreeOverwriteCell(tls, pCur, bp+56)
			}
		}
	}
	pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage
	if (*TMemPage)(unsafe.Pointer(pPage)).FnFree < 0 {
		if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) > int32(CURSOR_INVALID) {
			/* ^^^^^--- due to the moveToRoot() call above */
			**(**int32)(__ccgo_up(bp)) = _sqlite3CorruptError(tls, int32(82796))
		} else {
			**(**int32)(__ccgo_up(bp)) = _btreeComputeFreeSpace(tls, pPage)
		}
		if **(**int32)(__ccgo_up(bp)) != 0 {
			return **(**int32)(__ccgo_up(bp))
		}
	}
	newCell = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FpTmpSpace
	if flags&int32(BTREE_PREFORMAT) != 0 {
		**(**int32)(__ccgo_up(bp)) = SQLITE_OK
		**(**int32)(__ccgo_up(bp + 8)) = (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FnPreformatSize
		if **(**int32)(__ccgo_up(bp + 8)) < int32(4) {
			**(**int32)(__ccgo_up(bp + 8)) = int32(4)
			**(**uint8)(__ccgo_up(newCell + 3)) = uint8(0)
		}
		if (*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0 && **(**int32)(__ccgo_up(bp + 8)) > libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, newCell, bp+104)
			if (**(**TCellInfo)(__ccgo_up(bp + 104))).FnPayload != uint32((**(**TCellInfo)(__ccgo_up(bp + 104))).FnLocal) {
				ovfl = _sqlite3Get4byte(tls, newCell+uintptr(**(**int32)(__ccgo_up(bp + 8))-int32(4)))
				_ptrmapPut(tls, (*TBtree)(unsafe.Pointer(p)).FpBt, ovfl, uint8(PTRMAP_OVERFLOW1), (*TMemPage)(unsafe.Pointer(pPage)).Fpgno, bp)
				if **(**int32)(__ccgo_up(bp)) != 0 {
					goto end_insert
				}
			}
		}
	} else {
		**(**int32)(__ccgo_up(bp)) = _fillInCell(tls, pPage, newCell, pX, bp+8)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			goto end_insert
		}
	}
	idx = libc.Int32FromUint16((*TBtCursor)(unsafe.Pointer(pCur)).Fix)
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	if **(**int32)(__ccgo_up(bp + 4)) == 0 {
		if idx >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			return _sqlite3CorruptError(tls, int32(82838))
		}
		**(**int32)(__ccgo_up(bp)) = _sqlite3PagerWrite(tls, (*TMemPage)(unsafe.Pointer(pPage)).FpDbPage)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			goto end_insert
		}
		oldCell = (*TMemPage)(unsafe.Pointer(pPage)).FaData + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)))))
		if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
			libc.Xmemcpy(tls, newCell, oldCell, uint64(4))
		}
		(*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer(pPage)).FxParseCell})))(tls, pPage, oldCell, bp+128)
		if uint32((**(**TCellInfo)(__ccgo_up(bp + 128))).FnLocal) != (**(**TCellInfo)(__ccgo_up(bp + 128))).FnPayload {
			**(**int32)(__ccgo_up(bp)) = _clearCellOverflow(tls, pPage, oldCell, bp+128)
		} else {
			**(**int32)(__ccgo_up(bp)) = SQLITE_OK
		}
		v1 = pCur + 1
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(BTCF_ValidOvfl))
		if libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 128))).FnSize) == **(**int32)(__ccgo_up(bp + 8)) && uint32((**(**TCellInfo)(__ccgo_up(bp + 128))).FnLocal) == (**(**TCellInfo)(__ccgo_up(bp + 128))).FnPayload && (!((*TBtShared)(unsafe.Pointer((*TBtree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0) || **(**int32)(__ccgo_up(bp + 8)) < libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FminLocal)) {
			/* Overwrite the old cell with the new if they are the same size.
			 ** We could also try to do this if the old cell is smaller, then add
			 ** the leftover space to the free list.  But experiments show that
			 ** doing that is no faster then skipping this optimization and just
			 ** calling dropCell() and insertCell().
			 **
			 ** This optimization cannot be used on an autovacuum database if the
			 ** new entry uses overflow pages, as the insertCell() call below is
			 ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry.  */
			/* clearCell never fails when nLocal==nPayload */
			if oldCell < (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+uintptr(10) {
				return _sqlite3CorruptError(tls, int32(82865))
			}
			if oldCell+uintptr(**(**int32)(__ccgo_up(bp + 8))) > (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
				return _sqlite3CorruptError(tls, int32(82868))
			}
			libc.Xmemcpy(tls, oldCell, newCell, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 8))))
			return SQLITE_OK
		}
		_dropCell(tls, pPage, idx, libc.Int32FromUint16((**(**TCellInfo)(__ccgo_up(bp + 128))).FnSize), bp)
		if **(**int32)(__ccgo_up(bp)) != 0 {
			goto end_insert
		}
	} else {
		if **(**int32)(__ccgo_up(bp + 4)) < 0 && libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) > 0 {
			v1 = pCur + 86
			*(*Tu16)(unsafe.Pointer(v1)) = *(*Tu16)(unsafe.Pointer(v1)) + 1
			v2 = *(*Tu16)(unsafe.Pointer(v1))
			idx = libc.Int32FromUint16(v2)
			v1 = pCur + 1
			*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
		} else {
		}
	}
	**(**int32)(__ccgo_up(bp)) = _insertCellFast(tls, pPage, idx, newCell, **(**int32)(__ccgo_up(bp + 8)))
	/* If no error has occurred and pPage has an overflow cell, call balance()
	 ** to redistribute the cells within the tree. Since balance() may move
	 ** the cursor, zero the BtCursor.info.nSize and BTCF_ValidNKey
	 ** variables.
	 **
	 ** Previous versions of SQLite called moveToRoot() to move the cursor
	 ** back to the root page as balance() used to invalidate the contents
	 ** of BtCursor.apPage[] and BtCursor.aiIdx[]. Instead of doing that,
	 ** set the cursor state to "invalid". This makes common insert operations
	 ** slightly faster.
	 **
	 ** There is a subtle but important optimization here too. When inserting
	 ** multiple records into an intkey b-tree using a single cursor (as can
	 ** happen while processing an "INSERT INTO ... SELECT" statement), it
	 ** is advantageous to leave the cursor pointing to the last entry in
	 ** the b-tree if possible. If the cursor is left pointing to the last
	 ** entry in the table, and the next row inserted has an integer key
	 ** larger than the largest existing key, it is possible to insert the
	 ** row without seeking the cursor. This can be a big performance boost.
	 */
	if (*TMemPage)(unsafe.Pointer(pPage)).FnOverflow != 0 {
		v1 = pCur + 1
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(BTCF_ValidNKey) | libc.Int32FromInt32(BTCF_ValidOvfl)))
		**(**int32)(__ccgo_up(bp)) = _balance(tls, pCur)
		/* Must make sure nOverflow is reset to zero even if the balance()
		 ** fails. Internal data structure corruption will result otherwise.
		 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
		 ** from trying to save the current position of the cursor.  */
		(*TMemPage)(unsafe.Pointer((*TBtCursor)(unsafe.Pointer(pCur)).FpPage)).FnOverflow = uint8(0)
		(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_INVALID)
		if flags&int32(BTREE_SAVEPOSITION) != 0 && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			_btreeReleaseAllCursorPages(tls, pCur)
			if (*TBtCursor)(unsafe.Pointer(pCur)).FpKeyInfo != 0 {
				(*TBtCursor)(unsafe.Pointer(pCur)).FpKey = _sqlite3Malloc(tls, libc.Uint64FromInt64((*TBtreePayload)(unsafe.Pointer(pX)).FnKey))
				if (*TBtCursor)(unsafe.Pointer(pCur)).FpKey == uintptr(0) {
					**(**int32)(__ccgo_up(bp)) = int32(SQLITE_NOMEM)
				} else {
					libc.Xmemcpy(tls, (*TBtCursor)(unsafe.Pointer(pCur)).FpKey, (*TBtreePayload)(unsafe.Pointer(pX)).FpKey, libc.Uint64FromInt64((*TBtreePayload)(unsafe.Pointer(pX)).FnKey))
				}
			}
			(*TBtCursor)(unsafe.Pointer(pCur)).FeState = uint8(CURSOR_REQUIRESEEK)
			(*TBtCursor)(unsafe.Pointer(pCur)).FnKey = (*TBtreePayload)(unsafe.Pointer(pX)).FnKey
		}
	}
	goto end_insert
end_insert:
	;
	return **(**int32)(__ccgo_up(bp))
	return r
}

// C documentation
//
//	/* Move the cursor so that it points to an entry in a table (a.k.a INTKEY)
//	** table near the key intKey.   Return a success code.
//	**
//	** If an exact match is not found, then the cursor is always
//	** left pointing at a leaf page which would hold the entry if it
//	** were present.  The cursor might point to an entry that comes
//	** before or after the key.
//	**
//	** An integer is written into *pRes which is the result of
//	** comparing the key with the entry to which the cursor is
//	** pointing.  The meaning of the integer written into
//	** *pRes is as follows:
//	**
//	**     *pRes<0      The cursor is left pointing at an entry that
//	**                  is smaller than intKey or if the table is empty
//	**                  and the cursor is therefore left point to nothing.
//	**
//	**     *pRes==0     The cursor is left pointing at an entry that
//	**                  exactly matches intKey.
//	**
//	**     *pRes>0      The cursor is left pointing at an entry that
//	**                  is larger than intKey.
//	*/
func _sqlite3BtreeTableMoveto(tls *libc.TLS, pCur uintptr, intKey Ti64, biasRight int32, pRes uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var c, idx, lwr, rc, upr int32
	var chldPg TPgno
	var pCell, pPage, v3 uintptr
	var _ /* nCellKey at bp+0 */ Ti64
	_, _, _, _, _, _, _, _, _ = c, chldPg, idx, lwr, pCell, pPage, rc, upr, v3
	/* If the cursor is already positioned at the point we are trying
	 ** to move to, then just return without doing any work */
	if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_ValidNKey) != 0 {
		if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey {
			**(**int32)(__ccgo_up(pRes)) = 0
			return SQLITE_OK
		}
		if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey < intKey {
			if libc.Int32FromUint8((*TBtCursor)(unsafe.Pointer(pCur)).FcurFlags)&int32(BTCF_AtLast) != 0 {
				**(**int32)(__ccgo_up(pRes)) = -int32(1)
				return SQLITE_OK
			}
			/* If the requested key is one more than the previous key, then
			 ** try to get there using sqlite3BtreeNext() rather than a full
			 ** binary search.  This is an optimization only.  The correct answer
			 ** is still obtained without this case, only a little more slowly. */
			if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey+int64(1) == intKey {
				**(**int32)(__ccgo_up(pRes)) = 0
				rc = _sqlite3BtreeNext(tls, pCur, 0)
				if rc == SQLITE_OK {
					_getCellInfo(tls, pCur)
					if (*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey {
						return SQLITE_OK
					}
				} else {
					if rc != int32(SQLITE_DONE) {
						return rc
					}
				}
			}
		}
	}
	rc = _moveToRoot(tls, pCur)
	if rc != 0 {
		if rc == int32(SQLITE_EMPTY) {
			**(**int32)(__ccgo_up(pRes)) = -int32(1)
			return SQLITE_OK
		}
		return rc
	}
	for {
		pPage = (*TBtCursor)(unsafe.Pointer(pCur)).FpPage /* Pointer to current cell in pPage */
		/* pPage->nCell must be greater than zero. If this is the root-page
		 ** the cursor would have been INVALID above and this for(;;) loop
		 ** not run. If this is not the root-page, then the moveToChild() routine
		 ** would have already detected db corruption. Similarly, pPage must
		 ** be the right kind (index or table) of b-tree page. Otherwise
		 ** a moveToChild() or moveToRoot() call would have detected corruption.  */
		lwr = 0
		upr = libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) - int32(1)
		idx = upr >> (int32(1) - biasRight) /* idx = biasRight ? upr : (lwr+upr)/2; */
		for {
			pCell = (*TMemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*idx)))))
			if (*TMemPage)(unsafe.Pointer(pPage)).FintKeyLeaf != 0 {
				for {
					v3 = pCell
					pCell = pCell + 1
					if !(int32(0x80) <= libc.Int32FromUint8(**(**Tu8)(__ccgo_up(v3)))) {
						break
					}
					if pCell >= (*TMemPage)(unsafe.Pointer(pPage)).FaDataEnd {
						return _sqlite3CorruptError(tls, int32(79121))
					}
				}
			}
			_sqlite3GetVarint(tls, pCell, bp)
			if **(**Ti64)(__ccgo_up(bp)) < intKey {
				lwr = idx + int32(1)
				if lwr > upr {
					c = -int32(1)
					break
				}
			} else {
				if **(**Ti64)(__ccgo_up(bp)) > intKey {
					upr = idx - int32(1)
					if lwr > upr {
						c = +libc.Int32FromInt32(1)
						break
					}
				} else {
					(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
					if !((*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
						lwr = idx
						goto moveto_table_next_layer
					} else {
						v3 = pCur + 1
						*(*Tu8)(unsafe.Pointer(v3)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v3))) | libc.Int32FromInt32(BTCF_ValidNKey))
						(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey = **(**Ti64)(__ccgo_up(bp))
						(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
						**(**int32)(__ccgo_up(pRes)) = 0
						return SQLITE_OK
					}
				}
			}
			idx = (lwr + upr) >> int32(1) /* idx = (lwr+upr)/2; */
			goto _2
		_2:
		}
		if (*TMemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
			(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(idx)
			**(**int32)(__ccgo_up(pRes)) = c
			rc = SQLITE_OK
			goto moveto_table_finish
		}
		goto moveto_table_next_layer
	moveto_table_next_layer:
		;
		if lwr >= libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FnCell) {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint8((*TMemPage)(unsafe.Pointer(pPage)).FhdrOffset)+int32(8)))
		} else {
			chldPg = _sqlite3Get4byte(tls, (*TMemPage)(unsafe.Pointer(pPage)).FaData+uintptr(libc.Int32FromUint16((*TMemPage)(unsafe.Pointer(pPage)).FmaskPage)&libc.Int32FromUint16(**(**Tu16)(__ccgo_up((*TMemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(int32(2)*lwr))))))
		}
		(*TBtCursor)(unsafe.Pointer(pCur)).Fix = libc.Uint16FromInt32(lwr)
		rc = _moveToChild(tls, pCur, chldPg)
		if rc != 0 {
			break
		}
		goto _1
	_1:
	}
	goto moveto_table_finish
moveto_table_finish:
	;
	(*TBtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = uint16(0)
	return rc
}

// C documentation
//
//	/*
//	** This routine is used to check if the UTF-8 string zName is a legal
//	** unqualified name for a new schema object (table, index, view or
//	** trigger). All names are legal except those that begin with the string
//	** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
//	** is reserved for internal use.
//	**
//	** When parsing the sqlite_schema table, this routine also checks to
//	** make sure the "type", "name", and "tbl_name" columns are consistent
//	** with the SQL.
//	*/
func _sqlite3CheckObjectName(tls *libc.TLS, pParse uintptr, zName uintptr, zType uintptr, zTblName uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if _sqlite3WritableSchema(tls, db) != 0 || int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x60>>5)) != 0 || !(_sqlite3Config.FbExtraSchemaChecks != 0) {
		/* Skip these error checks for writable_schema=ON */
		return SQLITE_OK
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		if Xsqlite3_stricmp(tls, zType, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit))) != 0 || Xsqlite3_stricmp(tls, zName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 1*8))) != 0 || Xsqlite3_stricmp(tls, zTblName, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit + 2*8))) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1704, 0) /* corruptSchema() will supply the error */
			return int32(SQLITE_ERROR)
		}
	} else {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && 0 == Xsqlite3_strnicmp(tls, zName, __ccgo_ts+6760, int32(7)) || _sqlite3ReadOnlyShadowTables(tls, db) != 0 && _sqlite3ShadowTableName(tls, db, zName) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13767, libc.VaList(bp+8, zName))
			return int32(SQLITE_ERROR)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the declared type of a column.  Or return zDflt if the column
//	** has no declared type.
//	**
//	** The column type is an extra string stored after the zero-terminator on
//	** the column name if and only if the COLFLAG_HASTYPE flag is set.
//	*/
func _sqlite3ColumnType(tls *libc.TLS, pCol uintptr, zDflt uintptr) (r uintptr) {
	if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
		return (*TColumn)(unsafe.Pointer(pCol)).FzCnName + uintptr(libc.Xstrlen(tls, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)) + uintptr(1)
	} else {
		if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0 {
			return _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0))-int32(1)]
		} else {
			return zDflt
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Given an expression list (which is really the list of expressions
//	** that form the result set of a SELECT statement) compute appropriate
//	** column names for a table that would hold the expression list.
//	**
//	** All column names will be unique.
//	**
//	** Only the column names are computed.  Column.zType, Column.zColl,
//	** and other fields of Column are zeroed.
//	**
//	** Return SQLITE_OK on success.  If a memory allocation error occurs,
//	** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
//	**
//	** The only guarantee that SQLite makes about column names is that if the
//	** column has an AS clause assigning it a name, that will be the name used.
//	** That is the only documented guarantee.  However, countless applications
//	** developed over the years have made baseless assumptions about column names
//	** and will break if those assumptions changes.  Hence, use extreme caution
//	** when modifying this routine to avoid breaking legacy.
//	**
//	** See Also: sqlite3GenerateColumnNames()
//	*/
func _sqlite3ColumnsFromExprList(tls *libc.TLS, pParse uintptr, pEList uintptr, pnCol uintptr, paCol uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var aCol, db, pCol, pColExpr, pCollide, pTab, pX, zName, v2, v3 uintptr
	var i, iCol, j, nCol, nName int32
	var v5 bool
	var v8 Tu32
	var _ /* cnt at bp+0 */ Tu32
	var _ /* ht at bp+8 */ THash
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCol, db, i, iCol, j, nCol, nName, pCol, pColExpr, pCollide, pTab, pX, zName, v2, v3, v5, v8
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	_sqlite3HashInit(tls, bp+8)
	if pEList != 0 {
		nCol = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
		aCol = _sqlite3DbMallocZero(tls, db, uint64(uint64(16)*libc.Uint64FromInt32(nCol)))
		if nCol > int32(32767) {
			nCol = int32(32767)
		}
	} else {
		nCol = 0
		aCol = uintptr(0)
	}
	**(**Ti16)(__ccgo_up(pnCol)) = int16(nCol)
	**(**uintptr)(__ccgo_up(paCol)) = aCol
	i = 0
	pCol = aCol
	for {
		if !(i < nCol && !((*TParse)(unsafe.Pointer(pParse)).FnErr != 0)) {
			break
		}
		pX = pEList + 8 + uintptr(i)*32
		/* Get an appropriate name for the column
		 */
		v2 = (*TExprList_item)(unsafe.Pointer(pX)).FzEName
		zName = v2
		if v2 != uintptr(0) && int32(uint32(*(*uint16)(unsafe.Pointer(pX + 16 + 4))&0xc000>>14)) == ENAME_NAME {
			/* If the column contains an "AS <name>" phrase, use <name> as the name */
		} else {
			pColExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*TExprList_item)(unsafe.Pointer(pX)).FpExpr)
			for pColExpr != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_DOT) {
				pColExpr = (*TExpr)(unsafe.Pointer(pColExpr)).FpRight
			}
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_COLUMN) && (*TExpr)(unsafe.Pointer(pColExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)|libc.Int32FromInt32(EP_Subrtn)) == uint32(0) && *(*uintptr)(unsafe.Pointer(pColExpr + 64)) != uintptr(0) {
				/* For columns use the column name name */
				iCol = int32((*TExpr)(unsafe.Pointer(pColExpr)).FiColumn)
				pTab = *(*uintptr)(unsafe.Pointer(pColExpr + 64))
				if iCol < 0 {
					iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				}
				if iCol >= 0 {
					v2 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
				} else {
					v2 = __ccgo_ts + 17967
				}
				zName = v2
			} else {
				if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pColExpr)).Fop) == int32(TK_ID) {
					zName = *(*uintptr)(unsafe.Pointer(pColExpr + 8))
				} else {
					/* Use the original text of the column expression as its name */
					/* pointer comparison intended */
				}
			}
		}
		if zName != 0 && !(_sqlite3IsTrueOrFalse(tls, zName) != 0) {
			zName = _sqlite3DbStrDup(tls, db, zName)
		} else {
			zName = _sqlite3MPrintf(tls, db, __ccgo_ts+20636, libc.VaList(bp+40, i+int32(1)))
		}
		/* Make sure the column name is unique.  If the name is not unique,
		 ** append an integer to the name so that it becomes unique.
		 */
		**(**Tu32)(__ccgo_up(bp)) = uint32(0)
		for {
			if v5 = zName != 0; v5 {
				v2 = _sqlite3HashFind(tls, bp+8, zName)
				pCollide = v2
			}
			if !(v5 && v2 != uintptr(0)) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pCollide + 16 + 4))&0x100>>8)) != 0 {
				v3 = pCol + 14
				*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
			}
			nName = _sqlite3Strlen30(tls, zName)
			if nName > 0 {
				j = nName - int32(1)
				for {
					if !(j > 0 && libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(zName + uintptr(j))))])&int32(0x04) != 0) {
						break
					}
					goto _7
				_7:
					;
					j = j - 1
				}
				if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zName + uintptr(j)))) == int32(':') {
					nName = j
				}
			}
			**(**Tu32)(__ccgo_up(bp)) = **(**Tu32)(__ccgo_up(bp)) + 1
			v8 = **(**Tu32)(__ccgo_up(bp))
			zName = _sqlite3MPrintf(tls, db, __ccgo_ts+20645, libc.VaList(bp+40, nName, zName, v8))
			_sqlite3ProgressCheck(tls, pParse)
			if **(**Tu32)(__ccgo_up(bp)) > uint32(3) {
				Xsqlite3_randomness(tls, int32(4), bp)
			}
		}
		(*TColumn)(unsafe.Pointer(pCol)).FzCnName = zName
		(*TColumn)(unsafe.Pointer(pCol)).FhName = _sqlite3StrIHash(tls, zName)
		if int32(uint32(*(*uint16)(unsafe.Pointer(pX + 16 + 4))&0x80>>7)) != 0 {
			v2 = pCol + 14
			*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(COLFLAG_NOEXPAND))
		}
		if zName != 0 && _sqlite3HashInsert(tls, bp+8, zName, pX) == pX {
			_sqlite3OomFault(tls, db)
		}
		goto _1
	_1:
		;
		i = i + 1
		pCol += 16
	}
	_sqlite3HashClear(tls, bp+8)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		j = 0
		for {
			if !(j < i) {
				break
			}
			_sqlite3DbFree(tls, db, (**(**TColumn)(__ccgo_up(aCol + uintptr(j)*16))).FzCnName)
			goto _10
		_10:
			;
			j = j + 1
		}
		_sqlite3DbFree(tls, db, aCol)
		**(**uintptr)(__ccgo_up(paCol)) = uintptr(0)
		**(**Ti16)(__ccgo_up(pnCol)) = 0
		return (*TParse)(unsafe.Pointer(pParse)).Frc
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This routine generates code to finish the INSERT or UPDATE operation
//	** that was started by a prior call to sqlite3GenerateConstraintChecks.
//	** A consecutive range of registers starting at regNewData contains the
//	** rowid and the content to be inserted.
//	**
//	** The arguments to this routine should be the same as the first six
//	** arguments to sqlite3GenerateConstraintChecks.
//	*/
func _sqlite3CompleteInsertion(tls *libc.TLS, pParse uintptr, pTab uintptr, iDataCur int32, iIdxCur int32, regNewData int32, aRegIdx uintptr, update_flags int32, appendBias int32, useSeekResult int32) {
	var i, v2 int32
	var pIdx, v uintptr
	var pik_flags Tu8
	_, _, _, _, _ = i, pIdx, pik_flags, v, v2 /* Loop counter */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* This table is not a VIEW */
	i = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		/* All REPLACE indexes are at the end of the list */
		if **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)) == 0 {
			goto _1
		}
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)), _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
		}
		if useSeekResult != 0 {
			v2 = int32(OPFLAG_USESEEKRESULT)
		} else {
			v2 = 0
		}
		pik_flags = libc.Uint8FromInt32(v2)
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pik_flags = libc.Uint8FromInt32(int32(pik_flags) | libc.Int32FromInt32(OPFLAG_NCHANGE))
			pik_flags = libc.Uint8FromInt32(int32(pik_flags) | update_flags&libc.Int32FromInt32(OPFLAG_SAVEPOSITION))
			if update_flags == 0 {
				_codeWithoutRowidPreupdate(tls, pParse, pTab, iIdxCur+i, **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)))
			}
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x1000>>12)) != 0 {
			v2 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			v2 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		}
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iIdxCur+i, **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)), **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4))+int32(1), v2)
		_sqlite3VdbeChangeP5(tls, v, uint16(pik_flags))
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		i = i + 1
	}
	if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
		return
	}
	if (*TParse)(unsafe.Pointer(pParse)).Fnested != 0 {
		pik_flags = uint8(0)
	} else {
		pik_flags = uint8(OPFLAG_NCHANGE)
		if update_flags != 0 {
			v2 = update_flags
		} else {
			v2 = int32(OPFLAG_LASTROWID)
		}
		pik_flags = libc.Uint8FromInt32(int32(pik_flags) | v2)
	}
	if appendBias != 0 {
		pik_flags = libc.Uint8FromInt32(int32(pik_flags) | libc.Int32FromInt32(OPFLAG_APPEND))
	}
	if useSeekResult != 0 {
		pik_flags = libc.Uint8FromInt32(int32(pik_flags) | libc.Int32FromInt32(OPFLAG_USESEEKRESULT))
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iDataCur, **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)), regNewData)
	if !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
		_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
	}
	_sqlite3VdbeChangeP5(tls, v, uint16(pik_flags))
}

// C documentation
//
//	/*
//	** This function is exactly the same as sqlite3_create_function(), except
//	** that it is designed to be called by internal code. The difference is
//	** that if a malloc() fails in sqlite3_create_function(), an error code
//	** is returned and the mallocFailed flag cleared.
//	*/
func _sqlite3CreateFunc(tls *libc.TLS, db uintptr, zFunctionName uintptr, nArg int32, enc int32, pUserData uintptr, __ccgo_fp_xSFunc uintptr, __ccgo_fp_xStep uintptr, __ccgo_fp_xFinal uintptr, __ccgo_fp_xValue uintptr, __ccgo_fp_xInverse uintptr, pDestructor uintptr) (r int32) {
	var extraFlags, rc int32
	var p, v1 uintptr
	_, _, _, _ = extraFlags, p, rc, v1
	if zFunctionName == uintptr(0) || __ccgo_fp_xSFunc != uintptr(0) && __ccgo_fp_xFinal != uintptr(0) || libc.BoolInt32(__ccgo_fp_xFinal == uintptr(0)) != libc.BoolInt32(__ccgo_fp_xStep == uintptr(0)) || libc.BoolInt32(__ccgo_fp_xValue == uintptr(0)) != libc.BoolInt32(__ccgo_fp_xInverse == uintptr(0)) || (nArg < -int32(1) || nArg > int32(SQLITE_MAX_FUNCTION_ARG)) || int32(255) < _sqlite3Strlen30(tls, zFunctionName) {
		return _sqlite3MisuseError(tls, int32(189333))
	}
	extraFlags = enc & (libc.Int32FromInt32(SQLITE_DETERMINISTIC) | libc.Int32FromInt32(SQLITE_DIRECTONLY) | libc.Int32FromInt32(SQLITE_SUBTYPE) | libc.Int32FromInt32(SQLITE_INNOCUOUS) | libc.Int32FromInt32(SQLITE_RESULT_SUBTYPE) | libc.Int32FromInt32(SQLITE_SELFORDER1))
	enc = enc & (libc.Int32FromInt32(SQLITE_FUNC_ENCMASK) | libc.Int32FromInt32(SQLITE_ANY))
	/* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE.  But
	 ** the meaning is inverted.  So flip the bit. */
	extraFlags = extraFlags ^ int32(SQLITE_FUNC_UNSAFE) /* tag-20230109-1 */
	/* If SQLITE_UTF16 is specified as the encoding type, transform this
	 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
	 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
	 **
	 ** If SQLITE_ANY is specified, add three versions of the function
	 ** to the hash table.
	 */
	switch enc {
	case int32(SQLITE_UTF16):
		enc = int32(SQLITE_UTF16BE)
	case int32(SQLITE_ANY):
		rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF8)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pDestructor)
		if rc == SQLITE_OK {
			rc = _sqlite3CreateFunc(tls, db, zFunctionName, nArg, int32(SQLITE_UTF16LE)|extraFlags^int32(SQLITE_FUNC_UNSAFE), pUserData, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pDestructor)
		}
		if rc != SQLITE_OK {
			return rc
		}
		enc = int32(SQLITE_UTF16BE)
	case int32(SQLITE_UTF8):
		fallthrough
	case int32(SQLITE_UTF16LE):
		fallthrough
	case int32(SQLITE_UTF16BE):
	default:
		enc = int32(SQLITE_UTF8)
		break
	}
	/* Check if an existing function is being overridden or deleted. If so,
	 ** and there are active VMs, then return SQLITE_BUSY. If a function
	 ** is being overridden/deleted but there are no active VMs, allow the
	 ** operation to continue but invalidate all precompiled statements.
	 */
	p = _sqlite3FindFunction(tls, db, zFunctionName, nArg, libc.Uint8FromInt32(enc), uint8(0))
	if p != 0 && (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) == libc.Uint32FromInt32(enc) && int32((*TFuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_BUSY), __ccgo_ts+25915, 0)
			return int32(SQLITE_BUSY)
		} else {
			_sqlite3ExpirePreparedStatements(tls, db, 0)
		}
	} else {
		if __ccgo_fp_xSFunc == uintptr(0) && __ccgo_fp_xFinal == uintptr(0) {
			/* Trying to delete a function that does not exist.  This is a no-op.
			 ** https://sqlite.org/forum/forumpost/726219164b */
			return SQLITE_OK
		}
	}
	p = _sqlite3FindFunction(tls, db, zFunctionName, nArg, libc.Uint8FromInt32(enc), uint8(1))
	if !(p != 0) {
		return int32(SQLITE_NOMEM)
	}
	/* If an older version of the function with a configured destructor is
	 ** being replaced invoke the destructor function here. */
	_functionDestroy(tls, db, p)
	if pDestructor != 0 {
		(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef = (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef + 1
	}
	*(*uintptr)(unsafe.Pointer(p + 64)) = pDestructor
	(*TFuncDef)(unsafe.Pointer(p)).FfuncFlags = (*TFuncDef)(unsafe.Pointer(p)).FfuncFlags&uint32(SQLITE_FUNC_ENCMASK) | libc.Uint32FromInt32(extraFlags)
	if __ccgo_fp_xSFunc != 0 {
		v1 = __ccgo_fp_xSFunc
	} else {
		v1 = __ccgo_fp_xStep
	}
	(*TFuncDef)(unsafe.Pointer(p)).FxSFunc = v1
	(*TFuncDef)(unsafe.Pointer(p)).FxFinalize = __ccgo_fp_xFinal
	(*TFuncDef)(unsafe.Pointer(p)).FxValue = __ccgo_fp_xValue
	(*TFuncDef)(unsafe.Pointer(p)).FxInverse = __ccgo_fp_xInverse
	(*TFuncDef)(unsafe.Pointer(p)).FpUserData = pUserData
	(*TFuncDef)(unsafe.Pointer(p)).FnArg = libc.Int16FromUint16(libc.Uint16FromInt32(nArg))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Create a new index for an SQL table.  pName1.pName2 is the name of the index
//	** and pTblList is the name of the table that is to be indexed.  Both will
//	** be NULL for a primary key or an index that is created to satisfy a
//	** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
//	** as the table to be indexed.  pParse->pNewTable is a table that is
//	** currently being constructed by a CREATE TABLE statement.
//	**
//	** pList is a list of columns to be indexed.  pList will be NULL if this
//	** is a primary key or unique-constraint on the most recent column added
//	** to the table currently under construction.
//	*/
func _sqlite3CreateIndex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pTblName uintptr, pList uintptr, onError int32, pStart uintptr, pPIWhere uintptr, sortOrder int32, ifNotExist int32, idxType Tu8) {
	bp := tls.Alloc(176)
	defer tls.Free(176)
	var db, p, pCExpr, pCol, pDb, pExpr, pIdx, pIndex, pListItem, pLoop, pNext, pPk, pTab, pThis, ppFrom, v, z1, z2, zColl, zDb, zName, zStmt, v2 uintptr
	var i, iDb, iMem, j, k, n, n1, nColl, nExtra, nExtraCol, nName, requestedSortOrder, sortOrderMask, x, v5 int32
	var _ /* pName at bp+96 */ uintptr
	var _ /* prevCol at bp+112 */ TToken
	var _ /* sFix at bp+0 */ TDbFixer
	var _ /* zExtra at bp+104 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iDb, iMem, j, k, n, n1, nColl, nExtra, nExtraCol, nName, p, pCExpr, pCol, pDb, pExpr, pIdx, pIndex, pListItem, pLoop, pNext, pPk, pTab, pThis, ppFrom, requestedSortOrder, sortOrderMask, v, x, z1, z2, zColl, zDb, zName, zStmt, v2, v5
	pTab = uintptr(0)                               /* Table to be indexed */
	pIndex = uintptr(0)                             /* The index to be created */
	zName = uintptr(0)                              /* 1 to honor DESC in index.  0 to ignore. */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb      /* Index of the database that is being written */
	**(**uintptr)(__ccgo_up(bp + 96)) = uintptr(0)  /* For looping over pList */
	nExtra = 0                                      /* Number of extra columns needed */
	**(**uintptr)(__ccgo_up(bp + 104)) = uintptr(0) /* Extra space after the Index object */
	pPk = uintptr(0)                                /* PRIMARY KEY index for WITHOUT ROWID tables */
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto exit_create_index
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) == int32(PARSE_MODE_DECLARE_VTAB) && libc.Int32FromUint8(idxType) != int32(SQLITE_IDXTYPE_PRIMARYKEY) {
		goto exit_create_index
	}
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		goto exit_create_index
	}
	if _sqlite3HasExplicitNulls(tls, pParse, pList) != 0 {
		goto exit_create_index
	}
	/*
	 ** Find the table that is to be indexed.  Return early if not found.
	 */
	if pTblName != uintptr(0) {
		/* Use the two-part index name to determine the database
		 ** to search for the table. 'Fix' the table name to this db
		 ** before looking up the table.
		 */
		iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp+96)
		if iDb < 0 {
			goto exit_create_index
		}
		/* If the index name was unqualified, check if the table
		 ** is a temp table. If so, set the database to 1. Do not do this
		 ** if initializing a database schema.
		 */
		if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
			pTab = _sqlite3SrcListLookup(tls, pParse, pTblName)
			if (*TToken)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*TTable)(unsafe.Pointer(pTab)).FpSchema == (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*32))).FpSchema {
				iDb = int32(1)
			}
		}
		_sqlite3FixInit(tls, bp, pParse, iDb, __ccgo_ts+15417, **(**uintptr)(__ccgo_up(bp + 96)))
		if _sqlite3FixSrcList(tls, bp, pTblName) != 0 {
			/* Because the parser constructs pTblName from a single identifier,
			 ** sqlite3FixSrcList can never fail. */
		}
		pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pTblName+8)
		if pTab == uintptr(0) {
			goto exit_create_index
		}
		if iDb == int32(1) && (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema != (*TTable)(unsafe.Pointer(pTab)).FpSchema {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15423, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab)).FzName))
			goto exit_create_index
		}
		if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		}
	} else {
		pTab = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
		if !(pTab != 0) {
			goto exit_create_index
		}
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	}
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	if Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, __ccgo_ts+6760, int32(7)) == 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 && pTblName != uintptr(0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15473, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab)).FzName))
		goto exit_create_index
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15501, 0)
		goto exit_create_index
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15526, 0)
		goto exit_create_index
	}
	/*
	 ** Find the name of the index.  Make sure there is not already another
	 ** index or table with the same name.
	 **
	 ** Exception:  If we are reading the names of permanent indices from the
	 ** sqlite_schema table (because some other process changed the schema) and
	 ** one of the index names collides with the name of a temporary table or
	 ** index, then we will continue to process this index.
	 **
	 ** If pName==0 it means that we are
	 ** dealing with a primary key or UNIQUE constraint.  We have to invent our
	 ** own name.
	 */
	if **(**uintptr)(__ccgo_up(bp + 96)) != 0 {
		zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp + 96)))
		if zName == uintptr(0) {
			goto exit_create_index
		}
		if SQLITE_OK != _sqlite3CheckObjectName(tls, pParse, zName, __ccgo_ts+15417, (*TTable)(unsafe.Pointer(pTab)).FzName) {
			goto exit_create_index
		}
		if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
			if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
				if _sqlite3FindTable(tls, db, zName, (*TDb)(unsafe.Pointer(pDb)).FzDbSName) != uintptr(0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15560, libc.VaList(bp+136, zName))
					goto exit_create_index
				}
			}
			if _sqlite3FindIndex(tls, db, zName, (*TDb)(unsafe.Pointer(pDb)).FzDbSName) != uintptr(0) {
				if !(ifNotExist != 0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15594, libc.VaList(bp+136, zName))
				} else {
					_sqlite3CodeVerifySchema(tls, pParse, iDb)
					_sqlite3ForceNotReadOnly(tls, pParse)
				}
				goto exit_create_index
			}
		}
	} else {
		pLoop = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		n = libc.Int32FromInt32(1)
		for {
			if !(pLoop != 0) {
				break
			}
			goto _1
		_1:
			;
			pLoop = (*TIndex)(unsafe.Pointer(pLoop)).FpNext
			n = n + 1
		}
		zName = _sqlite3MPrintf(tls, db, __ccgo_ts+15618, libc.VaList(bp+136, (*TTable)(unsafe.Pointer(pTab)).FzName, n))
		if zName == uintptr(0) {
			goto exit_create_index
		}
		/* Automatic index names generated from within sqlite3_declare_vtab()
		 ** must have names that are distinct from normal automatic index names.
		 ** The following statement converts "sqlite3_autoindex..." into
		 ** "sqlite3_butoindex..." in order to make the names distinct.
		 ** The "vtab_err.test" test demonstrates the need of this statement. */
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
			**(**uint8)(__ccgo_up(zName + 7)) = **(**uint8)(__ccgo_up(zName + 7)) + 1
		}
	}
	/* Check for authorization to create an index.
	 */
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		zDb = (*TDb)(unsafe.Pointer(pDb)).FzDbSName
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			v2 = __ccgo_ts + 6768
		} else {
			v2 = __ccgo_ts + 6288
		}
		if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v2, uintptr(0), zDb) != 0 {
			goto exit_create_index
		}
		i = int32(SQLITE_CREATE_INDEX)
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			i = int32(SQLITE_CREATE_TEMP_INDEX)
		}
		if _sqlite3AuthCheck(tls, pParse, i, zName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDb) != 0 {
			goto exit_create_index
		}
	}
	/* If pList==0, it means this routine was called to make a primary
	 ** key out of the last column added to the table under construction.
	 ** So create a fake list to simulate this.
	 */
	if pList == uintptr(0) {
		pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1))*16
		v2 = pCol + 14
		*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(COLFLAG_UNIQUE))
		_sqlite3TokenInit(tls, bp+112, (*TColumn)(unsafe.Pointer(pCol)).FzCnName)
		pList = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprAlloc(tls, db, int32(TK_ID), bp+112, 0))
		if pList == uintptr(0) {
			goto exit_create_index
		}
		_sqlite3ExprListSetSortOrder(tls, pList, sortOrder, -int32(1))
	} else {
		_sqlite3ExprListCheckLength(tls, pParse, pList, __ccgo_ts+15417)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			goto exit_create_index
		}
	}
	/* Figure out how many bytes of space are required to store explicitly
	 ** specified collation sequence names.
	 */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLLATE) {
			nExtra = nExtra + (int32(1) + _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
		}
		goto _4
	_4:
		;
		i = i + 1
	}
	/*
	 ** Allocate the index structure.
	 */
	nName = _sqlite3Strlen30(tls, zName)
	if pPk != 0 {
		v5 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
	} else {
		v5 = int32(1)
	}
	nExtraCol = v5
	pIndex = _sqlite3AllocateIndexObject(tls, db, (*TExprList)(unsafe.Pointer(pList)).FnExpr+nExtraCol, nName+nExtra+int32(1), bp+104)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_create_index
	}
	(*TIndex)(unsafe.Pointer(pIndex)).FzName = **(**uintptr)(__ccgo_up(bp + 104))
	**(**uintptr)(__ccgo_up(bp + 104)) = **(**uintptr)(__ccgo_up(bp + 104)) + uintptr(nName+int32(1))
	libc.Xmemcpy(tls, (*TIndex)(unsafe.Pointer(pIndex)).FzName, zName, libc.Uint64FromInt32(nName+int32(1)))
	(*TIndex)(unsafe.Pointer(pIndex)).FpTable = pTab
	(*TIndex)(unsafe.Pointer(pIndex)).FonError = libc.Uint8FromInt32(onError)
	libc.SetBitFieldPtr16Uint32(pIndex+100, libc.BoolUint32(onError != libc.Int32FromInt32(OE_None)), 12, 0x1000)
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(idxType), 14, 0xc000)
	(*TIndex)(unsafe.Pointer(pIndex)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	(*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol = libc.Uint16FromInt32((*TExprList)(unsafe.Pointer(pList)).FnExpr)
	if pPIWhere != 0 {
		_sqlite3ResolveSelfReference(tls, pParse, pTab, int32(NC_PartIdx), pPIWhere, uintptr(0))
		(*TIndex)(unsafe.Pointer(pIndex)).FpPartIdxWhere = pPIWhere
		pPIWhere = uintptr(0)
	}
	/* Check to see if we should honor DESC requests on index columns
	 */
	if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) >= int32(4) {
		sortOrderMask = -int32(1) /* Honor DESC */
	} else {
		sortOrderMask = 0 /* Ignore DESC */
	}
	/* Analyze the list of expressions that form the terms of the index and
	 ** report any errors.  In the common case where the expression is exactly
	 ** a table column, store that column in aiColumn[].  For general expressions,
	 ** populate pIndex->aColExpr and store XN_EXPR (-2) in aiColumn[].
	 **
	 ** TODO: Issue a warning if two or more columns of the index are identical.
	 ** TODO: Issue a warning if the table primary key is used as part of the
	 ** index key.
	 */
	pListItem = pList + 8
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		(*TIndex)(unsafe.Pointer(pIndex)).FaColExpr = pList
		pList = uintptr(0)
	}
	i = 0
	for {
		if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol)) {
			break
		} /* Collation sequence name */
		_sqlite3StringToId(tls, (*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr)
		_sqlite3ResolveSelfReference(tls, pParse, pTab, int32(NC_IdxExpr), (*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr, uintptr(0))
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			goto exit_create_index
		}
		pCExpr = _sqlite3ExprSkipCollate(tls, (*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr)
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pCExpr)).Fop) != int32(TK_COLUMN) {
			if pTab == (*TParse)(unsafe.Pointer(pParse)).FpNewTable {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15641, 0)
				goto exit_create_index
			}
			if (*TIndex)(unsafe.Pointer(pIndex)).FaColExpr == uintptr(0) {
				(*TIndex)(unsafe.Pointer(pIndex)).FaColExpr = pList
				pList = uintptr(0)
			}
			j = -int32(2)
			**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-libc.Int32FromInt32(2))
			libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 12, 0x1000)
			libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 4, 0x10)
		} else {
			j = int32((*TExpr)(unsafe.Pointer(pCExpr)).FiColumn)
			if j < 0 {
				j = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
			} else {
				if int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16 + 8))&0xf0>>4)) == 0 {
					libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 12, 0x1000)
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 5, 0x20)
					libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 4, 0x10)
				}
			}
			**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(j)
		}
		zColl = uintptr(0)
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr)).Fop) == int32(TK_COLLATE) {
			zColl = *(*uintptr)(unsafe.Pointer((*TExprList_item)(unsafe.Pointer(pListItem)).FpExpr + 8))
			nColl = _sqlite3Strlen30(tls, zColl) + int32(1)
			libc.Xmemcpy(tls, **(**uintptr)(__ccgo_up(bp + 104)), zColl, libc.Uint64FromInt32(nColl))
			zColl = **(**uintptr)(__ccgo_up(bp + 104))
			**(**uintptr)(__ccgo_up(bp + 104)) = **(**uintptr)(__ccgo_up(bp + 104)) + uintptr(nColl)
			nExtra = nExtra - nColl
		} else {
			if j >= 0 {
				zColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*16)
			}
		}
		if !(zColl != 0) {
			zColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
		}
		if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) && !(_sqlite3LocateCollSeq(tls, pParse, zColl) != 0) {
			goto exit_create_index
		}
		**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8)) = zColl
		requestedSortOrder = libc.Int32FromUint8((*TExprList_item)(unsafe.Pointer(pListItem)).Ffg.FsortFlags) & sortOrderMask
		**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = libc.Uint8FromInt32(requestedSortOrder)
		goto _6
	_6:
		;
		i = i + 1
		pListItem += 32
	}
	/* Append the table key to the end of the index.  For WITHOUT ROWID
	 ** tables (when pPk!=0) this will be the declared PRIMARY KEY.  For
	 ** normal tables (when pPk==0) this will be the rowid.
	 */
	if pPk != 0 {
		j = 0
		for {
			if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
				break
			}
			x = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)))
			if _isDupColumn(tls, pIndex, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol), pPk, j) != 0 {
				(*TIndex)(unsafe.Pointer(pIndex)).FnColumn = (*TIndex)(unsafe.Pointer(pIndex)).FnColumn - 1
			} else {
				**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(x)
				**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8)) = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8))
				**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = **(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j)))
				i = i + 1
			}
			goto _7
		_7:
			;
			j = j + 1
		}
	} else {
		**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-libc.Int32FromInt32(1))
		**(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8)) = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
	}
	_sqlite3DefaultRowEst(tls, pIndex)
	if (*TParse)(unsafe.Pointer(pParse)).FpNewTable == uintptr(0) {
		_estimateIndexWidth(tls, pIndex)
	}
	/* If this index contains every column of its table, then mark
	 ** it as a covering index */
	_recomputeColumnsNotIndexed(tls, pIndex)
	if pTblName != uintptr(0) && libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnColumn) >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
		libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(1), 10, 0x400)
		j = 0
		for {
			if !(j < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
				goto _8
			}
			if _sqlite3TableColumnToIndex(tls, pIndex, j) >= 0 {
				goto _8
			}
			libc.SetBitFieldPtr16Uint32(pIndex+100, libc.Uint32FromInt32(0), 10, 0x400)
			break
			goto _8
		_8:
			;
			j = j + 1
		}
	}
	if pTab == (*TParse)(unsafe.Pointer(pParse)).FpNewTable {
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) != libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol) {
				goto _9
			}
			k = 0
			for {
				if !(k < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(k)*2))) != int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(k)*2))) {
					break
				}
				z1 = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(k)*8))
				z2 = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(k)*8))
				if _sqlite3StrICmp(tls, z1, z2) != 0 {
					break
				}
				goto _10
			_10:
				;
				k = k + 1
			}
			if k == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
				if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIndex)).FonError) {
					/* This constraint creates the same index as a previous
					 ** constraint specified somewhere in the CREATE TABLE statement.
					 ** However the ON CONFLICT clauses are different. If both this
					 ** constraint and the previous equivalent constraint have explicit
					 ** ON CONFLICT clauses this is an error. Otherwise, use the
					 ** explicitly specified behavior for the index.
					 */
					if !(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Default) || libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIndex)).FonError) == int32(OE_Default)) {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15702, libc.VaList(bp+136, 0))
					}
					if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Default) {
						(*TIndex)(unsafe.Pointer(pIdx)).FonError = (*TIndex)(unsafe.Pointer(pIndex)).FonError
					}
				}
				if libc.Int32FromUint8(idxType) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
					libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(idxType), 14, 0xc000)
				}
				if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
					(*TIndex)(unsafe.Pointer(pIndex)).FpNext = (*TParse)(unsafe.Pointer(pParse)).FpNewIndex
					(*TParse)(unsafe.Pointer(pParse)).FpNewIndex = pIndex
					pIndex = uintptr(0)
				}
				goto exit_create_index
			}
			goto _9
		_9:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	}
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		/* Link the new Index structure to its table and to the other
		 ** in-memory database structures.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
			if pTblName != uintptr(0) {
				(*TIndex)(unsafe.Pointer(pIndex)).Ftnum = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum
				if _sqlite3IndexHasDuplicateRootPage(tls, pIndex) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15744, 0)
					(*TParse)(unsafe.Pointer(pParse)).Frc = _sqlite3CorruptError(tls, int32(130930))
					goto exit_create_index
				}
			}
			p = _sqlite3HashInsert(tls, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema+32, (*TIndex)(unsafe.Pointer(pIndex)).FzName, pIndex)
			if p != 0 {
				/* Malloc must have failed */
				_sqlite3OomFault(tls, db)
				goto exit_create_index
			}
			**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_SchemaChange)
		} else {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || pTblName != uintptr(0) {
				v2 = pParse + 60
				*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
				v5 = *(*int32)(unsafe.Pointer(v2))
				iMem = v5
				v = _sqlite3GetVdbe(tls, pParse)
				if v == uintptr(0) {
					goto exit_create_index
				}
				_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
				/* Create the rootpage for the index using CreateIndex. But before
				 ** doing so, code a Noop instruction and store its address in
				 ** Index.tnum. This is required in case this index is actually a
				 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
				 ** that case the convertToWithoutRowidTable() routine will replace
				 ** the Noop with a Goto to jump over the VDBE code generated below. */
				(*TIndex)(unsafe.Pointer(pIndex)).Ftnum = libc.Uint32FromInt32(_sqlite3VdbeAddOp0(tls, v, int32(OP_Noop)))
				_sqlite3VdbeAddOp3(tls, v, int32(OP_CreateBtree), iDb, iMem, int32(BTREE_BLOBKEY))
				/* Gather the complete text of the CREATE INDEX statement into
				 ** the zStmt variable
				 */
				if pStart != 0 {
					n1 = libc.Int32FromUint32(libc.Uint32FromInt32(int32(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64((*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 96)))).Fz))) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn)
					if libc.Int32FromUint8(**(**uint8)(__ccgo_up((*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 96)))).Fz + uintptr(n1-int32(1))))) == int32(';') {
						n1 = n1 - 1
					}
					/* A named index with an explicit CREATE INDEX statement */
					if onError == OE_None {
						v2 = __ccgo_ts + 1704
					} else {
						v2 = __ccgo_ts + 15761
					}
					zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+15769, libc.VaList(bp+136, v2, n1, (*TToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 96)))).Fz))
				} else {
					/* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
					/* zStmt = sqlite3MPrintf(""); */
					zStmt = uintptr(0)
				}
				/* Add an entry in sqlite_schema for this index
				 */
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+15789, libc.VaList(bp+136, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TIndex)(unsafe.Pointer(pIndex)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, iMem, zStmt))
				_sqlite3DbFree(tls, db, zStmt)
				/* Fill the index with data and reparse the schema. Code an OP_Expire
				 ** to invalidate all pre-compiled statements.
				 */
				if pTblName != 0 {
					_sqlite3RefillIndex(tls, pParse, pIndex, iMem)
					_sqlite3ChangeCookie(tls, pParse, iDb)
					_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+15848, libc.VaList(bp+136, (*TIndex)(unsafe.Pointer(pIndex)).FzName)), uint16(0))
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Expire), 0, int32(1))
				}
				_sqlite3VdbeJumpHere(tls, v, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIndex)).Ftnum))
			}
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 || pTblName == uintptr(0) {
		(*TIndex)(unsafe.Pointer(pIndex)).FpNext = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		(*TTable)(unsafe.Pointer(pTab)).FpIndex = pIndex
		pIndex = uintptr(0)
	} else {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			(*TParse)(unsafe.Pointer(pParse)).FpNewIndex = pIndex
			pIndex = uintptr(0)
		}
	}
	/* Clean up before exiting */
	goto exit_create_index
exit_create_index:
	;
	if pIndex != 0 {
		_sqlite3FreeIndex(tls, db, pIndex)
	}
	if pTab != 0 {
		ppFrom = pTab + 16
		for {
			v2 = **(**uintptr)(__ccgo_up(ppFrom))
			pThis = v2
			if !(v2 != uintptr(0)) {
				break
			}
			if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pThis)).FonError) != int32(OE_Replace) {
				goto _14
			}
			for {
				v2 = (*TIndex)(unsafe.Pointer(pThis)).FpNext
				pNext = v2
				if !(v2 != uintptr(0) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pNext)).FonError) != int32(OE_Replace)) {
					break
				}
				**(**uintptr)(__ccgo_up(ppFrom)) = pNext
				(*TIndex)(unsafe.Pointer(pThis)).FpNext = (*TIndex)(unsafe.Pointer(pNext)).FpNext
				(*TIndex)(unsafe.Pointer(pNext)).FpNext = pThis
				ppFrom = pNext + 40
			}
			break
			goto _14
		_14:
			;
			ppFrom = pThis + 40
		}
	}
	_sqlite3ExprDelete(tls, db, pPIWhere)
	_sqlite3ExprListDelete(tls, db, pList)
	_sqlite3SrcListDelete(tls, db, pTblName)
	_sqlite3DbFree(tls, db, zName)
}

// C documentation
//
//	/*
//	** Generate code for a DELETE FROM statement.
//	**
//	**     DELETE FROM table_wxyz WHERE a<5 AND b NOT NULL;
//	**                 \________/       \________________/
//	**                  pTabList              pWhere
//	*/
func _sqlite3DeleteFrom(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)
	var aToOpen, db, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, v, v3 uintptr
	var addrBypass, addrEphOpen, addrLoop, bComplex, count, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, rcauth, v1, v2 int32
	var nKey, nPk Ti16
	var wcf Tu16
	var _ /* aiCurOnePass at bp+80 */ [2]int32
	var _ /* iDataCur at bp+0 */ int32
	var _ /* iIdxCur at bp+4 */ int32
	var _ /* sContext at bp+8 */ TAuthContext
	var _ /* sNC at bp+24 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aToOpen, addrBypass, addrEphOpen, addrLoop, bComplex, count, db, eOnePass, i, iAddrOnce, iDb, iEphCur, iKey, iPk, iRowSet, iTabCur, isView, memCnt, nIdx, nKey, nPk, pIdx, pPk, pTab, pTrigger, pVTab, pWInfo, rcauth, v, wcf, v1, v2, v3 /* Cursor number for the table */
	**(**int32)(__ccgo_up(bp)) = 0                                                                                                                                                                                                                                                                                                                /* VDBE cursor for the canonical data source */
	**(**int32)(__ccgo_up(bp + 4)) = 0                                                                                                                                                                                                                                                                                                            /* Database number */
	memCnt = 0                                                                                                                                                                                                                                                                                                                                    /* The write cursors opened by WHERE_ONEPASS */
	aToOpen = uintptr(0)                                                                                                                                                                                                                                                                                                                          /* The PRIMARY KEY index on the table */
	iPk = 0                                                                                                                                                                                                                                                                                                                                       /* First of nPk registers holding PRIMARY KEY value */
	nPk = int16(1)                                                                                                                                                                                                                                                                                                                                /* Number of memory cells in the row key */
	iEphCur = 0                                                                                                                                                                                                                                                                                                                                   /* Ephemeral table holding all primary key values */
	iRowSet = 0                                                                                                                                                                                                                                                                                                                                   /* Register for rowset of rows to delete */
	addrBypass = 0                                                                                                                                                                                                                                                                                                                                /* Address of jump over the delete logic */
	addrLoop = 0                                                                                                                                                                                                                                                                                                                                  /* Top of the delete loop */
	addrEphOpen = 0                                                                                                                                                                                                                                                                                                                               /* List of table triggers, if required */
	libc.Xmemset(tls, bp+8, 0, uint64(16))
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto delete_from_cleanup
	}
	/* Locate the table which we want to delete.  This table has to be
	 ** put in an SrcList structure because some of the subroutines we
	 ** will be calling are designed to work with multiple tables and expect
	 ** an SrcList* parameter instead of just a Table* parameter.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
	if pTab == uintptr(0) {
		goto delete_from_cleanup
	}
	/* Figure out if we have any triggers and if the table being
	 ** deleted from is a view
	 */
	pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_DELETE), uintptr(0), uintptr(0))
	isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
	bComplex = libc.BoolInt32(pTrigger != 0 || _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)
	/* If pTab is really a view, make sure it has been initialized.
	 */
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto delete_from_cleanup
	}
	if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
		goto delete_from_cleanup
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	rcauth = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
	if rcauth == int32(SQLITE_DENY) {
		goto delete_from_cleanup
	}
	/* Assign cursor numbers to the table and all its indices.
	 */
	v3 = pParse + 56
	v2 = *(*int32)(unsafe.Pointer(v3))
	*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
	v1 = v2
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = v1
	iTabCur = v1
	nIdx = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab + 1
		goto _4
	_4:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nIdx = nIdx + 1
	}
	/* Start the view context
	 */
	if isView != 0 {
		_sqlite3AuthContextPush(tls, pParse, bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName)
	}
	/* Begin generating code.
	 */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto delete_from_cleanup
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, bComplex, iDb)
	/* If we are trying to delete from a view, realize that view into
	 ** an ephemeral table.
	 */
	if isView != 0 {
		_sqlite3MaterializeView(tls, pParse, pTab, pWhere, pOrderBy, pLimit, iTabCur)
		v1 = iTabCur
		**(**int32)(__ccgo_up(bp + 4)) = v1
		**(**int32)(__ccgo_up(bp)) = v1
		pOrderBy = uintptr(0)
		pLimit = uintptr(0)
	}
	/* Resolve the column names in the WHERE clause.
	 */
	libc.Xmemset(tls, bp+24, 0, uint64(56))
	(**(**TNameContext)(__ccgo_up(bp + 24))).FpParse = pParse
	(**(**TNameContext)(__ccgo_up(bp + 24))).FpSrcList = pTabList
	if _sqlite3ResolveExprNames(tls, bp+24, pWhere) != 0 {
		goto delete_from_cleanup
	}
	/* Initialize the counter of the number of rows deleted, if
	 ** we are counting rows.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0) {
		v3 = pParse + 60
		*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
		v1 = *(*int32)(unsafe.Pointer(v3))
		memCnt = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, memCnt)
	}
	/* Special case: A DELETE without a WHERE clause deletes everything.
	 ** It is easier just to erase the whole table. Prior to version 3.6.5,
	 ** this optimization caused the row change count (the value returned by
	 ** API function sqlite3_count_changes) to be set incorrectly.
	 **
	 ** The "rcauth==SQLITE_OK" terms is the
	 ** IMPLEMENTATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
	 ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
	 ** the truncate optimization is disabled and all rows are deleted
	 ** individually.
	 */
	if rcauth == SQLITE_OK && pWhere == uintptr(0) && !(bComplex != 0) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback == uintptr(0) {
		_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(1), (*TTable)(unsafe.Pointer(pTab)).FzName)
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			if memCnt != 0 {
				v1 = memCnt
			} else {
				v1 = -int32(1)
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab)).Ftnum), iDb, v1, (*TTable)(unsafe.Pointer(pTab)).FzName, -int32(1))
		}
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
				if memCnt != 0 {
					v1 = memCnt
				} else {
					v1 = -int32(1)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb, v1)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			}
			goto _9
		_9:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	} else {
		wcf = libc.Uint16FromInt32(libc.Int32FromInt32(WHERE_ONEPASS_DESIRED) | libc.Int32FromInt32(WHERE_DUPLICATES_OK))
		if (**(**TNameContext)(__ccgo_up(bp + 24))).FncFlags&int32(NC_Subquery) != 0 {
			bComplex = int32(1)
		}
		if bComplex != 0 {
			v1 = 0
		} else {
			v1 = int32(WHERE_ONEPASS_MULTIROW)
		}
		wcf = libc.Uint16FromInt32(int32(wcf) | v1)
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			/* For a rowid table, initialize the RowSet to an empty set */
			pPk = uintptr(0)
			v3 = pParse + 60
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			v1 = *(*int32)(unsafe.Pointer(v3))
			iRowSet = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, iRowSet)
		} else {
			/* For a WITHOUT ROWID table, create an ephemeral table used to
			 ** hold all primary keys for rows to be deleted. */
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			nPk = libc.Int16FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += int32(nPk)
			v3 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v3))
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			iEphCur = v1
			addrEphOpen = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iEphCur, int32(nPk))
			_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
		}
		/* Construct a query to find the rowid or primary key for every row
		 ** to be deleted, based on the WHERE clause. Set variable eOnePass
		 ** to indicate the strategy used to implement this delete:
		 **
		 **  ONEPASS_OFF:    Two-pass approach - use a FIFO for rowids/PK values.
		 **  ONEPASS_SINGLE: One-pass approach - at most one row deleted.
		 **  ONEPASS_MULTI:  One-pass approach - any number of rows may be deleted.
		 */
		pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), wcf, iTabCur+int32(1))
		if pWInfo == uintptr(0) {
			goto delete_from_cleanup
		}
		eOnePass = _sqlite3WhereOkOnePass(tls, pWInfo, bp+80)
		if eOnePass != int32(ONEPASS_SINGLE) {
			_sqlite3MultiWrite(tls, pParse)
		}
		if _sqlite3WhereUsesDeferredSeek(tls, pWInfo) != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_FinishSeek), iTabCur)
		}
		/* Keep track of the number of rows to be deleted */
		if memCnt != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), memCnt, int32(1))
		}
		/* Extract the rowid or primary key for the current row */
		if pPk != 0 {
			i = 0
			for {
				if !(i < int32(nPk)) {
					break
				}
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
				goto _16
			_16:
				;
				i = i + 1
			}
			iKey = iPk
		} else {
			v3 = pParse + 60
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			v1 = *(*int32)(unsafe.Pointer(v3))
			iKey = v1
			_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, -int32(1), iKey)
		}
		if eOnePass != ONEPASS_OFF {
			/* For ONEPASS, no need to store the rowid/primary-key. There is only
			 ** one, so just keep it in its register(s) and fall through to the
			 ** delete code.  */
			nKey = nPk /* OP_Found will use an unpacked key */
			aToOpen = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt32(nIdx+int32(2)))
			if aToOpen == uintptr(0) {
				_sqlite3WhereEnd(tls, pWInfo)
				goto delete_from_cleanup
			}
			libc.Xmemset(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)))
			**(**Tu8)(__ccgo_up(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
			if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] >= 0 {
				**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[0]-iTabCur))) = uint8(0)
			}
			if (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0 {
				**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]-iTabCur))) = uint8(0)
			}
			if addrEphOpen != 0 {
				_sqlite3VdbeChangeToNoop(tls, v, addrEphOpen)
			}
			addrBypass = _sqlite3VdbeMakeLabel(tls, pParse)
		} else {
			if pPk != 0 {
				/* Add the PK key for this row to the temporary table */
				v3 = pParse + 60
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				v1 = *(*int32)(unsafe.Pointer(v3))
				iKey = v1
				nKey = 0 /* Zero tells OP_Found to use a composite key */
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(nPk), iKey, _sqlite3IndexAffinityStr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPk), int32(nPk))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEphCur, iKey, iPk, int32(nPk))
			} else {
				/* Add the rowid of the row to be deleted to the RowSet */
				nKey = int16(1) /* OP_DeferredSeek always uses a single rowid */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_RowSetAdd), iRowSet, iKey)
			}
			_sqlite3WhereEnd(tls, pWInfo)
		}
		/* Unless this is a view, open cursors for the table we are
		 ** deleting from and all its indices. If this is a view, then the
		 ** only effect this statement has is to fire the INSTEAD OF
		 ** triggers.
		 */
		if !(isView != 0) {
			iAddrOnce = 0
			if eOnePass == int32(ONEPASS_MULTI) {
				iAddrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			}
			_sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(OPFLAG_FORDELETE), iTabCur, aToOpen, bp, bp+4)
			if eOnePass == int32(ONEPASS_MULTI) {
				_sqlite3VdbeJumpHereOrPopInst(tls, v, iAddrOnce)
			}
		}
		/* Set up a loop over the rowids/primary-keys that were found in the
		 ** where-clause loop above.
		 */
		if eOnePass != ONEPASS_OFF {
			/* OP_Found will use an unpacked key */
			if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && **(**Tu8)(__ccgo_up(aToOpen + uintptr(**(**int32)(__ccgo_up(bp))-iTabCur))) != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), **(**int32)(__ccgo_up(bp)), addrBypass, iKey, int32(nKey))
			}
		} else {
			if pPk != 0 {
				addrLoop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), iEphCur)
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEphCur, 0, iKey)
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iEphCur, iKey)
				}
				/* OP_Found will use a composite key */
			} else {
				addrLoop = _sqlite3VdbeAddOp3(tls, v, int32(OP_RowSetRead), iRowSet, 0, iKey)
			}
		}
		/* Delete the row */
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			pVTab = _sqlite3GetVTable(tls, db, pTab)
			_sqlite3VtabMakeWritable(tls, pParse, pTab)
			_sqlite3MayAbort(tls, pParse)
			if eOnePass == int32(ONEPASS_SINGLE) {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iTabCur)
				if (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
					(*TParse)(unsafe.Pointer(pParse)).FisMultiWrite = uint8(0)
				}
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VUpdate), 0, int32(1), iKey, pVTab, -int32(12))
			_sqlite3VdbeChangeP5(tls, v, uint16(OE_Abort))
		} else {
			count = libc.BoolInt32(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0) /* True to count changes */
			_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), iKey, nKey, libc.Uint8FromInt32(count), uint8(OE_Default), libc.Uint8FromInt32(eOnePass), (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)])
		}
		/* End of the loop over all rowids/primary-keys. */
		if eOnePass != ONEPASS_OFF {
			_sqlite3VdbeResolveLabel(tls, v, addrBypass)
			_sqlite3WhereEnd(tls, pWInfo)
		} else {
			if pPk != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iEphCur, addrLoop+int32(1))
				_sqlite3VdbeJumpHere(tls, v, addrLoop)
			} else {
				_sqlite3VdbeGoto(tls, v, addrLoop)
				_sqlite3VdbeJumpHere(tls, v, addrLoop)
			}
		}
	} /* End non-truncate path */
	/* Update the sqlite_sequence table by storing the content of the
	 ** maximum rowid counter values recorded while inserting into
	 ** autoincrement tables.
	 */
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) {
		_sqlite3AutoincrementEnd(tls, pParse)
	}
	/* Return the number of rows that were deleted. If this routine is
	 ** generating code because of a call to sqlite3NestedParse(), do not
	 ** invoke the callback function.
	 */
	if memCnt != 0 {
		_sqlite3CodeChangeCount(tls, v, memCnt, __ccgo_ts+16449)
	}
	goto delete_from_cleanup
delete_from_cleanup:
	;
	_sqlite3AuthContextPop(tls, bp+8)
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprDelete(tls, db, pWhere)
	if aToOpen != 0 {
		_sqlite3DbNNFreeNN(tls, db, aToOpen)
	}
	return
}

/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).  */

// C documentation
//
//	/*
//	** This routine will drop an existing named index.  This routine
//	** implements the DROP INDEX statement.
//	*/
func _sqlite3DropIndex(tls *libc.TLS, pParse uintptr, pName uintptr, ifExists int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var code, iDb int32
	var db, pIndex, pTab, v, zDb, zTab, v1 uintptr
	_, _, _, _, _, _, _, _, _ = code, db, iDb, pIndex, pTab, v, zDb, zTab, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto exit_drop_index
	}
	/* Never called with prior non-OOM errors */
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		goto exit_drop_index
	}
	pIndex = _sqlite3FindIndex(tls, db, (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzName, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
	if pIndex == uintptr(0) {
		if !(ifExists != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15875, libc.VaList(bp+8, pName+8))
		} else {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, *(*uintptr)(unsafe.Pointer(pName + 8 + 72)))
			_sqlite3ForceNotReadOnly(tls, pParse)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
		goto exit_drop_index
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0xc000>>14)) != SQLITE_IDXTYPE_APPDEF {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15893, libc.VaList(bp+8, 0))
		goto exit_drop_index
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema)
	code = int32(SQLITE_DROP_INDEX)
	pTab = (*TIndex)(unsafe.Pointer(pIndex)).FpTable
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		v1 = __ccgo_ts + 6768
	} else {
		v1 = __ccgo_ts + 6288
	}
	zTab = v1
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_DELETE), zTab, uintptr(0), zDb) != 0 {
		goto exit_drop_index
	}
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
		code = int32(SQLITE_DROP_TEMP_INDEX)
	}
	if _sqlite3AuthCheck(tls, pParse, code, (*TIndex)(unsafe.Pointer(pIndex)).FzName, (*TTable)(unsafe.Pointer(pTab)).FzName, zDb) != 0 {
		goto exit_drop_index
	}
	/* Generate code to remove the index and from the schema table */
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+15966, libc.VaList(bp+8, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TIndex)(unsafe.Pointer(pIndex)).FzName))
		_sqlite3ClearStatTables(tls, pParse, iDb, __ccgo_ts+13048, (*TIndex)(unsafe.Pointer(pIndex)).FzName)
		_sqlite3ChangeCookie(tls, pParse, iDb)
		_destroyRootPage(tls, pParse, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIndex)).Ftnum), iDb)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_DropIndex), iDb, 0, 0, (*TIndex)(unsafe.Pointer(pIndex)).FzName, 0)
	}
	goto exit_drop_index
exit_drop_index:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** This function is called to drop a trigger from the database schema.
//	**
//	** This may be called directly from the parser and therefore identifies
//	** the trigger by name.  The sqlite3DropTriggerPtr() routine does the
//	** same job as this routine except it takes a pointer to the trigger
//	** instead of the trigger name.
//	**/
func _sqlite3DropTrigger(tls *libc.TLS, pParse uintptr, pName uintptr, noErr int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pTrigger, zDb, zName uintptr
	var i, j, v2 int32
	_, _, _, _, _, _, _ = db, i, j, pTrigger, zDb, zName, v2
	pTrigger = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto drop_trigger_cleanup
	}
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		goto drop_trigger_cleanup
	}
	zDb = *(*uintptr)(unsafe.Pointer(pName + 8 + 72))
	zName = (*(*TSrcItem)(unsafe.Pointer(pName + 8))).FzName
	i = OMIT_TEMPDB
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		if i < int32(2) {
			v2 = i ^ int32(1)
		} else {
			v2 = i
		}
		j = v2 /* Search TEMP before MAIN */
		if zDb != 0 && _sqlite3DbIsNamed(tls, db, j, zDb) == 0 {
			goto _1
		}
		pTrigger = _sqlite3HashFind(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32))).FpSchema+56, zName)
		if pTrigger != 0 {
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if !(pTrigger != 0) {
		if !(noErr != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22382, libc.VaList(bp+8, pName+8))
		} else {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
		goto drop_trigger_cleanup
	}
	_sqlite3DropTriggerPtr(tls, pParse, pTrigger)
	goto drop_trigger_cleanup
drop_trigger_cleanup:
	;
	_sqlite3SrcListDelete(tls, db, pName)
}

// C documentation
//
//	/*
//	** This routine is called to report the final ")" that terminates
//	** a CREATE TABLE statement.
//	**
//	** The table structure that other action routines have been building
//	** is added to the internal hash tables, assuming no errors have
//	** occurred.
//	**
//	** An entry for the table is made in the schema table on disk, unless
//	** this is a temporary table or db->init.busy==1.  When db->init.busy==1
//	** it means we are reading the sqlite_schema table because we just
//	** connected to the database or because the sqlite_schema table has
//	** recently changed, so the entry for this table already exists in
//	** the sqlite_schema table.  We do not want to create it again.
//	**
//	** If the pSelect argument is not NULL, it means that this routine
//	** was called to create a table generated from a
//	** "CREATE TABLE ... AS SELECT ..." statement.  The column names of
//	** the new table will match the result set of the SELECT.
//	*/
func _sqlite3EndTable(tls *libc.TLS, pParse uintptr, pCons uintptr, pEnd uintptr, tabOpts Tu32, pSelect uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var addrInsLoop, addrTop, iCsr, iDb, ii, ii1, n, nNG, regRec, regRowid, regYield, v4 int32
	var colFlags Tu32
	var db, p, pCol, pDb, pEnd2, pIdx, pOld, pSchema, pSelTab, pX, v, zStmt, zType, zType2, v5 uintptr
	var v12 Ti16
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrInsLoop, addrTop, colFlags, db, iCsr, iDb, ii, ii1, n, nNG, p, pCol, pDb, pEnd2, pIdx, pOld, pSchema, pSelTab, pX, regRec, regRowid, regYield, v, zStmt, zType, zType2, v12, v4, v5 /* The new table */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                                                                                                                                                                                                                                      /* An implied index of the table */
	if pEnd == uintptr(0) && pSelect == uintptr(0) {
		return
	}
	p = (*TParse)(unsafe.Pointer(pParse)).FpNewTable
	if p == uintptr(0) {
		return
	}
	if pSelect == uintptr(0) && _sqlite3ShadowTableName(tls, db, (*TTable)(unsafe.Pointer(p)).FzName) != 0 {
		**(**Tu32)(__ccgo_up(p + 48)) |= uint32(TF_Shadow)
	}
	/* If the db->init.busy is 1 it means we are reading the SQL off the
	 ** "sqlite_schema" or "sqlite_temp_schema" table on the disk.
	 ** So do not write to the disk again.  Extract the root page number
	 ** for the table from the db->init.newTnum field.  (The page number
	 ** should have been put there by the sqliteOpenCb routine.)
	 **
	 ** If the root page number is 1, that means this is the sqlite_schema
	 ** table itself.  So mark it read-only.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		if pSelect != 0 || !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) && (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+1704, 0)
			return
		}
		(*TTable)(unsafe.Pointer(p)).Ftnum = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum
		if (*TTable)(unsafe.Pointer(p)).Ftnum == uint32(1) {
			**(**Tu32)(__ccgo_up(p + 48)) |= uint32(TF_Readonly)
		}
	}
	/* Special processing for tables that include the STRICT keyword:
	 **
	 **   *  Do not allow custom column datatypes.  Every column must have
	 **      a datatype that is one of INT, INTEGER, REAL, TEXT, or BLOB.
	 **
	 **   *  If a PRIMARY KEY is defined, other than the INTEGER PRIMARY KEY,
	 **      then all columns of the PRIMARY KEY must have a NOT NULL
	 **      constraint.
	 */
	if tabOpts&uint32(TF_Strict) != 0 {
		**(**Tu32)(__ccgo_up(p + 48)) |= uint32(TF_Strict)
		ii = 0
		for {
			if !(ii < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
				break
			}
			pCol = (*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii)*16
			if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) == COLTYPE_CUSTOM {
				if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_HASTYPE) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14400, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1704)))
				} else {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14433, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
				}
				return
			} else {
				if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) == int32(COLTYPE_ANY) {
					(*TColumn)(unsafe.Pointer(pCol)).Faffinity = uint8(SQLITE_AFF_BLOB)
				}
			}
			if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 && int32((*TTable)(unsafe.Pointer(p)).FiPKey) != ii && int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) == OE_None {
				libc.SetBitFieldPtr8Uint32(pCol+8, libc.Uint32FromInt32(OE_Abort), 4, 0xf0)
				**(**Tu32)(__ccgo_up(p + 48)) |= uint32(TF_HasNotNull)
			}
			goto _1
		_1:
			;
			ii = ii + 1
		}
	}
	/* Special processing for WITHOUT ROWID Tables */
	if tabOpts&uint32(TF_WithoutRowid) != 0 {
		if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_Autoincrement) != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14460, 0)
			return
		}
		if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasPrimaryKey) == uint32(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14510, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName))
			return
		}
		**(**Tu32)(__ccgo_up(p + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid) | libc.Int32FromInt32(TF_NoVisibleRowid))
		_convertToWithoutRowidTable(tls, pParse, p)
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(p)).FpSchema)
	/* Resolve names in all CHECK constraint expressions.
	 */
	if (*TTable)(unsafe.Pointer(p)).FpCheck != 0 {
		_sqlite3ResolveSelfReference(tls, pParse, p, int32(NC_IsCheck), uintptr(0), (*TTable)(unsafe.Pointer(p)).FpCheck)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			/* If errors are seen, delete the CHECK constraints now, else they might
			 ** actually be used if PRAGMA writable_schema=ON is set. */
			_sqlite3ExprListDelete(tls, db, (*TTable)(unsafe.Pointer(p)).FpCheck)
			(*TTable)(unsafe.Pointer(p)).FpCheck = uintptr(0)
		} else {
		}
	}
	if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasGenerated) != 0 {
		nNG = 0
		ii1 = 0
		for {
			if !(ii1 < int32((*TTable)(unsafe.Pointer(p)).FnCol)) {
				break
			}
			colFlags = uint32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(p)).FaCol + uintptr(ii1)*16))).FcolFlags)
			if colFlags&uint32(COLFLAG_GENERATED) != uint32(0) {
				pX = _sqlite3ColumnExpr(tls, p, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(ii1)*16)
				if _sqlite3ResolveSelfReference(tls, pParse, p, int32(NC_GenCol), pX, uintptr(0)) != 0 {
					/* If there are errors in resolving the expression, change the
					 ** expression to a NULL.  This prevents code generators that operate
					 ** on the expression from inserting extra parts into the expression
					 ** tree that have been allocated from lookaside memory, which is
					 ** illegal in a schema and will lead to errors or heap corruption
					 ** when the database connection closes. */
					_sqlite3ColumnSetExpr(tls, pParse, p, (*TTable)(unsafe.Pointer(p)).FaCol+uintptr(ii1)*16, _sqlite3ExprAlloc(tls, db, int32(TK_NULL), uintptr(0), 0))
				}
			} else {
				nNG = nNG + 1
			}
			goto _2
		_2:
			;
			ii1 = ii1 + 1
		}
		if nNG == 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+14542, 0)
			return
		}
	}
	/* Estimate the average row size for the table and for all implied indices */
	_estimateTableWidth(tls, p)
	pIdx = (*TTable)(unsafe.Pointer(p)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		_estimateIndexWidth(tls, pIdx)
		goto _3
	_3:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	/* If not initializing, then create a record for the new table
	 ** in the schema table of the database.
	 **
	 ** If this is a TEMPORARY table, write the entry into the auxiliary
	 ** file instead of into the main database file.
	 */
	if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) { /* Text of the CREATE TABLE or CREATE VIEW statement */
		v = _sqlite3GetVdbe(tls, pParse)
		if v == uintptr(0) {
			return
		}
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), 0)
		/*
		 ** Initialize zType for the new view or table.
		 */
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
			/* A regular table */
			zType = __ccgo_ts + 9381
			zType2 = __ccgo_ts + 14586
		} else {
			/* A view */
			zType = __ccgo_ts + 11119
			zType2 = __ccgo_ts + 14592
		}
		/* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
		 ** statement to populate the new table. The root-page number for the
		 ** new table is in register pParse->u1.cr.regRoot.
		 **
		 ** Once the SELECT has been coded by sqlite3Select(), it is in a
		 ** suitable state to query for the column names and types to be used
		 ** by the new table.
		 **
		 ** A shared-cache write-lock is not required to write to the new table,
		 ** as a schema-lock must have already been obtained to create it. Since
		 ** a schema-lock excludes all other database users, the write-lock would
		 ** be redundant.
		 */
		if pSelect != 0 { /* Write cursor on the new table */
			if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
				(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
				(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
				return
			}
			v5 = pParse + 56
			v4 = *(*int32)(unsafe.Pointer(v5))
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			iCsr = v4
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v4 = *(*int32)(unsafe.Pointer(v5))
			regYield = v4
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v4 = *(*int32)(unsafe.Pointer(v5))
			regRec = v4
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v4 = *(*int32)(unsafe.Pointer(v5))
			regRowid = v4
			_sqlite3MayAbort(tls, pParse)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenWrite), iCsr, (*(*struct {
				FaddrCrTab      int32
				FregRowid       int32
				FregRoot        int32
				FconstraintName TToken
			})(unsafe.Pointer(pParse + 256))).FregRoot, iDb)
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_P2ISREG))
			addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, addrTop)
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return
			}
			pSelTab = _sqlite3ResultSetOfSelect(tls, pParse, pSelect, uint8(SQLITE_AFF_BLOB))
			if pSelTab == uintptr(0) {
				return
			}
			v12 = (*TTable)(unsafe.Pointer(pSelTab)).FnCol
			(*TTable)(unsafe.Pointer(p)).FnNVCol = v12
			(*TTable)(unsafe.Pointer(p)).FnCol = v12
			(*TTable)(unsafe.Pointer(p)).FaCol = (*TTable)(unsafe.Pointer(pSelTab)).FaCol
			(*TTable)(unsafe.Pointer(pSelTab)).FnCol = 0
			(*TTable)(unsafe.Pointer(pSelTab)).FaCol = uintptr(0)
			_sqlite3DeleteTable(tls, db, pSelTab)
			_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), regYield)
			_sqlite3Select(tls, pParse, pSelect, bp)
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return
			}
			_sqlite3VdbeEndCoroutine(tls, v, regYield)
			_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1))
			addrInsLoop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (**(**TSelectDest)(__ccgo_up(bp))).FiSDParm)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), (**(**TSelectDest)(__ccgo_up(bp))).FiSdst, (**(**TSelectDest)(__ccgo_up(bp))).FnSdst, regRec)
			_sqlite3TableAffinity(tls, v, p, 0)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iCsr, regRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iCsr, regRec, regRowid)
			_sqlite3VdbeGoto(tls, v, addrInsLoop)
			_sqlite3VdbeJumpHere(tls, v, addrInsLoop)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCsr)
		}
		/* Compute the complete text of the CREATE statement */
		if pSelect != 0 {
			zStmt = _createTableStmt(tls, db, p)
		} else {
			if tabOpts != 0 {
				v5 = pParse + 288
			} else {
				v5 = pEnd
			}
			pEnd2 = v5
			n = int32(int64((*TToken)(unsafe.Pointer(pEnd2)).Fz) - int64((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up((*TToken)(unsafe.Pointer(pEnd2)).Fz))) != int32(';') {
				n = libc.Int32FromUint32(uint32(n) + (*TToken)(unsafe.Pointer(pEnd2)).Fn)
			}
			zStmt = _sqlite3MPrintf(tls, db, __ccgo_ts+14597, libc.VaList(bp+48, zType2, n, (*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
		}
		/* A slot for the record has already been allocated in the
		 ** schema table.  We just need to update that slot with all
		 ** the information we've collected.
		 */
		_sqlite3NestedParse(tls, pParse, __ccgo_ts+14612, libc.VaList(bp+48, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, zType, (*TTable)(unsafe.Pointer(p)).FzName, (*TTable)(unsafe.Pointer(p)).FzName, (*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRoot, zStmt, (*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRowid))
		_sqlite3DbFree(tls, db, zStmt)
		_sqlite3ChangeCookie(tls, pParse, iDb)
		/* Check to see if we need to create an sqlite_sequence table for
		 ** keeping track of autoincrement keys.
		 */
		if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_Autoincrement) != uint32(0) && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
			pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
			if (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab == uintptr(0) {
				_sqlite3NestedParse(tls, pParse, __ccgo_ts+14710, libc.VaList(bp+48, (*TDb)(unsafe.Pointer(pDb)).FzDbSName))
			}
		}
		/* Reparse everything to update our internal data structures */
		_sqlite3VdbeAddParseSchemaOp(tls, v, iDb, _sqlite3MPrintf(tls, db, __ccgo_ts+14752, libc.VaList(bp+48, (*TTable)(unsafe.Pointer(p)).FzName)), uint16(0))
		/* Test for cycles in generated columns and illegal expressions
		 ** in CHECK constraints and in DEFAULT clauses. */
		if (*TTable)(unsafe.Pointer(p)).FtabFlags&uint32(TF_HasGenerated) != 0 {
			_sqlite3VdbeAddOp4(tls, v, int32(OP_SqlExec), int32(0x0001), 0, 0, _sqlite3MPrintf(tls, db, __ccgo_ts+14786, libc.VaList(bp+48, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TTable)(unsafe.Pointer(p)).FzName)), -int32(7))
		}
	}
	/* Add the table to the in-memory representation of the database.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
		pSchema = (*TTable)(unsafe.Pointer(p)).FpSchema
		pOld = _sqlite3HashInsert(tls, pSchema+8, (*TTable)(unsafe.Pointer(p)).FzName, p)
		if pOld != 0 {
			/* Malloc must have failed inside HashInsert() */
			_sqlite3OomFault(tls, db)
			return
		}
		(*TParse)(unsafe.Pointer(pParse)).FpNewTable = uintptr(0)
		**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_SchemaChange)
		/* If this is the magic sqlite_sequence table used by autoincrement,
		 ** then record a pointer to this table in the main database structure
		 ** so that INSERT can find the table easily.  */
		if libc.Xstrcmp(tls, (*TTable)(unsafe.Pointer(p)).FzName, __ccgo_ts+9903) == 0 {
			(*TSchema)(unsafe.Pointer((*TTable)(unsafe.Pointer(p)).FpSchema)).FpSeqTab = p
		}
	}
	if !(pSelect != 0) && libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
		if (*TToken)(unsafe.Pointer(pCons)).Fz == uintptr(0) {
			pCons = pEnd
		}
		(*(*struct {
			FaddColOffset int32
			FpFKey        uintptr
			FpDfltList    uintptr
		})(unsafe.Pointer(p + 64))).FaddColOffset = int32(13) + int32(int64((*TToken)(unsafe.Pointer(pCons)).Fz)-int64((*TParse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
	}
}

// C documentation
//
//	/* The input list pList is the list of result set terms from a RETURNING
//	** clause.  The table that we are returning from is pTab.
//	**
//	** This routine makes a copy of the pList, and at the same time expands
//	** any "*" wildcards to be the complete set of columns from pTab.
//	*/
func _sqlite3ExpandReturning(tls *libc.TLS, pParse uintptr, pList uintptr, pTab uintptr) (r uintptr) {
	var db, pItem, pItem1, pNew, pNewExpr, pNewExpr1, pOldExpr uintptr
	var i, jj int32
	_, _, _, _, _, _, _, _, _ = db, i, jj, pItem, pItem1, pNew, pNewExpr, pNewExpr1, pOldExpr
	pNew = uintptr(0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		pOldExpr = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr
		if pOldExpr == uintptr(0) {
			goto _1
		}
		if _isAsteriskTerm(tls, pParse, pOldExpr) != 0 {
			jj = 0
			for {
				if !(jj < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if libc.Int32FromUint16((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(jj)*16)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
					goto _2
				}
				pNewExpr = _sqlite3Expr(tls, db, int32(TK_ID), (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(jj)*16))).FzCnName)
				pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pNewExpr)
				if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
					pItem = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
					(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbStrDup(tls, db, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(jj)*16))).FzCnName)
					libc.SetBitFieldPtr16Uint32(pItem+16+4, libc.Uint32FromInt32(ENAME_NAME), 14, 0xc000)
				}
				goto _2
			_2:
				;
				jj = jj + 1
			}
		} else {
			pNewExpr1 = _sqlite3ExprDup(tls, db, pOldExpr, 0)
			pNew = _sqlite3ExprListAppend(tls, pParse, pNew, pNewExpr1)
			if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) && (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FzEName != uintptr(0) {
				pItem1 = pNew + 8 + uintptr((*TExprList)(unsafe.Pointer(pNew)).FnExpr-int32(1))*32
				(*TExprList_item)(unsafe.Pointer(pItem1)).FzEName = _sqlite3DbStrDup(tls, db, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FzEName)
				libc.SetBitFieldPtr16Uint32(pItem1+16+4, libc.Uint32FromInt32(int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0xc000>>14))), 14, 0xc000)
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return pNew
}

// C documentation
//
//	/*
//	** Mark every prepared statement associated with a database connection
//	** as expired.
//	**
//	** An expired statement means that recompilation of the statement is
//	** recommend.  Statements expire when things happen that make their
//	** programs obsolete.  Removing user-defined functions or collating
//	** sequences, or changing an authorization function are the types of
//	** things that make prepared statements obsolete.
//	**
//	** If iCode is 1, then expiration is advisory.  The statement should
//	** be reprepared before being restarted, but if it is already running
//	** it is allowed to run to completion.
//	**
//	** Internally, this function just sets the Vdbe.expired flag on all
//	** prepared statements.  The flag is set to 1 for an immediate expiration
//	** and set to 2 for an advisory expiration.
//	*/
func _sqlite3ExpirePreparedStatements(tls *libc.TLS, db uintptr, iCode int32) {
	var p uintptr
	_ = p
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpVdbe
	for {
		if !(p != 0) {
			break
		}
		libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(iCode+libc.Int32FromInt32(1)), 14, 0xc000)
		goto _1
	_1:
		;
		p = (*TVdbe)(unsafe.Pointer(p)).FpVNext
	}
}

// C documentation
//
//	/*
//	** Return FALSE if there is no chance that the expression can be NULL.
//	**
//	** If the expression might be NULL or if the expression is too complex
//	** to tell return TRUE.
//	**
//	** This routine is used as an optimization, to skip OP_IsNull opcodes
//	** when we know that a value cannot be NULL.  Hence, a false positive
//	** (returning TRUE when in fact the expression can never be NULL) might
//	** be a small performance hit but is otherwise harmless.  On the other
//	** hand, a false negative (returning FALSE when the result could be NULL)
//	** will likely result in an incorrect answer.  So when in doubt, return
//	** TRUE.
//	*/
func _sqlite3ExprCanBeNull(tls *libc.TLS, p uintptr) (r int32) {
	var op Tu8
	_ = op
	for libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UPLUS) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_UMINUS) {
		p = (*TExpr)(unsafe.Pointer(p)).FpLeft
	}
	op = (*TExpr)(unsafe.Pointer(p)).Fop
	if libc.Int32FromUint8(op) == int32(TK_REGISTER) {
		op = (*TExpr)(unsafe.Pointer(p)).Fop2
	}
	switch libc.Int32FromUint8(op) {
	case int32(TK_INTEGER):
		fallthrough
	case int32(TK_STRING):
		fallthrough
	case int32(TK_FLOAT):
		fallthrough
	case int32(TK_BLOB):
		return 0
	case int32(TK_COLUMN):
		return libc.BoolInt32((*TExpr)(unsafe.Pointer(p)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull)) != uint32(0) || *(*uintptr)(unsafe.Pointer(p + 64)) == uintptr(0) || int32((*TExpr)(unsafe.Pointer(p)).FiColumn) >= 0 && (*TTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FaCol != uintptr(0) && int32((*TExpr)(unsafe.Pointer(p)).FiColumn) < int32((*TTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FnCol) && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FaCol + uintptr((*TExpr)(unsafe.Pointer(p)).FiColumn)*16 + 8))&0xf0>>4)) == 0)
	default:
		return int32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Generate code that pushes the value of every element of the given
//	** expression list into a sequence of registers beginning at target.
//	**
//	** Return the number of elements evaluated.  The number returned will
//	** usually be pList->nExpr but might be reduced if SQLITE_ECEL_OMITREF
//	** is defined.
//	**
//	** The SQLITE_ECEL_DUP flag prevents the arguments from being
//	** filled using OP_SCopy.  OP_Copy must be used instead.
//	**
//	** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
//	** factored out into initialization code.
//	**
//	** The SQLITE_ECEL_REF flag means that expressions in the list with
//	** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
//	** in registers at srcReg, and so the value can be copied from there.
//	** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
//	** are simply omitted rather than being copied from srcReg.
//	*/
func _sqlite3ExprCodeExprList(tls *libc.TLS, pParse uintptr, pList uintptr, target int32, srcReg int32, flags Tu8) (r int32) {
	var copyOp Tu8
	var i, inReg, j, n, v1 int32
	var pExpr, pItem, pOp, v, v5 uintptr
	var v4 bool
	_, _, _, _, _, _, _, _, _, _, _, _ = copyOp, i, inReg, j, n, pExpr, pItem, pOp, v, v1, v4, v5
	if libc.Int32FromUint8(flags)&int32(SQLITE_ECEL_DUP) != 0 {
		v1 = int32(OP_Copy)
	} else {
		v1 = int32(OP_SCopy)
	}
	copyOp = libc.Uint8FromInt32(v1)
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* Never gets this far otherwise */
	n = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	if !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x100>>8)) != 0) {
		flags = libc.Uint8FromInt32(int32(flags) & ^libc.Int32FromInt32(SQLITE_ECEL_FACTOR))
	}
	pItem = pList + 8
	i = libc.Int32FromInt32(0)
	for {
		if !(i < n) {
			break
		}
		pExpr = (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr
		if v4 = libc.Int32FromUint8(flags)&int32(SQLITE_ECEL_REF) != 0; v4 {
			v1 = libc.Int32FromUint16((*(*struct {
				FiOrderByCol Tu16
				FiAlias      Tu16
			})(unsafe.Pointer(pItem + 24))).FiOrderByCol)
			j = v1
		}
		if v4 && v1 > 0 {
			if libc.Int32FromUint8(flags)&int32(SQLITE_ECEL_OMITREF) != 0 {
				i = i - 1
				n = n - 1
			} else {
				_sqlite3VdbeAddOp2(tls, v, libc.Int32FromUint8(copyOp), j+srcReg-int32(1), target+i)
			}
		} else {
			if libc.Int32FromUint8(flags)&int32(SQLITE_ECEL_FACTOR) != 0 && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
				_sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, target+i)
			} else {
				inReg = _sqlite3ExprCodeTarget(tls, pParse, pExpr, target+i)
				if inReg != target+i {
					if v4 = libc.Int32FromUint8(copyOp) == int32(OP_Copy); v4 {
						v5 = _sqlite3VdbeGetLastOp(tls, v)
						pOp = v5
					}
					if v4 && libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(v5)).Fopcode) == int32(OP_Copy) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1+(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3+int32(1) == inReg && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2+(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3+int32(1) == target+i && libc.Int32FromUint16((*TVdbeOp)(unsafe.Pointer(pOp)).Fp5) == 0 {
						(*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 = (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 + 1
					} else {
						_sqlite3VdbeAddOp2(tls, v, libc.Int32FromUint8(copyOp), inReg, target+i)
					}
				}
			}
		}
		goto _2
	_2:
		;
		i = i + 1
		pItem += 32
	}
	return n
}

// C documentation
//
//	/*
//	** Generate code that will evaluate expression pExpr and store the
//	** results in register target.  The results are guaranteed to appear
//	** in register target.  If the expression is constant, then this routine
//	** might choose to code the expression at initialization time.
//	*/
func _sqlite3ExprCodeFactorable(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x100>>8)) != 0 && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
		_sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, target)
	} else {
		_sqlite3ExprCodeCopy(tls, pParse, pExpr, target)
	}
}

// C documentation
//
//	/*
//	** Generate code for an IN expression.
//	**
//	**      x IN (SELECT ...)
//	**      x IN (value, value, ...)
//	**
//	** The left-hand side (LHS) is a scalar or vector expression.  The
//	** right-hand side (RHS) is an array of zero or more scalar values, or a
//	** subquery.  If the RHS is a subquery, the number of result columns must
//	** match the number of columns in the vector on the LHS.  If the RHS is
//	** a list of values, the LHS must be a scalar.
//	**
//	** The IN operator is true if the LHS value is contained within the RHS.
//	** The result is false if the LHS is definitely not in the RHS.  The
//	** result is NULL if the presence of the LHS in the RHS cannot be
//	** determined due to NULLs.
//	**
//	** This routine generates code that jumps to destIfFalse if the LHS is not
//	** contained within the RHS.  If due to NULLs we cannot determine if the LHS
//	** is contained in the RHS then jump to destIfNull.  If the LHS is contained
//	** within the RHS then fall through.
//	**
//	** See the separate in-operator.md documentation file in the canonical
//	** SQLite source tree for additional information.
//	*/
func _sqlite3ExprCodeIN(tls *libc.TLS, pParse uintptr, pExpr uintptr, destIfFalse int32, destIfNull int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var addrTop, addrTruthOp, destNotNull, destStep2, destStep6, eType, i, ii, labelOk, nVector, op, op1, r2, r3, rLhs, rLhsOrig, regCkNull, v3 int32
	var aiMap, p, p1, pColl, pColl1, pLeft, pList, pOp, pRhs, v, zAff, v1 uintptr
	var okConstFactor Tu8
	var _ /* iDummy at bp+4 */ int32
	var _ /* iTab at bp+8 */ int32
	var _ /* rRhsHasNull at bp+0 */ int32
	var _ /* regToFree at bp+12 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrTop, addrTruthOp, aiMap, destNotNull, destStep2, destStep6, eType, i, ii, labelOk, nVector, okConstFactor, op, op1, p, p1, pColl, pColl1, pLeft, pList, pOp, pRhs, r2, r3, rLhs, rLhsOrig, regCkNull, v, zAff, v1, v3
	**(**int32)(__ccgo_up(bp)) = 0     /* Statement under construction */
	aiMap = uintptr(0)                 /* Map from vector field to index column */
	zAff = uintptr(0)                  /* Where to jump when NULLs seen in step 2 */
	destStep6 = 0                      /* Top of the step-6 loop */
	**(**int32)(__ccgo_up(bp + 8)) = 0 /* Index to use */
	okConstFactor = libc.Uint8FromInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40)) & 0x100 >> 8)))
	pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
	if _sqlite3ExprCheckIN(tls, pParse, pExpr) != 0 {
		return
	}
	zAff = _exprINAffinity(tls, pParse, pExpr)
	nVector = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
	aiMap = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(libc.Uint64FromInt32(nVector)*uint64(4)))
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		goto sqlite3ExprCodeIN_oom_error
	}
	/* Attempt to compute the RHS. After this step, if anything other than
	 ** IN_INDEX_NOOP is returned, the table opened with cursor iTab
	 ** contains the values that make up the RHS. If IN_INDEX_NOOP is returned,
	 ** the RHS has not yet been coded.  */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* OOM detected prior to this routine */
	if destIfFalse == destIfNull {
		v1 = uintptr(0)
	} else {
		v1 = bp
	}
	eType = _sqlite3FindInIndex(tls, pParse, pExpr, libc.Uint32FromInt32(libc.Int32FromInt32(IN_INDEX_MEMBERSHIP)|libc.Int32FromInt32(IN_INDEX_NOOP_OK)), v1, aiMap, bp+8)
	/* Code the LHS, the <expr> from "<expr> IN (...)". If the LHS is a
	 ** vector, then it is stored in an array of nVector registers starting
	 ** at r1.
	 **
	 ** sqlite3FindInIndex() might have reordered the fields of the LHS vector
	 ** so that the fields are in the same order as an existing index.   The
	 ** aiMap[] array contains a mapping from the original LHS field order to
	 ** the field order that matches the RHS index.
	 **
	 ** Avoid factoring the LHS of the IN(...) expression out of the loop,
	 ** even if it is constant, as OP_Affinity may be used on the register
	 ** by code generated below.  */
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(0), 8, 0x100)
	rLhs = _exprCodeVector(tls, pParse, pLeft, bp+4)
	libc.SetBitFieldPtr16Uint32(pParse+40, uint32(okConstFactor), 8, 0x100)
	/* If sqlite3FindInIndex() did not find or create an index that is
	 ** suitable for evaluating the IN operator, then evaluate using a
	 ** sequence of comparisons.
	 **
	 ** This is step (1) in the in-operator.md optimized algorithm.
	 */
	if eType == int32(IN_INDEX_NOOP) {
		labelOk = _sqlite3VdbeMakeLabel(tls, pParse)
		regCkNull = 0
		pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		pColl = _sqlite3ExprCollSeq(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft)
		if destIfNull != destIfFalse {
			regCkNull = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_BitAnd), rLhs, rLhs, regCkNull)
		}
		ii = 0
		for {
			if !(ii < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			r2 = _sqlite3ExprCodeTemp(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ii)*32))).FpExpr, bp+12)
			if regCkNull != 0 && _sqlite3ExprCanBeNull(tls, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ii)*32))).FpExpr) != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_BitAnd), regCkNull, r2, regCkNull)
			}
			_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp + 12)))
			if ii < (*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1) || destIfNull != destIfFalse {
				if rLhs != r2 {
					v3 = int32(OP_Eq)
				} else {
					v3 = int32(OP_NotNull)
				}
				op = v3
				_sqlite3VdbeAddOp4(tls, v, op, rLhs, labelOk, r2, pColl, -int32(2))
				_sqlite3VdbeChangeP5(tls, v, uint16(**(**uint8)(__ccgo_up(zAff))))
			} else {
				if rLhs != r2 {
					v3 = int32(OP_Ne)
				} else {
					v3 = int32(OP_IsNull)
				}
				op1 = v3
				_sqlite3VdbeAddOp4(tls, v, op1, rLhs, destIfFalse, r2, pColl, -int32(2))
				_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(libc.Int32FromUint8(**(**uint8)(__ccgo_up(zAff)))|int32(SQLITE_JUMPIFNULL)))
			}
			goto _2
		_2:
			;
			ii = ii + 1
		}
		if regCkNull != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regCkNull, destIfNull)
			_sqlite3VdbeGoto(tls, v, destIfFalse)
		}
		_sqlite3VdbeResolveLabel(tls, v, labelOk)
		_sqlite3ReleaseTempReg(tls, pParse, regCkNull)
		goto sqlite3ExprCodeIN_finished
	}
	if eType != int32(IN_INDEX_ROWID) {
		/* If this IN operator will use an index, then the order of columns in the
		 ** vector might be different from the order in the index.  In that case,
		 ** we need to reorder the LHS values to be in index order.  Run Affinity
		 ** before reordering the columns, so that the affinity is correct.
		 */
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), rLhs, nVector, 0, zAff, nVector)
		i = 0
		for {
			if !(i < nVector && **(**int32)(__ccgo_up(aiMap + uintptr(i)*4)) == i) {
				break
			}
			goto _5
		_5:
			;
			i = i + 1
		} /* Are LHS fields reordered? */
		if i != nVector {
			/* Need to reorder the LHS fields according to aiMap */
			rLhsOrig = rLhs
			rLhs = _sqlite3GetTempRange(tls, pParse, nVector)
			i = 0
			for {
				if !(i < nVector) {
					break
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), rLhsOrig+i, rLhs+**(**int32)(__ccgo_up(aiMap + uintptr(i)*4)), 0)
				goto _6
			_6:
				;
				i = i + 1
			}
			_sqlite3ReleaseTempReg(tls, pParse, rLhsOrig)
		}
	}
	/* Step 2: Check to see if the LHS contains any NULL columns.  If the
	 ** LHS does contain NULLs then the result must be either FALSE or NULL.
	 ** We will then skip the binary search of the RHS.
	 */
	if destIfNull == destIfFalse {
		destStep2 = destIfFalse
	} else {
		v3 = _sqlite3VdbeMakeLabel(tls, pParse)
		destStep6 = v3
		destStep2 = v3
	}
	i = 0
	for {
		if !(i < nVector) {
			break
		}
		p = _sqlite3VectorFieldSubexpr(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, i)
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			goto sqlite3ExprCodeIN_oom_error
		}
		if _sqlite3ExprCanBeNull(tls, p) != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), rLhs+**(**int32)(__ccgo_up(aiMap + uintptr(i)*4)), destStep2)
		}
		goto _8
	_8:
		;
		i = i + 1
	}
	/* Step 3.  The LHS is now known to be non-NULL.  Do the binary search
	 ** of the RHS using the LHS as a probe.  If found, the result is
	 ** true.
	 */
	if eType == int32(IN_INDEX_ROWID) {
		/* In this case, the RHS is the ROWID of table b-tree and so we also
		 ** know that the RHS is non-NULL.  Hence, we combine steps 3 and 4
		 ** into a single opcode. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), **(**int32)(__ccgo_up(bp + 8)), destIfFalse, rLhs)
		addrTruthOp = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto)) /* Return True */
	} else {
		if destIfFalse == destIfNull {
			/* Combine Step 3 and Step 5 into a single opcode */
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subrtn)) != uint32(0) {
				pOp = _sqlite3VdbeGetOp(tls, v, (*(*struct {
					FiAddr     int32
					FregReturn int32
				})(unsafe.Pointer(pExpr + 64))).FiAddr)
				if (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 > 0 { /* tag-202407032019 */
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3, destIfFalse, rLhs, nVector)
				}
			}
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), **(**int32)(__ccgo_up(bp + 8)), destIfFalse, rLhs, nVector)
			goto sqlite3ExprCodeIN_finished
		}
		/* Ordinary Step 3, for the case where FALSE and NULL are distinct */
		addrTruthOp = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), **(**int32)(__ccgo_up(bp + 8)), 0, rLhs, nVector)
	}
	/* Step 4.  If the RHS is known to be non-NULL and we did not find
	 ** an match on the search above, then the result must be FALSE.
	 */
	if **(**int32)(__ccgo_up(bp)) != 0 && nVector == int32(1) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), **(**int32)(__ccgo_up(bp)), destIfFalse)
	}
	/* Step 5.  If we do not care about the difference between NULL and
	 ** FALSE, then just return false.
	 */
	if destIfFalse == destIfNull {
		_sqlite3VdbeGoto(tls, v, destIfFalse)
	}
	/* Step 6: Loop through rows of the RHS.  Compare each row to the LHS.
	 ** If any comparison is NULL, then the result is NULL.  If all
	 ** comparisons are FALSE then the final result is FALSE.
	 **
	 ** For a scalar LHS, it is sufficient to check just the first row
	 ** of the RHS.
	 */
	if destStep6 != 0 {
		_sqlite3VdbeResolveLabel(tls, v, destStep6)
	}
	addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), **(**int32)(__ccgo_up(bp + 8)), destIfFalse)
	if nVector > int32(1) {
		destNotNull = _sqlite3VdbeMakeLabel(tls, pParse)
	} else {
		/* For nVector==1, combine steps 6 and 7 by immediately returning
		 ** FALSE if the first comparison is not NULL */
		destNotNull = destIfFalse
	}
	i = 0
	for {
		if !(i < nVector) {
			break
		}
		r3 = _sqlite3GetTempReg(tls, pParse)
		p1 = _sqlite3VectorFieldSubexpr(tls, pLeft, i)
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			pRhs = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList + 8 + uintptr(i)*32))).FpExpr
			pColl1 = _sqlite3BinaryCompareCollSeq(tls, pParse, p1, pRhs)
		} else {
			/* If the RHS of the IN(...) expression are scalar expressions, do
			 ** not consider their collation sequences. The documentation says
			 ** "The collating sequence used for expressions of the form "x IN (y, z,
			 ** ...)" is the collating sequence of x.".  */
			pColl1 = _sqlite3ExprCollSeq(tls, pParse, p1)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), **(**int32)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(aiMap + uintptr(i)*4)), r3)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Ne), rLhs+**(**int32)(__ccgo_up(aiMap + uintptr(i)*4)), destNotNull, r3, pColl1, -int32(2))
		_sqlite3ReleaseTempReg(tls, pParse, r3)
		goto _9
	_9:
		;
		i = i + 1
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, destIfNull)
	if nVector > int32(1) {
		_sqlite3VdbeResolveLabel(tls, v, destNotNull)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), **(**int32)(__ccgo_up(bp + 8)), addrTop+int32(1))
		/* Step 7:  If we reach this point, we know that the result must
		 ** be false. */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, destIfFalse)
	}
	/* Jumps here in order to return true. */
	_sqlite3VdbeJumpHere(tls, v, addrTruthOp)
	goto sqlite3ExprCodeIN_finished
sqlite3ExprCodeIN_finished:
	;
	goto sqlite3ExprCodeIN_oom_error
sqlite3ExprCodeIN_oom_error:
	;
	_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, aiMap)
	_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zAff)
}

// C documentation
//
//	/*
//	** Generate code that will evaluate expression pExpr just one time
//	** per prepared statement execution.
//	**
//	** If the expression uses functions (that might throw an exception) then
//	** guard them with an OP_Once opcode to ensure that the code is only executed
//	** once. If no functions are involved, then factor the code out and put it at
//	** the end of the prepared statement in the initialization section.
//	**
//	** If regDest>0 then the result is always stored in that register and the
//	** result is not reusable.  If regDest<0 then this routine is free to
//	** store the value wherever it wants.  The register where the expression
//	** is stored is returned.  When regDest<0, two identical expressions might
//	** code to the same register, if they do not contain function calls and hence
//	** are factored out into the initialization section at the end of the
//	** prepared statement.
//	*/
func _sqlite3ExprCodeRunJustOnce(tls *libc.TLS, pParse uintptr, pExpr uintptr, regDest int32) (r int32) {
	var addr, i, v2 int32
	var p, pItem, pItem1, v, v3 uintptr
	_, _, _, _, _, _, _, _ = addr, i, p, pItem, pItem1, v, v2, v3
	p = (*TParse)(unsafe.Pointer(pParse)).FpConstExpr
	if regDest < 0 && p != 0 {
		pItem = p + 8
		i = (*TExprList)(unsafe.Pointer(p)).FnExpr
		for {
			if !(i > 0) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x1000>>12)) != 0 && _sqlite3ExprCompare(tls, uintptr(0), (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr, pExpr, -int32(1)) == 0 {
				return *(*int32)(unsafe.Pointer(pItem + 24))
			}
			goto _1
		_1:
			;
			pItem += 32
			i = i - 1
		}
	}
	pExpr = _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
	if pExpr != uintptr(0) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc)) != uint32(0) {
		v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
		addr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(0), 8, 0x100)
		if !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
			if regDest < 0 {
				v3 = pParse + 60
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				v2 = *(*int32)(unsafe.Pointer(v3))
				regDest = v2
			}
			_sqlite3ExprCode(tls, pParse, pExpr, regDest)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		_sqlite3VdbeJumpHere(tls, v, addr)
	} else {
		p = _sqlite3ExprListAppend(tls, pParse, p, pExpr)
		if p != 0 {
			pItem1 = p + 8 + uintptr((*TExprList)(unsafe.Pointer(p)).FnExpr-int32(1))*32
			libc.SetBitFieldPtr16Uint32(pItem1+16+4, libc.BoolUint32(regDest < libc.Int32FromInt32(0)), 12, 0x1000)
			if regDest < 0 {
				v3 = pParse + 60
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				v2 = *(*int32)(unsafe.Pointer(v3))
				regDest = v2
			}
			*(*int32)(unsafe.Pointer(pItem1 + 24)) = regDest
		}
		(*TParse)(unsafe.Pointer(pParse)).FpConstExpr = p
	}
	return regDest
}

// C documentation
//
//	/*
//	** Generate code into the current Vdbe to evaluate the given
//	** expression.  Attempt to store the results in register "target".
//	** Return the register where results are stored.
//	**
//	** With this routine, there is no guarantee that results will
//	** be stored in target.  The result might be stored in some other
//	** register if it is convenient to do so.  The calling function
//	** must check the return code and move the results to the desired
//	** register.
//	*/
func _sqlite3ExprCodeTarget(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) (r int32) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var aListelem, db, db1, pAggInfo, pAggInfo1, pCol, pCol1, pColl, pDef, pDel, pEList, pFarg, pInfo, pLeft, pLeft1, pLeft2, pTab, pTab1, pTab2, pTest, pX, v, z, zBlob, zId, v3 uintptr
	var addr, addrINR, addrIsNull, addrIsNull1, aff, bNormal, destIfFalse, destIfNull, endLabel, i, i1, iCol, iCol1, iReg, iSrc, iTab, inReg, isTrue, n, n1, nCol, nExpr, nFarg, nextCase, op, p1, p5, v1 int32
	var constMask Tu32
	var enc, exprOp, okConstFactor Tu8
	var v2 bool
	var _ /* opCompare at bp+88 */ TExpr
	var _ /* r1 at bp+8 */ int32
	var _ /* r2 at bp+12 */ int32
	var _ /* regFree1 at bp+0 */ int32
	var _ /* regFree2 at bp+4 */ int32
	var _ /* tempX at bp+16 */ TExpr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aListelem, addr, addrINR, addrIsNull, addrIsNull1, aff, bNormal, constMask, db, db1, destIfFalse, destIfNull, enc, endLabel, exprOp, i, i1, iCol, iCol1, iReg, iSrc, iTab, inReg, isTrue, n, n1, nCol, nExpr, nFarg, nextCase, okConstFactor, op, p1, p5, pAggInfo, pAggInfo1, pCol, pCol1, pColl, pDef, pDel, pEList, pFarg, pInfo, pLeft, pLeft1, pLeft2, pTab, pTab1, pTab2, pTest, pX, v, z, zBlob, zId, v1, v2, v3
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe /* The opcode being coded */
	inReg = target                               /* Results stored in register inReg */
	**(**int32)(__ccgo_up(bp)) = 0               /* If non-zero free this temporary register */
	**(**int32)(__ccgo_up(bp + 4)) = 0           /* Temporary expression node */
	p5 = 0
	goto expr_code_doover
expr_code_doover:
	;
	if pExpr == uintptr(0) {
		op = int32(TK_NULL)
	} else {
		if v2 = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr != uintptr(0) && !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Leaf)) != libc.Uint32FromInt32(0)); v2 {
			v1 = _sqlite3IndexedExprLookup(tls, pParse, pExpr, target)
			**(**int32)(__ccgo_up(bp + 8)) = v1
		}
		if v2 && v1 >= 0 {
			return **(**int32)(__ccgo_up(bp + 8))
		} else {
			op = libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop)
		}
	}
	switch op {
	case int32(TK_AGG_COLUMN):
		pAggInfo = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) >= (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn {
			/* Happens when the left table of a RIGHT JOIN is null and
			 ** is using an expression index */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
			break
		}
		pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)*32
		if !((*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode != 0) {
			return (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
		} else {
			if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FuseSortingIdx != 0 {
				pTab = (*TAggInfo_col)(unsafe.Pointer(pCol)).FpTab
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab, (*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn, target)
				if pTab == uintptr(0) {
					/* No comment added */
				} else {
					if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn < 0 {
					} else {
						if libc.Int32FromUint8((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr((*TAggInfo_col)(unsafe.Pointer(pCol)).FiColumn)*16))).Faffinity) == int32(SQLITE_AFF_REAL) {
							_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
						}
					}
				}
				return target
			} else {
				if *(*uintptr)(unsafe.Pointer(pExpr + 64)) == uintptr(0) {
					/* This case happens when the argument to an aggregate function
					 ** is rewritten by aggregateConvertIndexedExprRefToColumn() */
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TExpr)(unsafe.Pointer(pExpr)).FiTable, int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn), target)
					return target
				}
			}
		}
		/* Otherwise, fall thru into the TK_COLUMN case */
		fallthrough
	case int32(TK_COLUMN):
		iTab = (*TExpr)(unsafe.Pointer(pExpr)).FiTable
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_FixedCol)) != uint32(0) {
			iReg = _sqlite3ExprCodeTarget(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
			aff = libc.Int32FromUint8(_sqlite3TableColumnAffinity(tls, *(*uintptr)(unsafe.Pointer(pExpr + 64)), int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)))
			if aff > int32(SQLITE_AFF_BLOB) {
				_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), iReg, int32(1), 0, uintptr(unsafe.Pointer(&_zAff))+uintptr((aff-int32('B'))*int32(2)), -int32(1))
			}
			return iReg
		}
		if iTab < 0 {
			if (*TParse)(unsafe.Pointer(pParse)).FiSelfTab < 0 {
				iCol = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
				pTab1 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
				if iCol < 0 {
					return -int32(1) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
				}
				pCol1 = (*TTable)(unsafe.Pointer(pTab1)).FaCol + uintptr(iCol)*16
				iSrc = int32(_sqlite3TableColumnToStorage(tls, pTab1, int16(iCol))) - (*TParse)(unsafe.Pointer(pParse)).FiSelfTab
				if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_BUSY) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8456, libc.VaList(bp+168, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
						return 0
					}
					v3 = pCol1 + 14
					*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) | libc.Int32FromInt32(COLFLAG_BUSY))
					if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_NOTAVAIL) != 0 {
						_sqlite3ExprCodeGeneratedColumn(tls, pParse, pTab1, pCol1, iSrc)
					}
					v3 = pCol1 + 14
					*(*Tu16)(unsafe.Pointer(v3)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v3))) & ^(libc.Int32FromInt32(COLFLAG_BUSY) | libc.Int32FromInt32(COLFLAG_NOTAVAIL)))
					return iSrc
				} else {
					if libc.Int32FromUint8((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) == int32(SQLITE_AFF_REAL) {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), iSrc, target)
						_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
						return target
					} else {
						return iSrc
					}
				}
			} else {
				/* Coding an expression that is part of an index where column names
				 ** in the index refer to the table to which the index belongs */
				iTab = (*TParse)(unsafe.Pointer(pParse)).FiSelfTab - int32(1)
			}
		} else {
			if v2 = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr != 0; v2 {
				v1 = _exprPartidxExprLookup(tls, pParse, pExpr, target)
				**(**int32)(__ccgo_up(bp + 8)) = v1
			}
			if v2 && 0 != v1 {
				return **(**int32)(__ccgo_up(bp + 8))
			}
		}
		iReg = _sqlite3ExprCodeGetColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(pExpr + 64)), int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn), iTab, target, (*TExpr)(unsafe.Pointer(pExpr)).Fop2)
		return iReg
	case int32(TK_INTEGER):
		_codeInteger(tls, pParse, pExpr, 0, target)
		return target
	case int32(TK_TRUEFALSE):
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), _sqlite3ExprTruthValue(tls, pExpr), target)
		return target
	case int32(TK_FLOAT):
		_codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pExpr + 8)), 0, target)
		return target
	case int32(TK_STRING):
		_sqlite3VdbeLoadString(tls, v, target, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
		return target
	case int32(TK_NULLS):
		/* Set a range of registers to NULL.  pExpr->y.nReg registers starting
		 ** with target */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, target, target+*(*int32)(unsafe.Pointer(&(*TExpr)(unsafe.Pointer(pExpr)).Fy))-int32(1))
		return target
	default:
		/* Make NULL the default case so that if a bug causes an illegal
		 ** Expr node to be passed into this function, it will be handled
		 ** sanely and not crash.  But keep the assert() to bring the problem
		 ** to the attention of the developers. */
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
		return target
	case int32(TK_BLOB):
		z = *(*uintptr)(unsafe.Pointer(pExpr + 8)) + 2
		n = _sqlite3Strlen30(tls, z) - int32(1)
		zBlob = _sqlite3HexToBlob(tls, _sqlite3VdbeDb(tls, v), z, n)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Blob), n/int32(2), target, 0, zBlob, -int32(7))
		return target
	case int32(TK_VARIABLE):
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Variable), int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn), target)
		return target
	case int32(TK_REGISTER):
		return (*TExpr)(unsafe.Pointer(pExpr)).FiTable
	case int32(TK_CAST):
		/* Expressions of the form:   CAST(pLeft AS token) */
		_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Cast), target, libc.Int32FromUint8(_sqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0))))
		return inReg
	case int32(TK_IS):
		fallthrough
	case int32(TK_ISNOT):
		if op == int32(TK_IS) {
			v1 = int32(TK_EQ)
		} else {
			v1 = int32(TK_NE)
		}
		op = v1
		p5 = int32(SQLITE_NULLEQ)
		fallthrough
	case int32(TK_LT):
		fallthrough
	case int32(TK_LE):
		fallthrough
	case int32(TK_GT):
		fallthrough
	case int32(TK_GE):
		fallthrough
	case int32(TK_NE):
		fallthrough
	case int32(TK_EQ):
		pLeft = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		addrIsNull = 0
		if _sqlite3ExprIsVector(tls, pLeft) != 0 {
			_codeVectorCompare(tls, pParse, pExpr, target, libc.Uint8FromInt32(op), libc.Uint8FromInt32(p5))
		} else {
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) && p5 != int32(SQLITE_NULLEQ) {
				addrIsNull = _exprComputeOperands(tls, pParse, pExpr, bp+8, bp+12, bp, bp+4)
			} else {
				**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
				**(**int32)(__ccgo_up(bp + 12)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), inReg)
			_codeCompare(tls, pParse, pLeft, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, op, **(**int32)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 12)), _sqlite3VdbeCurrentAddr(tls, v)+int32(2), p5, libc.BoolInt32((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Commuted)) != uint32(0)))
			if p5 == int32(SQLITE_NULLEQ) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, inReg)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_ZeroOrNull), **(**int32)(__ccgo_up(bp + 8)), inReg, **(**int32)(__ccgo_up(bp + 12)))
				if addrIsNull != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
					_sqlite3VdbeJumpHere(tls, v, addrIsNull)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, inReg)
				}
			}
		}
	case int32(TK_AND):
		fallthrough
	case int32(TK_OR):
		inReg = _exprCodeTargetAndOr(tls, pParse, pExpr, target, bp)
	case int32(TK_PLUS):
		fallthrough
	case int32(TK_STAR):
		fallthrough
	case int32(TK_MINUS):
		fallthrough
	case int32(TK_REM):
		fallthrough
	case int32(TK_BITAND):
		fallthrough
	case int32(TK_BITOR):
		fallthrough
	case int32(TK_SLASH):
		fallthrough
	case int32(TK_LSHIFT):
		fallthrough
	case int32(TK_RSHIFT):
		fallthrough
	case int32(TK_CONCAT):
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
			addrIsNull1 = _exprComputeOperands(tls, pParse, pExpr, bp+8, bp+12, bp, bp+4)
		} else {
			**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
			**(**int32)(__ccgo_up(bp + 12)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
			addrIsNull1 = 0
		}
		_sqlite3VdbeAddOp3(tls, v, op, **(**int32)(__ccgo_up(bp + 12)), **(**int32)(__ccgo_up(bp + 8)), target)
		if addrIsNull1 != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
			_sqlite3VdbeJumpHere(tls, v, addrIsNull1)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
		}
	case int32(TK_UMINUS):
		pLeft1 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft1)).Fop) == int32(TK_INTEGER) {
			_codeInteger(tls, pParse, pLeft1, int32(1), target)
			return target
		} else {
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft1)).Fop) == int32(TK_FLOAT) {
				_codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pLeft1 + 8)), int32(1), target)
				return target
			} else {
				(**(**TExpr)(__ccgo_up(bp + 16))).Fop = uint8(TK_INTEGER)
				(**(**TExpr)(__ccgo_up(bp + 16))).Fflags = libc.Uint32FromInt32(libc.Int32FromInt32(EP_IntValue) | libc.Int32FromInt32(EP_TokenOnly))
				*(*int32)(unsafe.Pointer(bp + 16 + 8)) = 0
				**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, bp+16, bp)
				**(**int32)(__ccgo_up(bp + 12)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp+4)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Subtract), **(**int32)(__ccgo_up(bp + 12)), **(**int32)(__ccgo_up(bp + 8)), target)
			}
		}
	case int32(TK_BITNOT):
		fallthrough
	case int32(TK_NOT):
		**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		_sqlite3VdbeAddOp2(tls, v, op, **(**int32)(__ccgo_up(bp + 8)), inReg)
	case int32(TK_TRUTH): /* IS TRUE or IS FALSE */
		**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		isTrue = _sqlite3ExprTruthValue(tls, (*TExpr)(unsafe.Pointer(pExpr)).FpRight)
		bNormal = libc.BoolInt32(libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2) == int32(TK_IS))
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsTrue), **(**int32)(__ccgo_up(bp + 8)), inReg, libc.BoolInt32(!(isTrue != 0)), isTrue^bNormal)
	case int32(TK_ISNULL):
		fallthrough
	case int32(TK_NOTNULL):
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), target)
		**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
		addr = _sqlite3VdbeAddOp1(tls, v, op, **(**int32)(__ccgo_up(bp + 8)))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, target)
		_sqlite3VdbeJumpHere(tls, v, addr)
	case int32(TK_AGG_FUNCTION):
		pInfo = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
		if pInfo == uintptr(0) || int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) < 0 || int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg) >= (*TAggInfo)(unsafe.Pointer(pInfo)).FnFunc {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8517, libc.VaList(bp+168, pExpr))
		} else {
			return (*TAggInfo)(unsafe.Pointer(pInfo)).FiFirstReg + (*TAggInfo)(unsafe.Pointer(pInfo)).FnColumn + int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
		}
	case int32(TK_FUNCTION): /* The function name */
		constMask = uint32(0)                      /* Loop counter */
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* The database connection */
		enc = (*Tsqlite3)(unsafe.Pointer(db)).Fenc /* The text encoding used by this database */
		pColl = uintptr(0)                         /* A collating sequence */
		if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
			return (*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FregResult
		}
		if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x100>>8)) != 0 && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
			/* SQL functions can be expensive. So try to avoid running them
			 ** multiple times if we know they always give the same result */
			return _sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, -int32(1))
		}
		pFarg = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		if pFarg != 0 {
			v1 = (*TExprList)(unsafe.Pointer(pFarg)).FnExpr
		} else {
			v1 = 0
		}
		nFarg = v1
		zId = *(*uintptr)(unsafe.Pointer(pExpr + 8))
		pDef = _sqlite3FindFunction(tls, db, zId, nFarg, enc, uint8(0))
		if pDef == uintptr(0) || (*TFuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8544, libc.VaList(bp+168, pExpr))
			break
		}
		if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_INLINE) != uint32(0) && pFarg != uintptr(0) {
			return _exprCodeInlineFunction(tls, pParse, pFarg, int32(int64((*TFuncDef)(unsafe.Pointer(pDef)).FpUserData)), target)
		} else {
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_DIRECT)|libc.Int32FromInt32(SQLITE_FUNC_UNSAFE)) != 0 {
				_sqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
			}
		}
		i = 0
		for {
			if !(i < nFarg) {
				break
			}
			if i < int32(32) && _sqlite3ExprIsConstant(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + uintptr(i)*32))).FpExpr) != 0 {
				constMask = constMask | libc.Uint32FromInt32(1)<<i
			}
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != uint32(0) && !(pColl != 0) {
				pColl = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + uintptr(i)*32))).FpExpr)
			}
			goto _9
		_9:
			;
			i = i + 1
		}
		if pFarg != 0 {
			if constMask != 0 {
				**(**int32)(__ccgo_up(bp + 8)) = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
				**(**int32)(__ccgo_up(pParse + 60)) += nFarg
			} else {
				**(**int32)(__ccgo_up(bp + 8)) = _sqlite3GetTempRange(tls, pParse, nFarg)
			}
			/* For length() and typeof() and octet_length() functions,
			 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
			 ** or OPFLAG_TYPEOFARG or OPFLAG_BYTELENARG respectively, to avoid
			 ** unnecessary data loading.
			 */
			if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FUNC_LENGTH)|libc.Int32FromInt32(SQLITE_FUNC_TYPEOF)) != uint32(0) {
				exprOp = (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)).Fop
				if libc.Int32FromUint8(exprOp) == int32(TK_COLUMN) || libc.Int32FromUint8(exprOp) == int32(TK_AGG_COLUMN) {
					(*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)).Fop2 = uint8((*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags & uint32(OPFLAG_BYTELENARG))
				}
			}
			_sqlite3ExprCodeExprList(tls, pParse, pFarg, **(**int32)(__ccgo_up(bp + 8)), 0, uint8(SQLITE_ECEL_FACTOR))
		} else {
			**(**int32)(__ccgo_up(bp + 8)) = 0
		}
		/* Possibly overload the function if the first argument is
		 ** a virtual table column.
		 **
		 ** For infix functions (LIKE, GLOB, REGEXP, and MATCH) use the
		 ** second argument, not the first, as the argument to test to
		 ** see if it is a column in a virtual table.  This is done because
		 ** the left operand of infix functions (the operand we want to
		 ** control overloading) ends up as the second argument to the
		 ** function.  The expression "A glob B" is equivalent to
		 ** "glob(B,A).  We want to use the A in "A glob B" to test
		 ** for function overloading.  But we use the B term in "glob(B,A)".
		 */
		if nFarg >= int32(2) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_InfixFunc)) != uint32(0) {
			pDef = _sqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8 + 1*32))).FpExpr)
		} else {
			if nFarg > 0 {
				pDef = _sqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*(*TExprList_item)(unsafe.Pointer(pFarg + 8))).FpExpr)
			}
		}
		if (*TFuncDef)(unsafe.Pointer(pDef)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
			if !(pColl != 0) {
				pColl = (*Tsqlite3)(unsafe.Pointer(db)).FpDfltColl
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_CollSeq), 0, 0, 0, pColl, -int32(2))
		}
		_sqlite3VdbeAddFunctionCall(tls, pParse, libc.Int32FromUint32(constMask), **(**int32)(__ccgo_up(bp + 8)), target, nFarg, pDef, libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop2))
		if nFarg != 0 {
			if constMask == uint32(0) {
				_sqlite3ReleaseTempRange(tls, pParse, **(**int32)(__ccgo_up(bp + 8)), nFarg)
			} else {
			}
		}
		return target
	case int32(TK_EXISTS):
		fallthrough
	case int32(TK_SELECT):
		if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
			return 0
		} else {
			if v2 = op == int32(TK_SELECT) && (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0); v2 {
				v1 = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList)).FnExpr
				nCol = v1
			}
			if v2 && v1 != int32(1) {
				_sqlite3SubselectError(tls, pParse, nCol, int32(1))
			} else {
				return _sqlite3CodeSubselect(tls, pParse, pExpr)
			}
		}
	case int32(TK_SELECT_COLUMN):
		pLeft2 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		if (*TExpr)(unsafe.Pointer(pLeft2)).FiTable == 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn) > libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pLeft2)).Fop2) {
			(*TExpr)(unsafe.Pointer(pLeft2)).FiTable = _sqlite3CodeSubselect(tls, pParse, pLeft2)
			(*TExpr)(unsafe.Pointer(pLeft2)).Fop2 = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn
		}
		n1 = _sqlite3ExprVectorSize(tls, pLeft2)
		if (*TExpr)(unsafe.Pointer(pExpr)).FiTable != n1 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8129, libc.VaList(bp+168, (*TExpr)(unsafe.Pointer(pExpr)).FiTable, n1))
		}
		return (*TExpr)(unsafe.Pointer(pLeft2)).FiTable + int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
	case int32(TK_IN):
		destIfFalse = _sqlite3VdbeMakeLabel(tls, pParse)
		destIfNull = _sqlite3VdbeMakeLabel(tls, pParse)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
		_sqlite3ExprCodeIN(tls, pParse, pExpr, destIfFalse, destIfNull)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), target)
		_sqlite3VdbeResolveLabel(tls, v, destIfFalse)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), target, 0)
		_sqlite3VdbeResolveLabel(tls, v, destIfNull)
		return target
		/*
		 **    x BETWEEN y AND z
		 **
		 ** This is equivalent to
		 **
		 **    x>=y AND x<=z
		 **
		 ** X is stored in pExpr->pLeft.
		 ** Y is stored in pExpr->pList->a[0].pExpr.
		 ** Z is stored in pExpr->pList->a[1].pExpr.
		 */
		fallthrough
	case int32(TK_BETWEEN):
		_exprCodeBetween(tls, pParse, pExpr, target, uintptr(0), 0)
		return target
	case int32(TK_COLLATE):
		if !((*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)) != libc.Uint32FromInt32(0)) {
			/* A TK_COLLATE Expr node without the EP_Collate tag is a so-called
			 ** "SOFT-COLLATE" that is added to constraints that are pushed down
			 ** from outer queries into sub-queries by the WHERE-clause push-down
			 ** optimization. Clear subtypes as subtypes may not cross a subquery
			 ** boundary.
			 */
			_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_ClrSubtype), target)
			return target
		} else {
			pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
			goto expr_code_doover /* 2018-04-28: Prevent deep recursion. */
		}
		fallthrough
	case int32(TK_SPAN):
		fallthrough
	case int32(TK_UPLUS):
		pExpr = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		goto expr_code_doover /* 2018-04-28: Prevent deep recursion. OSSFuzz. */
	case int32(TK_TRIGGER):
		pTab2 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
		iCol1 = int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn)
		p1 = (*TExpr)(unsafe.Pointer(pExpr)).FiTable*(int32((*TTable)(unsafe.Pointer(pTab2)).FnCol)+int32(1)) + int32(1) + int32(_sqlite3TableColumnToStorage(tls, pTab2, int16(iCol1)))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Param), p1, target)
		/* If the column has REAL affinity, it may currently be stored as an
		 ** integer. Use OP_RealAffinity to make sure it is really real.
		 **
		 ** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
		 ** floating point when extracting it from the record.  */
		if iCol1 >= 0 && libc.Int32FromUint8((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab2)).FaCol + uintptr(iCol1)*16))).Faffinity) == int32(SQLITE_AFF_REAL) {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_RealAffinity), target)
		}
	case int32(TK_VECTOR):
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+6912, 0)
		break
		/* TK_IF_NULL_ROW Expr nodes are inserted ahead of expressions
		 ** that derive from the right-hand table of a LEFT JOIN.  The
		 ** Expr.iTable value is the table number for the right-hand table.
		 ** The expression is only evaluated if that table is not currently
		 ** on a LEFT JOIN NULL row.
		 */
		fallthrough
	case int32(TK_IF_NULL_ROW):
		okConstFactor = libc.Uint8FromInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40)) & 0x100 >> 8)))
		pAggInfo1 = (*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo
		if pAggInfo1 != 0 {
			if !((*TAggInfo)(unsafe.Pointer(pAggInfo1)).FdirectMode != 0) {
				inReg = (*TAggInfo)(unsafe.Pointer(pAggInfo1)).FiFirstReg + int32((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)
				break
			}
			if (*TAggInfo)(unsafe.Pointer((*TExpr)(unsafe.Pointer(pExpr)).FpAggInfo)).FuseSortingIdx != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TAggInfo)(unsafe.Pointer(pAggInfo1)).FsortingIdxPTab, (**(**TAggInfo_col)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo1)).FaCol + uintptr((*TExpr)(unsafe.Pointer(pExpr)).FiAgg)*32))).FiSorterColumn, target)
				inReg = target
				break
			}
		}
		addrINR = _sqlite3VdbeAddOp3(tls, v, int32(OP_IfNullRow), (*TExpr)(unsafe.Pointer(pExpr)).FiTable, 0, target)
		/* The OP_IfNullRow opcode above can overwrite the result register with
		 ** NULL.  So we have to ensure that the result register is not a value
		 ** that is suppose to be a constant.  Two defenses are needed:
		 **   (1)  Temporarily disable factoring of constant expressions
		 **   (2)  Make sure the computed value really is stored in register
		 **        "target" and not someplace else.
		 */
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(0), 8, 0x100) /* note (1) above */
		_sqlite3ExprCode(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, target)
		libc.SetBitFieldPtr16Uint32(pParse+40, uint32(okConstFactor), 8, 0x100)
		_sqlite3VdbeJumpHere(tls, v, addrINR)
		break
		/*
		 ** Form A:
		 **   CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
		 **
		 ** Form B:
		 **   CASE WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
		 **
		 ** Form A is can be transformed into the equivalent form B as follows:
		 **   CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
		 **        WHEN x=eN THEN rN ELSE y END
		 **
		 ** X (if it exists) is in pExpr->pLeft.
		 ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
		 ** odd.  The Y is also optional.  If the number of elements in x.pList
		 ** is even, then Y is omitted and the "otherwise" result is NULL.
		 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
		 **
		 ** The result of the expression is the Ri for the first matching Ei,
		 ** or if there is no matching Ei, the ELSE term Y, or if there is
		 ** no ELSE term, NULL.
		 */
		fallthrough
	case int32(TK_CASE): /* The X expression */
		pTest = uintptr(0) /* X==Ei (form A) or just Ei (form B) */
		pDel = uintptr(0)
		db1 = (*TParse)(unsafe.Pointer(pParse)).Fdb
		pEList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		aListelem = pEList + 8
		nExpr = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
		endLabel = _sqlite3VdbeMakeLabel(tls, pParse)
		v3 = (*TExpr)(unsafe.Pointer(pExpr)).FpLeft
		pX = v3
		if v3 != uintptr(0) {
			pDel = _sqlite3ExprDup(tls, db1, pX, 0)
			if (*Tsqlite3)(unsafe.Pointer(db1)).FmallocFailed != 0 {
				_sqlite3ExprDelete(tls, db1, pDel)
				break
			}
			_sqlite3ExprToRegister(tls, pDel, _exprCodeVector(tls, pParse, pDel, bp))
			libc.Xmemset(tls, bp+88, 0, uint64(72))
			(**(**TExpr)(__ccgo_up(bp + 88))).Fop = uint8(TK_EQ)
			(**(**TExpr)(__ccgo_up(bp + 88))).FpLeft = pDel
			pTest = bp + 88
			/* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
			 ** The value in regFree1 might get SCopy-ed into the file result.
			 ** So make sure that the regFree1 register is not reused for other
			 ** purposes and possibly overwritten.  */
			**(**int32)(__ccgo_up(bp)) = 0
		}
		i1 = 0
		for {
			if !(i1 < nExpr-int32(1)) {
				break
			}
			if pX != 0 {
				(**(**TExpr)(__ccgo_up(bp + 88))).FpRight = (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1)*32))).FpExpr
			} else {
				pTest = (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1)*32))).FpExpr
			}
			nextCase = _sqlite3VdbeMakeLabel(tls, pParse)
			_sqlite3ExprIfFalse(tls, pParse, pTest, nextCase, int32(SQLITE_JUMPIFNULL))
			_sqlite3ExprCode(tls, pParse, (**(**TExprList_item)(__ccgo_up(aListelem + uintptr(i1+int32(1))*32))).FpExpr, target)
			_sqlite3VdbeGoto(tls, v, endLabel)
			_sqlite3VdbeResolveLabel(tls, v, nextCase)
			goto _13
		_13:
			;
			i1 = i1 + int32(2)
		}
		if nExpr&int32(1) != 0 {
			_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(nExpr-int32(1))*32))).FpExpr, target)
		} else {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, target)
		}
		_sqlite3ExprDelete(tls, db1, pDel)
		_setDoNotMergeFlagOnCopy(tls, v)
		_sqlite3VdbeResolveLabel(tls, v, endLabel)
	case int32(TK_RAISE):
		if !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+8568, 0)
			return 0
		}
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr) == int32(OE_Abort) {
			_sqlite3MayAbort(tls, pParse)
		}
		if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr) == int32(OE_Ignore) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Halt), SQLITE_OK, int32(OE_Ignore))
		} else {
			**(**int32)(__ccgo_up(bp + 8)) = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pExpr)).FpLeft, bp)
			if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
				v1 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(7)<<libc.Int32FromInt32(8)
			} else {
				v1 = int32(SQLITE_ERROR)
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Halt), v1, libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).FaffExpr), **(**int32)(__ccgo_up(bp + 8)))
		}
		break
	}
	_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp)))
	_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp + 4)))
	return inReg
}

// C documentation
//
//	/*
//	** Generate code to evaluate an expression and store the results
//	** into a register.  Return the register number where the results
//	** are stored.
//	**
//	** If the register is a temporary register that can be deallocated,
//	** then write its number into *pReg.  If the result register is not
//	** a temporary, then set *pReg to zero.
//	**
//	** If pExpr is a constant, then this routine might generate this
//	** code to fill the register in the initialization section of the
//	** VDBE program, in order to factor it out of the evaluation loop.
//	*/
func _sqlite3ExprCodeTemp(tls *libc.TLS, pParse uintptr, pExpr uintptr, pReg uintptr) (r int32) {
	var r1, r2 int32
	_, _ = r1, r2
	pExpr = _sqlite3ExprSkipCollateAndLikely(tls, pExpr)
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x100>>8)) != 0 && pExpr != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) != int32(TK_REGISTER) && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
		**(**int32)(__ccgo_up(pReg)) = 0
		r2 = _sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, -int32(1))
	} else {
		r1 = _sqlite3GetTempReg(tls, pParse)
		r2 = _sqlite3ExprCodeTarget(tls, pParse, pExpr, r1)
		if r2 == r1 {
			**(**int32)(__ccgo_up(pReg)) = r1
		} else {
			_sqlite3ReleaseTempReg(tls, pParse, r1)
			**(**int32)(__ccgo_up(pReg)) = 0
		}
	}
	return r2
}

// C documentation
//
//	/*
//	** Set the sort order for the last element on the given ExprList.
//	*/
func _sqlite3ExprListSetSortOrder(tls *libc.TLS, p uintptr, iSortOrder int32, eNulls int32) {
	var pItem, v1 uintptr
	_, _ = pItem, v1
	if p == uintptr(0) {
		return
	}
	pItem = p + 8 + uintptr((*TExprList)(unsafe.Pointer(p)).FnExpr-int32(1))*32
	if iSortOrder == -int32(1) {
		iSortOrder = SQLITE_SO_ASC
	}
	(*TExprList_item)(unsafe.Pointer(pItem)).Ffg.FsortFlags = libc.Uint8FromInt32(iSortOrder)
	if eNulls != -int32(1) {
		libc.SetBitFieldPtr16Uint32(pItem+16+4, libc.Uint32FromInt32(1), 10, 0x400)
		if iSortOrder != eNulls {
			v1 = pItem + 16
			*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(KEYINFO_ORDER_BIGNULL))
		}
	}
}

// C documentation
//
//	/*
//	** Set the ExprList.a[].zSpan element of the most recently added item
//	** on the expression list.
//	**
//	** pList might be NULL following an OOM error.  But pSpan should never be
//	** NULL.  If a memory allocation fails, the pParse->db->mallocFailed flag
//	** is set.
//	*/
func _sqlite3ExprListSetSpan(tls *libc.TLS, pParse uintptr, pList uintptr, zStart uintptr, zEnd uintptr) {
	var db, pItem uintptr
	_, _ = db, pItem
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pList != 0 {
		pItem = pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*32
		if (*TExprList_item)(unsafe.Pointer(pItem)).FzEName == uintptr(0) {
			(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
			libc.SetBitFieldPtr16Uint32(pItem+16+4, libc.Uint32FromInt32(ENAME_SPAN), 14, 0xc000)
		}
	}
}

// C documentation
//
//	/*
//	** Make arrangements to invoke OP_Null on a range of registers
//	** during initialization.
//	*/
func _sqlite3ExprNullRegisterRange(tls *libc.TLS, pParse uintptr, iReg int32, nReg int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var okConstFactor Tu8
	var _ /* t at bp+0 */ TExpr
	_ = okConstFactor
	okConstFactor = libc.Uint8FromInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40)) & 0x100 >> 8)))
	libc.Xmemset(tls, bp, 0, uint64(72))
	(**(**TExpr)(__ccgo_up(bp))).Fop = uint8(TK_NULLS)
	*(*int32)(unsafe.Pointer(bp + 64)) = nReg
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
	_sqlite3ExprCodeRunJustOnce(tls, pParse, bp, iReg)
	libc.SetBitFieldPtr16Uint32(pParse+40, uint32(okConstFactor), 8, 0x100)
}

// C documentation
//
//	/*
//	** This routine is called after a single SQL statement has been
//	** parsed and a VDBE program to execute that statement has been
//	** prepared.  This routine puts the finishing touches on the
//	** VDBE program and resets the pParse structure for the next
//	** parse.
//	**
//	** Note that if an error occurred, it might be the case that
//	** no VDBE code was generated.
//	*/
func _sqlite3FinishCoding(tls *libc.TLS, pParse uintptr) {
	var addrRewind, i, iDb, reg, v2 int32
	var db, pEL, pRet, pReturning, pSchema, v, vtab uintptr
	_, _, _, _, _, _, _, _, _, _, _, _ = addrRewind, db, i, iDb, pEL, pRet, pReturning, pSchema, reg, v, vtab, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).Fnested != 0 {
		return
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
		}
		return
	}
	/* Begin by generating some termination code at the end of the
	 ** vdbe program
	 */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if v == uintptr(0) {
		if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 {
			(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_DONE)
			return
		}
		v = _sqlite3GetVdbe(tls, pParse)
		if v == uintptr(0) {
			(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
		}
	}
	if v != 0 {
		if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0 {
			pReturning = (*(*struct {
				FpReturning uintptr
			})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning
			if (*TReturning)(unsafe.Pointer(pReturning)).FnRetCol != 0 {
				_sqlite3VdbeAddOp0(tls, v, int32(OP_FkCheck))
				addrRewind = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur)
				reg = (*TReturning)(unsafe.Pointer(pReturning)).FiRetReg
				i = 0
				for {
					if !(i < (*TReturning)(unsafe.Pointer(pReturning)).FnRetCol) {
						break
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur, i, reg+i)
					goto _1
				_1:
					;
					i = i + 1
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), reg, i)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), (*TReturning)(unsafe.Pointer(pReturning)).FiRetCur, addrRewind+int32(1))
				_sqlite3VdbeJumpHere(tls, v, addrRewind)
			}
		}
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Halt))
		/* The cookie mask contains one bit for each database file open.
		 ** (Bit 0 is for main, bit 1 is for temp, and so forth.)  Bits are
		 ** set for each database that is used.  Generate code to start a
		 ** transaction on each used database and to verify the schema cookie
		 ** on each used database.
		 */
		_sqlite3VdbeJumpHere(tls, v, 0)
		iDb = 0
		for {
			if libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FcookieMask&(libc.Uint32FromInt32(1)<<iDb) != uint32(0)) == 0 {
				goto _3
			}
			_sqlite3VdbeUsesBtree(tls, v, iDb)
			pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
			_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Transaction), iDb, libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FwriteMask&(libc.Uint32FromInt32(1)<<iDb) != uint32(0)), (*TSchema)(unsafe.Pointer(pSchema)).Fschema_cookie, (*TSchema)(unsafe.Pointer(pSchema)).FiGeneration)
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
				_sqlite3VdbeChangeP5(tls, v, uint16(1))
			}
			goto _3
		_3:
			;
			iDb = iDb + 1
			v2 = iDb
			if !(v2 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
		}
		i = 0
		for {
			if !(i < (*TParse)(unsafe.Pointer(pParse)).FnVtabLock) {
				break
			}
			vtab = _sqlite3GetVTable(tls, db, **(**uintptr)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).FapVtabLock + uintptr(i)*8)))
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VBegin), 0, 0, 0, vtab, -int32(12))
			goto _4
		_4:
			;
			i = i + 1
		}
		(*TParse)(unsafe.Pointer(pParse)).FnVtabLock = 0
		/* Once all the cookies have been verified and transactions opened,
		 ** obtain the required table-locks. This is a no-op unless the
		 ** shared-cache feature is enabled.
		 */
		if (*TParse)(unsafe.Pointer(pParse)).FnTableLock != 0 {
			_codeTableLocks(tls, pParse)
		}
		/* Initialize any AUTOINCREMENT data structures required.
		 */
		if (*TParse)(unsafe.Pointer(pParse)).FpAinc != 0 {
			_sqlite3AutoincrementBegin(tls, pParse)
		}
		/* Code constant expressions that were factored out of inner loops.
		 */
		if (*TParse)(unsafe.Pointer(pParse)).FpConstExpr != 0 {
			pEL = (*TParse)(unsafe.Pointer(pParse)).FpConstExpr
			libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(0), 8, 0x100)
			i = 0
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pEL)).FnExpr) {
					break
				}
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pEL + 8 + uintptr(i)*32))).FpExpr, *(*int32)(unsafe.Pointer(pEL + 8 + uintptr(i)*32 + 24)))
				goto _5
			_5:
				;
				i = i + 1
			}
		}
		if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0 {
			pRet = (*(*struct {
				FpReturning uintptr
			})(unsafe.Pointer(&(*TParse)(unsafe.Pointer(pParse)).Fu1))).FpReturning
			if (*TReturning)(unsafe.Pointer(pRet)).FnRetCol != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TReturning)(unsafe.Pointer(pRet)).FiRetCur, (*TReturning)(unsafe.Pointer(pRet)).FnRetCol)
			}
		}
		/* Finally, jump back to the beginning of the executable code. */
		_sqlite3VdbeGoto(tls, v, int32(1))
	}
	/* Get the VDBE program ready for execution
	 */
	if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
		/* A minimum of one cursor is required if autoincrement is used
		 *  See ticket [a696379c1f08866] */
		_sqlite3VdbeMakeReady(tls, v, pParse)
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_DONE)
	} else {
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_ERROR)
	}
}

// C documentation
//
//	/*
//	** This function is called when inserting, deleting or updating a row of
//	** table pTab to generate VDBE code to perform foreign key constraint
//	** processing for the operation.
//	**
//	** For a DELETE operation, parameter regOld is passed the index of the
//	** first register in an array of (pTab->nCol+1) registers containing the
//	** rowid of the row being deleted, followed by each of the column values
//	** of the row being deleted, from left to right. Parameter regNew is passed
//	** zero in this case.
//	**
//	** For an INSERT operation, regOld is passed zero and regNew is passed the
//	** first register of an array of (pTab->nCol+1) registers containing the new
//	** row data.
//	**
//	** For an UPDATE operation, this function is called twice. Once before
//	** the original record is deleted from the table using the calling convention
//	** described for DELETE. Then again after the original record is deleted
//	** but before the new record is inserted using the INSERT convention.
//	*/
func _sqlite3FkCheck(tls *libc.TLS, pParse uintptr, pTab uintptr, regOld int32, regNew int32, aChange uintptr, bChngRowid int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aiCol, db, pFKey, pItem, pSrc, pTo, v, zCol, zDb, v7 uintptr
	var bIgnore, eAction, i, iDb, iFromCol, iJump, iReg, isIgnoreErrors, rcauth, v4 int32
	var _ /* aiCol at bp+32 */ uintptr
	var _ /* aiFree at bp+8 */ uintptr
	var _ /* iCol at bp+16 */ int32
	var _ /* pIdx at bp+0 */ uintptr
	var _ /* pIdx at bp+24 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aiCol, bIgnore, db, eAction, i, iDb, iFromCol, iJump, iReg, isIgnoreErrors, pFKey, pItem, pSrc, pTo, rcauth, v, zCol, zDb, v4, v7
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Name of database containing pTab */
	isIgnoreErrors = int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40)) & 0x8000 >> 15))
	/* Exactly one of regOld and regNew should be non-zero. */
	/* If foreign-keys are disabled, this function is a no-op. */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) == uint64(0) {
		return
	}
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		return
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	/* Loop through all the foreign key constraints for which pTab is the
	 ** child table (the table that the foreign key definition is part of).  */
	pFKey = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 64))).FpFKey
	for {
		if !(pFKey != 0) {
			break
		} /* Parent table of foreign key pFKey */
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Index on key columns in pTo */
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		bIgnore = 0
		if aChange != 0 && Xsqlite3_stricmp(tls, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TFKey)(unsafe.Pointer(pFKey)).FzTo) != 0 && _fkChildIsModified(tls, pTab, pFKey, aChange, bChngRowid) == 0 {
			goto _1
		}
		/* Find the parent table of this foreign key. Also find a unique index
		 ** on the parent key columns in the parent table. If either of these
		 ** schema items cannot be located, set an error in pParse and return
		 ** early.  */
		if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x8000>>15)) != 0 {
			pTo = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zDb)
		} else {
			pTo = _sqlite3LocateTable(tls, pParse, uint32(0), (*TFKey)(unsafe.Pointer(pFKey)).FzTo, zDb)
		}
		if !(pTo != 0) || _sqlite3FkLocateIndex(tls, pParse, pTo, pFKey, bp, bp+8) != 0 {
			if !(isIgnoreErrors != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return
			}
			if pTo == uintptr(0) {
				/* If isIgnoreErrors is true, then a table is being dropped. In this
				 ** case SQLite runs a "DELETE FROM xxx" on the table being dropped
				 ** before actually dropping it in order to check FK constraints.
				 ** If the parent table of an FK constraint on the current table is
				 ** missing, behave as if it is empty. i.e. decrement the relevant
				 ** FK counter for each row of the current table with non-NULL keys.
				 */
				v = _sqlite3GetVdbe(tls, pParse)
				iJump = _sqlite3VdbeCurrentAddr(tls, v) + (*TFKey)(unsafe.Pointer(pFKey)).FnCol + int32(1)
				i = 0
				for {
					if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
						break
					}
					iFromCol = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom
					iReg = int32(_sqlite3TableColumnToStorage(tls, (*TFKey)(unsafe.Pointer(pFKey)).FpFrom, int16(iFromCol))) + regOld + int32(1)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), iReg, iJump)
					goto _2
				_2:
					;
					i = i + 1
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_FkCounter), libc.Int32FromUint8((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred), -int32(1))
			}
			goto _1
		}
		if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
			aiCol = **(**uintptr)(__ccgo_up(bp + 8))
		} else {
			**(**int32)(__ccgo_up(bp + 16)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).FiFrom
			aiCol = bp + 16
		}
		i = 0
		for {
			if !(i < (*TFKey)(unsafe.Pointer(pFKey)).FnCol) {
				break
			}
			if **(**int32)(__ccgo_up(aiCol + uintptr(i)*4)) == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
				**(**int32)(__ccgo_up(aiCol + uintptr(i)*4)) = -int32(1)
			}
			/* Request permission to read the parent key columns. If the
			 ** authorization callback returns SQLITE_IGNORE, behave as if any
			 ** values read from the parent table are NULL. */
			if (*Tsqlite3)(unsafe.Pointer(db)).FxAuth != 0 {
				if **(**uintptr)(__ccgo_up(bp)) != 0 {
					v4 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FaiColumn + uintptr(i)*2)))
				} else {
					v4 = int32((*TTable)(unsafe.Pointer(pTo)).FiPKey)
				}
				zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTo)).FaCol + uintptr(v4)*16))).FzCnName
				rcauth = _sqlite3AuthReadCol(tls, pParse, (*TTable)(unsafe.Pointer(pTo)).FzName, zCol, iDb)
				bIgnore = libc.BoolInt32(rcauth == int32(SQLITE_IGNORE))
			}
			goto _3
		_3:
			;
			i = i + 1
		}
		/* Take a shared-cache advisory read-lock on the parent table. Allocate
		 ** a cursor to use to search the unique index on the parent key columns
		 ** in the parent table.  */
		_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTo)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTo)).FzName)
		(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab + 1
		if regOld != 0 {
			/* A row is being removed from the child table. Search for the parent.
			 ** If the parent does not exist, removing the child row resolves an
			 ** outstanding foreign key constraint violation. */
			_fkLookupParent(tls, pParse, iDb, pTo, **(**uintptr)(__ccgo_up(bp)), pFKey, aiCol, regOld, -int32(1), bIgnore)
		}
		if regNew != 0 && !(_isSetNullAction(tls, pParse, pFKey) != 0) {
			/* A row is being added to the child table. If a parent row cannot
			 ** be found, adding the child row has violated the FK constraint.
			 **
			 ** If this operation is being performed as part of a trigger program
			 ** that is actually a "SET NULL" action belonging to this very
			 ** foreign key, then omit this scan altogether. As all child key
			 ** values are guaranteed to be NULL, it is not possible for adding
			 ** this row to cause an FK violation.  */
			_fkLookupParent(tls, pParse, iDb, pTo, **(**uintptr)(__ccgo_up(bp)), pFKey, aiCol, regNew, +libc.Int32FromInt32(1), bIgnore)
		}
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 8)))
		goto _1
	_1:
		;
		pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
	}
	/* Loop through all the foreign key constraints that refer to this table.
	 ** (the "child" constraints) */
	pFKey = _sqlite3FkReferences(tls, pTab)
	for {
		if !(pFKey != 0) {
			break
		}
		**(**uintptr)(__ccgo_up(bp + 24)) = uintptr(0)
		**(**uintptr)(__ccgo_up(bp + 32)) = uintptr(0)
		if aChange != 0 && _fkParentIsModified(tls, pTab, pFKey, aChange, bChngRowid) == 0 {
			goto _5
		}
		if !((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred != 0) && !((*Tsqlite3)(unsafe.Pointer(db)).Fflags&libc.Uint64FromInt32(SQLITE_DeferFKs) != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0) && !((*TParse)(unsafe.Pointer(pParse)).FisMultiWrite != 0) {
			/* Inserting a single row into a parent table cannot cause (or fix)
			 ** an immediate foreign key violation. So do nothing in this case.  */
			goto _5
		}
		if _sqlite3FkLocateIndex(tls, pParse, pTab, pFKey, bp+24, bp+32) != 0 {
			if !(isIgnoreErrors != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return
			}
			goto _5
		}
		/* Create a SrcList structure containing the child table.  We need the
		 ** child table as a SrcList for sqlite3WhereBegin() */
		pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
		if pSrc != 0 {
			pItem = pSrc + 8
			(*TSrcItem)(unsafe.Pointer(pItem)).FpSTab = (*TFKey)(unsafe.Pointer(pFKey)).FpFrom
			(*TSrcItem)(unsafe.Pointer(pItem)).FzName = (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName
			(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FnTabRef = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FnTabRef + 1
			v7 = pParse + 56
			v4 = *(*int32)(unsafe.Pointer(v7))
			*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = v4
			if regNew != 0 {
				_fkScanChildren(tls, pParse, pSrc, pTab, **(**uintptr)(__ccgo_up(bp + 24)), pFKey, **(**uintptr)(__ccgo_up(bp + 32)), regNew, -int32(1))
			}
			if regOld != 0 {
				eAction = libc.Int32FromUint8(**(**Tu8)(__ccgo_up(pFKey + 45 + libc.BoolUintptr(aChange != uintptr(0)))))
				if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00008))<<libc.Int32FromInt32(32)) != 0 {
					eAction = OE_None
				}
				_fkScanChildren(tls, pParse, pSrc, pTab, **(**uintptr)(__ccgo_up(bp + 24)), pFKey, **(**uintptr)(__ccgo_up(bp + 32)), regOld, int32(1))
				/* If this is a deferred FK constraint, or a CASCADE or SET NULL
				 ** action applies, then any foreign key violations caused by
				 ** removing the parent key will be rectified by the action trigger.
				 ** So do not set the "may-abort" flag in this case.
				 **
				 ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
				 ** may-abort flag will eventually be set on this statement anyway
				 ** (when this function is called as part of processing the UPDATE
				 ** within the action trigger).
				 **
				 ** Note 2: At first glance it may seem like SQLite could simply omit
				 ** all OP_FkCounter related scans when either CASCADE or SET NULL
				 ** applies. The trouble starts if the CASCADE or SET NULL action
				 ** trigger causes other triggers or action rules attached to the
				 ** child table to fire. In these cases the fk constraint counters
				 ** might be set incorrectly if any OP_FkCounter related scans are
				 ** omitted.  */
				if !((*TFKey)(unsafe.Pointer(pFKey)).FisDeferred != 0) && eAction != int32(OE_Cascade) && eAction != int32(OE_SetNull) {
					_sqlite3MayAbort(tls, pParse)
				}
			}
			(*TSrcItem)(unsafe.Pointer(pItem)).FzName = uintptr(0)
			_sqlite3SrcListDelete(tls, db, pSrc)
		}
		_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 32)))
		goto _5
	_5:
		;
		pFKey = (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo
	}
}

// C documentation
//
//	/*
//	** This function is called to generate code that runs when table pTab is
//	** being dropped from the database. The SrcList passed as the second argument
//	** to this function contains a single entry guaranteed to resolve to
//	** table pTab.
//	**
//	** Normally, no code is required. However, if either
//	**
//	**   (a) The table is the parent table of a FK constraint, or
//	**   (b) The table is the child table of a deferred FK constraint and it is
//	**       determined at runtime that there are outstanding deferred FK
//	**       constraint violations in the database,
//	**
//	** then the equivalent of "DELETE FROM <tbl>" is executed before dropping
//	** the table from the database. Triggers are disabled while running this
//	** DELETE, but foreign key actions are not.
//	*/
func _sqlite3FkDropTable(tls *libc.TLS, pParse uintptr, pName uintptr, pTab uintptr) {
	var db, p, v uintptr
	var iSkip int32
	_, _, _, _ = db, iSkip, p, v
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM {
		iSkip = 0
		v = _sqlite3GetVdbe(tls, pParse)
		/* VDBE has already been allocated */
		if _sqlite3FkReferences(tls, pTab) == uintptr(0) {
			p = (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab + 64))).FpFKey
			for {
				if !(p != 0) {
					break
				}
				if (*TFKey)(unsafe.Pointer(p)).FisDeferred != 0 || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
					break
				}
				goto _1
			_1:
				;
				p = (*TFKey)(unsafe.Pointer(p)).FpNextFrom
			}
			if !(p != 0) {
				return
			}
			iSkip = _sqlite3VdbeMakeLabel(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_FkIfZero), int32(1), iSkip)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 15, 0x8000)
		_sqlite3DeleteFrom(tls, pParse, _sqlite3SrcListDup(tls, db, pName, 0), uintptr(0), uintptr(0), uintptr(0))
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(0), 15, 0x8000)
		/* If the DELETE has generated immediate foreign key constraint
		 ** violations, halt the VDBE and return an error at this point, before
		 ** any modifications to the schema are made. This is because statement
		 ** transactions are not able to rollback schema changes.
		 **
		 ** If the SQLITE_DeferFKs flag is set, then this is not required, as
		 ** the statement transaction will not be rolled back even if FK
		 ** constraints are violated.
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) == uint64(0) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_FkIfZero), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
			_sqlite3HaltConstraint(tls, pParse, libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), int32(OE_Abort), uintptr(0), int8(-libc.Int32FromInt32(1)), uint8(P5_ConstraintFK))
		}
		if iSkip != 0 {
			_sqlite3VdbeResolveLabel(tls, v, iSkip)
		}
	}
}

// C documentation
//
//	/*
//	** A foreign key constraint requires that the key columns in the parent
//	** table are collectively subject to a UNIQUE or PRIMARY KEY constraint.
//	** Given that pParent is the parent table for foreign key constraint pFKey,
//	** search the schema for a unique index on the parent key columns.
//	**
//	** If successful, zero is returned. If the parent key is an INTEGER PRIMARY
//	** KEY column, then output variable *ppIdx is set to NULL. Otherwise, *ppIdx
//	** is set to point to the unique index.
//	**
//	** If the parent key consists of a single column (the foreign key constraint
//	** is not a composite foreign key), output variable *paiCol is set to NULL.
//	** Otherwise, it is set to point to an allocated array of size N, where
//	** N is the number of columns in the parent key. The first element of the
//	** array is the index of the child table column that is mapped by the FK
//	** constraint to the parent table column stored in the left-most column
//	** of index *ppIdx. The second element of the array is the index of the
//	** child table column that corresponds to the second left-most column of
//	** *ppIdx, and so on.
//	**
//	** If the required index cannot be found, either because:
//	**
//	**   1) The named parent key columns do not exist, or
//	**
//	**   2) The named parent key columns do exist, but are not subject to a
//	**      UNIQUE or PRIMARY KEY constraint, or
//	**
//	**   3) No parent key columns were provided explicitly as part of the
//	**      foreign key definition, and the parent table does not have a
//	**      PRIMARY KEY, or
//	**
//	**   4) No parent key columns were provided explicitly as part of the
//	**      foreign key definition, and the PRIMARY KEY of the parent table
//	**      consists of a different number of columns to the child key in
//	**      the child table.
//	**
//	** then non-zero is returned, and a "foreign key mismatch" error loaded
//	** into pParse. If an OOM error occurs, non-zero is returned and the
//	** pParse->db->mallocFailed flag is set.
//	*/
func _sqlite3FkLocateIndex(tls *libc.TLS, pParse uintptr, pParent uintptr, pFKey uintptr, ppIdx uintptr, paiCol uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aiCol, pIdx, zDfltColl, zIdxCol, zKey uintptr
	var i, i1, j, nCol int32
	var iCol Ti16
	_, _, _, _, _, _, _, _, _, _ = aiCol, i, i1, iCol, j, nCol, pIdx, zDfltColl, zIdxCol, zKey
	pIdx = uintptr(0)                                       /* Value to return via *ppIdx */
	aiCol = uintptr(0)                                      /* Value to return via *paiCol */
	nCol = (*TFKey)(unsafe.Pointer(pFKey)).FnCol            /* Number of columns in parent key */
	zKey = (*(*TsColMap)(unsafe.Pointer(pFKey + 64))).FzCol /* Name of left-most parent key column */
	/* The caller is responsible for zeroing output parameters. */
	/* If this is a non-composite (single column) foreign key, check if it
	 ** maps to the INTEGER PRIMARY KEY of table pParent. If so, leave *ppIdx
	 ** and *paiCol set to zero and return early.
	 **
	 ** Otherwise, for a composite foreign key (more than one column), allocate
	 ** space for the aiCol array (returned via output parameter *paiCol).
	 ** Non-composite foreign keys do not require the aiCol array.
	 */
	if nCol == int32(1) {
		/* The FK maps to the IPK if any of the following are true:
		 **
		 **   1) There is an INTEGER PRIMARY KEY column and the FK is implicitly
		 **      mapped to the primary key of table pParent, or
		 **   2) The FK is explicitly mapped to a column declared as INTEGER
		 **      PRIMARY KEY.
		 */
		if int32((*TTable)(unsafe.Pointer(pParent)).FiPKey) >= 0 {
			if !(zKey != 0) {
				return 0
			}
			if !(_sqlite3StrICmp(tls, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr((*TTable)(unsafe.Pointer(pParent)).FiPKey)*16))).FzCnName, zKey) != 0) {
				return 0
			}
		}
	} else {
		if paiCol != 0 {
			aiCol = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(libc.Uint64FromInt32(nCol)*uint64(4)))
			if !(aiCol != 0) {
				return int32(1)
			}
			**(**uintptr)(__ccgo_up(paiCol)) = aiCol
		}
	}
	pIdx = (*TTable)(unsafe.Pointer(pParent)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) == nCol && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != OE_None && (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
			/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
			 ** of columns. If each indexed column corresponds to a foreign key
			 ** column of pFKey, then this index is a winner.  */
			if zKey == uintptr(0) {
				/* If zKey is NULL, then this foreign key is implicitly mapped to
				 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
				 ** identified by the test.  */
				if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
					if aiCol != 0 {
						i = 0
						for {
							if !(i < nCol) {
								break
							}
							**(**int32)(__ccgo_up(aiCol + uintptr(i)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16))).FiFrom
							goto _2
						_2:
							;
							i = i + 1
						}
					}
					break
				}
			} else {
				i1 = 0
				for {
					if !(i1 < nCol) {
						break
					}
					iCol = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2)) /* Name of indexed column */
					if int32(iCol) < 0 {
						break
					} /* No foreign keys against expression indexes */
					/* If the index uses a collation sequence that is different from
					 ** the default collation sequence for the column, this index is
					 ** unusable. Bail out early in this case.  */
					zDfltColl = _sqlite3ColumnColl(tls, (*TTable)(unsafe.Pointer(pParent)).FaCol+uintptr(iCol)*16)
					if !(zDfltColl != 0) {
						zDfltColl = uintptr(unsafe.Pointer(&_sqlite3StrBINARY))
					}
					if _sqlite3StrICmp(tls, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*8)), zDfltColl) != 0 {
						break
					}
					zIdxCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pParent)).FaCol + uintptr(iCol)*16))).FzCnName
					j = 0
					for {
						if !(j < nCol) {
							break
						}
						if _sqlite3StrICmp(tls, (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FzCol, zIdxCol) == 0 {
							if aiCol != 0 {
								**(**int32)(__ccgo_up(aiCol + uintptr(i1)*4)) = (*(*TsColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16))).FiFrom
							}
							break
						}
						goto _4
					_4:
						;
						j = j + 1
					}
					if j == nCol {
						break
					}
					goto _3
				_3:
					;
					i1 = i1 + 1
				}
				if i1 == nCol {
					break
				} /* pIdx is usable */
			}
		}
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	if !(pIdx != 0) {
		if !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x8000>>15)) != 0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17304, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName, (*TFKey)(unsafe.Pointer(pFKey)).FzTo))
		}
		_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, aiCol)
		return int32(1)
	}
	**(**uintptr)(__ccgo_up(ppIdx)) = pIdx
	return 0
}

// C documentation
//
//	/*
//	** Reclaim the memory used by an index
//	*/
func _sqlite3FreeIndex(tls *libc.TLS, db uintptr, p uintptr) {
	_sqlite3DeleteIndexSamples(tls, db, p)
	_sqlite3ExprDelete(tls, db, (*TIndex)(unsafe.Pointer(p)).FpPartIdxWhere)
	_sqlite3ExprListDelete(tls, db, (*TIndex)(unsafe.Pointer(p)).FaColExpr)
	_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(p)).FzColAff)
	if int32(uint32(*(*uint16)(unsafe.Pointer(p + 100))&0x800>>11)) != 0 {
		_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(p)).FazColl)
	}
	Xsqlite3_free(tls, (*TIndex)(unsafe.Pointer(p)).FaiRowEst)
	_sqlite3DbFree(tls, db, p)
}

// C documentation
//
//	/*
//	** Compute the column names for a SELECT statement.
//	**
//	** The only guarantee that SQLite makes about column names is that if the
//	** column has an AS clause assigning it a name, that will be the name used.
//	** That is the only documented guarantee.  However, countless applications
//	** developed over the years have made baseless assumptions about column names
//	** and will break if those assumptions changes.  Hence, use extreme caution
//	** when modifying this routine to avoid breaking legacy.
//	**
//	** See Also: sqlite3ColumnsFromExprList()
//	**
//	** The PRAGMA short_column_names and PRAGMA full_column_names settings are
//	** deprecated.  The default setting is short=ON, full=OFF.  99.9% of all
//	** applications should operate this way.  Nevertheless, we need to support the
//	** other modes for legacy:
//	**
//	**    short=OFF, full=OFF:      Column name is the text of the expression has it
//	**                              originally appears in the SELECT statement.  In
//	**                              other words, the zSpan of the result expression.
//	**
//	**    short=ON, full=OFF:       (This is the default setting).  If the result
//	**                              refers directly to a table column, then the
//	**                              result column name is just the table column
//	**                              name: COLUMN.  Otherwise use zSpan.
//	**
//	**    full=ON, short=ANY:       If the result refers directly to a table column,
//	**                              then the result column name with the table name
//	**                              prefix, ex: TABLE.COLUMN.  Otherwise use zSpan.
//	*/
func _sqlite3GenerateColumnNames(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pEList, pTab, pTabList, v, z, zCol, zName, zName1, v2 uintptr
	var fullName, i, iCol, srcName int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, fullName, i, iCol, p, pEList, pTab, pTabList, srcName, v, z, zCol, zName, zName1, v2
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* COLUMN or TABLE.COLUMN if no AS clause and is direct */
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x400>>10)) != 0 {
		return
	}
	/* Column names are determined by the left-most term of a compound select */
	for (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*TSelect)(unsafe.Pointer(pSelect)).FpPrior
	}
	pTabList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 10, 0x400)
	fullName = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_FullColNames) != uint64(0))
	srcName = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ShortColNames) != uint64(0) || fullName != 0)
	_sqlite3VdbeSetNumCols(tls, v, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		p = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FpExpr
		/* Agg processing has not run yet */
		/* Covering idx not yet coded */
		if (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0xc000>>14)) == ENAME_NAME {
			/* An AS clause always takes first priority */
			zName = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
			_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName, uintptr(-libc.Int32FromInt32(1)))
		} else {
			if srcName != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p)).Fop) == int32(TK_COLUMN) {
				iCol = int32((*TExpr)(unsafe.Pointer(p)).FiColumn)
				pTab = *(*uintptr)(unsafe.Pointer(p + 64))
				if iCol < 0 {
					iCol = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
				}
				if iCol < 0 {
					zCol = __ccgo_ts + 17967
				} else {
					zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*16))).FzCnName
				}
				if fullName != 0 {
					zName1 = uintptr(0)
					zName1 = _sqlite3MPrintf(tls, db, __ccgo_ts+13636, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, zCol))
					_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName1, __ccgo_fp(_sqlite3RowSetClear))
				} else {
					_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zCol, uintptr(-libc.Int32FromInt32(1)))
				}
			} else {
				z = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName
				if z == uintptr(0) {
					v2 = _sqlite3MPrintf(tls, db, __ccgo_ts+20636, libc.VaList(bp+8, i+int32(1)))
				} else {
					v2 = _sqlite3DbStrDup(tls, db, z)
				}
				z = v2
				_sqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, z, __ccgo_fp(_sqlite3RowSetClear))
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	_generateColumnTypes(tls, pParse, pTabList, pEList)
}

// C documentation
//
//	/*
//	** Generate code to do constraint checks prior to an INSERT or an UPDATE
//	** on table pTab.
//	**
//	** The regNewData parameter is the first register in a range that contains
//	** the data to be inserted or the data after the update.  There will be
//	** pTab->nCol+1 registers in this range.  The first register (the one
//	** that regNewData points to) will contain the new rowid, or NULL in the
//	** case of a WITHOUT ROWID table.  The second register in the range will
//	** contain the content of the first table column.  The third register will
//	** contain the content of the second table column.  And so forth.
//	**
//	** The regOldData parameter is similar to regNewData except that it contains
//	** the data prior to an UPDATE rather than afterwards.  regOldData is zero
//	** for an INSERT.  This routine can distinguish between UPDATE and INSERT by
//	** checking regOldData for zero.
//	**
//	** For an UPDATE, the pkChng boolean is true if the true primary key (the
//	** rowid for a normal table or the PRIMARY KEY for a WITHOUT ROWID table)
//	** might be modified by the UPDATE.  If pkChng is false, then the key of
//	** the iDataCur content table is guaranteed to be unchanged by the UPDATE.
//	**
//	** For an INSERT, the pkChng boolean indicates whether or not the rowid
//	** was explicitly specified as part of the INSERT statement.  If pkChng
//	** is zero, it means that the either rowid is computed automatically or
//	** that the table is a WITHOUT ROWID table and has no rowid.  On an INSERT,
//	** pkChng will only be true if the INSERT statement provides an integer
//	** value for either the rowid column or its INTEGER PRIMARY KEY alias.
//	**
//	** The code generated by this routine will store new index entries into
//	** registers identified by aRegIdx[].  No index entry is created for
//	** indices where aRegIdx[i]==0.  The order of indices in aRegIdx[] is
//	** the same as the order of indices on the linked list of indices
//	** at pTab->pIndex.
//	**
//	** (2019-05-07) The generated code also creates a new record for the
//	** main table, if pTab is a rowid table, and stores that record in the
//	** register identified by aRegIdx[nIdx] - in other words in the first
//	** entry of aRegIdx[] past the last index.  It is important that the
//	** record be generated during constraint checks to avoid affinity changes
//	** to the register content that occur after constraint checks but before
//	** the new record is inserted.
//	**
//	** The caller must have already opened writeable cursors on the main
//	** table and all applicable indices (that is to say, all indices for which
//	** aRegIdx[] is not zero).  iDataCur is the cursor for the main table when
//	** inserting or updating a rowid table, or the cursor for the PRIMARY KEY
//	** index when operating on a WITHOUT ROWID table.  iIdxCur is the cursor
//	** for the first index in the pTab->pIndex list.  Cursors for other indices
//	** are at iIdxCur+N for the N-th element of the pTab->pIndex list.
//	**
//	** This routine also generates code to check constraints.  NOT NULL,
//	** CHECK, and UNIQUE constraints are all checked.  If a constraint fails,
//	** then the appropriate action is performed.  There are five possible
//	** actions: ROLLBACK, ABORT, FAIL, REPLACE, and IGNORE.
//	**
//	**  Constraint type  Action       What Happens
//	**  ---------------  ----------   ----------------------------------------
//	**  any              ROLLBACK     The current transaction is rolled back and
//	**                                sqlite3_step() returns immediately with a
//	**                                return code of SQLITE_CONSTRAINT.
//	**
//	**  any              ABORT        Back out changes from the current command
//	**                                only (do not do a complete rollback) then
//	**                                cause sqlite3_step() to return immediately
//	**                                with SQLITE_CONSTRAINT.
//	**
//	**  any              FAIL         Sqlite3_step() returns immediately with a
//	**                                return code of SQLITE_CONSTRAINT.  The
//	**                                transaction is not rolled back and any
//	**                                changes to prior rows are retained.
//	**
//	**  any              IGNORE       The attempt in insert or update the current
//	**                                row is skipped, without throwing an error.
//	**                                Processing continues with the next row.
//	**                                (There is an immediate jump to ignoreDest.)
//	**
//	**  NOT NULL         REPLACE      The NULL value is replace by the default
//	**                                value for that column.  If the default value
//	**                                is NULL, the action is the same as ABORT.
//	**
//	**  UNIQUE           REPLACE      The other row that conflicts with the row
//	**                                being inserted is removed.
//	**
//	**  CHECK            REPLACE      Illegal.  The results in an exception.
//	**
//	** Which action to take is determined by the overrideError parameter.
//	** Or if overrideError==OE_Default, then the pParse->onError parameter
//	** is used.  Or if pParse->onError==OE_Default then the onError value
//	** for the constraint is used.
//	*/
func _sqlite3GenerateConstraintChecks(tls *libc.TLS, pParse uintptr, pTab uintptr, aRegIdx uintptr, iDataCur int32, iIdxCur int32, regNewData int32, regOldData int32, pkChng Tu8, overrideError Tu8, ignoreDest int32, pbMayReplace uintptr, aiChng uintptr, pUpsert uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var addr1, addrBypass, addrConflictCk, addrJump, addrRecheck, addrRowidOk, addrUniqueOk, allOk, b2ndPass, i, iField, iReg, iThisCur, ipkBottom, ipkTop, isGenerated, jj, lblRecheckOk, nCol, nConflictCk, nGenerated, nIdx, nPkField, nReplaceTrig, nSeenReplace, onError, op, p2, regCmp, regIdx, regR, regRec, regTrigCnt, seenReplace, upsertIpkDelay, upsertIpkReturn, x, x1, v2 int32
	var bAffinityDone, isUpdate Tu8
	var bUsed, db, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, v, zMsg, zName, zP4, v8 uintptr
	var nByte Tu64
	var _ /* ix at bp+0 */ int32
	var _ /* sIdxIter at bp+8 */ TIndexIterator
	var _ /* x at bp+32 */ TVdbeOp
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addrBypass, addrConflictCk, addrJump, addrRecheck, addrRowidOk, addrUniqueOk, allOk, b2ndPass, bAffinityDone, bUsed, db, i, iField, iReg, iThisCur, ipkBottom, ipkTop, isGenerated, isUpdate, jj, lblRecheckOk, nByte, nCol, nConflictCk, nGenerated, nIdx, nPkField, nReplaceTrig, nSeenReplace, onError, op, p2, p4, pCheck, pCol, pCopy, pExpr, pIdx, pPk, pTerm, pTrigger, pUpsertClause, regCmp, regIdx, regR, regRec, regTrigCnt, seenReplace, upsertIpkDelay, upsertIpkReturn, v, x, x1, zMsg, zName, zP4, v2, v8 /* Pointer to one of the indices */
	pPk = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Conflict resolution strategy */
	seenReplace = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
	pUpsertClause = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* True if this is an UPDATE operation */
	bAffinityDone = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* True if the OP_Affinity operation has been run */
	upsertIpkReturn = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Address of Goto at end of IPK uniqueness check */
	upsertIpkDelay = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* Address of Goto to bypass initial IPK check */
	ipkTop = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* Top of the IPK uniqueness check */
	ipkBottom = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /* Register used to count replace trigger invocations */
	addrRecheck = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* Jump here to recheck all uniqueness constraints */
	lblRecheckOk = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* List of DELETE triggers on the table pTab */
	nReplaceTrig = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Index iterator */
	isUpdate = libc.BoolUint8(regOldData != 0)
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	/* This table is not a VIEW */
	nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
	 ** normal rowid tables.  nPkField is the number of key fields in the
	 ** pPk index or 1 for a rowid table.  In other words, nPkField is the
	 ** number of fields in the true primary key of the table. */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		pPk = uintptr(0)
		nPkField = int32(1)
	} else {
		pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
		nPkField = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
	}
	/* Record that this module has started */
	/* Test all NOT NULL constraints.
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasNotNull) != 0 {
		b2ndPass = 0        /* True if currently running 2nd pass */
		nSeenReplace = 0    /* Number of ON CONFLICT REPLACE operations */
		nGenerated = 0      /* Number of generated columns with NOT NULL */
		for int32(1) != 0 { /* Make 2 passes over columns. Exit loop via "break" */
			i = 0
			for {
				if !(i < nCol) {
					break
				} /* Register holding column value */
				pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16 /* non-zero if column is generated */
				onError = int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8)) & 0xf0 >> 4))
				if onError == OE_None {
					goto _1
				} /* No NOT NULL on this column */
				if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					goto _1 /* ROWID is never NULL */
				}
				isGenerated = libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags) & int32(COLFLAG_GENERATED)
				if isGenerated != 0 && !(b2ndPass != 0) {
					nGenerated = nGenerated + 1
					goto _1 /* Generated columns processed on 2nd pass */
				}
				if aiChng != 0 && **(**int32)(__ccgo_up(aiChng + uintptr(i)*4)) < 0 && !(isGenerated != 0) {
					/* Do not check NOT NULL on columns that do not change */
					goto _1
				}
				if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
					onError = libc.Int32FromUint8(overrideError)
				} else {
					if onError == int32(OE_Default) {
						onError = int32(OE_Abort)
					}
				}
				if onError == int32(OE_Replace) {
					if b2ndPass != 0 || libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FiDflt) == 0 {
						onError = int32(OE_Abort)
					} else {
					}
				} else {
					if b2ndPass != 0 && !(isGenerated != 0) {
						goto _1
					}
				}
				iReg = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i))) + regNewData + int32(1)
				switch onError {
				case int32(OE_Replace):
					addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), iReg)
					nSeenReplace = nSeenReplace + 1
					_sqlite3ExprCodeCopy(tls, pParse, _sqlite3ColumnExpr(tls, pTab, pCol), iReg)
					_sqlite3VdbeJumpHere(tls, v, addr1)
				case int32(OE_Abort):
					_sqlite3MayAbort(tls, pParse)
					fallthrough
				case int32(OE_Rollback):
					fallthrough
				case int32(OE_Fail):
					zMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+13636, libc.VaList(bp+64, (*TTable)(unsafe.Pointer(pTab)).FzName, (*TColumn)(unsafe.Pointer(pCol)).FzCnName))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_HaltIfNull), libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(5)<<libc.Int32FromInt32(8), onError, iReg)
					_sqlite3VdbeAppendP4(tls, v, zMsg, -int32(7))
					_sqlite3VdbeChangeP5(tls, v, uint16(P5_ConstraintNotNull))
				default:
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), iReg, ignoreDest)
					break
				} /* end switch(onError) */
				goto _1
			_1:
				;
				i = i + 1
			} /* end loop i over columns */
			if nGenerated == 0 && nSeenReplace == 0 {
				/* If there are no generated columns with NOT NULL constraints
				 ** and no NOT NULL ON CONFLICT REPLACE constraints, then a single
				 ** pass is sufficient */
				break
			}
			if b2ndPass != 0 {
				break
			} /* Never need more than 2 passes */
			b2ndPass = int32(1)
			if nSeenReplace > 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
				/* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
				 ** first pass, recomputed values for all generated columns, as
				 ** those values might depend on columns affected by the REPLACE.
				 */
				_sqlite3ComputeGeneratedColumns(tls, pParse, regNewData+int32(1), pTab)
			}
		} /* end of 2-pass loop */
	} /* end if( has-not-null-constraints ) */
	/* Test all CHECK constraints
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FpCheck != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0) {
		pCheck = (*TTable)(unsafe.Pointer(pTab)).FpCheck
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
		if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
			v2 = libc.Int32FromUint8(overrideError)
		} else {
			v2 = int32(OE_Abort)
		}
		onError = v2
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pCheck)).FnExpr) {
				break
			}
			pExpr = (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32))).FpExpr
			if aiChng != 0 && !(_sqlite3ExprReferencesUpdatedColumn(tls, pExpr, aiChng, libc.Int32FromUint8(pkChng)) != 0) {
				/* The check constraints do not reference any of the columns being
				 ** updated so there is no point it verifying the check constraint */
				goto _3
			}
			if libc.Int32FromUint8(bAffinityDone) == 0 {
				_sqlite3TableAffinity(tls, v, pTab, regNewData+int32(1))
				bAffinityDone = uint8(1)
			}
			allOk = _sqlite3VdbeMakeLabel(tls, pParse)
			pCopy = _sqlite3ExprDup(tls, db, pExpr, 0)
			if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
				_sqlite3ExprIfTrue(tls, pParse, pCopy, allOk, int32(SQLITE_JUMPIFNULL))
			}
			_sqlite3ExprDelete(tls, db, pCopy)
			if onError == int32(OE_Ignore) {
				_sqlite3VdbeGoto(tls, v, ignoreDest)
			} else {
				zName = (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32))).FzEName
				if onError == int32(OE_Replace) {
					onError = int32(OE_Abort)
				} /* IMP: R-26383-51744 */
				_sqlite3HaltConstraint(tls, pParse, libc.Int32FromInt32(SQLITE_CONSTRAINT)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), onError, zName, P4_TRANSIENT, uint8(P5_ConstraintCheck))
			}
			_sqlite3VdbeResolveLabel(tls, v, allOk)
			goto _3
		_3:
			;
			i = i + 1
		}
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	}
	/* UNIQUE and PRIMARY KEY constraints should be handled in the following
	 ** order:
	 **
	 **   (1)  OE_Update
	 **   (2)  OE_Abort, OE_Fail, OE_Rollback, OE_Ignore
	 **   (3)  OE_Replace
	 **
	 ** OE_Fail and OE_Ignore must happen before any changes are made.
	 ** OE_Update guarantees that only a single row will change, so it
	 ** must happen before OE_Replace.  Technically, OE_Abort and OE_Rollback
	 ** could happen in any order, but they are grouped up front for
	 ** convenience.
	 **
	 ** 2018-08-14: Ticket https://sqlite.org/src/info/908f001483982c43
	 ** The order of constraints used to have OE_Update as (2) and OE_Abort
	 ** and so forth as (1). But apparently PostgreSQL checks the OE_Update
	 ** constraint before any others, so it had to be moved.
	 **
	 ** Constraint checking code is generated in this order:
	 **   (A)  The rowid constraint
	 **   (B)  Unique index constraints that do not have OE_Replace as their
	 **        default conflict resolution strategy
	 **   (C)  Unique index that do use OE_Replace by default.
	 **
	 ** The ordering of (2) and (3) is accomplished by making sure the linked
	 ** list of indexes attached to a table puts all OE_Replace indexes last
	 ** in the list.  See sqlite3CreateIndex() for where that happens.
	 */
	(**(**TIndexIterator)(__ccgo_up(bp + 8))).FeType = 0
	(**(**TIndexIterator)(__ccgo_up(bp + 8))).Fi = 0
	*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) = uintptr(0) /* Silence harmless compiler warning */
	*(*uintptr)(unsafe.Pointer(bp + 8 + 8)) = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	if pUpsert != 0 {
		if (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget == uintptr(0) {
			/* There is just on ON CONFLICT clause and it has no constraint-target */
			if libc.Int32FromUint8((*TUpsert)(unsafe.Pointer(pUpsert)).FisDoUpdate) == 0 {
				/* A single ON CONFLICT DO NOTHING clause, without a constraint-target.
				 ** Make all unique constraint resolution be OE_Ignore */
				overrideError = uint8(OE_Ignore)
				pUpsert = uintptr(0)
			} else {
				/* A single ON CONFLICT DO UPDATE.  Make all resolutions OE_Update */
				overrideError = uint8(OE_Update)
			}
		} else {
			if (*TTable)(unsafe.Pointer(pTab)).FpIndex != uintptr(0) {
				nIdx = 0
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					goto _4
				_4:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					nIdx = nIdx + 1
				}
				(**(**TIndexIterator)(__ccgo_up(bp + 8))).FeType = int32(1)
				*(*int32)(unsafe.Pointer(bp + 8 + 8)) = nIdx
				nByte = uint64((libc.Uint64FromInt64(16)+libc.Uint64FromInt32(1))*libc.Uint64FromInt32(nIdx) + libc.Uint64FromInt32(nIdx))
				*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) = _sqlite3DbMallocZero(tls, db, nByte)
				if *(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) == uintptr(0) {
					return
				} /* OOM */
				bUsed = *(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(nIdx)*16
				(*TUpsert)(unsafe.Pointer(pUpsert)).FpToFree = *(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8))
				i = 0
				pTerm = pUpsert
				for {
					if !(pTerm != 0) {
						break
					}
					if (*TUpsert)(unsafe.Pointer(pTerm)).FpUpsertTarget == uintptr(0) {
						break
					}
					if (*TUpsert)(unsafe.Pointer(pTerm)).FpUpsertIdx == uintptr(0) {
						goto _5
					} /* Skip ON CONFLICT for the IPK */
					jj = 0
					pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
					for pIdx != uintptr(0) && pIdx != (*TUpsert)(unsafe.Pointer(pTerm)).FpUpsertIdx {
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
						jj = jj + 1
					}
					if **(**Tu8)(__ccgo_up(bUsed + uintptr(jj))) != 0 {
						goto _5
					} /* Duplicate ON CONFLICT clause ignored */
					**(**Tu8)(__ccgo_up(bUsed + uintptr(jj))) = uint8(1)
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fp = pIdx
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fix = jj
					i = i + 1
					goto _5
				_5:
					;
					pTerm = (*TUpsert)(unsafe.Pointer(pTerm)).FpNextUpsert
				}
				jj = 0
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					if **(**Tu8)(__ccgo_up(bUsed + uintptr(jj))) != 0 {
						goto _6
					}
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fp = pIdx
					(**(**TIndexListTerm)(__ccgo_up(*(*uintptr)(unsafe.Pointer(bp + 8 + 8 + 8)) + uintptr(i)*16))).Fix = jj
					i = i + 1
					goto _6
				_6:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					jj = jj + 1
				}
			}
		}
	}
	/* Determine if it is possible that triggers (either explicitly coded
	 ** triggers or FK resolution actions) might run as a result of deletes
	 ** that happen when OE_Replace conflict resolution occurs. (Call these
	 ** "replace triggers".)  If any replace triggers run, we will need to
	 ** recheck all of the uniqueness constraints after they have all run.
	 ** But on the recheck, the resolution is OE_Abort instead of OE_Replace.
	 **
	 ** If replace triggers are a possibility, then
	 **
	 **   (1) Allocate register regTrigCnt and initialize it to zero.
	 **       That register will count the number of replace triggers that
	 **       fire.  Constraint recheck only occurs if the number is positive.
	 **   (2) Initialize pTrigger to the list of all DELETE triggers on pTab.
	 **   (3) Initialize addrRecheck and lblRecheckOk
	 **
	 ** The uniqueness rechecking code will create a series of tests to run
	 ** in a second pass.  The addrRecheck and lblRecheckOk variables are
	 ** used to link together these tests which are separated from each other
	 ** in the generate bytecode.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&libc.Uint64FromInt32(libc.Int32FromInt32(SQLITE_RecTriggers)|libc.Int32FromInt32(SQLITE_ForeignKeys)) == uint64(0) {
		/* There are not DELETE triggers nor FK constraints.  No constraint
		 ** rechecks are needed. */
		pTrigger = uintptr(0)
		regTrigCnt = 0
	} else {
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_RecTriggers) != 0 {
			pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_DELETE), uintptr(0), uintptr(0))
			regTrigCnt = libc.BoolInt32(pTrigger != uintptr(0) || _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)
		} else {
			pTrigger = uintptr(0)
			regTrigCnt = _sqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0)
		}
		if regTrigCnt != 0 {
			/* Replace triggers might exist.  Allocate the counter and
			 ** initialize it to zero. */
			v8 = pParse + 60
			*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
			v2 = *(*int32)(unsafe.Pointer(v8))
			regTrigCnt = v2
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regTrigCnt)
			lblRecheckOk = _sqlite3VdbeMakeLabel(tls, pParse)
			addrRecheck = lblRecheckOk
		}
	}
	/* If rowid is changing, make sure the new rowid does not previously
	 ** exist in the table.
	 */
	if pkChng != 0 && pPk == uintptr(0) {
		addrRowidOk = _sqlite3VdbeMakeLabel(tls, pParse)
		/* Figure out what action to take in case of a rowid collision */
		onError = libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FkeyConf)
		if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
			onError = libc.Int32FromUint8(overrideError)
		} else {
			if onError == int32(OE_Default) {
				onError = int32(OE_Abort)
			}
		}
		/* figure out whether or not upsert applies in this case */
		if pUpsert != 0 {
			pUpsertClause = _sqlite3UpsertOfIndex(tls, pUpsert, uintptr(0))
			if pUpsertClause != uintptr(0) {
				if libc.Int32FromUint8((*TUpsert)(unsafe.Pointer(pUpsertClause)).FisDoUpdate) == 0 {
					onError = int32(OE_Ignore) /* DO NOTHING is the same as INSERT OR IGNORE */
				} else {
					onError = int32(OE_Update) /* DO UPDATE */
				}
			}
			if pUpsertClause != pUpsert {
				/* The first ON CONFLICT clause has a conflict target other than
				 ** the IPK.  We have to jump ahead to that first ON CONFLICT clause
				 ** and then come back here and deal with the IPK afterwards */
				upsertIpkDelay = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
			}
		}
		/* If the response to a rowid conflict is REPLACE but the response
		 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
		 ** to defer the running of the rowid conflict checking until after
		 ** the UNIQUE constraints have run.
		 */
		if onError == int32(OE_Replace) && onError != libc.Int32FromUint8(overrideError) && (*TTable)(unsafe.Pointer(pTab)).FpIndex != 0 && !(upsertIpkDelay != 0) {
			ipkTop = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto)) + int32(1)
		}
		if isUpdate != 0 {
			/* pkChng!=0 does not mean that the rowid has changed, only that
			 ** it might have changed.  Skip the conflict logic below if the rowid
			 ** is unchanged. */
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regNewData, addrRowidOk, regOldData)
			_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
		}
		/* Check to see if the new rowid already exists in the table.  Skip
		 ** the following conflict logic if it does not. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, addrRowidOk, regNewData)
		switch onError {
		default:
			onError = int32(OE_Abort)
			fallthrough
		case int32(OE_Rollback):
			fallthrough
		case int32(OE_Abort):
			fallthrough
		case int32(OE_Fail):
			_sqlite3RowidConstraint(tls, pParse, onError, pTab)
		case int32(OE_Replace):
			/* If there are DELETE triggers on this table and the
			 ** recursive-triggers flag is set, call GenerateRowDelete() to
			 ** remove the conflicting row from the table. This will fire
			 ** the triggers and remove both the table and index b-tree entries.
			 **
			 ** Otherwise, if there are no triggers or the recursive-triggers
			 ** flag is not set, but the table has one or more indexes, call
			 ** GenerateRowIndexDelete(). This removes the index b-tree entries
			 ** only. The table b-tree entry will be replaced by the new entry
			 ** when it is inserted.
			 **
			 ** If either GenerateRowDelete() or GenerateRowIndexDelete() is called,
			 ** also invoke MultiWrite() to indicate that this VDBE may require
			 ** statement rollback (if the statement is aborted after the delete
			 ** takes place). Earlier versions called sqlite3MultiWrite() regardless,
			 ** but being more selective here allows statements like:
			 **
			 **   REPLACE INTO t(rowid) VALUES($newrowid)
			 **
			 ** to run without a statement journal if there are no indexes on the
			 ** table.
			 */
			if regTrigCnt != 0 {
				_sqlite3MultiWrite(tls, pParse)
				_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur, regNewData, int16(1), uint8(0), uint8(OE_Replace), uint8(1), -int32(1))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regTrigCnt, int32(1)) /* incr trigger cnt */
				nReplaceTrig = nReplaceTrig + 1
			} else {
				/* This OP_Delete opcode fires the pre-update-hook only. It does
				 ** not modify the b-tree. It is more efficient to let the coming
				 ** OP_Insert replace the existing entry than it is to delete the
				 ** existing entry and then insert a new one. */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Delete), iDataCur, int32(OPFLAG_ISNOOP))
				_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
				if (*TTable)(unsafe.Pointer(pTab)).FpIndex != 0 {
					_sqlite3MultiWrite(tls, pParse)
					_sqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, uintptr(0), -int32(1))
				}
			}
			seenReplace = int32(1)
		case int32(OE_Update):
			_sqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, uintptr(0), iDataCur)
			fallthrough
		case int32(OE_Ignore):
			_sqlite3VdbeGoto(tls, v, ignoreDest)
			break
		}
		_sqlite3VdbeResolveLabel(tls, v, addrRowidOk)
		if pUpsert != 0 && pUpsertClause != pUpsert {
			upsertIpkReturn = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
		} else {
			if ipkTop != 0 {
				ipkBottom = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
				_sqlite3VdbeJumpHere(tls, v, ipkTop-int32(1))
			}
		}
	}
	/* Test all UNIQUE constraints by creating entries for each UNIQUE
	 ** index and making sure that duplicate entries do not already exist.
	 ** Compute the revised record entries for indices as we go.
	 **
	 ** This loop also handles the case of the PRIMARY KEY index for a
	 ** WITHOUT ROWID table.
	 */
	pIdx = _indexIteratorFirst(tls, bp+8, bp)
	for {
		if !(pIdx != 0) {
			break
		} /* First opcode in the conflict check logic */
		if **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)) == 0 {
			goto _9
		} /* Skip indices that do not change */
		if pUpsert != 0 {
			pUpsertClause = _sqlite3UpsertOfIndex(tls, pUpsert, pIdx)
			if upsertIpkDelay != 0 && pUpsertClause == pUpsert {
				_sqlite3VdbeJumpHere(tls, v, upsertIpkDelay)
			}
		}
		addrUniqueOk = _sqlite3VdbeMakeLabel(tls, pParse)
		if libc.Int32FromUint8(bAffinityDone) == 0 {
			_sqlite3TableAffinity(tls, v, pTab, regNewData+int32(1))
			bAffinityDone = uint8(1)
		}
		iThisCur = iIdxCur + **(**int32)(__ccgo_up(bp))
		/* Skip partial indices for which the WHERE clause is not true */
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)))
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
			_sqlite3ExprIfFalseDup(tls, pParse, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, addrUniqueOk, int32(SQLITE_JUMPIFNULL))
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
		}
		/* Create a record for this index entry as it should appear after
		 ** the insert or update.  Store that record in the aRegIdx[ix] register
		 */
		regIdx = **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)) + int32(1)
		i = 0
		for {
			if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
				break
			}
			iField = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
			if iField == -int32(2) {
				(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + int32(1))
				_sqlite3ExprCodeCopy(tls, pParse, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*32))).FpExpr, regIdx+i)
				(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
			} else {
				if iField == -int32(1) || iField == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					x = regNewData
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IntCopy), x, regIdx+i)
				} else {
					x = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(iField))) + regNewData + int32(1)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), x, regIdx+i)
				}
			}
			goto _10
		_10:
			;
			i = i + 1
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn), **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4)))
		/* In an UPDATE operation, if this index is the PRIMARY KEY index
		 ** of a WITHOUT ROWID table and there has been no change the
		 ** primary key, then no collision is possible.  The collision detection
		 ** logic below can all be skipped. */
		if isUpdate != 0 && pPk == pIdx && libc.Int32FromUint8(pkChng) == 0 {
			_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			goto _9
		}
		/* Find out what action to take in case there is a uniqueness conflict */
		onError = libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError)
		if onError == OE_None {
			_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			goto _9 /* pIdx is not a UNIQUE index */
		}
		if libc.Int32FromUint8(overrideError) != int32(OE_Default) {
			onError = libc.Int32FromUint8(overrideError)
		} else {
			if onError == int32(OE_Default) {
				onError = int32(OE_Abort)
			}
		}
		/* Figure out if the upsert clause applies to this index */
		if pUpsertClause != 0 {
			if libc.Int32FromUint8((*TUpsert)(unsafe.Pointer(pUpsertClause)).FisDoUpdate) == 0 {
				onError = int32(OE_Ignore) /* DO NOTHING is the same as INSERT OR IGNORE */
			} else {
				onError = int32(OE_Update) /* DO UPDATE */
			}
		}
		/* Collision detection may be omitted if all of the following are true:
		 **   (1) The conflict resolution algorithm is REPLACE
		 **   (2) The table is a WITHOUT ROWID table
		 **   (3) There are no secondary indexes on the table
		 **   (4) No delete triggers need to be fired if there is a conflict
		 **   (5) No FK constraint counters need to be updated if a conflict occurs.
		 **
		 ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
		 ** must be explicitly deleted in order to ensure any pre-update hook
		 ** is invoked.  */
		/* Check to see if the new index entry will be unique */
		addrConflictCk = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_NoConflict), iThisCur, addrUniqueOk, regIdx, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol))
		/* Generate code to handle collisions */
		if pIdx == pPk {
			v2 = regIdx
		} else {
			v2 = _sqlite3GetTempRange(tls, pParse, nPkField)
		}
		regR = v2
		if isUpdate != 0 || onError == int32(OE_Replace) {
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), iThisCur, regR)
				/* Conflict only if the rowid of the existing index entry
				 ** is different from old-rowid */
				if isUpdate != 0 {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regR, addrUniqueOk, regOldData)
					_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
				}
			} else {
				/* Extract the PRIMARY KEY from the end of the index entry and
				 ** store it in registers regR..regR+nPk-1 */
				if pIdx != pPk {
					i = 0
					for {
						if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
							break
						}
						x1 = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iThisCur, x1, regR+i)
						goto _12
					_12:
						;
						i = i + 1
					}
				}
				if isUpdate != 0 {
					/* If currently processing the PRIMARY KEY of a WITHOUT ROWID
					 ** table, only conflict if the new PRIMARY KEY values are actually
					 ** different from the old.  See TH3 withoutrowid04.test.
					 **
					 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
					 ** of the matched index row are different from the original PRIMARY
					 ** KEY values of this row before the update.  */
					addrJump = _sqlite3VdbeCurrentAddr(tls, v) + libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
					op = int32(OP_Ne)
					if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
						v2 = regIdx
					} else {
						v2 = regR
					}
					regCmp = v2
					i = 0
					for {
						if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
							break
						}
						p4 = _sqlite3LocateCollSeq(tls, pParse, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8)))
						x1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))
						if i == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)-int32(1) {
							addrJump = addrUniqueOk
							op = int32(OP_Eq)
						}
						x1 = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(x1)))
						_sqlite3VdbeAddOp4(tls, v, op, regOldData+int32(1)+x1, addrJump, regCmp+i, p4, -int32(2))
						_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
						goto _14
					_14:
						;
						i = i + 1
					}
				}
			}
		}
		/* Generate code that executes if the new index entry is not unique */
		switch onError {
		case int32(OE_Rollback):
			fallthrough
		case int32(OE_Abort):
			fallthrough
		case int32(OE_Fail):
			_sqlite3UniqueConstraint(tls, pParse, onError, pIdx)
		case int32(OE_Update):
			_sqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, pIdx, iIdxCur+**(**int32)(__ccgo_up(bp)))
			fallthrough
		case int32(OE_Ignore):
			_sqlite3VdbeGoto(tls, v, ignoreDest)
		default: /* Number of opcodes in conflict check logic */
			nConflictCk = _sqlite3VdbeCurrentAddr(tls, v) - addrConflictCk
			if regTrigCnt != 0 {
				_sqlite3MultiWrite(tls, pParse)
				nReplaceTrig = nReplaceTrig + 1
			}
			if pTrigger != 0 && isUpdate != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorLock), iDataCur)
			}
			if pIdx == pPk {
				v2 = int32(ONEPASS_SINGLE)
			} else {
				v2 = ONEPASS_OFF
			}
			_sqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur, regR, int16(nPkField), uint8(0), uint8(OE_Replace), libc.Uint8FromInt32(v2), iThisCur)
			if pTrigger != 0 && isUpdate != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_CursorUnlock), iDataCur)
			}
			if regTrigCnt != 0 { /* Jump destination to bypass recheck logic */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regTrigCnt, int32(1)) /* incr trigger cnt */
				addrBypass = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))            /* Bypass recheck */
				/* Here we insert code that will be invoked after all constraint
				 ** checks have run, if and only if one or more replace triggers
				 ** fired. */
				_sqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
				lblRecheckOk = _sqlite3VdbeMakeLabel(tls, pParse)
				if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
					/* Bypass the recheck if this partial index is not defined
					 ** for the current row */
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regIdx-int32(1), lblRecheckOk)
				}
				/* Copy the constraint check code from above, except change
				 ** the constraint-ok jump destination to be the address of
				 ** the next retest block */
				for nConflictCk > 0 { /* Conflict check opcode to copy */
					/* The sqlite3VdbeAddOp4() call might reallocate the opcode array.
					 ** Hence, make a complete copy of the opcode, rather than using
					 ** a pointer to the opcode. */
					**(**TVdbeOp)(__ccgo_up(bp + 32)) = **(**TVdbeOp)(__ccgo_up(_sqlite3VdbeGetOp(tls, v, addrConflictCk)))
					if libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode) != int32(OP_IdxRowid) {
						if libc.Int32FromUint8(_sqlite3OpcodeProperty[(**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode])&int32(OPFLG_JUMP) != 0 {
							p2 = lblRecheckOk
						} else {
							p2 = (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp2
						}
						if int32((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp4type) == -int32(3) {
							v8 = uintptr(int64(*(*int32)(unsafe.Pointer(bp + 32 + 16))))
						} else {
							v8 = *(*uintptr)(unsafe.Pointer(bp + 32 + 16))
						}
						zP4 = v8
						_sqlite3VdbeAddOp4(tls, v, libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fopcode), (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp1, p2, (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp3, zP4, int32((**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp4type))
						_sqlite3VdbeChangeP5(tls, v, (**(**TVdbeOp)(__ccgo_up(bp + 32))).Fp5)
					}
					nConflictCk = nConflictCk - 1
					addrConflictCk = addrConflictCk + 1
				}
				/* If the retest fails, issue an abort */
				_sqlite3UniqueConstraint(tls, pParse, int32(OE_Abort), pIdx)
				_sqlite3VdbeJumpHere(tls, v, addrBypass) /* Terminate the recheck bypass */
			}
			seenReplace = int32(1)
			break
		}
		_sqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
		if regR != regIdx {
			_sqlite3ReleaseTempRange(tls, pParse, regR, nPkField)
		}
		if pUpsertClause != 0 && upsertIpkReturn != 0 && _sqlite3UpsertNextIsIPK(tls, pUpsertClause) != 0 {
			_sqlite3VdbeGoto(tls, v, upsertIpkDelay+int32(1))
			_sqlite3VdbeJumpHere(tls, v, upsertIpkReturn)
			upsertIpkReturn = 0
		}
		goto _9
	_9:
		;
		pIdx = _indexIteratorNext(tls, bp+8, bp)
	}
	/* If the IPK constraint is a REPLACE, run it last */
	if ipkTop != 0 {
		_sqlite3VdbeGoto(tls, v, ipkTop)
		_sqlite3VdbeJumpHere(tls, v, ipkBottom)
	}
	/* Recheck all uniqueness constraints after replace triggers have run */
	if nReplaceTrig != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), regTrigCnt, lblRecheckOk)
		if !(pPk != 0) {
			if isUpdate != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regNewData, addrRecheck, regOldData)
				_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, addrRecheck, regNewData)
			_sqlite3RowidConstraint(tls, pParse, int32(OE_Abort), pTab)
		} else {
			_sqlite3VdbeGoto(tls, v, addrRecheck)
		}
		_sqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
	}
	/* Generate the table record */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		regRec = **(**int32)(__ccgo_up(aRegIdx + uintptr(**(**int32)(__ccgo_up(bp)))*4))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regNewData+int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol), regRec)
		if !(bAffinityDone != 0) {
			_sqlite3TableAffinity(tls, v, pTab, 0)
		}
	}
	**(**int32)(__ccgo_up(pbMayReplace)) = seenReplace
}

// C documentation
//
//	/*
//	** Generate code that will assemble an index key and stores it in register
//	** regOut.  The key with be for index pIdx which is an index on pTab.
//	** iCur is the index of a cursor open on the pTab table and pointing to
//	** the entry that needs indexing.  If pTab is a WITHOUT ROWID table, then
//	** iCur must be the cursor of the PRIMARY KEY index.
//	**
//	** Return a register number which is the first in a block of
//	** registers that holds the elements of the index key.  The
//	** block of registers has already been deallocated by the time
//	** this routine returns.
//	**
//	** If *piPartIdxLabel is not NULL, fill it in with a label and jump
//	** to that label if pIdx is a partial index that should be skipped.
//	** The label should be resolved using sqlite3ResolvePartIdxLabel().
//	** A partial index should be skipped if its WHERE clause evaluates
//	** to false or null.  If pIdx is not a partial index, *piPartIdxLabel
//	** will be set to zero which is an empty label that is ignored by
//	** sqlite3ResolvePartIdxLabel().
//	**
//	** The pPrior and regPrior parameters are used to implement a cache to
//	** avoid unnecessary register loads.  If pPrior is not NULL, then it is
//	** a pointer to a different index for which an index key has just been
//	** computed into register regPrior.  If the current pIdx index is generating
//	** its key into the same sequence of registers and if pPrior and pIdx share
//	** a column in common, then the register corresponding to that column already
//	** holds the correct value and the loading of that register is skipped.
//	** This optimization is helpful when doing a DELETE or an INTEGRITY_CHECK
//	** on a table with multiple indices, and especially with the ROWID or
//	** PRIMARY KEY columns of the index.
//	*/
func _sqlite3GenerateIndexKey(tls *libc.TLS, pParse uintptr, pIdx uintptr, iDataCur int32, regOut int32, prefixOnly int32, piPartIdxLabel uintptr, pPrior uintptr, regPrior int32) (r int32) {
	var j, nCol, regBase, v1 int32
	var v uintptr
	_, _, _, _, _ = j, nCol, regBase, v, v1
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if piPartIdxLabel != 0 {
		if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			**(**int32)(__ccgo_up(piPartIdxLabel)) = _sqlite3VdbeMakeLabel(tls, pParse)
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iDataCur + int32(1)
			_sqlite3ExprIfFalseDup(tls, pParse, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, **(**int32)(__ccgo_up(piPartIdxLabel)), int32(SQLITE_JUMPIFNULL))
			(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
			pPrior = uintptr(0) /* Ticket a9efb42811fa41ee 2019-11-02;
			 ** pPartIdxWhere may have corrupted regPrior registers */
		} else {
			**(**int32)(__ccgo_up(piPartIdxLabel)) = 0
		}
	}
	if prefixOnly != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x1000>>12)) != 0 {
		v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	} else {
		v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
	}
	nCol = v1
	regBase = _sqlite3GetTempRange(tls, pParse, nCol)
	if pPrior != 0 && (regBase != regPrior || (*TIndex)(unsafe.Pointer(pPrior)).FpPartIdxWhere != 0) {
		pPrior = uintptr(0)
	}
	j = 0
	for {
		if !(j < nCol) {
			break
		}
		if pPrior != 0 && int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPrior)).FaiColumn + uintptr(j)*2))) == int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) && int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPrior)).FaiColumn + uintptr(j)*2))) != -int32(2) {
			/* This column was already computed by the previous index */
			goto _2
		}
		_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iDataCur, j, regBase+j)
		if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) >= 0 {
			/* If the column affinity is REAL but the number is an integer, then it
			 ** might be stored in the table as an integer (using a compact
			 ** representation) then converted to REAL by an OP_RealAffinity opcode.
			 ** But we are getting ready to store this value back into an index, where
			 ** it should be converted by to INTEGER again.  So omit the
			 ** OP_RealAffinity opcode if it is present */
			_sqlite3VdbeDeletePriorOpcode(tls, v, uint8(OP_RealAffinity))
		}
		goto _2
	_2:
		;
		j = j + 1
	}
	if regOut != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regBase, nCol, regOut)
	}
	_sqlite3ReleaseTempRange(tls, pParse, regBase, nCol)
	return regBase
}

// C documentation
//
//	/*
//	** This routine generates VDBE code that causes the deletion of all
//	** index entries associated with a single row of a single table, pTab
//	**
//	** Preconditions:
//	**
//	**   1.  A read/write cursor "iDataCur" must be open on the canonical storage
//	**       btree for the table pTab.  (This will be either the table itself
//	**       for rowid tables or to the primary key index for WITHOUT ROWID
//	**       tables.)
//	**
//	**   2.  Read/write cursors for all indices of pTab must be open as
//	**       cursor number iIdxCur+i for the i-th index.  (The pTab->pIndex
//	**       index is the 0-th index.)
//	**
//	**   3.  The "iDataCur" cursor must be already be positioned on the row
//	**       that is to be deleted.
//	*/
func _sqlite3GenerateRowIndexDelete(tls *libc.TLS, pParse uintptr, pTab uintptr, iDataCur int32, iIdxCur int32, aRegIdx uintptr, iIdxNoSeek int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, r1, v3 int32
	var pIdx, pPk, pPrior, v, v1 uintptr
	var _ /* iPartIdxLabel at bp+0 */ int32
	_, _, _, _, _, _, _, _ = i, pIdx, pPk, pPrior, r1, v, v1, v3 /* Index loop counter */
	r1 = -int32(1)                                               /* Current index */
	pPrior = uintptr(0)                                          /* PRIMARY KEY index, or NULL for rowid tables */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		v1 = uintptr(0)
	} else {
		v1 = _sqlite3PrimaryKeyIndex(tls, pTab)
	}
	pPk = v1
	i = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if aRegIdx != uintptr(0) && **(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)) == 0 {
			goto _2
		}
		if pIdx == pPk {
			goto _2
		}
		if iIdxCur+i == iIdxNoSeek {
			goto _2
		}
		r1 = _sqlite3GenerateIndexKey(tls, pParse, pIdx, iDataCur, 0, int32(1), bp, pPrior, r1)
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x1000>>12)) != 0 {
			v3 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			v3 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_IdxDelete), iIdxCur+i, r1, v3)
		_sqlite3VdbeChangeP4(tls, v, -int32(1), pIdx, -int32(6))
		_sqlite3ResolvePartIdxLabel(tls, pParse, **(**int32)(__ccgo_up(bp)))
		pPrior = pIdx
		goto _2
	_2:
		;
		i = i + 1
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
}

// C documentation
//
//	/*
//	** Read or write a four-byte big-endian integer value.
//	*/
func _sqlite3Get4byte(tls *libc.TLS, p uintptr) (r Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* x at bp+0 */ Tu32
	libc.Xmemcpy(tls, bp, p, uint64(4))
	return **(**Tu32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Get a VDBE for the given parser context.  Create a new one if necessary.
//	** If an error occurs, return NULL and leave a message in pParse.
//	*/
func _sqlite3GetVdbe(tls *libc.TLS, pParse uintptr) (r uintptr) {
	if (*TParse)(unsafe.Pointer(pParse)).FpVdbe != 0 {
		return (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	}
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_FactorOutConst)) == uint32(0) {
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 8, 0x100)
	}
	return _sqlite3VdbeCreate(tls, pParse)
}

// C documentation
//
//	/*
//	** If expression list pList contains an expression that was parsed with
//	** an explicit "NULLS FIRST" or "NULLS LAST" clause, leave an error in
//	** pParse and return non-zero. Otherwise, return zero.
//	*/
func _sqlite3HasExplicitNulls(tls *libc.TLS, pParse uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var sf Tu8
	var v2 uintptr
	_, _, _ = i, sf, v2
	if pList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0x400>>10)) != 0 {
				sf = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).Ffg.FsortFlags
				if libc.Int32FromUint8(sf) == 0 || libc.Int32FromUint8(sf) == int32(3) {
					v2 = __ccgo_ts + 15378
				} else {
					v2 = __ccgo_ts + 15384
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+15389, libc.VaList(bp+8, v2))
				return int32(1)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** If the source-list item passed as an argument was augmented with an
//	** INDEXED BY clause, then try to locate the specified index. If there
//	** was such a clause and the named index cannot be found, return
//	** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
//	** pFrom->pIndex and return SQLITE_OK.
//	*/
func _sqlite3IndexedByLookup(tls *libc.TLS, pParse uintptr, pFrom uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pIdx, pTab, zIndexedBy uintptr
	_, _, _ = pIdx, pTab, zIndexedBy
	pTab = (*TSrcItem)(unsafe.Pointer(pFrom)).FpSTab
	zIndexedBy = *(*uintptr)(unsafe.Pointer(pFrom + 48))
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0 && _sqlite3StrICmp(tls, (*TIndex)(unsafe.Pointer(pIdx)).FzName, zIndexedBy) != 0) {
			break
		}
		goto _1
	_1:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
	}
	if !(pIdx != 0) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21018, libc.VaList(bp+8, zIndexedBy, 0))
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
		return int32(SQLITE_ERROR)
	}
	*(*uintptr)(unsafe.Pointer(pFrom + 56)) = pIdx
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This is the callback routine for the code that initializes the
//	** database.  See sqlite3Init() below for additional information.
//	** This routine is also called from the OP_ParseSchema opcode of the VDBE.
//	**
//	** Each callback contains the following information:
//	**
//	**     argv[0] = type of object: "table", "index", "trigger", or "view".
//	**     argv[1] = name of thing being created
//	**     argv[2] = associated table if an index or trigger
//	**     argv[3] = root page number for table or index. 0 for trigger or view.
//	**     argv[4] = SQL text for the CREATE statement.
//	**
//	*/
func _sqlite3InitCallback(tls *libc.TLS, pInit uintptr, argc int32, argv uintptr, NotUsed uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pData, pIndex uintptr
	var iDb, rc int32
	var saved_iDb Tu8
	var _ /* pStmt at bp+0 */ uintptr
	_, _, _, _, _, _ = db, iDb, pData, pIndex, rc, saved_iDb
	pData = pInit
	db = (*TInitData)(unsafe.Pointer(pData)).Fdb
	iDb = (*TInitData)(unsafe.Pointer(pData)).FiDb
	_ = NotUsed
	_ = argc
	**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_EncodingFixed)
	if argv == uintptr(0) {
		return 0
	} /* Might happen if EMPTY_RESULT_CALLBACKS are on */
	(*TInitData)(unsafe.Pointer(pData)).FnInitRow = (*TInitData)(unsafe.Pointer(pData)).FnInitRow + 1
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_corruptSchema(tls, pData, argv, uintptr(0))
		return int32(1)
	}
	if **(**uintptr)(__ccgo_up(argv + 3*8)) == uintptr(0) {
		_corruptSchema(tls, pData, argv, uintptr(0))
	} else {
		if **(**uintptr)(__ccgo_up(argv + 4*8)) != 0 && int32('c') == libc.Int32FromUint8(_sqlite3UpperToLower[uint8(**(**uint8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*8)))))]) && int32('r') == libc.Int32FromUint8(_sqlite3UpperToLower[uint8(**(**uint8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*8)) + 1)))]) {
			saved_iDb = (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb
			/* Return code from sqlite3_prepare() */
			(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = libc.Uint8FromInt32(iDb)
			if _sqlite3GetUInt32(tls, **(**uintptr)(__ccgo_up(argv + 3*8)), db+192) == 0 || (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum > (*TInitData)(unsafe.Pointer(pData)).FmxPage && (*TInitData)(unsafe.Pointer(pData)).FmxPage > uint32(0) {
				if _sqlite3Config.FbExtraSchemaChecks != 0 {
					_corruptSchema(tls, pData, argv, __ccgo_ts+15744)
				}
			}
			libc.SetBitFieldPtr8Uint32(db+192+8, libc.Uint32FromInt32(0), 7, 0x80)
			(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = argv
			**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
			_sqlite3Prepare(tls, db, **(**uintptr)(__ccgo_up(argv + 4*8)), -int32(1), uint32(0), uintptr(0), bp, uintptr(0))
			rc = (*Tsqlite3)(unsafe.Pointer(db)).FerrCode
			(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb = saved_iDb
			/* assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 ); */
			if SQLITE_OK != rc {
				if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x80>>7)) != 0 {
				} else {
					if rc > (*TInitData)(unsafe.Pointer(pData)).Frc {
						(*TInitData)(unsafe.Pointer(pData)).Frc = rc
					}
					if rc == int32(SQLITE_NOMEM) {
						_sqlite3OomFault(tls, db)
					} else {
						if rc != int32(SQLITE_INTERRUPT) && rc&int32(0xFF) != int32(SQLITE_LOCKED) {
							_corruptSchema(tls, pData, argv, Xsqlite3_errmsg(tls, db))
						}
					}
				}
			}
			(*Tsqlite3)(unsafe.Pointer(db)).Finit1.FazInit = uintptr(unsafe.Pointer(&_sqlite3StdType)) /* Any array of string ptrs will do */
			Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		} else {
			if **(**uintptr)(__ccgo_up(argv + 1*8)) == uintptr(0) || **(**uintptr)(__ccgo_up(argv + 4*8)) != uintptr(0) && libc.Int32FromUint8(**(**uint8)(__ccgo_up(**(**uintptr)(__ccgo_up(argv + 4*8))))) != 0 {
				_corruptSchema(tls, pData, argv, uintptr(0))
			} else {
				pIndex = _sqlite3FindIndex(tls, db, **(**uintptr)(__ccgo_up(argv + 1*8)), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
				if pIndex == uintptr(0) {
					_corruptSchema(tls, pData, argv, __ccgo_ts+20094)
				} else {
					if _sqlite3GetUInt32(tls, **(**uintptr)(__ccgo_up(argv + 3*8)), pIndex+88) == 0 || (*TIndex)(unsafe.Pointer(pIndex)).Ftnum < uint32(2) || (*TIndex)(unsafe.Pointer(pIndex)).Ftnum > (*TInitData)(unsafe.Pointer(pData)).FmxPage || _sqlite3IndexHasDuplicateRootPage(tls, pIndex) != 0 {
						if _sqlite3Config.FbExtraSchemaChecks != 0 {
							_corruptSchema(tls, pData, argv, __ccgo_ts+15744)
						}
					}
				}
			}
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** This routine is called to handle SQL of the following forms:
//	**
//	**    insert into TABLE (IDLIST) values(EXPRLIST),(EXPRLIST),...
//	**    insert into TABLE (IDLIST) select
//	**    insert into TABLE (IDLIST) default values
//	**
//	** The IDLIST following the table name is always optional.  If omitted,
//	** then a list of all (non-hidden) columns for the table is substituted.
//	** The IDLIST appears in the pColumn parameter.  pColumn is NULL if IDLIST
//	** is omitted.
//	**
//	** For the pSelect parameter holds the values to be inserted for the
//	** first two forms shown above.  A VALUES clause is really just short-hand
//	** for a SELECT statement that omits the FROM clause and everything else
//	** that follows.  If the pSelect parameter is NULL, that means that the
//	** DEFAULT VALUES form of the INSERT statement is intended.
//	**
//	** The code generated follows one of four templates.  For a simple
//	** insert with data coming from a single-row VALUES clause, the code executes
//	** once straight down through.  Pseudo-code follows (we call this
//	** the "1st template"):
//	**
//	**         open write cursor to <table> and its indices
//	**         put VALUES clause expressions into registers
//	**         write the resulting record into <table>
//	**         cleanup
//	**
//	** The three remaining templates assume the statement is of the form
//	**
//	**   INSERT INTO <table> SELECT ...
//	**
//	** If the SELECT clause is of the restricted form "SELECT * FROM <table2>" -
//	** in other words if the SELECT pulls all columns from a single table
//	** and there is no WHERE or LIMIT or GROUP BY or ORDER BY clauses, and
//	** if <table2> and <table1> are distinct tables but have identical
//	** schemas, including all the same indices, then a special optimization
//	** is invoked that copies raw records from <table2> over to <table1>.
//	** See the xferOptimization() function for the implementation of this
//	** template.  This is the 2nd template.
//	**
//	**         open a write cursor to <table>
//	**         open read cursor on <table2>
//	**         transfer all records in <table2> over to <table>
//	**         close cursors
//	**         foreach index on <table>
//	**           open a write cursor on the <table> index
//	**           open a read cursor on the corresponding <table2> index
//	**           transfer all records from the read to the write cursors
//	**           close cursors
//	**         end foreach
//	**
//	** The 3rd template is for when the second template does not apply
//	** and the SELECT clause does not read from <table> at any time.
//	** The generated code follows this template:
//	**
//	**         X <- A
//	**         goto B
//	**      A: setup for the SELECT
//	**         loop over the rows in the SELECT
//	**           load values into registers R..R+n
//	**           yield X
//	**         end loop
//	**         cleanup after the SELECT
//	**         end-coroutine X
//	**      B: open write cursor to <table> and its indices
//	**      C: yield X, at EOF goto D
//	**         insert the select result into <table> from R..R+n
//	**         goto C
//	**      D: cleanup
//	**
//	** The 4th template is used if the insert statement takes its
//	** values from a SELECT but the data is being inserted into a table
//	** that is also read as part of the SELECT.  In the third form,
//	** we have to use an intermediate table to store the results of
//	** the select.  The template is like this:
//	**
//	**         X <- A
//	**         goto B
//	**      A: setup for the SELECT
//	**         loop over the tables in the SELECT
//	**           load value into register R..R+n
//	**           yield X
//	**         end loop
//	**         cleanup after the SELECT
//	**         end co-routine R
//	**      B: open temp table
//	**      L: yield X, at EOF goto M
//	**         insert row from R..R+n into temp table
//	**         goto L
//	**      M: open write cursor to <table> and its indices
//	**         rewind temp table
//	**      C: loop over rows of intermediate table
//	**           transfer values form intermediate table into <table>
//	**         end loop
//	**      D: cleanup
//	*/
func _sqlite3Insert(tls *libc.TLS, pParse uintptr, pTabList uintptr, pSelect uintptr, pColumn uintptr, onError int32, pUpsert uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var aRegIdx, aTabColMap, db, pIdx, pIpk, pItem, pList, pNx, pSubq, pTab, pTrigger, pVTab, pX, v, v5 uintptr
	var addr1, addr11, addrCont, addrInsTop, addrL, addrTop, bUseSeek, endOfLoop, i, iDb, iRegStore, ipkColumn, isView, j, k, nColumn, nHidden, nIdx, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, y, v1 int32
	var appendFlag, bIdListInOrder, useTempTable, withoutRowid Tu8
	var colFlags, v20 Tu32
	var _ /* dest at bp+8 */ TSelectDest
	var _ /* iDataCur at bp+0 */ int32
	var _ /* iIdxCur at bp+4 */ int32
	var _ /* isReplace at bp+112 */ int32
	var _ /* sNC at bp+56 */ TNameContext
	var _ /* tmask at bp+48 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, aTabColMap, addr1, addr11, addrCont, addrInsTop, addrL, addrTop, appendFlag, bIdListInOrder, bUseSeek, colFlags, db, endOfLoop, i, iDb, iRegStore, ipkColumn, isView, j, k, nColumn, nHidden, nIdx, pIdx, pIpk, pItem, pList, pNx, pSubq, pTab, pTrigger, pVTab, pX, rc, regAutoinc, regCols, regData, regFromSelect, regIns, regRec, regRowCount, regRowid, regTempRowid, regYield, srcTab, useTempTable, v, withoutRowid, y, v1, v20, v5 /* Number of columns in the data */
	nHidden = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         /* Number of hidden columns if TABLE is virtual */
	**(**int32)(__ccgo_up(bp)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* VDBE cursor that is the main data repository */
	**(**int32)(__ccgo_up(bp + 4)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* First index cursor */
	ipkColumn = -int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Label for the end of the insertion loop */
	srcTab = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* Data comes from this temporary cursor if >=0 */
	addrInsTop = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* Jump to label "D" */
	addrCont = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* Index of database holding TABLE */
	useTempTable = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             /* Store SELECT results in intermediate table */
	appendFlag = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* True if IDLIST is in table order */
	pList = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Register in which to store next column */
	/* Register allocations */
	regFromSelect = 0       /* Base register for data coming from SELECT */
	regAutoinc = 0          /* Register holding the AUTOINCREMENT counter */
	regRowCount = 0         /* register holding first column to insert */
	aRegIdx = uintptr(0)    /* One register allocated to each index */
	aTabColMap = uintptr(0) /* Mask of trigger times */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto insert_cleanup
	}
	(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm = 0 /* Suppress a harmless compiler warning */
	/* If the Select object is really just a simple VALUES() list with a
	 ** single row (the common case) then keep that one row of values
	 ** and discard the other (unused) parts of the pSelect object
	 */
	if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FselFlags&uint32(SF_Values) != uint32(0) && (*TSelect)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0) {
		pList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
		(*TSelect)(unsafe.Pointer(pSelect)).FpEList = uintptr(0)
		_sqlite3SelectDelete(tls, db, pSelect)
		pSelect = uintptr(0)
	}
	/* Locate the table into which we will be inserting new information.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
	if pTab == uintptr(0) {
		goto insert_cleanup
	}
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
		goto insert_cleanup
	}
	withoutRowid = libc.BoolUint8(!((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)))
	/* Figure out if we have any triggers and if the table being
	 ** inserted into is a view
	 */
	pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_INSERT), uintptr(0), bp+48)
	isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
	/* If pTab is really a view, make sure it has been initialized.
	 ** ViewGetColumnNames() is a no-op if pTab is not a view.
	 */
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto insert_cleanup
	}
	/* Cannot insert into a read-only table.
	 */
	if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
		goto insert_cleanup
	}
	/* Allocate a VDBE
	 */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto insert_cleanup
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, libc.BoolInt32(pSelect != 0 || pTrigger != 0), iDb)
	/* If the statement is of the form
	 **
	 **       INSERT INTO <table1> SELECT * FROM <table2>;
	 **
	 ** Then special optimizations can be applied that make the transfer
	 ** very fast and which reduce fragmentation of indices.
	 **
	 ** This is the 2nd template.
	 */
	if pColumn == uintptr(0) && pSelect != uintptr(0) && pTrigger == uintptr(0) && _xferOptimization(tls, pParse, pTab, pSelect, onError, iDb) != 0 {
		goto insert_end
	}
	/* If this is an AUTOINCREMENT table, look up the sequence number in the
	 ** sqlite_sequence table and store it in memory cell regAutoinc.
	 */
	regAutoinc = _autoIncBegin(tls, pParse, iDb, pTab)
	/* Allocate a block registers to hold the rowid and the values
	 ** for all columns of the new row.
	 */
	v1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + libc.Int32FromInt32(1)
	regIns = v1
	regRowid = v1
	**(**int32)(__ccgo_up(pParse + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol) + int32(1)
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		regRowid = regRowid + 1
		(*TParse)(unsafe.Pointer(pParse)).FnMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + 1
	}
	regData = regRowid + int32(1)
	/* If the INSERT statement included an IDLIST term, then make sure
	 ** all elements of the IDLIST really are columns of the table and
	 ** remember the column indices.
	 **
	 ** If the table has an INTEGER PRIMARY KEY column and that column
	 ** is named in the IDLIST, then record in the ipkColumn variable
	 ** the index into IDLIST of the primary key column.  ipkColumn is
	 ** the index of the primary key as it appears in IDLIST, not as
	 ** is appears in the original table.  (The index of the INTEGER
	 ** PRIMARY KEY in the original table is pTab->iPKey.)  After this
	 ** loop, if ipkColumn==(-1), that means that integer primary key
	 ** is unspecified, and hence the table is either WITHOUT ROWID or
	 ** it will automatically generated an integer primary key.
	 **
	 ** bIdListInOrder is true if the columns in IDLIST are in storage
	 ** order.  This enables an optimization that avoids shuffling the
	 ** columns into storage order.  False negatives are harmless,
	 ** but false positives will cause database corruption.
	 */
	bIdListInOrder = libc.BoolUint8((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(libc.Int32FromInt32(TF_OOOHidden)|libc.Int32FromInt32(TF_HasStored)) == uint32(0))
	if pColumn != 0 {
		aTabColMap = _sqlite3DbMallocZero(tls, db, uint64(libc.Uint64FromInt16((*TTable)(unsafe.Pointer(pTab)).FnCol)*uint64(4)))
		if aTabColMap == uintptr(0) {
			goto insert_cleanup
		}
		i = 0
		for {
			if !(i < (*TIdList)(unsafe.Pointer(pColumn)).FnId) {
				break
			}
			j = _sqlite3ColumnIndex(tls, pTab, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName)
			if j >= 0 {
				if **(**int32)(__ccgo_up(aTabColMap + uintptr(j)*4)) == 0 {
					**(**int32)(__ccgo_up(aTabColMap + uintptr(j)*4)) = i + int32(1)
				}
				if i != j {
					bIdListInOrder = uint8(0)
				}
				if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
					ipkColumn = i
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&(libc.Int32FromInt32(COLFLAG_STORED)|libc.Int32FromInt32(COLFLAG_VIRTUAL)) != 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17349, libc.VaList(bp+128, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FzCnName))
					goto insert_cleanup
				}
			} else {
				if _sqlite3IsRowid(tls, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName) != 0 && !(withoutRowid != 0) {
					ipkColumn = i
					bIdListInOrder = uint8(0)
				} else {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17390, libc.VaList(bp+128, pTabList+8, (*(*TIdList_item)(unsafe.Pointer(pColumn + 8 + uintptr(i)*8))).FzName))
					libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
					goto insert_cleanup
				}
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	/* Figure out how many columns of data are supplied.  If the data
	 ** is coming from a SELECT statement, then generate a co-routine that
	 ** produces a single row of the SELECT on each invocation.  The
	 ** co-routine is the common header to the 3rd and 4th templates.
	 */
	if pSelect != 0 { /* Result code */
		if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc)).FnSrc == int32(1) && int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8 + 24 + 4))&0x2000000>>25) != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0) {
			pItem = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8
			pSubq = *(*uintptr)(unsafe.Pointer(pItem + 72))
			(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
			regFromSelect = (*TSubquery)(unsafe.Pointer(pSubq)).FregResult
			nColumn = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pSubq)).FpSelect)).FpEList)).FnExpr
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+17422, libc.VaList(bp+128, pItem))
			if bIdListInOrder != 0 && nColumn == int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
				regData = regFromSelect
				regRowid = regData - int32(1)
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					v1 = int32(1)
				} else {
					v1 = 0
				}
				regIns = regRowid - v1
			}
		} else {
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v1 = *(*int32)(unsafe.Pointer(v5)) /* Top of the co-routine */
			regYield = v1
			addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, addrTop)
			_sqlite3SelectDestInit(tls, bp+8, int32(SRT_Coroutine), regYield)
			if bIdListInOrder != 0 {
				v1 = regData
			} else {
				v1 = 0
			}
			(**(**TSelectDest)(__ccgo_up(bp + 8))).FiSdst = v1
			(**(**TSelectDest)(__ccgo_up(bp + 8))).FnSdst = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			rc = _sqlite3Select(tls, pParse, pSelect, bp+8)
			regFromSelect = (**(**TSelectDest)(__ccgo_up(bp + 8))).FiSdst
			if rc != 0 || (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				goto insert_cleanup
			}
			_sqlite3VdbeEndCoroutine(tls, v, regYield)
			_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1)) /* label B: */
			nColumn = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpEList)).FnExpr
		}
		/* Set useTempTable to TRUE if the result of the SELECT statement
		 ** should be written into a temporary table (template 4).  Set to
		 ** FALSE if each output row of the SELECT can be written directly into
		 ** the destination table (template 3).
		 **
		 ** A temp table must be used if the table being updated is also one
		 ** of the tables being read by the SELECT statement.  Also use a
		 ** temp table in the case of row triggers.
		 */
		if pTrigger != 0 || _readsTable(tls, pParse, iDb, pTab) != 0 {
			useTempTable = uint8(1)
		}
		if useTempTable != 0 { /* Label "L" */
			v5 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v5))
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			srcTab = v1
			regRec = _sqlite3GetTempReg(tls, pParse)
			regTempRowid = _sqlite3GetTempReg(tls, pParse)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), srcTab, nColumn)
			addrL = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regFromSelect, nColumn, regRec)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), srcTab, regTempRowid)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), srcTab, regRec, regTempRowid)
			_sqlite3VdbeGoto(tls, v, addrL)
			_sqlite3VdbeJumpHere(tls, v, addrL)
			_sqlite3ReleaseTempReg(tls, pParse, regRec)
			_sqlite3ReleaseTempReg(tls, pParse, regTempRowid)
		}
	} else {
		libc.Xmemset(tls, bp+56, 0, uint64(56))
		(**(**TNameContext)(__ccgo_up(bp + 56))).FpParse = pParse
		srcTab = -int32(1)
		if pList != 0 {
			nColumn = (*TExprList)(unsafe.Pointer(pList)).FnExpr
			if _sqlite3ResolveExprListNames(tls, bp+56, pList) != 0 {
				goto insert_cleanup
			}
		} else {
			nColumn = 0
		}
	}
	/* If there is no IDLIST term but the table has an integer primary
	 ** key, the set the ipkColumn variable to the integer primary key
	 ** column index in the original table definition.
	 */
	if pColumn == uintptr(0) && nColumn > 0 {
		ipkColumn = int32((*TTable)(unsafe.Pointer(pTab)).FiPKey)
		if ipkColumn >= 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != uint32(0) {
			i = ipkColumn - int32(1)
			for {
				if !(i >= 0) {
					break
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					ipkColumn = ipkColumn - 1
				}
				goto _9
			_9:
				;
				i = i - 1
			}
		}
		/* Make sure the number of columns in the source data matches the number
		 ** of columns to be inserted into the table.
		 */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(libc.Int32FromInt32(TF_HasGenerated)|libc.Int32FromInt32(TF_HasHidden)) != uint32(0) {
			i = 0
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_NOINSERT) != 0 {
					nHidden = nHidden + 1
				}
				goto _10
			_10:
				;
				i = i + 1
			}
		}
		if nColumn != int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-nHidden {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17430, libc.VaList(bp+128, pTabList+8, int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-nHidden, nColumn))
			goto insert_cleanup
		}
	}
	if pColumn != uintptr(0) && nColumn != (*TIdList)(unsafe.Pointer(pColumn)).FnId {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17482, libc.VaList(bp+128, nColumn, (*TIdList)(unsafe.Pointer(pColumn)).FnId))
		goto insert_cleanup
	}
	/* Initialize the count of rows to be inserted
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0) {
		v5 = pParse + 60
		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
		v1 = *(*int32)(unsafe.Pointer(v5))
		regRowCount = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regRowCount)
	}
	/* If this is not a view, open the table and and all indices */
	if !(isView != 0) {
		nIdx = _sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(0), -int32(1), uintptr(0), bp, bp+4)
		aRegIdx = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(nIdx+libc.Int32FromInt32(2))))
		if aRegIdx == uintptr(0) {
			goto insert_cleanup
		}
		i = 0
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(i < nIdx) {
				break
			}
			v5 = pParse + 60
			*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
			v1 = *(*int32)(unsafe.Pointer(v5))
			**(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)) = v1
			**(**int32)(__ccgo_up(pParse + 60)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
			goto _13
		_13:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
			i = i + 1
		}
		v5 = pParse + 60
		*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
		v1 = *(*int32)(unsafe.Pointer(v5))
		**(**int32)(__ccgo_up(aRegIdx + uintptr(i)*4)) = v1 /* Register to store the table record */
	}
	if pUpsert != 0 {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17507, libc.VaList(bp+128, (*TTable)(unsafe.Pointer(pTab)).FzName))
			goto insert_cleanup
		}
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+17553, 0)
			goto insert_cleanup
		}
		if _sqlite3HasExplicitNulls(tls, pParse, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget) != 0 {
			goto insert_cleanup
		}
		(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = **(**int32)(__ccgo_up(bp))
		pNx = pUpsert
		for cond := true; cond; cond = pNx != uintptr(0) {
			(*TUpsert)(unsafe.Pointer(pNx)).FpUpsertSrc = pTabList
			(*TUpsert)(unsafe.Pointer(pNx)).FregData = regData
			(*TUpsert)(unsafe.Pointer(pNx)).FiDataCur = **(**int32)(__ccgo_up(bp))
			(*TUpsert)(unsafe.Pointer(pNx)).FiIdxCur = **(**int32)(__ccgo_up(bp + 4))
			if (*TUpsert)(unsafe.Pointer(pNx)).FpUpsertTarget != 0 {
				if _sqlite3UpsertAnalyzeTarget(tls, pParse, pTabList, pNx, pUpsert) != 0 {
					goto insert_cleanup
				}
			}
			pNx = (*TUpsert)(unsafe.Pointer(pNx)).FpNextUpsert
		}
	}
	/* This is the top of the main insertion loop */
	if useTempTable != 0 {
		/* This block codes the top of loop only.  The complete loop is the
		 ** following pseudocode (template 4):
		 **
		 **         rewind temp table, if empty goto D
		 **      C: loop over rows of intermediate table
		 **           transfer values form intermediate table into <table>
		 **         end loop
		 **      D: ...
		 */
		addrInsTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), srcTab)
		addrCont = _sqlite3VdbeCurrentAddr(tls, v)
	} else {
		if pSelect != 0 {
			/* This block codes the top of loop only.  The complete loop is the
			 ** following pseudocode (template 3):
			 **
			 **      C: yield X, at EOF goto D
			 **         insert the select result into <table> from R..R+n
			 **         goto C
			 **      D: ...
			 */
			v1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Yield), (**(**TSelectDest)(__ccgo_up(bp + 8))).FiSDParm)
			addrCont = v1
			addrInsTop = v1
			if ipkColumn >= 0 {
				/* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the
				 ** SELECT, go ahead and copy the value into the rowid slot now, so that
				 ** the value does not get overwritten by a NULL at tag-20191021-002. */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regFromSelect+ipkColumn, regRowid)
			}
		}
	}
	/* Compute data for ordinary columns of the new entry.  Values
	 ** are written in storage order into registers starting with regData.
	 ** Only ordinary columns are computed in this loop. The rowid
	 ** (if there is one) is computed later and generated columns are
	 ** computed after the rowid since they might depend on the value
	 ** of the rowid.
	 */
	nHidden = 0
	iRegStore = regData
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
			/* tag-20191021-002: References to the INTEGER PRIMARY KEY are filled
			 ** using the rowid. So put a NULL in the IPK slot of the record to avoid
			 ** using excess space.  The file format definition requires this extra
			 ** NULL - we cannot optimize further by skipping the column completely */
			_sqlite3VdbeAddOp1(tls, v, int32(OP_SoftNull), iRegStore)
			goto _19
		}
		v20 = uint32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)
		colFlags = v20
		if v20&uint32(COLFLAG_NOINSERT) != uint32(0) {
			nHidden = nHidden + 1
			if colFlags&uint32(COLFLAG_VIRTUAL) != uint32(0) {
				/* Virtual columns do not participate in OP_MakeRecord.  So back up
				 ** iRegStore by one slot to compensate for the iRegStore++ in the
				 ** outer for() loop */
				iRegStore = iRegStore - 1
				goto _19
			} else {
				if colFlags&uint32(COLFLAG_STORED) != uint32(0) {
					/* Stored columns are computed later.  But if there are BEFORE
					 ** triggers, the slots used for stored columns will be OP_Copy-ed
					 ** to a second block of registers, so the register needs to be
					 ** initialized to NULL to avoid an uninitialized register read */
					if **(**int32)(__ccgo_up(bp + 48))&int32(TRIGGER_BEFORE) != 0 {
						_sqlite3VdbeAddOp1(tls, v, int32(OP_SoftNull), iRegStore)
					}
					goto _19
				} else {
					if pColumn == uintptr(0) {
						/* Hidden columns that are not explicitly named in the INSERT
						 ** get their default value */
						_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), iRegStore)
						goto _19
					}
				}
			}
		}
		if pColumn != 0 {
			j = **(**int32)(__ccgo_up(aTabColMap + uintptr(i)*4))
			if j == 0 {
				/* A column not named in the insert column list gets its
				 ** default value */
				_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), iRegStore)
				goto _19
			}
			k = j - int32(1)
		} else {
			if nColumn == 0 {
				/* This is INSERT INTO ... DEFAULT VALUES.  Load the default value. */
				_sqlite3ExprCodeFactorable(tls, pParse, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), iRegStore)
				goto _19
			} else {
				k = i - nHidden
			}
		}
		if useTempTable != 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, k, iRegStore)
		} else {
			if pSelect != 0 {
				if regFromSelect != regData {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_SCopy), regFromSelect+k, iRegStore)
				}
			} else {
				pX = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(k)*32))).FpExpr
				y = _sqlite3ExprCodeTarget(tls, pParse, pX, iRegStore)
				if y != iRegStore {
					if (*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
						v1 = int32(OP_Copy)
					} else {
						v1 = int32(OP_SCopy)
					}
					_sqlite3VdbeAddOp2(tls, v, v1, y, iRegStore)
				}
			}
		}
		goto _19
	_19:
		;
		i = i + 1
		iRegStore = iRegStore + 1
	}
	/* Run the BEFORE and INSTEAD OF triggers, if there are any
	 */
	endOfLoop = _sqlite3VdbeMakeLabel(tls, pParse)
	if **(**int32)(__ccgo_up(bp + 48))&int32(TRIGGER_BEFORE) != 0 {
		regCols = _sqlite3GetTempRange(tls, pParse, int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))
		/* build the NEW.* reference row.  Note that if there is an INTEGER
		 ** PRIMARY KEY into which a NULL is being inserted, that NULL will be
		 ** translated into a unique ID for the row.  But on a BEFORE trigger,
		 ** we do not know what the unique ID will be (because the insert has
		 ** not happened yet) so we substitute a rowid of -1
		 */
		if ipkColumn < 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), -int32(1), regCols)
		} else {
			if useTempTable != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, ipkColumn, regCols)
			} else {
				/* Otherwise useTempTable is true */
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32))).FpExpr, regCols)
			}
			addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), regCols)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), -int32(1), regCols)
			_sqlite3VdbeJumpHere(tls, v, addr1)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), regCols)
		}
		/* Copy the new data already generated. */
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regRowid+int32(1), regCols+int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnNVCol)-int32(1))
		/* Compute the new value for generated columns after all other
		 ** columns have already been computed.  This must be done after
		 ** computing the ROWID in case one of the generated columns
		 ** refers to the ROWID. */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
			_sqlite3ComputeGeneratedColumns(tls, pParse, regCols+int32(1), pTab)
		}
		/* If this is an INSERT on a view with an INSTEAD OF INSERT trigger,
		 ** do not attempt any conversions before assembling the record.
		 ** If this is a real table, attempt conversions as required by the
		 ** table column affinities.
		 */
		if !(isView != 0) {
			_sqlite3TableAffinity(tls, v, pTab, regCols+int32(1))
		}
		/* Fire BEFORE or INSTEAD OF triggers */
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_INSERT), uintptr(0), int32(TRIGGER_BEFORE), pTab, regCols-int32((*TTable)(unsafe.Pointer(pTab)).FnCol)-int32(1), onError, endOfLoop)
		_sqlite3ReleaseTempRange(tls, pParse, regCols, int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(1))
	}
	if !(isView != 0) {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			/* The row that the VUpdate opcode will delete: none */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regIns)
		}
		if ipkColumn >= 0 {
			/* Compute the new rowid */
			if useTempTable != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), srcTab, ipkColumn, regRowid)
			} else {
				if pSelect != 0 {
					/* Rowid already initialized at tag-20191021-001 */
				} else {
					pIpk = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32))).FpExpr
					if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pIpk)).Fop) == int32(TK_NULL) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), **(**int32)(__ccgo_up(bp)), regRowid, regAutoinc)
						appendFlag = uint8(1)
					} else {
						_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32))).FpExpr, regRowid)
					}
				}
			}
			/* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
			 ** to generate a unique primary key value.
			 */
			if !(appendFlag != 0) {
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
					addr11 = _sqlite3VdbeAddOp1(tls, v, int32(OP_NotNull), regRowid)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), **(**int32)(__ccgo_up(bp)), regRowid, regAutoinc)
					_sqlite3VdbeJumpHere(tls, v, addr11)
				} else {
					addr11 = _sqlite3VdbeCurrentAddr(tls, v)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regRowid, addr11+int32(2))
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), regRowid)
			}
		} else {
			if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) || withoutRowid != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regRowid)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NewRowid), **(**int32)(__ccgo_up(bp)), regRowid, regAutoinc)
				appendFlag = uint8(1)
			}
		}
		_autoIncStep(tls, pParse, regAutoinc, regRowid)
		/* Compute the new value for generated columns after all other
		 ** columns have already been computed.  This must be done after
		 ** computing the ROWID in case one of the generated columns
		 ** is derived from the INTEGER PRIMARY KEY. */
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
			_sqlite3ComputeGeneratedColumns(tls, pParse, regRowid+int32(1), pTab)
		}
		/* Generate code to check constraints and generate index keys and
		 ** do the insertion.
		 */
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
			pVTab = _sqlite3GetVTable(tls, db, pTab)
			_sqlite3VtabMakeWritable(tls, pParse, pTab)
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VUpdate), int32(1), int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+int32(2), regIns, pVTab, -int32(12))
			if onError == int32(OE_Default) {
				v1 = int32(OE_Abort)
			} else {
				v1 = onError
			}
			_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(v1))
			_sqlite3MayAbort(tls, pParse)
		} else {
			**(**int32)(__ccgo_up(bp + 112)) = 0 /* True to use OPFLAG_SEEKRESULT */
			_sqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), regIns, 0, libc.BoolUint8(ipkColumn >= 0), libc.Uint8FromInt32(onError), endOfLoop, bp+112, uintptr(0), pUpsert)
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 {
				_sqlite3FkCheck(tls, pParse, pTab, 0, regIns, uintptr(0), 0)
			}
			/* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
			 ** constraints or (b) there are no triggers and this table is not a
			 ** parent table in a foreign key constraint. It is safe to set the
			 ** flag in the second case as if any REPLACE constraint is hit, an
			 ** OP_Delete or OP_IdxDelete instruction will be executed on each
			 ** cursor that is disturbed. And these instructions both clear the
			 ** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
			 ** functionality.  */
			bUseSeek = libc.BoolInt32(**(**int32)(__ccgo_up(bp + 112)) == 0 || !(_sqlite3VdbeHasSubProgram(tls, v) != 0))
			_sqlite3CompleteInsertion(tls, pParse, pTab, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), regIns, aRegIdx, 0, libc.Int32FromUint8(appendFlag), bUseSeek)
		}
	}
	/* Update the count of rows that are inserted
	 */
	if regRowCount != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regRowCount, int32(1))
	}
	if pTrigger != 0 {
		/* Code AFTER triggers */
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_INSERT), uintptr(0), int32(TRIGGER_AFTER), pTab, regData-int32(2)-int32((*TTable)(unsafe.Pointer(pTab)).FnCol), onError, endOfLoop)
	}
	/* The bottom of the main insertion loop, if the data source
	 ** is a SELECT statement.
	 */
	_sqlite3VdbeResolveLabel(tls, v, endOfLoop)
	if useTempTable != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), srcTab, addrCont)
		_sqlite3VdbeJumpHere(tls, v, addrInsTop)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), srcTab)
	} else {
		if pSelect != 0 {
			_sqlite3VdbeGoto(tls, v, addrCont)
			_sqlite3VdbeJumpHere(tls, v, addrInsTop)
		}
	}
	goto insert_end
insert_end:
	;
	/* Update the sqlite_sequence table by storing the content of the
	 ** maximum rowid counter values recorded while inserting into
	 ** autoincrement tables.
	 */
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) {
		_sqlite3AutoincrementEnd(tls, pParse)
	}
	/*
	 ** Return the number of rows inserted. If this routine is
	 ** generating code because of a call to sqlite3NestedParse(), do not
	 ** invoke the callback function.
	 */
	if regRowCount != 0 {
		_sqlite3CodeChangeCount(tls, v, regRowCount, __ccgo_ts+17574)
	}
	goto insert_cleanup
insert_cleanup:
	;
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprListDelete(tls, db, pList)
	_sqlite3UpsertDelete(tls, db, pUpsert)
	_sqlite3SelectDelete(tls, db, pSelect)
	if pColumn != 0 {
		_sqlite3IdListDelete(tls, db, pColumn)
		_sqlite3DbFree(tls, db, aTabColMap)
	}
	if aRegIdx != 0 {
		_sqlite3DbNNFreeNN(tls, db, aRegIdx)
	}
}

/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).  */

/*
** Meanings of bits in of pWalker->eCode for
** sqlite3ExprReferencesUpdatedColumn()
 */

// C documentation
//
//	/*
//	** Return a KeyInfo structure that is appropriate for the given Index.
//	**
//	** The caller should invoke sqlite3KeyInfoUnref() on the returned object
//	** when it has finished using it.
//	*/
func _sqlite3KeyInfoOfIndex(tls *libc.TLS, pParse uintptr, pIdx uintptr) (r uintptr) {
	var i, nCol, nKey int32
	var pKey, zColl, v2 uintptr
	_, _, _, _, _, _ = i, nCol, nKey, pKey, zColl, v2
	nCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
	nKey = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x1000>>12)) != 0 {
		pKey = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nKey, nCol-nKey)
	} else {
		pKey = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, nCol, 0)
	}
	if pKey != 0 {
		i = 0
		for {
			if !(i < nCol) {
				break
			}
			zColl = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8))
			if zColl == uintptr(unsafe.Pointer(&_sqlite3StrBINARY)) {
				v2 = uintptr(0)
			} else {
				v2 = _sqlite3LocateCollSeq(tls, pParse, zColl)
			}
			*(*uintptr)(unsafe.Pointer(pKey + 32 + uintptr(i)*8)) = v2
			**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKey)).FaSortFlags + uintptr(i))) = **(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i)))
			goto _1
		_1:
			;
			i = i + 1
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x80>>7)) == 0 && _sqlite3HashFind(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpSchema+32, (*TIndex)(unsafe.Pointer(pIdx)).FzName) != 0 {
				/* Deactivate the index because it contains an unknown collating
				 ** sequence.  The only way to reactive the index is to reload the
				 ** schema.  Adding the missing collating sequence later does not
				 ** reactive the index.  The application had the chance to register
				 ** the missing index using the collation-needed callback.  For
				 ** simplicity, SQLite will not give the application a second chance.
				 **
				 ** Except, do not do this if the index is not in the schema hash
				 ** table. In this case the index is currently being constructed
				 ** by a CREATE INDEX statement, and retrying will not help.  */
				libc.SetBitFieldPtr16Uint32(pIdx+100, libc.Uint32FromInt32(1), 7, 0x80)
				(*TParse)(unsafe.Pointer(pParse)).Frc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
			}
			_sqlite3KeyInfoUnref(tls, pKey)
			pKey = uintptr(0)
		}
	}
	return pKey
}

// C documentation
//
//	/*
//	** Locate the in-memory structure that describes a particular database
//	** table given the name of that table and (optionally) the name of the
//	** database containing the table.  Return NULL if not found.  Also leave an
//	** error message in pParse->zErrMsg.
//	**
//	** The difference between this routine and sqlite3FindTable() is that this
//	** routine leaves an error message in pParse->zErrMsg where
//	** sqlite3FindTable() does not.
//	*/
func _sqlite3LocateTable(tls *libc.TLS, pParse uintptr, flags Tu32, zName uintptr, zDbase uintptr) (r uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, p, pMod, zMsg, v1 uintptr
	_, _, _, _, _ = db, p, pMod, zMsg, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	/* Read the database schema. If an error occurs, leave an error message
	 ** and code in pParse and return NULL. */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_SchemaKnownOk) == uint32(0) && SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		return uintptr(0)
	}
	p = _sqlite3FindTable(tls, db, zName, zDbase)
	if p == uintptr(0) {
		/* If zName is the not the name of a table in the schema created using
		 ** CREATE, then check to see if it is the name of an virtual table that
		 ** can be an eponymous virtual table. */
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_NO_VTAB) == 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
			pMod = _sqlite3HashFind(tls, db+576, zName)
			if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13690, int32(7)) == 0 {
				pMod = _sqlite3PragmaVtabRegister(tls, db, zName)
			}
			if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, __ccgo_ts+13698, int32(4)) == 0 {
				pMod = _sqlite3JsonVtabRegister(tls, db, zName)
			}
			if pMod != 0 && _sqlite3VtabEponymousTableInit(tls, pParse, pMod) != 0 {
				return (*TModule)(unsafe.Pointer(pMod)).FpEpoTab
			}
		}
		if flags&uint32(LOCATE_NOERR) != 0 {
			return uintptr(0)
		}
		libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
	} else {
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(p)).FeTabType) == int32(TABTYP_VTAB) && libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FprepFlags)&int32(SQLITE_PREPARE_NO_VTAB) != 0 {
			p = uintptr(0)
		}
	}
	if p == uintptr(0) {
		if flags&uint32(LOCATE_VIEW) != 0 {
			v1 = __ccgo_ts + 13703
		} else {
			v1 = __ccgo_ts + 13716
		}
		zMsg = v1
		if zDbase != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7024, libc.VaList(bp+8, zMsg, zDbase, zName))
		} else {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+7095, libc.VaList(bp+8, zMsg, zName))
		}
	} else {
	}
	return p
}

// C documentation
//
//	/*
//	** Locate the table identified by *p.
//	**
//	** This is a wrapper around sqlite3LocateTable(). The difference between
//	** sqlite3LocateTable() and this function is that this function restricts
//	** the search to schema (p->pSchema) if it is not NULL. p->pSchema may be
//	** non-NULL if it is part of a view or trigger program definition. See
//	** sqlite3FixSrcList() for details.
//	*/
func _sqlite3LocateTableItem(tls *libc.TLS, pParse uintptr, flags Tu32, p uintptr) (r uintptr) {
	var iDb int32
	var zDb uintptr
	_, _ = iDb, zDb
	if int32(*(*uint32)(unsafe.Pointer(p + 24 + 4))&0x8000>>15) != 0 {
		iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(p + 72)))
		zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*32))).FzDbSName
	} else {
		zDb = *(*uintptr)(unsafe.Pointer(p + 72))
	}
	return _sqlite3LocateTable(tls, pParse, flags, (*TSrcItem)(unsafe.Pointer(p)).FzName, zDb)
}

// C documentation
//
//	/*
//	** Subqueries store the original database, table and column names for their
//	** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN",
//	** and mark the expression-list item by setting ExprList.a[].fg.eEName
//	** to ENAME_TAB.
//	**
//	** Check to see if the zSpan/eEName of the expression-list item passed to this
//	** routine matches the zDb, zTab, and zCol.  If any of zDb, zTab, and zCol are
//	** NULL then those fields will match anything. Return true if there is a match,
//	** or false otherwise.
//	**
//	** SF_NestedFrom subqueries also store an entry for the implicit rowid (or
//	** _rowid_, or oid) column by setting ExprList.a[].fg.eEName to ENAME_ROWID,
//	** and setting zSpan to "DATABASE.TABLE.<rowid-alias>". This type of pItem
//	** argument matches if zCol is a rowid alias. If it is not NULL, (*pbRowid)
//	** is set to 1 if there is this kind of match.
//	*/
func _sqlite3MatchEName(tls *libc.TLS, pItem uintptr, zCol uintptr, zTab uintptr, zDb uintptr, pbRowid uintptr) (r int32) {
	var eEName, n int32
	var zSpan uintptr
	_, _, _ = eEName, n, zSpan
	eEName = int32(uint32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4)) & 0xc000 >> 14))
	if eEName != int32(ENAME_TAB) && (eEName != int32(ENAME_ROWID) || pbRowid == uintptr(0)) {
		return 0
	}
	zSpan = (*TExprList_item)(unsafe.Pointer(pItem)).FzEName
	n = 0
	for {
		if !(**(**uint8)(__ccgo_up(zSpan + uintptr(n))) != 0 && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zSpan + uintptr(n)))) != int32('.')) {
			break
		}
		goto _1
	_1:
		;
		n = n + 1
	}
	if zDb != 0 && (Xsqlite3_strnicmp(tls, zSpan, zDb, n) != 0 || libc.Int32FromUint8(**(**uint8)(__ccgo_up(zDb + uintptr(n)))) != 0) {
		return 0
	}
	zSpan = zSpan + uintptr(n+int32(1))
	n = 0
	for {
		if !(**(**uint8)(__ccgo_up(zSpan + uintptr(n))) != 0 && libc.Int32FromUint8(**(**uint8)(__ccgo_up(zSpan + uintptr(n)))) != int32('.')) {
			break
		}
		goto _2
	_2:
		;
		n = n + 1
	}
	if zTab != 0 && (Xsqlite3_strnicmp(tls, zSpan, zTab, n) != 0 || libc.Int32FromUint8(**(**uint8)(__ccgo_up(zTab + uintptr(n)))) != 0) {
		return 0
	}
	zSpan = zSpan + uintptr(n+int32(1))
	if zCol != 0 {
		if eEName == int32(ENAME_TAB) && _sqlite3StrICmp(tls, zSpan, zCol) != 0 {
			return 0
		}
		if eEName == int32(ENAME_ROWID) && _sqlite3IsRowid(tls, zCol) == 0 {
			return 0
		}
	}
	if eEName == int32(ENAME_ROWID) {
		**(**int32)(__ccgo_up(pbRowid)) = int32(1)
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** The code generator calls this routine if is discovers that it is
//	** possible to abort a statement prior to completion.  In order to
//	** perform this abort without corrupting the database, we need to make
//	** sure that the statement is protected by a statement transaction.
//	**
//	** Technically, we only need to set the mayAbort flag if the
//	** isMultiWrite flag was previously set.  There is a time dependency
//	** such that the abort must occur after the multiwrite.  This makes
//	** some statements involving the REPLACE conflict resolution algorithm
//	** go a little faster.  But taking advantage of this time dependency
//	** makes it more difficult to prove that the code is correct (in
//	** particular, it prevents us from writing an effective
//	** implementation of sqlite3AssertMayAbort()) and so we have chosen
//	** to take the safe route and skip the optimization.
//	*/
func _sqlite3MayAbort(tls *libc.TLS, pParse uintptr) {
	var pToplevel, v1 uintptr
	_, _ = pToplevel, v1
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pToplevel = v1
	libc.SetBitFieldPtr16Uint32(pToplevel+40, libc.Uint32FromInt32(1), 14, 0x4000)
}

// C documentation
//
//	/*
//	** This function is called by the parser for the second and subsequent
//	** rows of a multi-row VALUES clause. Argument pLeft is the part of
//	** the VALUES clause already parsed, argument pRow is the vector of values
//	** for the new row. The Select object returned represents the complete
//	** VALUES clause, including the new row.
//	**
//	** There are two ways in which this may be achieved - by incremental
//	** coding of a co-routine (the "co-routine" method) or by returning a
//	** Select object equivalent to the following (the "UNION ALL" method):
//	**
//	**        "pLeft UNION ALL SELECT pRow"
//	**
//	** If the VALUES clause contains a lot of rows, this compound Select
//	** object may consume a lot of memory.
//	**
//	** When the co-routine method is used, each row that will be returned
//	** by the VALUES clause is coded into part of a co-routine as it is
//	** passed to this function. The returned Select object is equivalent to:
//	**
//	**     SELECT * FROM (
//	**       Select object to read co-routine
//	**     )
//	**
//	** The co-routine method is used in most cases. Exceptions are:
//	**
//	**    a) If the current statement has a WITH clause. This is to avoid
//	**       statements like:
//	**
//	**            WITH cte AS ( VALUES('x'), ('y') ... )
//	**            SELECT * FROM cte AS a, cte AS b;
//	**
//	**       This will not work, as the co-routine uses a hard-coded register
//	**       for its OP_Yield instructions, and so it is not possible for two
//	**       cursors to iterate through it concurrently.
//	**
//	**    b) The schema is currently being parsed (i.e. the VALUES clause is part
//	**       of a schema item like a VIEW or TRIGGER). In this case there is no VM
//	**       being generated when parsing is taking place, and so generating
//	**       a co-routine is not possible.
//	**
//	**    c) There are non-constant expressions in the VALUES clause (e.g.
//	**       the VALUES clause is part of a correlated sub-query).
//	**
//	**    d) One or more of the values in the first row of the VALUES clause
//	**       has an affinity (i.e. is a CAST expression). This causes problems
//	**       because the complex rules SQLite uses (see function
//	**       sqlite3SubqueryColumnTypes() in select.c) to determine the effective
//	**       affinity of such a column for all rows require access to all values in
//	**       the column simultaneously.
//	*/
func _sqlite3MultiValues(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRow uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var f, v1 int32
	var p, pRet, pSelect, pSubq, pSubq1, v, v2 uintptr
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _, _, _, _, _, _ = f, p, pRet, pSelect, pSubq, pSubq1, v, v1, v2
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x200>>9)) != 0 || (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy != 0 || _exprListIsConstant(tls, pParse, pRow) == 0 || (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pLeft)).FpSrc)).FnSrc == 0 && _exprListIsNoAffinity(tls, pParse, (*TSelect)(unsafe.Pointer(pLeft)).FpEList) == 0 || libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
		/* The co-routine method cannot be used. Fall back to UNION ALL. */
		pSelect = uintptr(0)
		f = libc.Int32FromInt32(SF_Values) | libc.Int32FromInt32(SF_MultiValue)
		if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pLeft)).FpSrc)).FnSrc != 0 {
			_sqlite3MultiValuesEnd(tls, pParse, pLeft)
			f = int32(SF_Values)
		} else {
			if (*TSelect)(unsafe.Pointer(pLeft)).FpPrior != 0 {
				/* In this case set the SF_MultiValue flag only if it was set on pLeft */
				f = libc.Int32FromUint32(libc.Uint32FromInt32(f) & (*TSelect)(unsafe.Pointer(pLeft)).FselFlags)
			}
		}
		pSelect = _sqlite3SelectNew(tls, pParse, pRow, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), libc.Uint32FromInt32(f), uintptr(0))
		**(**Tu32)(__ccgo_up(pLeft + 4)) &= ^libc.Uint32FromInt32(SF_MultiValue)
		if pSelect != 0 {
			(*TSelect)(unsafe.Pointer(pSelect)).Fop = uint8(TK_ALL)
			(*TSelect)(unsafe.Pointer(pSelect)).FpPrior = pLeft
			pLeft = pSelect
		}
	} else {
		p = uintptr(0) /* SrcItem that reads from co-routine */
		if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pLeft)).FpSrc)).FnSrc == 0 {
			/* Co-routine has not yet been started and the special Select object
			 ** that accesses the co-routine has not yet been created. This block
			 ** does both those things. */
			v = _sqlite3GetVdbe(tls, pParse)
			pRet = _sqlite3SelectNew(tls, pParse, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
			/* Ensure the database schema has been read. This is to ensure we have
			 ** the correct text encoding.  */
			if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&uint32(DBFLAG_SchemaKnownOk) == uint32(0) {
				_sqlite3ReadSchema(tls, pParse)
			}
			if pRet != 0 {
				(*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pRet)).FpSrc)).FnSrc = int32(1)
				(*TSelect)(unsafe.Pointer(pRet)).FpPrior = (*TSelect)(unsafe.Pointer(pLeft)).FpPrior
				(*TSelect)(unsafe.Pointer(pRet)).Fop = (*TSelect)(unsafe.Pointer(pLeft)).Fop
				if (*TSelect)(unsafe.Pointer(pRet)).FpPrior != 0 {
					**(**Tu32)(__ccgo_up(pRet + 4)) |= uint32(SF_Values)
				}
				(*TSelect)(unsafe.Pointer(pLeft)).FpPrior = uintptr(0)
				(*TSelect)(unsafe.Pointer(pLeft)).Fop = uint8(TK_SELECT)
				p = (*TSelect)(unsafe.Pointer(pRet)).FpSrc + 8
				libc.SetBitFieldPtr32Uint32(p+24+4, libc.Uint32FromInt32(1), 25, 0x2000000)
				(*TSrcItem)(unsafe.Pointer(p)).FiCursor = -int32(1)
				*(*Tu32)(unsafe.Pointer(&(*TSrcItem)(unsafe.Pointer(p)).Fu1)) = uint32(2)
				if _sqlite3SrcItemAttachSubquery(tls, pParse, p, pLeft, 0) != 0 {
					pSubq = *(*uintptr)(unsafe.Pointer(p + 72))
					(*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
					v2 = pParse + 60
					*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
					v1 = *(*int32)(unsafe.Pointer(v2))
					(*TSubquery)(unsafe.Pointer(pSubq)).FregReturn = v1
					_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, 0, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
					_sqlite3SelectDestInit(tls, bp, int32(SRT_Coroutine), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn)
					/* Allocate registers for the output of the co-routine. Do so so
					 ** that there are two unused registers immediately before those
					 ** used by the co-routine. This allows the code in sqlite3Insert()
					 ** to use these registers directly, instead of copying the output
					 ** of the co-routine to a separate array for processing.  */
					(**(**TSelectDest)(__ccgo_up(bp))).FiSdst = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(3)
					(**(**TSelectDest)(__ccgo_up(bp))).FnSdst = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pLeft)).FpEList)).FnExpr
					**(**int32)(__ccgo_up(pParse + 60)) += int32(2) + (**(**TSelectDest)(__ccgo_up(bp))).FnSdst
					**(**Tu32)(__ccgo_up(pLeft + 4)) |= uint32(SF_MultiValue)
					_sqlite3Select(tls, pParse, pLeft, bp)
					(*TSubquery)(unsafe.Pointer(pSubq)).FregResult = (**(**TSelectDest)(__ccgo_up(bp))).FiSdst
				}
				pLeft = pRet
			}
		} else {
			p = (*TSelect)(unsafe.Pointer(pLeft)).FpSrc + 8
			*(*Tu32)(unsafe.Pointer(&(*TSrcItem)(unsafe.Pointer(p)).Fu1)) = *(*Tu32)(unsafe.Pointer(&(*TSrcItem)(unsafe.Pointer(p)).Fu1)) + 1
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
			pSubq1 = *(*uintptr)(unsafe.Pointer(p + 72))
			if (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pSubq1)).FpSelect)).FpEList)).FnExpr != (*TExprList)(unsafe.Pointer(pRow)).FnExpr {
				_sqlite3SelectWrongNumTermsError(tls, pParse, (*TSubquery)(unsafe.Pointer(pSubq1)).FpSelect)
			} else {
				_sqlite3ExprCodeExprList(tls, pParse, pRow, (*TSubquery)(unsafe.Pointer(pSubq1)).FregResult, 0, uint8(0))
				_sqlite3VdbeAddOp1(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Yield), (*TSubquery)(unsafe.Pointer(pSubq1)).FregReturn)
			}
		}
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pRow)
	}
	return pLeft
}

// C documentation
//
//	/*
//	** If argument pVal is a Select object returned by an sqlite3MultiValues()
//	** that was able to use the co-routine optimization, finish coding the
//	** co-routine.
//	*/
func _sqlite3MultiValuesEnd(tls *libc.TLS, pParse uintptr, pVal uintptr) {
	var pItem uintptr
	_ = pItem
	if pVal != 0 && (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pVal)).FpSrc)).FnSrc > 0 {
		pItem = (*TSelect)(unsafe.Pointer(pVal)).FpSrc + 8
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
			_sqlite3VdbeEndCoroutine(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FregReturn)
			_sqlite3VdbeJumpHere(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FaddrFillSub-int32(1))
		}
	}
}

// C documentation
//
//	/*
//	** Allocate cursors for the pTab table and all its indices and generate
//	** code to open and initialized those cursors.
//	**
//	** The cursor for the object that contains the complete data (normally
//	** the table itself, but the PRIMARY KEY index in the case of a WITHOUT
//	** ROWID table) is returned in *piDataCur.  The first index cursor is
//	** returned in *piIdxCur.  The number of indices is returned.
//	**
//	** Use iBase as the first cursor (either the *piDataCur for rowid tables
//	** or the first index for WITHOUT ROWID tables) if it is non-negative.
//	** If iBase is negative, then allocate the next available cursor.
//	**
//	** For a rowid table, *piDataCur will be exactly one less than *piIdxCur.
//	** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
//	** of *piIdxCurs, depending on where the PRIMARY KEY index appears on the
//	** pTab->pIndex list.
//	**
//	** If pTab is a virtual table, then this routine is a no-op and the
//	** *piDataCur and *piIdxCur values are left uninitialized.
//	*/
func _sqlite3OpenTableAndIndices(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, p5 Tu8, iBase int32, aToOpen uintptr, piDataCur uintptr, piIdxCur uintptr) (r int32) {
	var i, iDataCur, iDb, iIdxCur, v1 int32
	var pIdx, v uintptr
	_, _, _, _, _, _, _ = i, iDataCur, iDb, iIdxCur, pIdx, v, v1
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		/* This routine is a no-op for virtual tables. Leave the output
		 ** variables *piDataCur and *piIdxCur set to illegal cursor numbers
		 ** for improved error detection. */
		v1 = -libc.Int32FromInt32(999)
		**(**int32)(__ccgo_up(piIdxCur)) = v1
		**(**int32)(__ccgo_up(piDataCur)) = v1
		return 0
	}
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	if iBase < 0 {
		iBase = (*TParse)(unsafe.Pointer(pParse)).FnTab
	}
	v1 = iBase
	iBase = iBase + 1
	iDataCur = v1
	**(**int32)(__ccgo_up(piDataCur)) = iDataCur
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && (aToOpen == uintptr(0) || **(**Tu8)(__ccgo_up(aToOpen)) != 0) {
		_sqlite3OpenTable(tls, pParse, iDataCur, iDb, pTab, op)
	} else {
		if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FnoSharedCache) == 0 {
			_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, libc.BoolUint8(op == int32(OP_OpenWrite)), (*TTable)(unsafe.Pointer(pTab)).FzName)
		}
	}
	**(**int32)(__ccgo_up(piIdxCur)) = iBase
	i = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		v1 = iBase
		iBase = iBase + 1
		iIdxCur = v1
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			**(**int32)(__ccgo_up(piDataCur)) = iIdxCur
			p5 = uint8(0)
		}
		if aToOpen == uintptr(0) || **(**Tu8)(__ccgo_up(aToOpen + uintptr(i+int32(1)))) != 0 {
			_sqlite3VdbeAddOp3(tls, v, op, iIdxCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
			_sqlite3VdbeChangeP5(tls, v, uint16(p5))
		}
		goto _3
	_3:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		i = i + 1
	}
	if iBase > (*TParse)(unsafe.Pointer(pParse)).FnTab {
		(*TParse)(unsafe.Pointer(pParse)).FnTab = iBase
	}
	return i
}

// C documentation
//
//	/*
//	** Process a pragma statement.
//	**
//	** Pragmas are of this form:
//	**
//	**      PRAGMA [schema.]id [= value]
//	**
//	** The identifier might also be a string.  The value is a string, and
//	** identifier, or a number.  If minusFlag is true, then the value is
//	** a number that was preceded by a minus sign.
//	**
//	** If the left side is "database.id" then pId1 is the database name
//	** and pId2 is the id.  If the left side is just "id" then pId1 is the
//	** id and pId2 is any empty string.
//	*/
func _sqlite3Pragma(tls *libc.TLS, pParse uintptr, pId1 uintptr, pId2 uintptr, pValue uintptr, minusFlag int32) {
	bp := tls.Alloc(240)
	defer tls.Free(240)
	var a1, a11, addr, addr1, addrCkFault, addrCkOk, addrOk, addrTop, b, bStrict, ckUniq, cnt, doTypeCheck, eAuto, eMode, eMode1, eMode2, i, i1, i10, i2, i3, i4, i5, i6, i7, i8, i9, iAddr, iAddr1, iBt, iCol, iCol1, iCookie, iDb, iDbLast, iEnd, iIdxDb, iLevel, iReg, iTab, iTabCur, iTabDb, iTabDb1, ii, ii1, ii2, ii3, ii4, initNCol, isHidden, isQuick, j2, j3, j4, jmp, jmp2, jmp21, jmp3, jmp4, jmp5, jmp6, jmp61, jmp7, k, k3, kk, label6, labelError, labelOk, loopTop, mx, mxCol, n, nBtree, nCheck, nHidden, nIdx, nIndex, nLimit, p11, p3, p4, r1, r11, r2, rc, regResult, regRow, showInternFunc, size, size1, size2, uniqOk, x1, v2 int32
	var aOp, aOp1, aOp2, aOp3, aOp4, aOp5, aRoot, db, j, j1, k1, k2, k4, p, p1, pBt, pBt1, pBt2, pCheck, pCol, pCol1, pColExpr, pColl, pDb, pEnc, pFK, pFK1, pHash, pIdx, pIdx1, pIdx3, pIdx4, pIdx5, pIdx6, pIdx7, pMod, pObjTab, pPager, pPager1, pParent, pPk, pPk1, pPragma, pPrior, pSchema, pTab, pTab1, pTab10, pTab11, pTab12, pTab2, pTab3, pTab4, pTab5, pTab6, pTab7, pTab8, pTab9, pTbls, pVTab, v, x2, zDb, zErr, zErr1, zErr2, zLeft, zMod, zMode, zOpt, zRet, zRight, zSql, zSubSql, zType, v1, v5 uintptr
	var azOrigin [3]uintptr
	var cnum Ti16
	var enc Tu8
	var iPrior Tsqlite3_int64
	var iRange, szThreshold TLogEst
	var mask Tu64
	var opMask Tu32
	var _ /* N at bp+136 */ Tsqlite3_int64
	var _ /* N at bp+144 */ Tsqlite3_int64
	var _ /* N at bp+152 */ Tsqlite3_int64
	var _ /* N at bp+160 */ Tsqlite3_int64
	var _ /* aFcntl at bp+8 */ [4]uintptr
	var _ /* aiCols at bp+96 */ uintptr
	var _ /* iDataCur at bp+108 */ int32
	var _ /* iIdxCur at bp+112 */ int32
	var _ /* iLimit at bp+48 */ Ti64
	var _ /* iLimit at bp+56 */ int32
	var _ /* jmp3 at bp+128 */ int32
	var _ /* mxErr at bp+104 */ int32
	var _ /* pDfltValue at bp+120 */ uintptr
	var _ /* pDummy at bp+80 */ uintptr
	var _ /* pId at bp+0 */ uintptr
	var _ /* pIdx at bp+88 */ uintptr
	var _ /* res at bp+72 */ int32
	var _ /* size at bp+60 */ int32
	var _ /* sz at bp+64 */ Tsqlite3_int64
	var _ /* x at bp+40 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a1, a11, aOp, aOp1, aOp2, aOp3, aOp4, aOp5, aRoot, addr, addr1, addrCkFault, addrCkOk, addrOk, addrTop, azOrigin, b, bStrict, ckUniq, cnt, cnum, db, doTypeCheck, eAuto, eMode, eMode1, eMode2, enc, i, i1, i10, i2, i3, i4, i5, i6, i7, i8, i9, iAddr, iAddr1, iBt, iCol, iCol1, iCookie, iDb, iDbLast, iEnd, iIdxDb, iLevel, iPrior, iRange, iReg, iTab, iTabCur, iTabDb, iTabDb1, ii, ii1, ii2, ii3, ii4, initNCol, isHidden, isQuick, j, j1, j2, j3, j4, jmp, jmp2, jmp21, jmp3, jmp4, jmp5, jmp6, jmp61, jmp7, k, k1, k2, k3, k4, kk, label6, labelError, labelOk, loopTop, mask, mx, mxCol, n, nBtree, nCheck, nHidden, nIdx, nIndex, nLimit, opMask, p, p1, p11, p3, p4, pBt, pBt1, pBt2, pCheck, pCol, pCol1, pColExpr, pColl, pDb, pEnc, pFK, pFK1, pHash, pIdx, pIdx1, pIdx3, pIdx4, pIdx5, pIdx6, pIdx7, pMod, pObjTab, pPager, pPager1, pParent, pPk, pPk1, pPragma, pPrior, pSchema, pTab, pTab1, pTab10, pTab11, pTab12, pTab2, pTab3, pTab4, pTab5, pTab6, pTab7, pTab8, pTab9, pTbls, pVTab, r1, r11, r2, rc, regResult, regRow, showInternFunc, size, size1, size2, szThreshold, uniqOk, v, x1, x2, zDb, zErr, zErr1, zErr2, zLeft, zMod, zMode, zOpt, zRet, zRight, zSql, zSubSql, zType, v1, v2, v5
	zLeft = uintptr(0)                         /* Nul-terminated UTF-8 string <id> */
	zRight = uintptr(0)                        /* Nul-terminated UTF-8 string <value>, or NULL */
	zDb = uintptr(0)                           /* return value form SQLITE_FCNTL_PRAGMA */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* The specific database being pragmaed */
	v = _sqlite3GetVdbe(tls, pParse)           /* The pragma */
	if v == uintptr(0) {
		return
	}
	_sqlite3VdbeRunOnlyOnce(tls, v)
	(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(2)
	/* Interpret the [schema.] part of the pragma statement. iDb is the
	 ** index of the database this pragma is being applied to in db.aDb[]. */
	iDb = _sqlite3TwoPartName(tls, pParse, pId1, pId2, bp)
	if iDb < 0 {
		return
	}
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	/* If the temp database has been explicitly named as part of the
	 ** pragma, make sure it is open.
	 */
	if iDb == int32(1) && _sqlite3OpenTempDatabase(tls, pParse) != 0 {
		return
	}
	zLeft = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
	if !(zLeft != 0) {
		return
	}
	if minusFlag != 0 {
		zRight = _sqlite3MPrintf(tls, db, __ccgo_ts+19218, libc.VaList(bp+176, pValue))
	} else {
		zRight = _sqlite3NameFromToken(tls, db, pValue)
	}
	if (*TToken)(unsafe.Pointer(pId2)).Fn > uint32(0) {
		v1 = (*TDb)(unsafe.Pointer(pDb)).FzDbSName
	} else {
		v1 = uintptr(0)
	}
	zDb = v1
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_PRAGMA), zLeft, zRight, zDb) != 0 {
		goto pragma_out
	}
	/* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
	 ** connection.  If it returns SQLITE_OK, then assume that the VFS
	 ** handled the pragma and generate a no-op prepared statement.
	 **
	 ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
	 ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
	 ** object corresponding to the database file to which the pragma
	 ** statement refers.
	 **
	 ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
	 ** file control is an array of pointers to strings (char**) in which the
	 ** second element of the array is the name of the pragma and the third
	 ** element is the argument to the pragma or NULL if the pragma has no
	 ** argument.
	 */
	(**(**[4]uintptr)(__ccgo_up(bp + 8)))[0] = uintptr(0)
	(**(**[4]uintptr)(__ccgo_up(bp + 8)))[int32(1)] = zLeft
	(**(**[4]uintptr)(__ccgo_up(bp + 8)))[int32(2)] = zRight
	(**(**[4]uintptr)(__ccgo_up(bp + 8)))[int32(3)] = uintptr(0)
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	rc = Xsqlite3_file_control(tls, db, zDb, int32(SQLITE_FCNTL_PRAGMA), bp+8)
	if rc == SQLITE_OK {
		_sqlite3VdbeSetNumCols(tls, v, int32(1))
		_sqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, (**(**[4]uintptr)(__ccgo_up(bp + 8)))[0], uintptr(-libc.Int32FromInt32(1)))
		_returnSingleText(tls, v, (**(**[4]uintptr)(__ccgo_up(bp + 8)))[0])
		Xsqlite3_free(tls, (**(**[4]uintptr)(__ccgo_up(bp + 8)))[0])
		goto pragma_out
	}
	if rc != int32(SQLITE_NOTFOUND) {
		if (**(**[4]uintptr)(__ccgo_up(bp + 8)))[0] != 0 {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+3944, libc.VaList(bp+176, (**(**[4]uintptr)(__ccgo_up(bp + 8)))[0]))
			Xsqlite3_free(tls, (**(**[4]uintptr)(__ccgo_up(bp + 8)))[0])
		}
		(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
		(*TParse)(unsafe.Pointer(pParse)).Frc = rc
		goto pragma_out
	}
	/* Locate the pragma in the lookup table */
	pPragma = _pragmaLocate(tls, zLeft)
	if pPragma == uintptr(0) {
		/* IMP: R-43042-22504 No error messages are generated if an
		 ** unknown pragma is issued. */
		goto pragma_out
	}
	/* Make sure the database schema is loaded if the pragma requires that */
	if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NeedSchema) != 0 {
		if _sqlite3ReadSchema(tls, pParse) != 0 {
			goto pragma_out
		}
	}
	/* Register the result column names for pragmas that return results */
	if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns) == 0 && (libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns1) == 0 || zRight == uintptr(0)) {
		_setPragmaResultColumnNames(tls, v, pPragma)
	}
	/* Jump to the appropriate pragma handler */
	switch libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FePragTyp) {
	/*
	 **  PRAGMA [schema.]default_cache_size
	 **  PRAGMA [schema.]default_cache_size=N
	 **
	 ** The first form reports the current persistent setting for the
	 ** page cache size.  The value returned is the maximum number of
	 ** pages in the page cache.  The second form sets both the current
	 ** page cache size value and the persistent page cache size value
	 ** stored in the database file.
	 **
	 ** Older versions of SQLite would set the default cache size to a
	 ** negative number to indicate synchronous=OFF.  These days, synchronous
	 ** is always on by default regardless of the sign of the default cache
	 ** size.  But continue to take the absolute value of the default cache
	 ** size of historical compatibility.
	 */
	case int32(PragTyp_DEFAULT_CACHE_SIZE):
		_sqlite3VdbeUsesBtree(tls, v, iDb)
		if !(zRight != 0) {
			**(**int32)(__ccgo_up(pParse + 60)) += int32(2)
			aOp = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(36)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_getCacheSize)), _iLn3)
			if 0 != 0 {
				break
			}
			(**(**TVdbeOp)(__ccgo_up(aOp))).Fp1 = iDb
			(**(**TVdbeOp)(__ccgo_up(aOp + 1*24))).Fp1 = iDb
			(**(**TVdbeOp)(__ccgo_up(aOp + 6*24))).Fp1 = -int32(2000)
		} else {
			size = _sqlite3AbsInt32(tls, _sqlite3Atoi(tls, zRight))
			_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_DEFAULT_CACHE_SIZE), size)
			(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size
			_sqlite3BtreeSetCacheSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
		}
		break
		/*
		 **  PRAGMA [schema.]page_size
		 **  PRAGMA [schema.]page_size=N
		 **
		 ** The first form reports the current setting for the
		 ** database page size in bytes.  The second form sets the
		 ** database page size value.  The value can only be set if
		 ** the database has not yet been created.
		 */
		fallthrough
	case int32(PragTyp_PAGE_SIZE):
		pBt = (*TDb)(unsafe.Pointer(pDb)).FpBt
		if !(zRight != 0) {
			if pBt != 0 {
				v2 = _sqlite3BtreeGetPageSize(tls, pBt)
			} else {
				v2 = 0
			}
			size1 = v2
			_returnSingleInt(tls, v, int64(size1))
		} else {
			/* Malloc may fail when setting the page-size, as there is an internal
			 ** buffer that the pager module resizes using sqlite3_realloc().
			 */
			(*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize = _sqlite3Atoi(tls, zRight)
			if int32(SQLITE_NOMEM) == _sqlite3BtreeSetPageSize(tls, pBt, (*Tsqlite3)(unsafe.Pointer(db)).FnextPagesize, 0, 0) {
				_sqlite3OomFault(tls, db)
			}
		}
		break
		/*
		 **  PRAGMA [schema.]secure_delete
		 **  PRAGMA [schema.]secure_delete=ON/OFF/FAST
		 **
		 ** The first form reports the current setting for the
		 ** secure_delete flag.  The second form changes the secure_delete
		 ** flag setting and reports the new value.
		 */
		fallthrough
	case int32(PragTyp_SECURE_DELETE):
		pBt1 = (*TDb)(unsafe.Pointer(pDb)).FpBt
		b = -int32(1)
		if zRight != 0 {
			if Xsqlite3_stricmp(tls, zRight, __ccgo_ts+19222) == 0 {
				b = int32(2)
			} else {
				b = libc.Int32FromUint8(_sqlite3GetBoolean(tls, zRight, uint8(0)))
			}
		}
		if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) && b >= 0 {
			ii = 0
			for {
				if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
					break
				}
				_sqlite3BtreeSecureDelete(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*32))).FpBt, b)
				goto _3
			_3:
				;
				ii = ii + 1
			}
		}
		b = _sqlite3BtreeSecureDelete(tls, pBt1, b)
		_returnSingleInt(tls, v, int64(b))
		break
		/*
		 **  PRAGMA [schema.]max_page_count
		 **  PRAGMA [schema.]max_page_count=N
		 **
		 ** The first form reports the current setting for the
		 ** maximum number of pages in the database file.  The
		 ** second form attempts to change this setting.  Both
		 ** forms return the current setting.
		 **
		 ** The absolute value of N is used.  This is undocumented and might
		 ** change.  The only purpose is to provide an easy way to test
		 ** the sqlite3AbsInt32() function.
		 **
		 **  PRAGMA [schema.]page_count
		 **
		 ** Return the number of pages in the specified database.
		 */
		fallthrough
	case int32(PragTyp_PAGE_COUNT):
		**(**Ti64)(__ccgo_up(bp + 40)) = 0
		_sqlite3CodeVerifySchema(tls, pParse, iDb)
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v2 = *(*int32)(unsafe.Pointer(v1))
		iReg = v2
		if libc.Int32FromUint8(_sqlite3UpperToLower[uint8(**(**uint8)(__ccgo_up(zLeft)))]) == int32('p') {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Pagecount), iDb, iReg)
		} else {
			if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+40) == 0 {
				if **(**Ti64)(__ccgo_up(bp + 40)) < 0 {
					**(**Ti64)(__ccgo_up(bp + 40)) = 0
				} else {
					if **(**Ti64)(__ccgo_up(bp + 40)) > libc.Int64FromUint32(0xfffffffe) {
						**(**Ti64)(__ccgo_up(bp + 40)) = libc.Int64FromUint32(0xfffffffe)
					}
				}
			} else {
				**(**Ti64)(__ccgo_up(bp + 40)) = 0
			}
			_sqlite3VdbeAddOp3(tls, v, int32(OP_MaxPgcnt), iDb, iReg, int32(**(**Ti64)(__ccgo_up(bp + 40))))
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), iReg, int32(1))
		break
		/*
		 **  PRAGMA [schema.]locking_mode
		 **  PRAGMA [schema.]locking_mode = (normal|exclusive)
		 */
		fallthrough
	case int32(PragTyp_LOCKING_MODE):
		zRet = __ccgo_ts + 19013
		eMode = _getLockingMode(tls, zRight)
		if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) && eMode == -int32(1) {
			/* Simple "PRAGMA locking_mode;" statement. This is a query for
			 ** the current default locking mode (which may be different to
			 ** the locking-mode of the main database).
			 */
			eMode = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode)
		} else {
			if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
				ii1 = int32(2)
				for {
					if !(ii1 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
						break
					}
					pPager = _sqlite3BtreePager(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii1)*32))).FpBt)
					_sqlite3PagerLockingMode(tls, pPager, eMode)
					goto _6
				_6:
					;
					ii1 = ii1 + 1
				}
				(*Tsqlite3)(unsafe.Pointer(db)).FdfltLockMode = libc.Uint8FromInt32(eMode)
			}
			pPager = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
			eMode = _sqlite3PagerLockingMode(tls, pPager, eMode)
		}
		if eMode == int32(PAGER_LOCKINGMODE_EXCLUSIVE) {
			zRet = __ccgo_ts + 19003
		}
		_returnSingleText(tls, v, zRet)
		break
		/*
		 **  PRAGMA [schema.]journal_mode
		 **  PRAGMA [schema.]journal_mode =
		 **                      (delete|persist|off|truncate|memory|wal|off)
		 */
		fallthrough
	case int32(PragTyp_JOURNAL_MODE): /* Loop counter */
		if zRight == uintptr(0) {
			/* If there is no "=MODE" part of the pragma, do a query for the
			 ** current mode */
			eMode1 = -int32(1)
		} else {
			n = _sqlite3Strlen30(tls, zRight)
			eMode1 = 0
			for {
				v1 = _sqlite3JournalModename(tls, eMode1)
				zMode = v1
				if !(v1 != uintptr(0)) {
					break
				}
				if Xsqlite3_strnicmp(tls, zRight, zMode, n) == 0 {
					break
				}
				goto _7
			_7:
				;
				eMode1 = eMode1 + 1
			}
			if !(zMode != 0) {
				/* If the "=MODE" part does not match any known journal mode,
				 ** then do a query */
				eMode1 = -int32(1)
			}
			if eMode1 == int32(PAGER_JOURNALMODE_OFF) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0) {
				/* Do not allow journal-mode "OFF" in defensive since the database
				 ** can become corrupted using ordinary SQL when the journal is off */
				eMode1 = -int32(1)
			}
		}
		if eMode1 == -int32(1) && (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
			/* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
			iDb = 0
			(*TToken)(unsafe.Pointer(pId2)).Fn = uint32(1)
		}
		ii2 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
		for {
			if !(ii2 >= 0) {
				break
			}
			if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii2)*32))).FpBt != 0 && (ii2 == iDb || (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
				_sqlite3VdbeUsesBtree(tls, v, ii2)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_JournalMode), ii2, int32(1), eMode1)
			}
			goto _9
		_9:
			;
			ii2 = ii2 - 1
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(1))
		break
		/*
		 **  PRAGMA [schema.]journal_size_limit
		 **  PRAGMA [schema.]journal_size_limit=N
		 **
		 ** Get or set the size limit on rollback journal files.
		 */
		fallthrough
	case int32(PragTyp_JOURNAL_SIZE_LIMIT):
		pPager1 = _sqlite3BtreePager(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt)
		**(**Ti64)(__ccgo_up(bp + 48)) = int64(-int32(2))
		if zRight != 0 {
			_sqlite3DecOrHexToI64(tls, zRight, bp+48)
			if **(**Ti64)(__ccgo_up(bp + 48)) < int64(-int32(1)) {
				**(**Ti64)(__ccgo_up(bp + 48)) = int64(-int32(1))
			}
		}
		**(**Ti64)(__ccgo_up(bp + 48)) = _sqlite3PagerJournalSizeLimit(tls, pPager1, **(**Ti64)(__ccgo_up(bp + 48)))
		_returnSingleInt(tls, v, **(**Ti64)(__ccgo_up(bp + 48)))
		break
		/*
		 **  PRAGMA [schema.]auto_vacuum
		 **  PRAGMA [schema.]auto_vacuum=N
		 **
		 ** Get or set the value of the database 'auto-vacuum' parameter.
		 ** The value is one of:  0 NONE 1 FULL 2 INCREMENTAL
		 */
		fallthrough
	case int32(PragTyp_AUTO_VACUUM):
		pBt2 = (*TDb)(unsafe.Pointer(pDb)).FpBt
		if !(zRight != 0) {
			_returnSingleInt(tls, v, int64(_sqlite3BtreeGetAutoVacuum(tls, pBt2)))
		} else {
			eAuto = _getAutoVacuum(tls, zRight)
			(*Tsqlite3)(unsafe.Pointer(db)).FnextAutovac = libc.Int8FromUint8(libc.Uint8FromInt32(eAuto))
			/* Call SetAutoVacuum() to set initialize the internal auto and
			 ** incr-vacuum flags. This is required in case this connection
			 ** creates the database file. It is important that it is created
			 ** as an auto-vacuum capable db.
			 */
			rc = _sqlite3BtreeSetAutoVacuum(tls, pBt2, eAuto)
			if rc == SQLITE_OK && (eAuto == int32(1) || eAuto == int32(2)) {
				iAddr = _sqlite3VdbeCurrentAddr(tls, v)
				aOp1 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(20)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_setMeta6)), _iLn11)
				if 0 != 0 {
					break
				}
				(**(**TVdbeOp)(__ccgo_up(aOp1))).Fp1 = iDb
				(**(**TVdbeOp)(__ccgo_up(aOp1 + 1*24))).Fp1 = iDb
				(**(**TVdbeOp)(__ccgo_up(aOp1 + 2*24))).Fp2 = iAddr + int32(4)
				(**(**TVdbeOp)(__ccgo_up(aOp1 + 4*24))).Fp1 = iDb
				(**(**TVdbeOp)(__ccgo_up(aOp1 + 4*24))).Fp3 = eAuto - int32(1)
				_sqlite3VdbeUsesBtree(tls, v, iDb)
			}
		}
		break
		/*
		 **  PRAGMA [schema.]incremental_vacuum(N)
		 **
		 ** Do N steps of incremental vacuuming on a database.
		 */
		fallthrough
	case int32(PragTyp_INCREMENTAL_VACUUM):
		**(**int32)(__ccgo_up(bp + 56)) = 0
		if zRight == uintptr(0) || !(_sqlite3GetInt32(tls, zRight, bp+56) != 0) || **(**int32)(__ccgo_up(bp + 56)) <= 0 {
			**(**int32)(__ccgo_up(bp + 56)) = int32(0x7fffffff)
		}
		_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), **(**int32)(__ccgo_up(bp + 56)), int32(1))
		addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IncrVacuum), iDb)
		_sqlite3VdbeAddOp1(tls, v, int32(OP_ResultRow), int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), int32(1), -int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), int32(1), addr)
		_sqlite3VdbeJumpHere(tls, v, addr)
		break
		/*
		 **  PRAGMA [schema.]cache_size
		 **  PRAGMA [schema.]cache_size=N
		 **
		 ** The first form reports the current local setting for the
		 ** page cache size. The second form sets the local
		 ** page cache size value.  If N is positive then that is the
		 ** number of pages in the cache.  If N is negative, then the
		 ** number of pages is adjusted so that the cache uses -N kibibytes
		 ** of memory.
		 */
		fallthrough
	case int32(PragTyp_CACHE_SIZE):
		if !(zRight != 0) {
			_returnSingleInt(tls, v, int64((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size))
		} else {
			size2 = _sqlite3Atoi(tls, zRight)
			(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size2
			_sqlite3BtreeSetCacheSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
		}
		break
		/*
		 **  PRAGMA [schema.]cache_spill
		 **  PRAGMA cache_spill=BOOLEAN
		 **  PRAGMA [schema.]cache_spill=N
		 **
		 ** The first form reports the current local setting for the
		 ** page cache spill size. The second form turns cache spill on
		 ** or off.  When turning cache spill on, the size is set to the
		 ** current cache_size.  The third form sets a spill size that
		 ** may be different form the cache size.
		 ** If N is positive then that is the
		 ** number of pages in the cache.  If N is negative, then the
		 ** number of pages is adjusted so that the cache uses -N kibibytes
		 ** of memory.
		 **
		 ** If the number of cache_spill pages is less then the number of
		 ** cache_size pages, no spilling occurs until the page count exceeds
		 ** the number of cache_size pages.
		 **
		 ** The cache_spill=BOOLEAN setting applies to all attached schemas,
		 ** not just the schema specified.
		 */
		fallthrough
	case int32(PragTyp_CACHE_SPILL):
		if !(zRight != 0) {
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_CacheSpill) == uint64(0) {
				v2 = 0
			} else {
				v2 = _sqlite3BtreeSetSpillSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, 0)
			}
			_returnSingleInt(tls, v, int64(v2))
		} else {
			**(**int32)(__ccgo_up(bp + 60)) = int32(1)
			if _sqlite3GetInt32(tls, zRight, bp+60) != 0 {
				_sqlite3BtreeSetSpillSize(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, **(**int32)(__ccgo_up(bp + 60)))
			}
			if _sqlite3GetBoolean(tls, zRight, libc.BoolUint8(**(**int32)(__ccgo_up(bp + 60)) != 0)) != 0 {
				**(**Tu64)(__ccgo_up(db + 48)) |= uint64(SQLITE_CacheSpill)
			} else {
				**(**Tu64)(__ccgo_up(db + 48)) &= ^libc.Uint64FromInt32(SQLITE_CacheSpill)
			}
			_setAllPagerFlags(tls, db)
		}
		break
		/*
		 **  PRAGMA [schema.]mmap_size(N)
		 **
		 ** Used to set mapping size limit. The mapping size limit is
		 ** used to limit the aggregate size of all memory mapped regions of the
		 ** database file. If this parameter is set to zero, then memory mapping
		 ** is not used at all.  If N is negative, then the default memory map
		 ** limit determined by sqlite3_config(SQLITE_CONFIG_MMAP_SIZE) is set.
		 ** The parameter N is measured in bytes.
		 **
		 ** This value is advisory.  The underlying VFS is free to memory map
		 ** as little or as much as it wants.  Except, if N is set to 0 then the
		 ** upper layers will never invoke the xFetch interfaces to the VFS.
		 */
		fallthrough
	case int32(PragTyp_MMAP_SIZE):
		if zRight != 0 {
			_sqlite3DecOrHexToI64(tls, zRight, bp+64)
			if **(**Tsqlite3_int64)(__ccgo_up(bp + 64)) < 0 {
				**(**Tsqlite3_int64)(__ccgo_up(bp + 64)) = _sqlite3Config.FszMmap
			}
			if (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0) {
				(*Tsqlite3)(unsafe.Pointer(db)).FszMmap = **(**Tsqlite3_int64)(__ccgo_up(bp + 64))
			}
			ii3 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
			for {
				if !(ii3 >= 0) {
					break
				}
				if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii3)*32))).FpBt != 0 && (ii3 == iDb || (*TToken)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
					_sqlite3BtreeSetMmapLimit(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii3)*32))).FpBt, **(**Tsqlite3_int64)(__ccgo_up(bp + 64)))
				}
				goto _11
			_11:
				;
				ii3 = ii3 - 1
			}
		}
		**(**Tsqlite3_int64)(__ccgo_up(bp + 64)) = int64(-int32(1))
		rc = Xsqlite3_file_control(tls, db, zDb, int32(SQLITE_FCNTL_MMAP_SIZE), bp+64)
		if rc == SQLITE_OK {
			_returnSingleInt(tls, v, **(**Tsqlite3_int64)(__ccgo_up(bp + 64)))
		} else {
			if rc != int32(SQLITE_NOTFOUND) {
				(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
				(*TParse)(unsafe.Pointer(pParse)).Frc = rc
			}
		}
		break
		/*
		 **   PRAGMA temp_store
		 **   PRAGMA temp_store = "default"|"memory"|"file"
		 **
		 ** Return or set the local value of the temp_store flag.  Changing
		 ** the local value does not make changes to the disk file and the default
		 ** value will be restored the next time the database is opened.
		 **
		 ** Note that it is possible for the library compile-time options to
		 ** override this setting
		 */
		fallthrough
	case int32(PragTyp_TEMP_STORE):
		if !(zRight != 0) {
			_returnSingleInt(tls, v, libc.Int64FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store))
		} else {
			_changeTempStorage(tls, pParse, zRight)
		}
		break
		/*
		 **   PRAGMA temp_store_directory
		 **   PRAGMA temp_store_directory = ""|"directory_name"
		 **
		 ** Return or set the local value of the temp_store_directory flag.  Changing
		 ** the value sets a specific directory to be used for temporary files.
		 ** Setting to a null string reverts to the default temporary directory search.
		 ** If temporary directory is changed, then invalidateTempStorage.
		 **
		 */
		fallthrough
	case int32(PragTyp_TEMP_STORE_DIRECTORY):
		Xsqlite3_mutex_enter(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
		if !(zRight != 0) {
			_returnSingleText(tls, v, Xsqlite3_temp_directory)
		} else {
			if **(**uint8)(__ccgo_up(zRight)) != 0 {
				rc = _sqlite3OsAccess(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, zRight, int32(SQLITE_ACCESS_READWRITE), bp+72)
				if rc != SQLITE_OK || **(**int32)(__ccgo_up(bp + 72)) == 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19227, 0)
					Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
					goto pragma_out
				}
			}
			if libc.Bool(false) || libc.Bool(true) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) <= int32(1) || libc.Bool(libc.Bool(false) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Ftemp_store) == int32(1)) {
				_invalidateTempStorage(tls, pParse)
			}
			Xsqlite3_free(tls, Xsqlite3_temp_directory)
			if **(**uint8)(__ccgo_up(zRight)) != 0 {
				Xsqlite3_temp_directory = Xsqlite3_mprintf(tls, __ccgo_ts+3944, libc.VaList(bp+176, zRight))
			} else {
				Xsqlite3_temp_directory = uintptr(0)
			}
		}
		Xsqlite3_mutex_leave(tls, _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1)))
		break
		/*
		 **   PRAGMA [schema.]synchronous
		 **   PRAGMA [schema.]synchronous=OFF|ON|NORMAL|FULL|EXTRA
		 **
		 ** Return or set the local value of the synchronous flag.  Changing
		 ** the local value does not make changes to the disk file and the
		 ** default value will be restored the next time the database is
		 ** opened.
		 */
		fallthrough
	case int32(PragTyp_SYNCHRONOUS):
		if !(zRight != 0) {
			_returnSingleInt(tls, v, int64(libc.Int32FromUint8((*TDb)(unsafe.Pointer(pDb)).Fsafety_level)-int32(1)))
		} else {
			if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19252, 0)
			} else {
				if iDb != int32(1) {
					iLevel = (libc.Int32FromUint8(_getSafetyLevel(tls, zRight, 0, uint8(1))) + int32(1)) & int32(PAGER_SYNCHRONOUS_MASK)
					if iLevel == 0 {
						iLevel = int32(1)
					}
					(*TDb)(unsafe.Pointer(pDb)).Fsafety_level = libc.Uint8FromInt32(iLevel)
					(*TDb)(unsafe.Pointer(pDb)).FbSyncSet = uint8(1)
					_setAllPagerFlags(tls, db)
				}
			}
		}
	case int32(PragTyp_FLAG):
		if zRight == uintptr(0) {
			_setPragmaResultColumnNames(tls, v, pPragma)
			_returnSingleInt(tls, v, libc.BoolInt64((*Tsqlite3)(unsafe.Pointer(db)).Fflags&(*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != uint64(0)))
		} else {
			mask = (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg /* Mask of bits to set or clear. */
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
				/* Foreign key support may not be enabled or disabled while not
				 ** in auto-commit mode.  */
				mask = mask & libc.Uint64FromInt32(^libc.Int32FromInt32(SQLITE_ForeignKeys))
			}
			if _sqlite3GetBoolean(tls, zRight, uint8(0)) != 0 {
				if mask&uint64(SQLITE_WriteSchema) == uint64(0) || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) == uint64(0) {
					**(**Tu64)(__ccgo_up(db + 48)) |= mask
				}
			} else {
				**(**Tu64)(__ccgo_up(db + 48)) &= ^mask
				if mask == uint64(SQLITE_DeferFKs) {
					(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = 0
					(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = 0
				}
				if mask&uint64(SQLITE_WriteSchema) != uint64(0) && Xsqlite3_stricmp(tls, zRight, __ccgo_ts+19305) == 0 {
					/* IMP: R-60817-01178 If the argument is "RESET" then schema
					 ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
					 ** in addition, the schema is reloaded. */
					_sqlite3ResetAllSchemasOfConnection(tls, db)
				}
			}
			/* Many of the flag-pragmas modify the code generated by the SQL
			 ** compiler (eg. count_changes). So add an opcode to expire all
			 ** compiled SQL statements after modifying a pragma value.
			 */
			_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
			_setAllPagerFlags(tls, db)
		}
		break
		/*
		 **   PRAGMA table_info(<table>)
		 **
		 ** Return a single row for each column of the named table. The columns of
		 ** the returned data set are:
		 **
		 ** cid:        Column id (numbered from left to right, starting at 0)
		 ** name:       Column name
		 ** type:       Column declaration type.
		 ** notnull:    True if 'NOT NULL' is part of column declaration
		 ** dflt_value: The default value for the column, if any.
		 ** pk:         Non-zero for PK fields.
		 */
		fallthrough
	case int32(PragTyp_TABLE_INFO):
		if zRight != 0 {
			_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
			pTab = _sqlite3LocateTable(tls, pParse, uint32(LOCATE_NOERR), zRight, zDb)
			if pTab != 0 {
				nHidden = 0
				pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
				(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(7)
				_sqlite3ViewGetColumnNames(tls, pParse, pTab)
				i = 0
				pCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
				for {
					if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
						break
					}
					isHidden = 0
					if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_NOINSERT) != 0 {
						if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg == uint64(0) {
							nHidden = nHidden + 1
							goto _12
						}
						if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
							isHidden = int32(2) /* GENERATED ALWAYS AS ... VIRTUAL */
						} else {
							if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_STORED) != 0 {
								isHidden = int32(3) /* GENERATED ALWAYS AS ... STORED */
							} else {
								isHidden = int32(1) /* HIDDEN */
							}
						}
					}
					if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol)).FcolFlags)&int32(COLFLAG_PRIMKEY) == 0 {
						k = 0
					} else {
						if pPk == uintptr(0) {
							k = int32(1)
						} else {
							k = int32(1)
							for {
								if !(k <= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) && int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(k-int32(1))*2))) != i) {
									break
								}
								goto _13
							_13:
								;
								k = k + 1
							}
						}
					}
					pColExpr = _sqlite3ColumnExpr(tls, pTab, pCol)
					if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
						v1 = __ccgo_ts + 19311
					} else {
						v1 = __ccgo_ts + 19319
					}
					if int32(uint32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) != 0 {
						v2 = int32(1)
					} else {
						v2 = 0
					}
					if isHidden >= int32(2) || pColExpr == uintptr(0) {
						v5 = uintptr(0)
					} else {
						v5 = *(*uintptr)(unsafe.Pointer(pColExpr + 8))
					}
					_sqlite3VdbeMultiLoad(tls, v, int32(1), v1, libc.VaList(bp+176, i-nHidden, (*TColumn)(unsafe.Pointer(pCol)).FzCnName, _sqlite3ColumnType(tls, pCol, __ccgo_ts+1704), v2, v5, k, isHidden))
					goto _12
				_12:
					;
					i = i + 1
					pCol += 16
				}
			}
		}
		break
		/*
		 **   PRAGMA table_list
		 **
		 ** Return a single row for each table, virtual table, or view in the
		 ** entire schema.
		 **
		 ** schema:     Name of attached database hold this table
		 ** name:       Name of the table itself
		 ** type:       "table", "view", "virtual", "shadow"
		 ** ncol:       Number of columns
		 ** wr:         True for a WITHOUT ROWID table
		 ** strict:     True for a STRICT table
		 */
		fallthrough
	case int32(PragTyp_TABLE_LIST):
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
		_sqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
		ii4 = 0
		for {
			if !(ii4 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if zDb != 0 && Xsqlite3_stricmp(tls, zDb, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*32))).FzDbSName) != 0 {
				goto _17
			}
			/* Ensure that the Table.nCol field is initialized for all views
			 ** and virtual tables.  Each time we initialize a Table.nCol value
			 ** for a table, that can potentially disrupt the hash table, so restart
			 ** the initialization scan.
			 */
			pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*32))).FpSchema + 8
			initNCol = libc.Int32FromUint32((*THash)(unsafe.Pointer(pHash)).Fcount)
			for {
				v2 = initNCol
				initNCol = initNCol - 1
				if !(v2 != 0) {
					break
				}
				k1 = (*THash)(unsafe.Pointer(pHash)).Ffirst
				for {
					if !(int32(1) != 0) {
						break
					}
					if k1 == uintptr(0) {
						initNCol = 0
						break
					}
					pTab1 = (*THashElem)(unsafe.Pointer(k1)).Fdata
					if int32((*TTable)(unsafe.Pointer(pTab1)).FnCol) == 0 {
						zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+19326, libc.VaList(bp+176, (*TTable)(unsafe.Pointer(pTab1)).FzName))
						if zSql != 0 {
							**(**uintptr)(__ccgo_up(bp + 80)) = uintptr(0)
							Xsqlite3_prepare_v3(tls, db, zSql, -int32(1), uint32(SQLITE_PREPARE_DONT_LOG), bp+80, uintptr(0))
							Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 80)))
							_sqlite3DbFree(tls, db, zSql)
						}
						if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
							_sqlite3ErrorMsg(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpParse, __ccgo_ts+1674, 0)
							(*TParse)(unsafe.Pointer((*Tsqlite3)(unsafe.Pointer(db)).FpParse)).Frc = int32(SQLITE_NOMEM)
						}
						pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*32))).FpSchema + 8
						break
					}
					goto _19
				_19:
					;
					k1 = (*THashElem)(unsafe.Pointer(k1)).Fnext
				}
			}
			k1 = (*THash)(unsafe.Pointer(pHash)).Ffirst
			for {
				if !(k1 != 0) {
					break
				}
				pTab2 = (*THashElem)(unsafe.Pointer(k1)).Fdata
				if zRight != 0 && Xsqlite3_stricmp(tls, zRight, (*TTable)(unsafe.Pointer(pTab2)).FzName) != 0 {
					goto _20
				}
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab2)).FeTabType) == int32(TABTYP_VIEW) {
					zType = __ccgo_ts + 11119
				} else {
					if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab2)).FeTabType) == int32(TABTYP_VTAB) {
						zType = __ccgo_ts + 14304
					} else {
						if (*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_Shadow) != 0 {
							zType = __ccgo_ts + 19342
						} else {
							zType = __ccgo_ts + 9381
						}
					}
				}
				_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19349, libc.VaList(bp+176, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii4)*32))).FzDbSName, _sqlite3PreferredTableName(tls, (*TTable)(unsafe.Pointer(pTab2)).FzName), zType, int32((*TTable)(unsafe.Pointer(pTab2)).FnCol), libc.BoolInt32((*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_WithoutRowid) != uint32(0)), libc.BoolInt32((*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_Strict) != uint32(0))))
				goto _20
			_20:
				;
				k1 = (*THashElem)(unsafe.Pointer(k1)).Fnext
			}
			goto _17
		_17:
			;
			ii4 = ii4 + 1
		}
	case int32(PragTyp_INDEX_INFO):
		if zRight != 0 {
			pIdx = _sqlite3FindIndex(tls, db, zRight, zDb)
			if pIdx == uintptr(0) {
				/* If there is no index named zRight, check to see if there is a
				 ** WITHOUT ROWID table named zRight, and if there is, show the
				 ** structure of the PRIMARY KEY index for that table. */
				pTab3 = _sqlite3LocateTable(tls, pParse, uint32(LOCATE_NOERR), zRight, zDb)
				if pTab3 != 0 && !((*TTable)(unsafe.Pointer(pTab3)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
					pIdx = _sqlite3PrimaryKeyIndex(tls, pTab3)
				}
			}
			if pIdx != 0 {
				iIdxDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIdx)).FpSchema)
				if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
					/* PRAGMA index_xinfo (newer version with more rows and columns) */
					mx = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
					(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
				} else {
					/* PRAGMA index_info (legacy version) */
					mx = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
					(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(3)
				}
				pTab3 = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
				_sqlite3CodeVerifySchema(tls, pParse, iIdxDb)
				i1 = 0
				for {
					if !(i1 < mx) {
						break
					}
					cnum = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2))
					if int32(cnum) < 0 {
						v1 = uintptr(0)
					} else {
						v1 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab3)).FaCol + uintptr(cnum)*16))).FzCnName
					}
					_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19356, libc.VaList(bp+176, i1, int32(cnum), v1))
					if (*TPragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
						_sqlite3VdbeMultiLoad(tls, v, int32(4), __ccgo_ts+19361, libc.VaList(bp+176, libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i1)))), **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*8)), libc.BoolInt32(i1 < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol))))
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), (*TParse)(unsafe.Pointer(pParse)).FnMem)
					goto _21
				_21:
					;
					i1 = i1 + 1
				}
			}
		}
	case int32(PragTyp_INDEX_LIST):
		if zRight != 0 {
			pTab4 = _sqlite3FindTable(tls, db, zRight, zDb)
			if pTab4 != 0 {
				iTabDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab4)).FpSchema)
				(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(5)
				_sqlite3CodeVerifySchema(tls, pParse, iTabDb)
				pIdx1 = (*TTable)(unsafe.Pointer(pTab4)).FpIndex
				i2 = libc.Int32FromInt32(0)
				for {
					if !(pIdx1 != 0) {
						break
					}
					azOrigin = [3]uintptr{
						0: __ccgo_ts + 19366,
						1: __ccgo_ts + 19368,
						2: __ccgo_ts + 17855,
					}
					_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19370, libc.VaList(bp+176, i2, (*TIndex)(unsafe.Pointer(pIdx1)).FzName, libc.BoolInt32(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx1)).FonError) != OE_None), azOrigin[int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0xc000>>14))], libc.BoolInt32((*TIndex)(unsafe.Pointer(pIdx1)).FpPartIdxWhere != uintptr(0))))
					goto _23
				_23:
					;
					pIdx1 = (*TIndex)(unsafe.Pointer(pIdx1)).FpNext
					i2 = i2 + 1
				}
			}
		}
	case int32(PragTyp_DATABASE_LIST):
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(3)
		i3 = 0
		for {
			if !(i3 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*32))).FpBt == uintptr(0) {
				goto _24
			}
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19376, libc.VaList(bp+176, i3, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*32))).FzDbSName, _sqlite3BtreeGetFilename(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i3)*32))).FpBt)))
			goto _24
		_24:
			;
			i3 = i3 + 1
		}
	case int32(PragTyp_COLLATION_LIST):
		i4 = 0
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(2)
		p = (*THash)(unsafe.Pointer(db + 648)).Ffirst
		for {
			if !(p != 0) {
				break
			}
			pColl = (*THashElem)(unsafe.Pointer(p)).Fdata
			v2 = i4
			i4 = i4 + 1
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19380, libc.VaList(bp+176, v2, (*TCollSeq)(unsafe.Pointer(pColl)).FzName))
			goto _25
		_25:
			;
			p = (*THashElem)(unsafe.Pointer(p)).Fnext
		}
	case int32(PragTyp_FUNCTION_LIST):
		showInternFunc = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_InternalFunc) != uint32(0))
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
		i5 = 0
		for {
			if !(i5 < int32(SQLITE_FUNC_HASH_SZ)) {
				break
			}
			p1 = **(**uintptr)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(i5)*8))
			for {
				if !(p1 != 0) {
					break
				}
				_pragmaFunclistLine(tls, v, p1, int32(1), showInternFunc)
				goto _28
			_28:
				;
				p1 = *(*uintptr)(unsafe.Pointer(p1 + 64))
			}
			goto _27
		_27:
			;
			i5 = i5 + 1
		}
		j = (*THash)(unsafe.Pointer(db + 624)).Ffirst
		for {
			if !(j != 0) {
				break
			}
			p1 = (*THashElem)(unsafe.Pointer(j)).Fdata
			_pragmaFunclistLine(tls, v, p1, 0, showInternFunc)
			goto _29
		_29:
			;
			j = (*THashElem)(unsafe.Pointer(j)).Fnext
		}
	case int32(PragTyp_MODULE_LIST):
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(1)
		j1 = (*THash)(unsafe.Pointer(db + 576)).Ffirst
		for {
			if !(j1 != 0) {
				break
			}
			pMod = (*THashElem)(unsafe.Pointer(j1)).Fdata
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+7913, libc.VaList(bp+176, (*TModule)(unsafe.Pointer(pMod)).FzName))
			goto _30
		_30:
			;
			j1 = (*THashElem)(unsafe.Pointer(j1)).Fnext
		}
	case int32(PragTyp_PRAGMA_LIST):
		i6 = 0
		for {
			if !(i6 < libc.Int32FromUint64(libc.Uint64FromInt64(1584)/libc.Uint64FromInt64(24))) {
				break
			}
			_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+7913, libc.VaList(bp+176, _aPragmaName[i6].FzName))
			goto _31
		_31:
			;
			i6 = i6 + 1
		}
	case int32(PragTyp_FOREIGN_KEY_LIST):
		if zRight != 0 {
			pTab5 = _sqlite3FindTable(tls, db, zRight, zDb)
			if pTab5 != 0 && libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab5)).FeTabType) == TABTYP_NORM {
				pFK = (*(*struct {
					FaddColOffset int32
					FpFKey        uintptr
					FpDfltList    uintptr
				})(unsafe.Pointer(pTab5 + 64))).FpFKey
				if pFK != 0 {
					iTabDb1 = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab5)).FpSchema)
					i7 = 0
					(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(8)
					_sqlite3CodeVerifySchema(tls, pParse, iTabDb1)
					for pFK != 0 {
						j2 = 0
						for {
							if !(j2 < (*TFKey)(unsafe.Pointer(pFK)).FnCol) {
								break
							}
							_sqlite3VdbeMultiLoad(tls, v, int32(1), __ccgo_ts+19383, libc.VaList(bp+176, i7, j2, (*TFKey)(unsafe.Pointer(pFK)).FzTo, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab5)).FaCol + uintptr((*(*TsColMap)(unsafe.Pointer(pFK + 64 + uintptr(j2)*16))).FiFrom)*16))).FzCnName, (*(*TsColMap)(unsafe.Pointer(pFK + 64 + uintptr(j2)*16))).FzCol, _actionName(tls, **(**Tu8)(__ccgo_up(pFK + 45 + 1))), _actionName(tls, **(**Tu8)(__ccgo_up(pFK + 45))), __ccgo_ts+19392))
							goto _32
						_32:
							;
							j2 = j2 + 1
						}
						i7 = i7 + 1
						pFK = (*TFKey)(unsafe.Pointer(pFK)).FpNextFrom
					}
				}
			}
		}
	case int32(PragTyp_FOREIGN_KEY_CHECK): /* child to parent column mapping */
		regResult = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += int32(4)
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v2 = *(*int32)(unsafe.Pointer(v1))
		regRow = v2
		k2 = (*THash)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema + 8)).Ffirst
		for k2 != 0 {
			if zRight != 0 {
				pTab6 = _sqlite3LocateTable(tls, pParse, uint32(0), zRight, zDb)
				k2 = uintptr(0)
			} else {
				pTab6 = (*THashElem)(unsafe.Pointer(k2)).Fdata
				k2 = (*THashElem)(unsafe.Pointer(k2)).Fnext
			}
			if pTab6 == uintptr(0) || !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab6)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) || (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab6 + 64))).FpFKey == uintptr(0) {
				continue
			}
			iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab6)).FpSchema)
			zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
			_sqlite3CodeVerifySchema(tls, pParse, iDb)
			_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab6)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab6)).FzName)
			_sqlite3TouchRegister(tls, pParse, int32((*TTable)(unsafe.Pointer(pTab6)).FnCol)+regRow)
			_sqlite3OpenTable(tls, pParse, 0, iDb, pTab6, int32(OP_OpenRead))
			_sqlite3VdbeLoadString(tls, v, regResult, (*TTable)(unsafe.Pointer(pTab6)).FzName)
			i8 = int32(1)
			pFK1 = (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab6 + 64))).FpFKey
			for {
				if !(pFK1 != 0) {
					break
				}
				pParent = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
				if pParent == uintptr(0) {
					goto _35
				}
				**(**uintptr)(__ccgo_up(bp + 88)) = uintptr(0)
				_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pParent)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pParent)).FzName)
				x1 = _sqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+88, uintptr(0))
				if x1 == 0 {
					if **(**uintptr)(__ccgo_up(bp + 88)) == uintptr(0) {
						_sqlite3OpenTable(tls, pParse, i8, iDb, pParent, int32(OP_OpenRead))
					} else {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), i8, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 88)))).Ftnum), iDb)
						_sqlite3VdbeSetP4KeyInfo(tls, pParse, **(**uintptr)(__ccgo_up(bp + 88)))
					}
				} else {
					k2 = uintptr(0)
					break
				}
				goto _35
			_35:
				;
				i8 = i8 + 1
				pFK1 = (*TFKey)(unsafe.Pointer(pFK1)).FpNextFrom
			}
			if pFK1 != 0 {
				break
			}
			if (*TParse)(unsafe.Pointer(pParse)).FnTab < i8 {
				(*TParse)(unsafe.Pointer(pParse)).FnTab = i8
			}
			addrTop = _sqlite3VdbeAddOp1(tls, v, int32(OP_Rewind), 0)
			i8 = int32(1)
			pFK1 = (*(*struct {
				FaddColOffset int32
				FpFKey        uintptr
				FpDfltList    uintptr
			})(unsafe.Pointer(pTab6 + 64))).FpFKey
			for {
				if !(pFK1 != 0) {
					break
				}
				pParent = _sqlite3FindTable(tls, db, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
				**(**uintptr)(__ccgo_up(bp + 88)) = uintptr(0)
				**(**uintptr)(__ccgo_up(bp + 96)) = uintptr(0)
				if pParent != 0 {
					x1 = _sqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+88, bp+96)
				}
				addrOk = _sqlite3VdbeMakeLabel(tls, pParse)
				/* Generate code to read the child key values into registers
				 ** regRow..regRow+n. If any of the child key values are NULL, this
				 ** row cannot cause an FK violation. Jump directly to addrOk in
				 ** this case. */
				_sqlite3TouchRegister(tls, pParse, regRow+(*TFKey)(unsafe.Pointer(pFK1)).FnCol)
				j3 = 0
				for {
					if !(j3 < (*TFKey)(unsafe.Pointer(pFK1)).FnCol) {
						break
					}
					if **(**uintptr)(__ccgo_up(bp + 96)) != 0 {
						v2 = **(**int32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 96)) + uintptr(j3)*4))
					} else {
						v2 = (*(*TsColMap)(unsafe.Pointer(pFK1 + 64 + uintptr(j3)*16))).FiFrom
					}
					iCol = v2
					_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab6, 0, iCol, regRow+j3)
					_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regRow+j3, addrOk)
					goto _37
				_37:
					;
					j3 = j3 + 1
				}
				/* Generate code to query the parent index for a matching parent
				 ** key. If a match is found, jump to addrOk. */
				if **(**uintptr)(__ccgo_up(bp + 88)) != 0 {
					_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), regRow, (*TFKey)(unsafe.Pointer(pFK1)).FnCol, 0, _sqlite3IndexAffinityStr(tls, db, **(**uintptr)(__ccgo_up(bp + 88))), (*TFKey)(unsafe.Pointer(pFK1)).FnCol)
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), i8, addrOk, regRow, (*TFKey)(unsafe.Pointer(pFK1)).FnCol)
				} else {
					if pParent != 0 {
						jmp = _sqlite3VdbeCurrentAddr(tls, v) + int32(2)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), i8, jmp, regRow)
						_sqlite3VdbeGoto(tls, v, addrOk)
					}
				}
				/* Generate code to report an FK violation to the caller. */
				if (*TTable)(unsafe.Pointer(pTab6)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), 0, regResult+int32(1))
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regResult+int32(1))
				}
				_sqlite3VdbeMultiLoad(tls, v, regResult+int32(2), __ccgo_ts+19397, libc.VaList(bp+176, (*TFKey)(unsafe.Pointer(pFK1)).FzTo, i8-int32(1)))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), regResult, int32(4))
				_sqlite3VdbeResolveLabel(tls, v, addrOk)
				_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up(bp + 96)))
				goto _36
			_36:
				;
				i8 = i8 + 1
				pFK1 = (*TFKey)(unsafe.Pointer(pFK1)).FpNextFrom
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), 0, addrTop+int32(1))
			_sqlite3VdbeJumpHere(tls, v, addrTop)
		}
		break
		/* Reinstall the LIKE and GLOB functions.  The variant of LIKE
		 ** used will be case sensitive or not depending on the RHS.
		 */
		fallthrough
	case int32(PragTyp_CASE_SENSITIVE_LIKE):
		if zRight != 0 {
			_sqlite3RegisterLikeFunctions(tls, db, libc.Int32FromUint8(_sqlite3GetBoolean(tls, zRight, uint8(0))))
		}
		break
		/*    PRAGMA integrity_check
		 **    PRAGMA integrity_check(N)
		 **    PRAGMA quick_check
		 **    PRAGMA quick_check(N)
		 **
		 ** Verify the integrity of the database.
		 **
		 ** The "quick_check" is reduced version of
		 ** integrity_check designed to detect most database corruption
		 ** without the overhead of cross-checking indexes.  Quick_check
		 ** is linear time whereas integrity_check is O(NlogN).
		 **
		 ** The maximum number of errors is 100 by default.  A different default
		 ** can be specified using a numeric parameter N.
		 **
		 ** Or, the parameter N can be the name of a table.  In that case, only
		 ** the one table named is verified.  The freelist is only verified if
		 ** the named table is "sqlite_schema" (or one of its aliases).
		 **
		 ** All schemas are checked by default.  To check just a single
		 ** schema, use the form:
		 **
		 **      PRAGMA schema.integrity_check;
		 */
		fallthrough
	case int32(PragTyp_INTEGRITY_CHECK):
		pObjTab = uintptr(0) /* Check only this one table, if not NULL */
		isQuick = libc.BoolInt32(libc.Int32FromUint8(_sqlite3UpperToLower[uint8(**(**uint8)(__ccgo_up(zLeft)))]) == int32('q'))
		/* If the PRAGMA command was of the form "PRAGMA <db>.integrity_check",
		 ** then iDb is set to the index of the database identified by <db>.
		 ** In this case, the integrity of database iDb only is verified by
		 ** the VDBE created below.
		 **
		 ** Otherwise, if the command was simply "PRAGMA integrity_check" (or
		 ** "PRAGMA quick_check"), then iDb is set to 0. In this case, set iDb
		 ** to -1 here, to indicate that the VDBE should verify the integrity
		 ** of all attached databases.  */
		if (*TToken)(unsafe.Pointer(pId2)).Fz == uintptr(0) {
			iDb = -int32(1)
		}
		/* Initialize the VDBE program */
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(6)
		/* Set the maximum error count */
		**(**int32)(__ccgo_up(bp + 104)) = int32(SQLITE_INTEGRITY_CHECK_ERROR_MAX)
		if zRight != 0 {
			if _sqlite3GetInt32(tls, (*TToken)(unsafe.Pointer(pValue)).Fz, bp+104) != 0 {
				if **(**int32)(__ccgo_up(bp + 104)) <= 0 {
					**(**int32)(__ccgo_up(bp + 104)) = int32(SQLITE_INTEGRITY_CHECK_ERROR_MAX)
				}
			} else {
				if iDb >= 0 {
					v1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
				} else {
					v1 = uintptr(0)
				}
				pObjTab = _sqlite3LocateTable(tls, pParse, uint32(0), zRight, v1)
			}
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), **(**int32)(__ccgo_up(bp + 104))-int32(1), int32(1)) /* reg[1] holds errors left */
		/* Do an integrity check on each database file */
		i9 = 0
		for {
			if !(i9 < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			} /* Array of root page numbers of all btrees */
			cnt = 0 /* Number of entries in aRoot[] */
			if libc.Bool(OMIT_TEMPDB != 0) && i9 == int32(1) {
				goto _40
			}
			if iDb >= 0 && i9 != iDb {
				goto _40
			}
			_sqlite3CodeVerifySchema(tls, pParse, i9)
			libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(0), 8, 0x100) /* tag-20230327-1 */
			/* Do an integrity check of the B-Tree
			 **
			 ** Begin by finding the root pages numbers
			 ** for all tables and indices in the database.
			 */
			pTbls = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i9)*32))).FpSchema + 8
			cnt = 0
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				pTab7 = (*THashElem)(unsafe.Pointer(x2)).Fdata /* Number of indexes on pTab */
				if _tableSkipIntegrityCheck(tls, pTab7, pObjTab) != 0 {
					goto _41
				}
				if (*TTable)(unsafe.Pointer(pTab7)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					cnt = cnt + 1
				}
				nIdx = 0
				pIdx3 = (*TTable)(unsafe.Pointer(pTab7)).FpIndex
				for {
					if !(pIdx3 != 0) {
						break
					}
					cnt = cnt + 1
					goto _42
				_42:
					;
					pIdx3 = (*TIndex)(unsafe.Pointer(pIdx3)).FpNext
					nIdx = nIdx + 1
				}
				goto _41
			_41:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			if cnt == 0 {
				goto _40
			}
			if pObjTab != 0 {
				cnt = cnt + 1
			}
			aRoot = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(cnt+libc.Int32FromInt32(1))))
			if aRoot == uintptr(0) {
				break
			}
			cnt = 0
			if pObjTab != 0 {
				cnt = cnt + 1
				v2 = cnt
				**(**int32)(__ccgo_up(aRoot + uintptr(v2)*4)) = 0
			}
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				pTab8 = (*THashElem)(unsafe.Pointer(x2)).Fdata
				if _tableSkipIntegrityCheck(tls, pTab8, pObjTab) != 0 {
					goto _44
				}
				if (*TTable)(unsafe.Pointer(pTab8)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					cnt = cnt + 1
					v2 = cnt
					**(**int32)(__ccgo_up(aRoot + uintptr(v2)*4)) = libc.Int32FromUint32((*TTable)(unsafe.Pointer(pTab8)).Ftnum)
				}
				pIdx4 = (*TTable)(unsafe.Pointer(pTab8)).FpIndex
				for {
					if !(pIdx4 != 0) {
						break
					}
					cnt = cnt + 1
					v2 = cnt
					**(**int32)(__ccgo_up(aRoot + uintptr(v2)*4)) = libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIdx4)).Ftnum)
					goto _46
				_46:
					;
					pIdx4 = (*TIndex)(unsafe.Pointer(pIdx4)).FpNext
				}
				goto _44
			_44:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			**(**int32)(__ccgo_up(aRoot)) = cnt
			/* Make sure sufficient number of registers have been allocated */
			_sqlite3TouchRegister(tls, pParse, int32(8)+cnt)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, int32(8), int32(8)+cnt)
			_sqlite3ClearTempRegCache(tls, pParse)
			/* Do the b-tree integrity checks */
			_sqlite3VdbeAddOp4(tls, v, int32(OP_IntegrityCk), int32(1), cnt, int32(8), aRoot, -int32(15))
			_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(i9))
			addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), int32(2))
			_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+19401, libc.VaList(bp+176, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i9)*32))).FzDbSName)), -int32(7))
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(2), int32(3), int32(3))
			_integrityCheckResultRow(tls, v)
			_sqlite3VdbeJumpHere(tls, v, addr1)
			/* Check that the indexes all have the right number of rows */
			if pObjTab != 0 {
				v2 = int32(1)
			} else {
				v2 = 0
			}
			cnt = v2
			_sqlite3VdbeLoadString(tls, v, int32(2), __ccgo_ts+19425)
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				iTab = 0
				pTab9 = (*THashElem)(unsafe.Pointer(x2)).Fdata
				if _tableSkipIntegrityCheck(tls, pTab9, pObjTab) != 0 {
					goto _49
				}
				if (*TTable)(unsafe.Pointer(pTab9)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					v2 = cnt
					cnt = cnt + 1
					iTab = v2
				} else {
					iTab = cnt
					pIdx5 = (*TTable)(unsafe.Pointer(pTab9)).FpIndex
					for {
						if !(pIdx5 != 0) {
							break
						}
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx5 + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
							break
						}
						iTab = iTab + 1
						goto _51
					_51:
						;
						pIdx5 = (*TIndex)(unsafe.Pointer(pIdx5)).FpNext
					}
				}
				pIdx5 = (*TTable)(unsafe.Pointer(pTab9)).FpIndex
				for {
					if !(pIdx5 != 0) {
						break
					}
					if (*TIndex)(unsafe.Pointer(pIdx5)).FpPartIdxWhere == uintptr(0) {
						addr1 = _sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), int32(8)+cnt, 0, int32(8)+iTab)
						_sqlite3VdbeLoadString(tls, v, int32(4), (*TIndex)(unsafe.Pointer(pIdx5)).FzName)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(4), int32(2), int32(3))
						_integrityCheckResultRow(tls, v)
						_sqlite3VdbeJumpHere(tls, v, addr1)
					}
					cnt = cnt + 1
					goto _52
				_52:
					;
					pIdx5 = (*TIndex)(unsafe.Pointer(pIdx5)).FpNext
				}
				goto _49
			_49:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			/* Make sure all the indices are constructed correctly.
			 */
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				pTab10 = (*THashElem)(unsafe.Pointer(x2)).Fdata
				pPrior = uintptr(0)
				r1 = -int32(1) /* Maximum non-virtual column number */
				if _tableSkipIntegrityCheck(tls, pTab10, pObjTab) != 0 {
					goto _53
				}
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab10)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
					goto _53
				}
				if isQuick != 0 || (*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					pPk1 = uintptr(0)
					r2 = 0
				} else {
					pPk1 = _sqlite3PrimaryKeyIndex(tls, pTab10)
					r2 = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), int32(1), r2, r2+libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol)-int32(1))
				}
				_sqlite3OpenTableAndIndices(tls, pParse, pTab10, int32(OP_OpenRead), uint8(0), int32(1), uintptr(0), bp+108, bp+112)
				/* reg[7] counts the number of entries in the table.
				 ** reg[8+i] counts the number of entries in the i-th index
				 */
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, int32(7))
				j4 = 0
				pIdx6 = (*TTable)(unsafe.Pointer(pTab10)).FpIndex
				for {
					if !(pIdx6 != 0) {
						break
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, int32(8)+j4) /* index entries counter */
					goto _54
				_54:
					;
					pIdx6 = (*TIndex)(unsafe.Pointer(pIdx6)).FpNext
					j4 = j4 + 1
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), **(**int32)(__ccgo_up(bp + 108)), 0)
				loopTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), int32(7), int32(1))
				/* Fetch the right-most column from the table.  This will cause
				 ** the entire record header to be parsed and sanity checked.  It
				 ** will also prepopulate the cursor column cache that is used
				 ** by the OP_IsType code, so it is a required step.
				 */
				if (*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
					mxCol = -int32(1)
					j4 = 0
					for {
						if !(j4 < int32((*TTable)(unsafe.Pointer(pTab10)).FnCol)) {
							break
						}
						if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) == 0 {
							mxCol = mxCol + 1
						}
						goto _55
					_55:
						;
						j4 = j4 + 1
					}
					if mxCol == int32((*TTable)(unsafe.Pointer(pTab10)).FiPKey) {
						mxCol = mxCol - 1
					}
				} else {
					/* COLFLAG_VIRTUAL columns are not included in the WITHOUT ROWID
					 ** PK index column-count, so there is no need to account for them
					 ** in this case. */
					mxCol = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(_sqlite3PrimaryKeyIndex(tls, pTab10))).FnColumn) - int32(1)
				}
				if mxCol >= 0 {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), **(**int32)(__ccgo_up(bp + 108)), mxCol, int32(3))
					_sqlite3VdbeTypeofColumn(tls, v, int32(3))
				}
				if !(isQuick != 0) {
					if pPk1 != 0 {
						a1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxGT), **(**int32)(__ccgo_up(bp + 108)), 0, r2, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
						_sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), r2)
						zErr = _sqlite3MPrintf(tls, db, __ccgo_ts+19454, libc.VaList(bp+176, (*TTable)(unsafe.Pointer(pTab10)).FzName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr, -int32(7))
						_integrityCheckResultRow(tls, v)
						_sqlite3VdbeJumpHere(tls, v, a1)
						_sqlite3VdbeJumpHere(tls, v, a1+int32(1))
						j4 = 0
						for {
							if !(j4 < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol)) {
								break
							}
							_sqlite3ExprCodeLoadIndexColumn(tls, pParse, pPk1, **(**int32)(__ccgo_up(bp + 108)), j4, r2+j4)
							goto _56
						_56:
							;
							j4 = j4 + 1
						}
					}
				}
				/* Verify datatypes for all columns:
				 **
				 **   (1) NOT NULL columns may not contain a NULL
				 **   (2) Datatype must be exact for non-ANY columns in STRICT tables
				 **   (3) Datatype for TEXT columns in non-STRICT tables must be
				 **       NULL, TEXT, or BLOB.
				 **   (4) Datatype for numeric columns in non-STRICT tables must not
				 **       be a TEXT value that can be losslessly converted to numeric.
				 */
				bStrict = libc.BoolInt32((*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_Strict) != uint32(0))
				j4 = 0
				for {
					if !(j4 < int32((*TTable)(unsafe.Pointer(pTab10)).FnCol)) {
						break
					}
					pCol1 = (*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*16 /* Check datatypes (besides NOT NULL) */
					if j4 == int32((*TTable)(unsafe.Pointer(pTab10)).FiPKey) {
						goto _57
					}
					if bStrict != 0 {
						doTypeCheck = libc.BoolInt32(int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf>>0)) > int32(COLTYPE_ANY))
					} else {
						doTypeCheck = libc.BoolInt32(libc.Int32FromUint8((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) > int32(SQLITE_AFF_BLOB))
					}
					if int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf0>>4)) == 0 && !(doTypeCheck != 0) {
						goto _57
					}
					/* Compute the operands that will be needed for OP_IsType */
					p4 = int32(SQLITE_NULL)
					if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pCol1)).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab10, **(**int32)(__ccgo_up(bp + 108)), j4, int32(3))
						p11 = -int32(1)
						p3 = int32(3)
					} else {
						if (*TColumn)(unsafe.Pointer(pCol1)).FiDflt != 0 {
							**(**uintptr)(__ccgo_up(bp + 120)) = uintptr(0)
							_sqlite3ValueFromExpr(tls, db, _sqlite3ColumnExpr(tls, pTab10, pCol1), (*Tsqlite3)(unsafe.Pointer(db)).Fenc, (*TColumn)(unsafe.Pointer(pCol1)).Faffinity, bp+120)
							if **(**uintptr)(__ccgo_up(bp + 120)) != 0 {
								p4 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(bp + 120)))
								_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up(bp + 120)))
							}
						}
						p11 = **(**int32)(__ccgo_up(bp + 108))
						if !((*TTable)(unsafe.Pointer(pTab10)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
							p3 = _sqlite3TableColumnToIndex(tls, _sqlite3PrimaryKeyIndex(tls, pTab10), j4)
						} else {
							p3 = int32(_sqlite3TableColumnToStorage(tls, pTab10, int16(j4)))
						}
					}
					labelError = _sqlite3VdbeMakeLabel(tls, pParse)
					labelOk = _sqlite3VdbeMakeLabel(tls, pParse)
					if int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf0>>4)) != 0 {
						jmp2 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
						if p11 < 0 {
							_sqlite3VdbeChangeP5(tls, v, uint16(0x0f)) /* INT, REAL, TEXT, or BLOB */
							jmp3 = jmp2
						} else {
							_sqlite3VdbeChangeP5(tls, v, uint16(0x0d)) /* INT, TEXT, or BLOB */
							/* OP_IsType does not detect NaN values in the database file
							 ** which should be treated as a NULL.  So if the header type
							 ** is REAL, we have to load the actual data using OP_Column
							 ** to reliably determine if the value is a NULL. */
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), p11, p3, int32(3))
							_sqlite3ColumnDefault(tls, v, pTab10, j4, int32(3))
							jmp3 = _sqlite3VdbeAddOp2(tls, v, int32(OP_NotNull), int32(3), labelOk)
						}
						zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19490, libc.VaList(bp+176, (*TTable)(unsafe.Pointer(pTab10)).FzName, (*TColumn)(unsafe.Pointer(pCol1)).FzCnName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
						if doTypeCheck != 0 {
							_sqlite3VdbeGoto(tls, v, labelError)
							_sqlite3VdbeJumpHere(tls, v, jmp2)
							_sqlite3VdbeJumpHere(tls, v, jmp3)
						} else {
							/* VDBE byte code will fall thru */
						}
					}
					if bStrict != 0 && doTypeCheck != 0 {
						_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
						_sqlite3VdbeChangeP5(tls, v, uint16(_aStdTypeMask[int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf>>0))-int32(1)]))
						zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19510, libc.VaList(bp+176, _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf>>0))-int32(1)], (*TTable)(unsafe.Pointer(pTab10)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*16))).FzCnName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
					} else {
						if !(bStrict != 0) && libc.Int32FromUint8((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) == int32(SQLITE_AFF_TEXT) {
							/* (3) Datatype for TEXT columns in non-STRICT tables must be
							 **     NULL, TEXT, or BLOB. */
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
							_sqlite3VdbeChangeP5(tls, v, uint16(0x1c)) /* NULL, TEXT, or BLOB */
							zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19532, libc.VaList(bp+176, (*TTable)(unsafe.Pointer(pTab10)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*16))).FzCnName))
							_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
						} else {
							if !(bStrict != 0) && libc.Int32FromUint8((*TColumn)(unsafe.Pointer(pCol1)).Faffinity) >= int32(SQLITE_AFF_NUMERIC) {
								/* (4) Datatype for numeric columns in non-STRICT tables must not
								 **     be a TEXT value that can be converted to numeric. */
								_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), p11, labelOk, p3, p4)
								_sqlite3VdbeChangeP5(tls, v, uint16(0x1b)) /* NULL, INT, FLOAT, or BLOB */
								if p11 >= 0 {
									_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab10, **(**int32)(__ccgo_up(bp + 108)), j4, int32(3))
								}
								_sqlite3VdbeAddOp4(tls, v, int32(OP_Affinity), int32(3), int32(1), 0, __ccgo_ts+19555, -int32(1))
								_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IsType), -int32(1), labelOk, int32(3), p4)
								_sqlite3VdbeChangeP5(tls, v, uint16(0x1c)) /* NULL, TEXT, or BLOB */
								zErr1 = _sqlite3MPrintf(tls, db, __ccgo_ts+19557, libc.VaList(bp+176, (*TTable)(unsafe.Pointer(pTab10)).FzName, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(j4)*16))).FzCnName))
								_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr1, -int32(7))
							}
						}
					}
					_sqlite3VdbeResolveLabel(tls, v, labelError)
					_integrityCheckResultRow(tls, v)
					_sqlite3VdbeResolveLabel(tls, v, labelOk)
					goto _57
				_57:
					;
					j4 = j4 + 1
				}
				/* Verify CHECK constraints */
				if (*TTable)(unsafe.Pointer(pTab10)).FpCheck != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0) {
					pCheck = _sqlite3ExprListDup(tls, db, (*TTable)(unsafe.Pointer(pTab10)).FpCheck, 0)
					if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
						addrCkFault = _sqlite3VdbeMakeLabel(tls, pParse)
						addrCkOk = _sqlite3VdbeMakeLabel(tls, pParse)
						(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = **(**int32)(__ccgo_up(bp + 108)) + int32(1)
						k3 = (*TExprList)(unsafe.Pointer(pCheck)).FnExpr - int32(1)
						for {
							if !(k3 > 0) {
								break
							}
							_sqlite3ExprIfFalse(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(k3)*32))).FpExpr, addrCkFault, 0)
							goto _58
						_58:
							;
							k3 = k3 - 1
						}
						_sqlite3ExprIfTrue(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pCheck + 8))).FpExpr, addrCkOk, int32(SQLITE_JUMPIFNULL))
						_sqlite3VdbeResolveLabel(tls, v, addrCkFault)
						(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
						zErr2 = _sqlite3MPrintf(tls, db, __ccgo_ts+19577, libc.VaList(bp+176, (*TTable)(unsafe.Pointer(pTab10)).FzName))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, zErr2, -int32(7))
						_integrityCheckResultRow(tls, v)
						_sqlite3VdbeResolveLabel(tls, v, addrCkOk)
					}
					_sqlite3ExprListDelete(tls, db, pCheck)
				}
				if !(isQuick != 0) { /* Omit the remaining tests for quick_check */
					/* Validate index entries for the current row */
					j4 = 0
					pIdx6 = (*TTable)(unsafe.Pointer(pTab10)).FpIndex
					for {
						if !(pIdx6 != 0) {
							break
						}
						ckUniq = _sqlite3VdbeMakeLabel(tls, pParse)
						if pPk1 == pIdx6 {
							goto _59
						}
						r1 = _sqlite3GenerateIndexKey(tls, pParse, pIdx6, **(**int32)(__ccgo_up(bp + 108)), 0, 0, bp+128, pPrior, r1)
						pPrior = pIdx6
						_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), int32(8)+j4, int32(1)) /* increment entry count */
						/* Verify that an index entry exists for the current table row */
						_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), **(**int32)(__ccgo_up(bp + 112))+j4, ckUniq, r1, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnColumn))
						jmp21 = _sqlite3VdbeAddOp3(tls, v, int32(OP_IFindKey), **(**int32)(__ccgo_up(bp + 112))+j4, ckUniq, r1)
						_sqlite3VdbeChangeP4(tls, v, -int32(1), pIdx6, -int32(6))
						_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, int32(3), 0, _sqlite3MPrintf(tls, db, __ccgo_ts+19607, libc.VaList(bp+176, (*TIndex)(unsafe.Pointer(pIdx6)).FzName)), -int32(7))
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
						_integrityCheckResultRow(tls, v)
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, ckUniq)
						_sqlite3VdbeJumpHere(tls, v, jmp21)
						_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19666)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
						_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19671)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(4), int32(3), int32(3))
						jmp5 = _sqlite3VdbeLoadString(tls, v, int32(4), (*TIndex)(unsafe.Pointer(pIdx6)).FzName)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(4), int32(3), int32(3))
						jmp4 = _integrityCheckResultRow(tls, v)
						_sqlite3VdbeResolveLabel(tls, v, ckUniq)
						/* The OP_IdxRowid opcode is an optimized version of OP_Column
						 ** that extracts the rowid off the end of the index record.
						 ** But it only works correctly if index record does not have
						 ** any extra bytes at the end.  Verify that this is the case. */
						if (*TTable)(unsafe.Pointer(pTab10)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
							_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxRowid), **(**int32)(__ccgo_up(bp + 112))+j4, int32(3))
							jmp7 = _sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), int32(3), 0, r1+libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnColumn)-int32(1))
							_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19692)
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
							_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19728)
							_sqlite3VdbeGoto(tls, v, jmp5-int32(1))
							_sqlite3VdbeJumpHere(tls, v, jmp7)
						}
						/* Any indexed columns with non-BINARY collations must still hold
						 ** the exact same text value as the table. */
						label6 = 0
						kk = 0
						for {
							if !(kk < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol)) {
								break
							}
							if **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx6)).FazColl + uintptr(kk)*8)) == uintptr(unsafe.Pointer(&_sqlite3StrBINARY)) {
								goto _60
							}
							if label6 == 0 {
								label6 = _sqlite3VdbeMakeLabel(tls, pParse)
							}
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), **(**int32)(__ccgo_up(bp + 112))+j4, kk, int32(3))
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), int32(3), label6, r1+kk)
							goto _60
						_60:
							;
							kk = kk + 1
						}
						if label6 != 0 {
							jmp6 = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
							_sqlite3VdbeResolveLabel(tls, v, label6)
							_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19666)
							_sqlite3VdbeAddOp3(tls, v, int32(OP_Concat), int32(7), int32(3), int32(3))
							_sqlite3VdbeLoadString(tls, v, int32(4), __ccgo_ts+19739)
							_sqlite3VdbeGoto(tls, v, jmp5-int32(1))
							_sqlite3VdbeJumpHere(tls, v, jmp6)
						}
						/* For UNIQUE indexes, verify that only one entry exists with the
						 ** current key.  The entry is unique if (1) any column is NULL
						 ** or (2) the next entry has a different key */
						if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx6)).FonError) != OE_None {
							uniqOk = _sqlite3VdbeMakeLabel(tls, pParse)
							kk = 0
							for {
								if !(kk < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol)) {
									break
								}
								iCol1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx6)).FaiColumn + uintptr(kk)*2)))
								if iCol1 >= 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer(pTab10)).FaCol + uintptr(iCol1)*16 + 8))&0xf0>>4)) != 0 {
									goto _61
								}
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), r1+kk, uniqOk)
								goto _61
							_61:
								;
								kk = kk + 1
							}
							jmp61 = _sqlite3VdbeAddOp1(tls, v, int32(OP_Next), **(**int32)(__ccgo_up(bp + 112))+j4)
							_sqlite3VdbeGoto(tls, v, uniqOk)
							_sqlite3VdbeJumpHere(tls, v, jmp61)
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxGT), **(**int32)(__ccgo_up(bp + 112))+j4, uniqOk, r1, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx6)).FnKeyCol))
							_sqlite3VdbeLoadString(tls, v, int32(3), __ccgo_ts+19766)
							_sqlite3VdbeGoto(tls, v, jmp5)
							_sqlite3VdbeResolveLabel(tls, v, uniqOk)
						}
						_sqlite3VdbeJumpHere(tls, v, jmp4)
						_sqlite3ResolvePartIdxLabel(tls, pParse, **(**int32)(__ccgo_up(bp + 128)))
						goto _59
					_59:
						;
						pIdx6 = (*TIndex)(unsafe.Pointer(pIdx6)).FpNext
						j4 = j4 + 1
					}
				}
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), **(**int32)(__ccgo_up(bp + 108)), loopTop)
				_sqlite3VdbeJumpHere(tls, v, loopTop-int32(1))
				if pPk1 != 0 {
					_sqlite3ReleaseTempRange(tls, pParse, r2, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
				}
				goto _53
			_53:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			/* Second pass to invoke the xIntegrity method on all virtual
			 ** tables.
			 */
			x2 = (*THash)(unsafe.Pointer(pTbls)).Ffirst
			for {
				if !(x2 != 0) {
					break
				}
				pTab11 = (*THashElem)(unsafe.Pointer(x2)).Fdata
				if _tableSkipIntegrityCheck(tls, pTab11, pObjTab) != 0 {
					goto _62
				}
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab11)).FeTabType) == TABTYP_NORM {
					goto _62
				}
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab11)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
					goto _62
				}
				if int32((*TTable)(unsafe.Pointer(pTab11)).FnCol) <= 0 {
					zMod = **(**uintptr)(__ccgo_up((*(*struct {
						FnArg  int32
						FazArg uintptr
						Fp     uintptr
					})(unsafe.Pointer(pTab11 + 64))).FazArg))
					if _sqlite3HashFind(tls, db+576, zMod) == uintptr(0) {
						goto _62
					}
				}
				_sqlite3ViewGetColumnNames(tls, pParse, pTab11)
				if (*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(pTab11 + 64))).Fp == uintptr(0) {
					goto _62
				}
				pVTab = (*TVTable)(unsafe.Pointer((*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(pTab11 + 64))).Fp)).FpVtab
				if pVTab == uintptr(0) {
					goto _62
				}
				if (*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FpModule == uintptr(0) {
					goto _62
				}
				if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FpModule)).FiVersion < int32(4) {
					goto _62
				}
				if (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVTab)).FpModule)).FxIntegrity == uintptr(0) {
					goto _62
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_VCheck), i9, int32(3), isQuick)
				(*TTable)(unsafe.Pointer(pTab11)).FnTabRef = (*TTable)(unsafe.Pointer(pTab11)).FnTabRef + 1
				_sqlite3VdbeAppendP4(tls, v, pTab11, -int32(17))
				a11 = _sqlite3VdbeAddOp1(tls, v, int32(OP_IsNull), int32(3))
				_integrityCheckResultRow(tls, v)
				_sqlite3VdbeJumpHere(tls, v, a11)
				goto _62
				goto _62
			_62:
				;
				x2 = (*THashElem)(unsafe.Pointer(x2)).Fnext
			}
			goto _40
		_40:
			;
			i9 = i9 + 1
		}
		aOp2 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(28)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_endCode)), _iLn21)
		if aOp2 != 0 {
			(**(**TVdbeOp)(__ccgo_up(aOp2))).Fp2 = int32(1) - **(**int32)(__ccgo_up(bp + 104))
			(**(**TVdbeOp)(__ccgo_up(aOp2 + 2*24))).Fp4type = int8(-libc.Int32FromInt32(1))
			*(*uintptr)(unsafe.Pointer(aOp2 + 2*24 + 16)) = __ccgo_ts + 19793
			(**(**TVdbeOp)(__ccgo_up(aOp2 + 5*24))).Fp4type = int8(-libc.Int32FromInt32(1))
			*(*uintptr)(unsafe.Pointer(aOp2 + 5*24 + 16)) = _sqlite3ErrStr(tls, int32(SQLITE_CORRUPT))
		}
		_sqlite3VdbeChangeP3(tls, v, 0, _sqlite3VdbeCurrentAddr(tls, v)-int32(2))
		break
		/*
		 **   PRAGMA encoding
		 **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
		 **
		 ** In its first form, this pragma returns the encoding of the main
		 ** database. If the database is not initialized, it is initialized now.
		 **
		 ** The second form of this pragma is a no-op if the main database file
		 ** has not already been initialized. In this case it sets the default
		 ** encoding that will be used for the main database file if a new file
		 ** is created. If an existing main database file is opened, then the
		 ** default text encoding for the existing database is used.
		 **
		 ** In all cases new databases created using the ATTACH command are
		 ** created to use the same default text encoding as the main database. If
		 ** the main database has not been initialized and/or created when ATTACH
		 ** is executed, this is done before the ATTACH operation.
		 **
		 ** In the second form this pragma sets the text encoding to be used in
		 ** new database files created using this database handle. It is only
		 ** useful if invoked immediately after the main database i
		 */
		fallthrough
	case int32(PragTyp_ENCODING):
		if !(zRight != 0) { /* "PRAGMA encoding" */
			if _sqlite3ReadSchema(tls, pParse) != 0 {
				goto pragma_out
			}
			_returnSingleText(tls, v, _encnames1[(*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Fenc].FzName)
		} else { /* "PRAGMA encoding = XXX" */
			/* Only change the value of sqlite.enc if the database handle is not
			 ** initialized. If the main database exists, the new sqlite.enc value
			 ** will be overwritten when the schema is next loaded. If it does not
			 ** already exists, it will be created to use the new encoding value.
			 */
			if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_EncodingFixed) == uint32(0) {
				pEnc = uintptr(unsafe.Pointer(&_encnames1))
				for {
					if !((*struct {
						FzName uintptr
						Fenc   Tu8
					})(unsafe.Pointer(pEnc)).FzName != 0) {
						break
					}
					if 0 == _sqlite3StrICmp(tls, zRight, (*struct {
						FzName uintptr
						Fenc   Tu8
					})(unsafe.Pointer(pEnc)).FzName) {
						if (*struct {
							FzName uintptr
							Fenc   Tu8
						})(unsafe.Pointer(pEnc)).Fenc != 0 {
							v2 = libc.Int32FromUint8((*struct {
								FzName uintptr
								Fenc   Tu8
							})(unsafe.Pointer(pEnc)).Fenc)
						} else {
							v2 = int32(SQLITE_UTF16BE)
						}
						enc = libc.Uint8FromInt32(v2)
						(*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb))).FpSchema)).Fenc = enc
						_sqlite3SetTextEncoding(tls, db, enc)
						break
					}
					goto _63
				_63:
					;
					pEnc += 16
				}
				if !((*struct {
					FzName uintptr
					Fenc   Tu8
				})(unsafe.Pointer(pEnc)).FzName != 0) {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+19854, libc.VaList(bp+176, zRight))
				}
			}
		}
		break
		/*
		 **   PRAGMA [schema.]schema_version
		 **   PRAGMA [schema.]schema_version = <integer>
		 **
		 **   PRAGMA [schema.]user_version
		 **   PRAGMA [schema.]user_version = <integer>
		 **
		 **   PRAGMA [schema.]freelist_count
		 **
		 **   PRAGMA [schema.]data_version
		 **
		 **   PRAGMA [schema.]application_id
		 **   PRAGMA [schema.]application_id = <integer>
		 **
		 ** The pragma's schema_version and user_version are used to set or get
		 ** the value of the schema-version and user-version, respectively. Both
		 ** the schema-version and the user-version are 32-bit signed integers
		 ** stored in the database header.
		 **
		 ** The schema-cookie is usually only manipulated internally by SQLite. It
		 ** is incremented by SQLite whenever the database schema is modified (by
		 ** creating or dropping a table or index). The schema version is used by
		 ** SQLite each time a query is executed to ensure that the internal cache
		 ** of the schema used when compiling the SQL query matches the schema of
		 ** the database against which the compiled query is actually executed.
		 ** Subverting this mechanism by using "PRAGMA schema_version" to modify
		 ** the schema-version is potentially dangerous and may lead to program
		 ** crashes or database corruption. Use with caution!
		 **
		 ** The user-version is not used internally by SQLite. It may be used by
		 ** applications for any purpose.
		 */
		fallthrough
	case int32(PragTyp_HEADER_VALUE):
		iCookie = libc.Int32FromUint64((*TPragmaName)(unsafe.Pointer(pPragma)).FiArg) /* Which cookie to read or write */
		_sqlite3VdbeUsesBtree(tls, v, iDb)
		if zRight != 0 && libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_ReadOnly) == 0 {
			aOp3 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(8)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_setCookie)), 0)
			if 0 != 0 {
				break
			}
			(**(**TVdbeOp)(__ccgo_up(aOp3))).Fp1 = iDb
			(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*24))).Fp1 = iDb
			(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*24))).Fp2 = iCookie
			(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*24))).Fp3 = _sqlite3Atoi(tls, zRight)
			(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*24))).Fp5 = uint16(1)
			if iCookie == int32(BTREE_SCHEMA_VERSION) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0) {
				/* Do not allow the use of PRAGMA schema_version=VALUE in defensive
				 ** mode.  Change the OP_SetCookie opcode into a no-op.  */
				(**(**TVdbeOp)(__ccgo_up(aOp3 + 1*24))).Fopcode = uint8(OP_Noop)
			}
		} else {
			aOp4 = _sqlite3VdbeAddOpList(tls, v, libc.Int32FromUint64(libc.Uint64FromInt64(12)/libc.Uint64FromInt64(4)), uintptr(unsafe.Pointer(&_readCookie)), 0)
			if 0 != 0 {
				break
			}
			(**(**TVdbeOp)(__ccgo_up(aOp4))).Fp1 = iDb
			(**(**TVdbeOp)(__ccgo_up(aOp4 + 1*24))).Fp1 = iDb
			(**(**TVdbeOp)(__ccgo_up(aOp4 + 1*24))).Fp3 = iCookie
			_sqlite3VdbeReusable(tls, v)
		}
		break
		/*
		 **   PRAGMA compile_options
		 **
		 ** Return the names of all compile-time options used in this build,
		 ** one option per row.
		 */
		fallthrough
	case int32(PragTyp_COMPILE_OPTIONS):
		i10 = 0
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(1)
		for {
			v2 = i10
			i10 = i10 + 1
			v1 = Xsqlite3_compileoption_get(tls, v2)
			zOpt = v1
			if !(v1 != uintptr(0)) {
				break
			}
			_sqlite3VdbeLoadString(tls, v, int32(1), zOpt)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(1))
		}
		_sqlite3VdbeReusable(tls, v)
		break
		/*
		 **   PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
		 **
		 ** Checkpoint the database.
		 */
		fallthrough
	case int32(PragTyp_WAL_CHECKPOINT):
		if (*TToken)(unsafe.Pointer(pId2)).Fz != 0 {
			v2 = iDb
		} else {
			v2 = libc.Int32FromInt32(SQLITE_MAX_ATTACHED) + libc.Int32FromInt32(2)
		}
		iBt = v2
		eMode2 = SQLITE_CHECKPOINT_PASSIVE
		if zRight != 0 {
			if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19020) == 0 {
				eMode2 = int32(SQLITE_CHECKPOINT_FULL)
			} else {
				if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19879) == 0 {
					eMode2 = int32(SQLITE_CHECKPOINT_RESTART)
				} else {
					if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19173) == 0 {
						eMode2 = int32(SQLITE_CHECKPOINT_TRUNCATE)
					} else {
						if _sqlite3StrICmp(tls, zRight, __ccgo_ts+19887) == 0 {
							eMode2 = -int32(1)
						}
					}
				}
			}
		}
		(*TParse)(unsafe.Pointer(pParse)).FnMem = int32(3)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Checkpoint), iBt, eMode2, int32(1))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), int32(1), int32(3))
		break
		/*
		 **   PRAGMA wal_autocheckpoint
		 **   PRAGMA wal_autocheckpoint = N
		 **
		 ** Configure a database connection to automatically checkpoint a database
		 ** after accumulating N frames in the log. Or query for the current value
		 ** of N.
		 */
		fallthrough
	case int32(PragTyp_WAL_AUTOCHECKPOINT):
		if zRight != 0 {
			Xsqlite3_wal_autocheckpoint(tls, db, _sqlite3Atoi(tls, zRight))
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback == __ccgo_fp(_sqlite3WalDefaultHook) {
			v2 = int32(int64((*Tsqlite3)(unsafe.Pointer(db)).FpWalArg))
		} else {
			v2 = 0
		}
		_returnSingleInt(tls, v, int64(v2))
		break
		/*
		 **  PRAGMA shrink_memory
		 **
		 ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
		 ** connection on which it is invoked to free up as much memory as it
		 ** can, by calling sqlite3_db_release_memory().
		 */
		fallthrough
	case int32(PragTyp_SHRINK_MEMORY):
		Xsqlite3_db_release_memory(tls, db)
		break
		/*
		 **  PRAGMA optimize
		 **  PRAGMA optimize(MASK)
		 **  PRAGMA schema.optimize
		 **  PRAGMA schema.optimize(MASK)
		 **
		 ** Attempt to optimize the database.  All schemas are optimized in the first
		 ** two forms, and only the specified schema is optimized in the latter two.
		 **
		 ** The details of optimizations performed by this pragma are expected
		 ** to change and improve over time.  Applications should anticipate that
		 ** this pragma will perform new optimizations in future releases.
		 **
		 ** The optional argument is a bitmask of optimizations to perform:
		 **
		 **    0x00001    Debugging mode.  Do not actually perform any optimizations
		 **               but instead return one line of text for each optimization
		 **               that would have been done.  Off by default.
		 **
		 **    0x00002    Run ANALYZE on tables that might benefit.  On by default.
		 **               See below for additional information.
		 **
		 **    0x00010    Run all ANALYZE operations using an analysis_limit that
		 **               is the lessor of the current analysis_limit and the
		 **               SQLITE_DEFAULT_OPTIMIZE_LIMIT compile-time option.
		 **               The default value of SQLITE_DEFAULT_OPTIMIZE_LIMIT is
		 **               currently (2024-02-19) set to 2000, which is such that
		 **               the worst case run-time for PRAGMA optimize on a 100MB
		 **               database will usually be less than 100 milliseconds on
		 **               a RaspberryPI-4 class machine.  On by default.
		 **
		 **    0x10000    Look at tables to see if they need to be reanalyzed
		 **               due to growth or shrinkage even if they have not been
		 **               queried during the current connection.  Off by default.
		 **
		 ** The default MASK is and always shall be 0x0fffe.  In the current
		 ** implementation, the default mask only covers the 0x00002 optimization,
		 ** though additional optimizations that are covered by 0x0fffe might be
		 ** added in the future.  Optimizations that are off by default and must
		 ** be explicitly requested have masks of 0x10000 or greater.
		 **
		 ** DETERMINATION OF WHEN TO RUN ANALYZE
		 **
		 ** In the current implementation, a table is analyzed if only if all of
		 ** the following are true:
		 **
		 ** (1) MASK bit 0x00002 is set.
		 **
		 ** (2) The table is an ordinary table, not a virtual table or view.
		 **
		 ** (3) The table name does not begin with "sqlite_".
		 **
		 ** (4) One or more of the following is true:
		 **      (4a) The 0x10000 MASK bit is set.
		 **      (4b) One or more indexes on the table lacks an entry
		 **           in the sqlite_stat1 table.
		 **      (4c) The query planner used sqlite_stat1-style statistics for one
		 **           or more indexes of the table at some point during the lifetime
		 **           of the current connection.
		 **
		 ** (5) One or more of the following is true:
		 **      (5a) One or more indexes on the table lacks an entry
		 **           in the sqlite_stat1 table.  (Same as 4a)
		 **      (5b) The number of rows in the table has increased or decreased by
		 **           10-fold.  In other words, the current size of the table is
		 **           10 times larger than the size in sqlite_stat1 or else the
		 **           current size is less than 1/10th the size in sqlite_stat1.
		 **
		 ** The rules for when tables are analyzed are likely to change in
		 ** future releases.  Future versions of SQLite might accept a string
		 ** literal argument to this pragma that contains a mnemonic description
		 ** of the options rather than a bitmap.
		 */
		fallthrough
	case int32(PragTyp_OPTIMIZE): /* Analysis limit to use */
		nCheck = 0 /* Number of tables to be optimized */
		nBtree = 0 /* Number of indexes on the current table */
		if zRight != 0 {
			opMask = libc.Uint32FromInt32(_sqlite3Atoi(tls, zRight))
			if opMask&uint32(0x02) == uint32(0) {
				break
			}
		} else {
			opMask = uint32(0xfffe)
		}
		if opMask&uint32(0x10) == uint32(0) {
			nLimit = 0
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit < int32(SQLITE_DEFAULT_OPTIMIZE_LIMIT) {
				nLimit = 0
			} else {
				nLimit = int32(SQLITE_DEFAULT_OPTIMIZE_LIMIT)
			}
		}
		v1 = pParse + 56
		v2 = *(*int32)(unsafe.Pointer(v1))
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		iTabCur = v2
		if zDb != 0 {
			v2 = iDb
		} else {
			v2 = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
		}
		iDbLast = v2
		for {
			if !(iDb <= iDbLast) {
				break
			}
			if iDb == int32(1) {
				goto _71
			}
			_sqlite3CodeVerifySchema(tls, pParse, iDb)
			pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
			k4 = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
			for {
				if !(k4 != 0) {
					break
				}
				pTab12 = (*THashElem)(unsafe.Pointer(k4)).Fdata
				/* This only works for ordinary tables */
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab12)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
					goto _73
				}
				/* Do not scan system tables */
				if 0 == Xsqlite3_strnicmp(tls, (*TTable)(unsafe.Pointer(pTab12)).FzName, __ccgo_ts+6760, int32(7)) {
					goto _73
				}
				/* Find the size of the table as last recorded in sqlite_stat1.
				 ** If any index is unanalyzed, then the threshold is -1 to
				 ** indicate a new, unanalyzed index
				 */
				szThreshold = (*TTable)(unsafe.Pointer(pTab12)).FnRowLogEst
				nIndex = 0
				pIdx7 = (*TTable)(unsafe.Pointer(pTab12)).FpIndex
				for {
					if !(pIdx7 != 0) {
						break
					}
					nIndex = nIndex + 1
					if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIdx7 + 100))&0x100>>8)) != 0) {
						szThreshold = int16(-int32(1)) /* Always analyze if any index lacks statistics */
					}
					goto _74
				_74:
					;
					pIdx7 = (*TIndex)(unsafe.Pointer(pIdx7)).FpNext
				}
				/* If table pTab has not been used in a way that would benefit from
				 ** having analysis statistics during the current session, then skip it,
				 ** unless the 0x10000 MASK bit is set. */
				if (*TTable)(unsafe.Pointer(pTab12)).FtabFlags&uint32(TF_MaybeReanalyze) != uint32(0) {
					/* Check for size change if stat1 has been used for a query */
				} else {
					if opMask&uint32(0x10000) != 0 {
						/* Check for size change if 0x10000 is set */
					} else {
						if (*TTable)(unsafe.Pointer(pTab12)).FpIndex != uintptr(0) && int32(szThreshold) < 0 {
							/* Do analysis if unanalyzed indexes exists */
						} else {
							/* Otherwise, we can skip this table */
							goto _73
						}
					}
				}
				nCheck = nCheck + 1
				if nCheck == int32(2) {
					/* If ANALYZE might be invoked two or more times, hold a write
					 ** transaction for efficiency */
					_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
				}
				nBtree = nBtree + (nIndex + int32(1))
				/* Reanalyze if the table is 10 times larger or smaller than
				 ** the last analysis.  Unconditional reanalysis if there are
				 ** unanalyzed indexes. */
				_sqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab12, int32(OP_OpenRead))
				if int32(szThreshold) >= 0 {
					iRange = int16(33) /* 10x size change */
					if int32(szThreshold) >= int32(iRange) {
						v2 = int32(szThreshold) - int32(iRange)
					} else {
						v2 = -int32(1)
					}
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IfSizeBetween), iTabCur, libc.Int32FromUint32(libc.Uint32FromInt32(_sqlite3VdbeCurrentAddr(tls, v)+int32(2))+opMask&uint32(1)), v2, int32(szThreshold)+int32(iRange))
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iTabCur, libc.Int32FromUint32(libc.Uint32FromInt32(_sqlite3VdbeCurrentAddr(tls, v)+int32(2))+opMask&uint32(1)))
				}
				zSubSql = _sqlite3MPrintf(tls, db, __ccgo_ts+19892, libc.VaList(bp+176, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName, (*TTable)(unsafe.Pointer(pTab12)).FzName))
				if opMask&uint32(0x01) != 0 {
					r11 = _sqlite3GetTempReg(tls, pParse)
					_sqlite3VdbeAddOp4(tls, v, int32(OP_String8), 0, r11, 0, zSubSql, -int32(7))
					_sqlite3VdbeAddOp2(tls, v, int32(OP_ResultRow), r11, int32(1))
				} else {
					if nLimit != 0 {
						v2 = int32(0x02)
					} else {
						v2 = 00
					}
					_sqlite3VdbeAddOp4(tls, v, int32(OP_SqlExec), v2, nLimit, 0, zSubSql, -int32(7))
				}
				goto _73
			_73:
				;
				k4 = (*THashElem)(unsafe.Pointer(k4)).Fnext
			}
			goto _71
		_71:
			;
			iDb = iDb + 1
		}
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Expire))
		/* In a schema with a large number of tables and indexes, scale back
		 ** the analysis_limit to avoid excess run-time in the worst case.
		 */
		if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) && nLimit > 0 && nBtree > int32(100) {
			nLimit = int32(100) * nLimit / nBtree
			if nLimit < int32(100) {
				nLimit = int32(100)
			}
			aOp5 = _sqlite3VdbeGetOp(tls, v, 0)
			iEnd = _sqlite3VdbeCurrentAddr(tls, v)
			iAddr1 = 0
			for {
				if !(iAddr1 < iEnd) {
					break
				}
				if libc.Int32FromUint8((**(**TVdbeOp)(__ccgo_up(aOp5 + uintptr(iAddr1)*24))).Fopcode) == int32(OP_SqlExec) {
					(**(**TVdbeOp)(__ccgo_up(aOp5 + uintptr(iAddr1)*24))).Fp2 = nLimit
				}
				goto _77
			_77:
				;
				iAddr1 = iAddr1 + 1
			}
		}
		break
		/*
		 **   PRAGMA busy_timeout
		 **   PRAGMA busy_timeout = N
		 **
		 ** Call sqlite3_busy_timeout(db, N).  Return the current timeout value
		 ** if one is set.  If no busy handler or a different busy handler is set
		 ** then 0 is returned.  Setting the busy_timeout to 0 or negative
		 ** disables the timeout.
		 */
		/*case PragTyp_BUSY_TIMEOUT*/
		fallthrough
	default:
		if zRight != 0 {
			Xsqlite3_busy_timeout(tls, db, _sqlite3Atoi(tls, zRight))
		}
		_returnSingleInt(tls, v, int64((*Tsqlite3)(unsafe.Pointer(db)).FbusyTimeout))
		break
		/*
		 **   PRAGMA soft_heap_limit
		 **   PRAGMA soft_heap_limit = N
		 **
		 ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
		 ** sqlite3_soft_heap_limit64() interface with the argument N, if N is
		 ** specified and is a non-negative integer.
		 ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
		 ** returns the same integer that would be returned by the
		 ** sqlite3_soft_heap_limit64(-1) C-language function.
		 */
		fallthrough
	case int32(PragTyp_SOFT_HEAP_LIMIT):
		if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+136) == SQLITE_OK {
			Xsqlite3_soft_heap_limit64(tls, **(**Tsqlite3_int64)(__ccgo_up(bp + 136)))
		}
		_returnSingleInt(tls, v, Xsqlite3_soft_heap_limit64(tls, int64(-int32(1))))
		break
		/*
		 **   PRAGMA hard_heap_limit
		 **   PRAGMA hard_heap_limit = N
		 **
		 ** Invoke sqlite3_hard_heap_limit64() to query or set the hard heap
		 ** limit.  The hard heap limit can be activated or lowered by this
		 ** pragma, but not raised or deactivated.  Only the
		 ** sqlite3_hard_heap_limit64() C-language API can raise or deactivate
		 ** the hard heap limit.  This allows an application to set a heap limit
		 ** constraint that cannot be relaxed by an untrusted SQL script.
		 */
		fallthrough
	case int32(PragTyp_HARD_HEAP_LIMIT):
		if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+144) == SQLITE_OK {
			iPrior = Xsqlite3_hard_heap_limit64(tls, int64(-int32(1)))
			if **(**Tsqlite3_int64)(__ccgo_up(bp + 144)) > 0 && (iPrior == 0 || iPrior > **(**Tsqlite3_int64)(__ccgo_up(bp + 144))) {
				Xsqlite3_hard_heap_limit64(tls, **(**Tsqlite3_int64)(__ccgo_up(bp + 144)))
			}
		}
		_returnSingleInt(tls, v, Xsqlite3_hard_heap_limit64(tls, int64(-int32(1))))
		break
		/*
		 **   PRAGMA threads
		 **   PRAGMA threads = N
		 **
		 ** Configure the maximum number of worker threads.  Return the new
		 ** maximum, which might be less than requested.
		 */
		fallthrough
	case int32(PragTyp_THREADS):
		if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+152) == SQLITE_OK && **(**Tsqlite3_int64)(__ccgo_up(bp + 152)) >= 0 {
			Xsqlite3_limit(tls, db, int32(SQLITE_LIMIT_WORKER_THREADS), int32(**(**Tsqlite3_int64)(__ccgo_up(bp + 152))&libc.Int64FromInt32(0x7fffffff)))
		}
		_returnSingleInt(tls, v, int64(Xsqlite3_limit(tls, db, int32(SQLITE_LIMIT_WORKER_THREADS), -int32(1))))
		break
		/*
		 **   PRAGMA analysis_limit
		 **   PRAGMA analysis_limit = N
		 **
		 ** Configure the maximum number of rows that ANALYZE will examine
		 ** in each index that it looks at.  Return the new limit.
		 */
		fallthrough
	case int32(PragTyp_ANALYSIS_LIMIT):
		if zRight != 0 && _sqlite3DecOrHexToI64(tls, zRight, bp+160) == SQLITE_OK && **(**Tsqlite3_int64)(__ccgo_up(bp + 160)) >= 0 {
			(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = int32(**(**Tsqlite3_int64)(__ccgo_up(bp + 160)) & libc.Int64FromInt32(0x7fffffff))
		}
		_returnSingleInt(tls, v, int64((*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit)) /* IMP: R-57594-65522 */
		break
	} /* End of the PRAGMA switch */
	/* The following block is a no-op unless SQLITE_DEBUG is defined. Its only
	 ** purpose is to execute assert() statements to verify that if the
	 ** PragFlg_NoColumns1 flag is set and the caller specified an argument
	 ** to the PRAGMA, the implementation has not added any OP_ResultRow
	 ** instructions to the VM.  */
	if libc.Int32FromUint8((*TPragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&int32(PragFlg_NoColumns1) != 0 && zRight != 0 {
	}
	goto pragma_out
pragma_out:
	;
	_sqlite3DbFree(tls, db, zLeft)
	_sqlite3DbFree(tls, db, zRight)
}

// C documentation
//
//	/*
//	** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
//	*/
func _sqlite3Prepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags Tu32, pReprepare uintptr, ppStmt uintptr, pzTail uintptr) (r int32) {
	bp := tls.Alloc(448)
	defer tls.Free(448)
	var i, mxLen, rc, v1 int32
	var pBt, pT, zDb, zSqlCopy uintptr
	var _ /* sParse at bp+0 */ TParse
	_, _, _, _, _, _, _, _ = i, mxLen, pBt, pT, rc, zDb, zSqlCopy, v1
	rc = SQLITE_OK /* Parsing context */
	/* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
	libc.Xmemset(tls, bp+uintptr(uint64(libc.UintptrFromInt32(0)+8)), 0, uint64(libc.UintptrFromInt32(0)+192)-uint64(libc.UintptrFromInt32(0)+8))
	libc.Xmemset(tls, bp+uintptr(uint64(libc.UintptrFromInt32(0)+288)), 0, libc.Uint64FromInt64(424)-uint64(libc.UintptrFromInt32(0)+288))
	(**(**TParse)(__ccgo_up(bp))).FpOuterParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	(*Tsqlite3)(unsafe.Pointer(db)).FpParse = bp
	(**(**TParse)(__ccgo_up(bp))).Fdb = db
	if pReprepare != 0 {
		(**(**TParse)(__ccgo_up(bp))).FpReprepare = pReprepare
		(**(**TParse)(__ccgo_up(bp))).Fexplain = libc.Uint8FromInt32(Xsqlite3_stmt_isexplain(tls, pReprepare))
	} else {
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ErrorMsg(tls, bp, __ccgo_ts+1674, 0)
		v1 = libc.Int32FromInt32(SQLITE_NOMEM)
		rc = v1
		(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = v1
		goto end_prepare
	}
	/* For a long-term use prepared statement avoid the use of
	 ** lookaside memory.
	 */
	if prepFlags&uint32(SQLITE_PREPARE_PERSISTENT) != 0 {
		(**(**TParse)(__ccgo_up(bp))).FdisableLookaside = (**(**TParse)(__ccgo_up(bp))).FdisableLookaside + 1
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
		(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
	}
	(**(**TParse)(__ccgo_up(bp))).FprepFlags = uint8(prepFlags & uint32(0xff))
	/* Check to verify that it is possible to get a read lock on all
	 ** database schemas.  The inability to get a read lock indicates that
	 ** some other database connection is holding a write-lock, which in
	 ** turn means that the other connection has made uncommitted changes
	 ** to the schema.
	 **
	 ** Were we to proceed and prepare the statement against the uncommitted
	 ** schema changes and if those schema changes are subsequently rolled
	 ** back and different changes are made in their place, then when this
	 ** prepared statement goes to run the schema cookie would fail to detect
	 ** the schema change.  Disaster would follow.
	 **
	 ** This thread is currently holding mutexes on all Btrees (because
	 ** of the sqlite3BtreeEnterAll() in sqlite3LockAndPrepare()) so it
	 ** is not possible for another thread to start a new schema change
	 ** while this routine is running.  Hence, we do not need to hold
	 ** locks on the schema, we just need to make sure nobody else is
	 ** holding them.
	 **
	 ** Note that setting READ_UNCOMMITTED overrides most lock detection,
	 ** but it does *not* override schema lock detection, so this all still
	 ** works even if READ_UNCOMMITTED is set.
	 */
	if !((*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache != 0) {
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FpBt
			if pBt != 0 {
				rc = _sqlite3BtreeSchemaLocked(tls, pBt)
				if rc != 0 {
					zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))).FzDbSName
					_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+20239, libc.VaList(bp+432, zDb))
					goto end_prepare
				}
			}
			goto _2
		_2:
			;
			i = i + 1
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FpDisconnect != 0 {
		_sqlite3VtabUnlockList(tls, db)
	}
	if nBytes >= 0 && (nBytes == 0 || libc.Int32FromUint8(**(**uint8)(__ccgo_up(zSql + uintptr(nBytes-int32(1))))) != 0) {
		mxLen = **(**int32)(__ccgo_up(db + 136 + 1*4))
		if nBytes > mxLen {
			_sqlite3ErrorWithMsg(tls, db, int32(SQLITE_TOOBIG), __ccgo_ts+20269, 0)
			rc = _sqlite3ApiExit(tls, db, int32(SQLITE_TOOBIG))
			goto end_prepare
		}
		zSqlCopy = _sqlite3DbStrNDup(tls, db, zSql, libc.Uint64FromInt32(nBytes))
		if zSqlCopy != 0 {
			_sqlite3RunParser(tls, bp, zSqlCopy)
			(**(**TParse)(__ccgo_up(bp))).FzTail = zSql + uintptr(int64((**(**TParse)(__ccgo_up(bp))).FzTail)-int64(zSqlCopy))
			_sqlite3DbFree(tls, db, zSqlCopy)
		} else {
			(**(**TParse)(__ccgo_up(bp))).FzTail = zSql + uintptr(nBytes)
		}
	} else {
		_sqlite3RunParser(tls, bp, zSql)
	}
	if pzTail != 0 {
		**(**uintptr)(__ccgo_up(pzTail)) = (**(**TParse)(__ccgo_up(bp))).FzTail
	}
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
		_sqlite3VdbeSetSql(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe, zSql, int32(int64((**(**TParse)(__ccgo_up(bp))).FzTail)-int64(zSql)), uint8(prepFlags))
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(**(**TParse)(__ccgo_up(bp))).Frc = int32(SQLITE_NOMEM)
		libc.SetBitFieldPtr16Uint32(bp+40, libc.Uint32FromInt32(0), 7, 0x80)
	}
	if (**(**TParse)(__ccgo_up(bp))).Frc != SQLITE_OK && (**(**TParse)(__ccgo_up(bp))).Frc != int32(SQLITE_DONE) {
		if int32(Tbft(*(*uint16)(unsafe.Pointer(bp + 40))&0x80>>7)) != 0 && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy) == 0 {
			_schemaIsValid(tls, bp)
		}
		if (**(**TParse)(__ccgo_up(bp))).FpVdbe != 0 {
			_sqlite3VdbeFinalize(tls, (**(**TParse)(__ccgo_up(bp))).FpVdbe)
		}
		rc = (**(**TParse)(__ccgo_up(bp))).Frc
		if (**(**TParse)(__ccgo_up(bp))).FzErrMsg != 0 {
			_sqlite3ErrorWithMsg(tls, db, rc, __ccgo_ts+3944, libc.VaList(bp+432, (**(**TParse)(__ccgo_up(bp))).FzErrMsg))
			_sqlite3DbFree(tls, db, (**(**TParse)(__ccgo_up(bp))).FzErrMsg)
		} else {
			_sqlite3Error(tls, db, rc)
		}
	} else {
		**(**uintptr)(__ccgo_up(ppStmt)) = (**(**TParse)(__ccgo_up(bp))).FpVdbe
		rc = SQLITE_OK
		_sqlite3ErrorClear(tls, db)
	}
	/* Delete any TriggerPrg structures allocated while parsing this statement. */
	for (**(**TParse)(__ccgo_up(bp))).FpTriggerPrg != 0 {
		pT = (**(**TParse)(__ccgo_up(bp))).FpTriggerPrg
		(**(**TParse)(__ccgo_up(bp))).FpTriggerPrg = (*TTriggerPrg)(unsafe.Pointer(pT)).FpNext
		_sqlite3DbFree(tls, db, pT)
	}
	goto end_prepare
end_prepare:
	;
	_sqlite3ParseObjectReset(tls, bp)
	return rc
}

// C documentation
//
//	/*
//	** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
//	*/
func _sqlite3Prepare16(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags Tu32, ppStmt uintptr, pzTail uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var chars_parsed, rc, sz, sz1 int32
	var z, z1, zSql8 uintptr
	var _ /* zTail8 at bp+0 */ uintptr
	_, _, _, _, _, _, _ = chars_parsed, rc, sz, sz1, z, z1, zSql8
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	rc = SQLITE_OK
	**(**uintptr)(__ccgo_up(ppStmt)) = uintptr(0)
	if !(_sqlite3SafetyCheckOk(tls, db) != 0) || zSql == uintptr(0) {
		return _sqlite3MisuseError(tls, int32(148902))
	}
	/* Make sure nBytes is non-negative and correct.  It should be the
	 ** number of bytes until the end of the input buffer or until the first
	 ** U+0000 character.  If the input nBytes is odd, convert it into
	 ** an even number.  If the input nBytes is negative, then the input
	 ** must be terminated by at least one U+0000 character */
	if nBytes >= 0 {
		z = zSql
		sz = 0
		for {
			if !(sz < nBytes && (libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(sz)))) != 0 || libc.Int32FromUint8(**(**uint8)(__ccgo_up(z + uintptr(sz+int32(1))))) != 0)) {
				break
			}
			goto _1
		_1:
			;
			sz = sz + int32(2)
		}
		nBytes = sz
	} else {
		z1 = zSql
		sz1 = 0
		for {
			if !(libc.Int32FromUint8(**(**uint8)(__ccgo_up(z1 + uintptr(sz1)))) != 0 || libc.Int32FromUint8(**(**uint8)(__ccgo_up(z1 + uintptr(sz1+int32(1))))) != 0) {
				break
			}
			goto _2
		_2:
			;
			sz1 = sz1 + int32(2)
		}
		nBytes = sz1
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	zSql8 = _sqlite3Utf16to8(tls, db, zSql, nBytes, uint8(SQLITE_UTF16BE))
	if zSql8 != 0 {
		rc = _sqlite3LockAndPrepare(tls, db, zSql8, -int32(1), prepFlags, uintptr(0), ppStmt, bp)
	}
	if **(**uintptr)(__ccgo_up(bp)) != 0 && pzTail != 0 {
		/* If sqlite3_prepare returns a tail pointer, we calculate the
		 ** equivalent pointer into the UTF-16 string by counting the unicode
		 ** characters between zSql8 and zTail8, and then returning a pointer
		 ** the same number of characters into the UTF-16 string.
		 */
		chars_parsed = _sqlite3Utf8CharLen(tls, zSql8, int32(int64(**(**uintptr)(__ccgo_up(bp)))-int64(zSql8)))
		**(**uintptr)(__ccgo_up(pzTail)) = zSql + uintptr(_sqlite3Utf16ByteLen(tls, zSql, nBytes, chars_parsed))
	}
	_sqlite3DbFree(tls, db, zSql8)
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Return the PRIMARY KEY index of a table
//	*/
func _sqlite3PrimaryKeyIndex(tls *libc.TLS, pTab uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(p != 0 && !(int32(uint32(*(*uint16)(unsafe.Pointer(p + 100))&0xc000>>14)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))) {
			break
		}
		goto _1
	_1:
		;
		p = (*TIndex)(unsafe.Pointer(p)).FpNext
	}
	return p
}

// C documentation
//
//	/*
//	** This routine processes the join information for a SELECT statement.
//	**
//	**   *  A NATURAL join is converted into a USING join.  After that, we
//	**      do not need to be concerned with NATURAL joins and we only have
//	**      think about USING joins.
//	**
//	**   *  ON and USING clauses result in extra terms being added to the
//	**      WHERE clause to enforce the specified constraints.  The extra
//	**      WHERE clause terms will be tagged with EP_OuterON or
//	**      EP_InnerON so that we know that they originated in ON/USING.
//	**
//	** The terms of a FROM clause are contained in the Select.pSrc structure.
//	** The left most table is the first entry in Select.pSrc.  The right-most
//	** table is the last entry.  The join operator is held in the entry to
//	** the right.  Thus entry 1 contains the join operator for the join between
//	** entries 0 and 1.  Any ON or USING clauses associated with the join are
//	** also attached to the right entry.
//	**
//	** This routine returns the number of errors encountered.
//	*/
func _sqlite3ProcessJoin(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pE1, pE2, pEq, pFuncArgs, pLeft, pList, pRight, pRightTab, pSrc, pUsing, zName, zName1 uintptr
	var i, iRightCol, j, v2 int32
	var joinType Tu32
	var _ /* iLeft at bp+0 */ int32
	var _ /* iLeftCol at bp+4 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, i, iRightCol, j, joinType, pE1, pE2, pEq, pFuncArgs, pLeft, pList, pRight, pRightTab, pSrc, pUsing, zName, zName1, v2 /* Right table being joined */
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
	pLeft = pSrc + 8
	pRight = pLeft + 1*80
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc-int32(1)) {
			break
		}
		pRightTab = (*TSrcItem)(unsafe.Pointer(pRight)).FpSTab
		if (*TSrcItem)(unsafe.Pointer(pLeft)).FpSTab == uintptr(0) || pRightTab == uintptr(0) {
			goto _1
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&int32(JT_OUTER) != 0 {
			v2 = int32(EP_OuterON)
		} else {
			v2 = int32(EP_InnerON)
		}
		joinType = libc.Uint32FromInt32(v2)
		/* If this is a NATURAL join, synthesize an appropriate USING clause
		 ** to specify which columns should be joined.
		 */
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&int32(JT_NATURAL) != 0 {
			pUsing = uintptr(0)
			if int32(*(*uint32)(unsafe.Pointer(pRight + 24 + 4))&0x100000>>20) != 0 || *(*uintptr)(unsafe.Pointer(pRight + 64)) != 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20318, libc.VaList(bp+16, 0))
				return int32(1)
			}
			j = 0
			for {
				if !(j < int32((*TTable)(unsafe.Pointer(pRightTab)).FnCol)) {
					break
				} /* Name of column in the right table */
				if libc.Int32FromUint16((*TColumn)(unsafe.Pointer((*TTable)(unsafe.Pointer(pRightTab)).FaCol+uintptr(j)*16)).FcolFlags)&int32(COLFLAG_HIDDEN) != 0 {
					goto _3
				}
				zName = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pRightTab)).FaCol + uintptr(j)*16))).FzCnName
				if _tableAndColumnIndex(tls, pSrc, 0, i, zName, uintptr(0), uintptr(0), int32(1)) != 0 {
					pUsing = _sqlite3IdListAppend(tls, pParse, pUsing, uintptr(0))
					if pUsing != 0 {
						(*(*TIdList_item)(unsafe.Pointer(pUsing + 8 + uintptr((*TIdList)(unsafe.Pointer(pUsing)).FnId-int32(1))*8))).FzName = _sqlite3DbStrDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, zName)
					}
				}
				goto _3
			_3:
				;
				j = j + 1
			}
			if pUsing != 0 {
				libc.SetBitFieldPtr32Uint32(pRight+24+4, libc.Uint32FromInt32(1), 20, 0x100000)
				libc.SetBitFieldPtr32Uint32(pRight+24+4, libc.Uint32FromInt32(1), 18, 0x40000)
				*(*uintptr)(unsafe.Pointer(pRight + 64)) = pUsing
			}
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return int32(1)
			}
		}
		/* Create extra terms on the WHERE clause for each column named
		 ** in the USING clause.  Example: If the two tables to be joined are
		 ** A and B and the USING clause names X, Y, and Z, then add this
		 ** to the WHERE clause:    A.X=B.X AND A.Y=B.Y AND A.Z=B.Z
		 ** Report an error if any column mentioned in the USING clause is
		 ** not contained in both tables to be joined.
		 */
		if int32(*(*uint32)(unsafe.Pointer(pRight + 24 + 4))&0x100000>>20) != 0 {
			pList = *(*uintptr)(unsafe.Pointer(pRight + 64))
			db = (*TParse)(unsafe.Pointer(pParse)).Fdb
			j = 0
			for {
				if !(j < (*TIdList)(unsafe.Pointer(pList)).FnId) {
					break
				} /* Equality constraint.  pE1 == pE2 */
				zName1 = (*(*TIdList_item)(unsafe.Pointer(pList + 8 + uintptr(j)*8))).FzName
				iRightCol = _sqlite3ColumnIndex(tls, pRightTab, zName1)
				if iRightCol < 0 || _tableAndColumnIndex(tls, pSrc, 0, i, zName1, bp, bp+4, int32(*(*uint32)(unsafe.Pointer(pRight + 24 + 4))&0x40000>>18)) == 0 {
					_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20368, libc.VaList(bp+16, zName1))
					return int32(1)
				}
				pE1 = _sqlite3CreateColumnExpr(tls, db, pSrc, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
				_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(**(**int32)(__ccgo_up(bp)))*80, **(**int32)(__ccgo_up(bp + 4)))
				if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSrc + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0 && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
					/* This branch runs if the query contains one or more RIGHT or FULL
					 ** JOINs.  If only a single table on the left side of this join
					 ** contains the zName column, then this branch is a no-op.
					 ** But if there are two or more tables on the left side
					 ** of the join, construct a coalesce() function that gathers all
					 ** such tables.  Raise an error if more than one of those references
					 ** to zName is not also within a prior USING clause.
					 **
					 ** We really ought to raise an error if there are two or more
					 ** non-USING references to zName on the left of an INNER or LEFT
					 ** JOIN.  But older versions of SQLite do not do that, so we avoid
					 ** adding a new error so as to not break legacy applications.
					 */
					pFuncArgs = uintptr(0) /* Arguments to the coalesce() */
					**(**Tu32)(__ccgo_up(pE1 + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
					for _tableAndColumnIndex(tls, pSrc, **(**int32)(__ccgo_up(bp))+int32(1), i, zName1, bp, bp+4, int32(*(*uint32)(unsafe.Pointer(pRight + 24 + 4))&0x40000>>18)) != 0 {
						if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(**(**int32)(__ccgo_up(bp)))*80 + 24 + 4))&0x100000>>20) == 0 || _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(**(**int32)(__ccgo_up(bp)))*80 + 64)), zName1) < 0 {
							_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+20432, libc.VaList(bp+16, zName1))
							break
						}
						pFuncArgs = _sqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
						pE1 = _sqlite3CreateColumnExpr(tls, db, pSrc, **(**int32)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
						_sqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(**(**int32)(__ccgo_up(bp)))*80, **(**int32)(__ccgo_up(bp + 4)))
					}
					if pFuncArgs != 0 {
						pFuncArgs = _sqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
						pE1 = _sqlite3ExprFunction(tls, pParse, pFuncArgs, uintptr(unsafe.Pointer(&_tkCoalesce)), 0)
						if pE1 != 0 {
							(*TExpr)(unsafe.Pointer(pE1)).FaffExpr = uint8(SQLITE_AFF_DEFER)
						}
					}
				} else {
					if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i+int32(1))*80))).Ffg.Fjointype)&int32(JT_LEFT) != 0 && (*TParse)(unsafe.Pointer(pParse)).FnErr == 0 {
						**(**Tu32)(__ccgo_up(pE1 + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(EP_CanBeNull))
					}
				}
				pE2 = _sqlite3CreateColumnExpr(tls, db, pSrc, i+int32(1), iRightCol)
				_sqlite3SrcItemColumnUsed(tls, pRight, iRightCol)
				pEq = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pE1, pE2)
				if pEq != 0 {
					**(**Tu32)(__ccgo_up(pEq + 4)) |= joinType
					*(*int32)(unsafe.Pointer(pEq + 52)) = (*TExpr)(unsafe.Pointer(pE2)).FiTable
				}
				(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWhere, pEq)
				goto _4
			_4:
				;
				j = j + 1
			}
		} else {
			if *(*uintptr)(unsafe.Pointer(pRight + 64)) != 0 {
				_sqlite3SetJoinExpr(tls, *(*uintptr)(unsafe.Pointer(pRight + 64)), (*TSrcItem)(unsafe.Pointer(pRight)).FiCursor, joinType)
				(*TSelect)(unsafe.Pointer(p)).FpWhere = _sqlite3ExprAnd(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpWhere, *(*uintptr)(unsafe.Pointer(pRight + 64)))
				*(*uintptr)(unsafe.Pointer(pRight + 64)) = uintptr(0)
				libc.SetBitFieldPtr32Uint32(pRight+24+4, libc.Uint32FromInt32(1), 19, 0x80000)
				**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_OnToWhere)
			}
		}
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pRightTab)).FeTabType) == int32(TABTYP_VTAB) && joinType == uint32(EP_OuterON) && *(*uintptr)(unsafe.Pointer(pRight + 48)) != 0 {
			**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_OnToWhere)
		}
		goto _1
	_1:
		;
		i = i + 1
		pRight += 80
		pLeft += 80
	}
	return 0
}

func _sqlite3Put4byte(tls *libc.TLS, p uintptr, _v Tu32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Tu32)(unsafe.Pointer(bp)) = _v
	libc.Xmemcpy(tls, p, bp, uint64(4))
}

// C documentation
//
//	/*
//	** Generate code that will erase and refill index *pIdx.  This is
//	** used to initialize a newly created index or to recompute the
//	** content of an index in response to a REINDEX command.
//	**
//	** if memRootPage is not negative, it means that the index is newly
//	** created.  The register specified by memRootPage contains the
//	** root page number of the index.  If memRootPage is negative, then
//	** the index already exists and must be cleared before being refilled and
//	** the root page number of the index is taken from pIndex->tnum.
//	*/
func _sqlite3RefillIndex(tls *libc.TLS, pParse uintptr, pIndex uintptr, memRootPage int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var addr1, addr2, iDb, iIdx, iSorter, iTab, j2, regRecord, v1, v3 int32
	var db, pKey, pTab, v, v2, v4 uintptr
	var tnum TPgno
	var _ /* iPartIdxLabel at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addr2, db, iDb, iIdx, iSorter, iTab, j2, pKey, pTab, regRecord, tnum, v, v1, v2, v3, v4
	pTab = (*TIndex)(unsafe.Pointer(pIndex)).FpTable
	v2 = pParse + 56
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1 /* The table that is indexed */
	iTab = v1
	v4 = pParse + 56
	v3 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1 /* Btree cursor used for pTab */
	iIdx = v3                                                         /* Register holding assembled index record */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                        /* The database connection */
	iDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIndex)).FpSchema)
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_REINDEX), (*TIndex)(unsafe.Pointer(pIndex)).FzName, uintptr(0), (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName) != 0 {
		return
	}
	/* Require a write-lock on the table to perform this operation */
	_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(1), (*TTable)(unsafe.Pointer(pTab)).FzName)
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		return
	}
	if memRootPage >= 0 {
		tnum = libc.Uint32FromInt32(memRootPage)
	} else {
		tnum = (*TIndex)(unsafe.Pointer(pIndex)).Ftnum
	}
	pKey = _sqlite3KeyInfoOfIndex(tls, pParse, pIndex)
	/* Open the sorter cursor if we are to use one. */
	v2 = pParse + 56
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	iSorter = v1
	_sqlite3VdbeAddOp4(tls, v, int32(OP_SorterOpen), iSorter, 0, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol), _sqlite3KeyInfoRef(tls, pKey), -int32(9))
	/* Open the table. Loop through all rows of the table, inserting index
	 ** records into the sorter. */
	_sqlite3OpenTable(tls, pParse, iTab, iDb, pTab, int32(OP_OpenRead))
	addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iTab, 0)
	regRecord = _sqlite3GetTempReg(tls, pParse)
	_sqlite3MultiWrite(tls, pParse)
	_sqlite3GenerateIndexKey(tls, pParse, pIndex, iTab, regRecord, 0, bp, uintptr(0), 0)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterInsert), iSorter, regRecord)
	_sqlite3ResolvePartIdxLabel(tls, pParse, **(**int32)(__ccgo_up(bp)))
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iTab, addr1+int32(1))
	_sqlite3VdbeJumpHere(tls, v, addr1)
	if memRootPage < 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Clear), libc.Int32FromUint32(tnum), iDb)
	}
	_sqlite3VdbeAddOp4(tls, v, int32(OP_OpenWrite), iIdx, libc.Int32FromUint32(tnum), iDb, pKey, -int32(9))
	if memRootPage >= 0 {
		v1 = int32(OPFLAG_P2ISREG)
	} else {
		v1 = 0
	}
	_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(int32(OPFLAG_BULKCSR)|v1))
	addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), iSorter, 0)
	if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIndex)).FonError) != OE_None {
		j2 = _sqlite3VdbeGoto(tls, v, int32(1))
		addr2 = _sqlite3VdbeCurrentAddr(tls, v)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_SorterCompare), iSorter, j2, regRecord, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol))
		_sqlite3UniqueConstraint(tls, pParse, int32(OE_Abort), pIndex)
		_sqlite3VdbeJumpHere(tls, v, j2)
	} else {
		/* Most CREATE INDEX and REINDEX statements that are not UNIQUE can not
		 ** abort. The exception is if one of the indexed expressions contains a
		 ** user function that throws an exception when it is evaluated. But the
		 ** overhead of adding a statement journal to a CREATE INDEX statement is
		 ** very small (since most of the pages written do not contain content that
		 ** needs to be restored if the statement aborts), so we call
		 ** sqlite3MayAbort() for all CREATE INDEX statements.  */
		_sqlite3MayAbort(tls, pParse)
		addr2 = _sqlite3VdbeCurrentAddr(tls, v)
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_SorterData), iSorter, regRecord, iIdx)
	if !(int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x40>>6)) != 0) {
		/* This OP_SeekEnd opcode makes index insert for a REINDEX go much
		 ** faster by avoiding unnecessary seeks.  But the optimization does
		 ** not work for UNIQUE constraint indexes on WITHOUT ROWID tables
		 ** with DESC primary keys, since those indexes have there keys in
		 ** a different order from the main table.
		 ** See ticket: https://sqlite.org/src/info/bba7b69f9849b5bf
		 */
		_sqlite3VdbeAddOp1(tls, v, int32(OP_SeekEnd), iIdx)
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iIdx, regRecord)
	_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
	_sqlite3ReleaseTempReg(tls, pParse, regRecord)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterNext), iSorter, addr2)
	_sqlite3VdbeJumpHere(tls, v, addr1)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iTab)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iIdx)
	_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iSorter)
}

// C documentation
//
//	/*
//	** Generate code for the REINDEX command.
//	**
//	**        REINDEX                            -- 1
//	**        REINDEX  <collation>               -- 2
//	**        REINDEX  ?<database>.?<indexname>  -- 3
//	**        REINDEX  ?<database>.?<tablename>  -- 4
//	**        REINDEX  EXPRESSIONS               -- 5
//	**
//	** Form 1 causes all indexes in all attached databases to be rebuilt.
//	** Form 2 rebuilds all indexes in all databases that use the named
//	** collating function.  Forms 3 and 4 rebuild the named index or all
//	** indexes associated with the named table, respectively.  Form 5
//	** rebuilds all expression indexes in addition to all collations,
//	** indexes, or tables named "EXPRESSIONS".
//	**
//	** If the name is ambiguous such that it matches two or more of
//	** forms 2 through 5, then rebuild the union of all matching indexes,
//	** taken care to avoid rebuilding the same index more than once.
//	*/
func _sqlite3Reindex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bAll, bMatch, iDb, iReDb, isExprIdx int32
	var db, k, pDb, pIdx, pReIndex, pReTab, pTab, z, zColl, zDb, v1 uintptr
	var v2 bool
	var _ /* pObjName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bAll, bMatch, db, iDb, iReDb, isExprIdx, k, pDb, pIdx, pReIndex, pReTab, pTab, z, zColl, zDb, v1, v2
	z = uintptr(0)                             /* Name of a table or index or collation */
	zDb = uintptr(0)                           /* Name of the database */
	iReDb = -int32(1)                          /* The database index number */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Name of the table or index to be reindexed */
	bMatch = 0                                 /* At least one name match */
	zColl = uintptr(0)                         /* Rebuild indexes using this collation */
	pReTab = uintptr(0)                        /* Rebuild all indexes of this table */
	pReIndex = uintptr(0)                      /* Rebuild this index */
	isExprIdx = 0                              /* Rebuild all expression indexes */
	bAll = 0                                   /* Rebuild all indexes */
	/* Read the database schema. If an error occurs, leave an error message
	 ** and code in pParse and return NULL. */
	if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
		return
	}
	if pName1 == uintptr(0) {
		/* rebuild all indexes */
		bMatch = int32(1)
		bAll = int32(1)
	} else {
		if pName2 == uintptr(0) || (*TToken)(unsafe.Pointer(pName2)).Fz == uintptr(0) {
			z = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName1)
			if z == uintptr(0) {
				return
			}
		} else {
			iReDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
			if iReDb < 0 {
				return
			}
			z = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
			if z == uintptr(0) {
				return
			}
			zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iReDb)*32))).FzDbSName
		}
	}
	if !(bAll != 0) {
		if zDb == uintptr(0) && _sqlite3StrICmp(tls, z, __ccgo_ts+16230) == 0 {
			isExprIdx = int32(1)
			bMatch = int32(1)
		}
		if zDb == uintptr(0) && _sqlite3FindCollSeq(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).Fenc, z, 0) != uintptr(0) {
			zColl = z
			bMatch = int32(1)
		}
		if v2 = zColl == uintptr(0); v2 {
			v1 = _sqlite3FindTable(tls, db, z, zDb)
			pReTab = v1
		}
		if v2 && v1 != uintptr(0) {
			bMatch = int32(1)
		}
		if v2 = zColl == uintptr(0); v2 {
			v1 = _sqlite3FindIndex(tls, db, z, zDb)
			pReIndex = v1
		}
		if v2 && v1 != uintptr(0) {
			bMatch = int32(1)
		}
	}
	if bMatch != 0 {
		iDb = 0
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
		for {
			if !(iDb < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
				break
			}
			if iReDb >= 0 && iReDb != iDb {
				goto _5
			}
			k = (*THash)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema + 8)).Ffirst
			for {
				if !(k != 0) {
					break
				}
				pTab = (*THashElem)(unsafe.Pointer(k)).Fdata
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					goto _6
				}
				pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
				for {
					if !(pIdx != 0) {
						break
					}
					if bAll != 0 || pTab == pReTab || pIdx == pReIndex || isExprIdx != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x10>>4)) != 0 || zColl != uintptr(0) && _collationMatch(tls, zColl, pIdx) != 0 {
						_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
						_sqlite3RefillIndex(tls, pParse, pIdx, -int32(1))
					}
					goto _7
				_7:
					;
					pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
				} /* End loop over indexes of pTab */
				goto _6
			_6:
				;
				k = (*THashElem)(unsafe.Pointer(k)).Fnext
			} /* End loop over tables of iDb */
			goto _5
		_5:
			;
			iDb = iDb + 1
			pDb += 32
		} /* End loop over databases */
	} else {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16242, 0)
	}
	_sqlite3DbFree(tls, db, z)
	return
}

// C documentation
//
//	/*
//	** Remove all nodes that are part of expression-list pEList from the
//	** rename list.
//	*/
func _sqlite3RenameExprlistUnmap(tls *libc.TLS, pParse uintptr, pEList uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var _ /* sWalker at bp+0 */ TWalker
	_ = i
	if pEList != 0 {
		libc.Xmemset(tls, bp, 0, uint64(48))
		(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
		(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_renameUnmapExprCb)
		_sqlite3WalkExprList(tls, bp, pEList)
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0xc000>>14)) == ENAME_NAME {
				_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32))).FzEName)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** Generate byte-code for the SELECT statement given in the p argument.
//	**
//	** The results are returned according to the SelectDest structure.
//	** See comments in sqliteInt.h for further information.
//	**
//	** This routine returns the number of errors.  If any errors are
//	** encountered, then an appropriate error message is left in
//	** pParse->zErrMsg.
//	**
//	** This routine does NOT free the Select structure passed in.  The
//	** calling function needs to do that.
//	**
//	** This is a long function.  The following is an outline of the processing
//	** steps, with tags referencing various milestones:
//	**
//	**  *  Resolve names and similar preparation                tag-select-0100
//	**  *  Scan of the FROM clause                              tag-select-0200
//	**      +  OUTER JOIN strength reduction                      tag-select-0220
//	**      +  Sub-query ORDER BY removal                         tag-select-0230
//	**      +  Query flattening                                   tag-select-0240
//	**  *  Separate subroutine for compound-SELECT              tag-select-0300
//	**  *  WHERE-clause constant propagation                    tag-select-0330
//	**  *  Count()-of-VIEW optimization                         tag-select-0350
//	**  *  Scan of the FROM clause again                        tag-select-0400
//	**      +  Authorize unreferenced tables                      tag-select-0410
//	**      +  Predicate push-down optimization                   tag-select-0420
//	**      +  Omit unused subquery columns optimization          tag-select-0440
//	**      +  Generate code to implement subqueries              tag-select-0480
//	**         -  Co-routines                                       tag-select-0482
//	**         -  Reuse previously computed CTE                     tag-select-0484
//	**         -  REuse previously computed VIEW                    tag-select-0486
//	**         -  Materialize a VIEW or CTE                         tag-select-0488
//	**  *  DISTINCT ORDER BY -> GROUP BY optimization           tag-select-0500
//	**  *  Set up for ORDER BY                                  tag-select-0600
//	**  *  Create output table                                  tag-select-0630
//	**  *  Prepare registers for LIMIT                          tag-select-0650
//	**  *  Setup for DISTINCT                                   tag-select-0680
//	**  *  Generate code for non-aggregate and non-GROUP BY     tag-select-0700
//	**  *  Generate code for aggregate and/or GROUP BY          tag-select-0800
//	**      +  GROUP BY queries                                   tag-select-0810
//	**      +  non-GROUP BY queries                               tag-select-0820
//	**         -  Special case of count() w/o GROUP BY              tag-select-0821
//	**         -  General case of non-GROUP BY aggregates           tag-select-0822
//	**  *  Sort results, as needed                              tag-select-0900
//	**  *  Internal self-checks                                 tag-select-1000
//	*/
func _sqlite3Select(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) (r int32) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var addr1, addrEnd, addrGosub, addrOutputRow, addrReset, addrSetAbort, addrSortingIdx, addrTop, addrTopOfLoop, eDist, eDist1, groupBySort, i, iAMem, iAbortFlag, iBMem, iBreak, iCont, iCsr, iDb, iDb1, iEnd, iOrderByCol, iUseFlag, ii, isAgg, j, k, nCol, nGroupBy, onceAddr, orderByGrp, rc, regAcc, regBase, regGosub, regOutputRow, regRecord, regReset, sortOut, sortPTab, topAddr, v12, v15 int32
	var db, p0, pAggInfo, pBase, pBest, pCol, pCteUse, pCteUse1, pDistinct, pDistinct1, pEList, pExpr, pF, pF1, pGroupBy, pHaving, pI2, pIdx, pItem, pItem1, pItem2, pKeyInfo, pKeyInfo1, pKeyInfo2, pPrior, pPriorSubq, pSub, pSub1, pSubq, pTab, pTab1, pTabList, pWInfo, pWhere, pWin, pX, v, zDb, zSavedAuthContext, v1, v3 uintptr
	var distFlag, distFlag1, wctrlFlags Tu16
	var iRoot TPgno
	var minMaxFlag Tu8
	var _ /* dest at bp+72 */ TSelectDest
	var _ /* pMinMaxOrderBy at bp+64 */ uintptr
	var _ /* sDistinct at bp+0 */ TDistinctCtx
	var _ /* sNC at bp+112 */ TNameContext
	var _ /* sSort at bp+16 */ TSortCtx
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addrEnd, addrGosub, addrOutputRow, addrReset, addrSetAbort, addrSortingIdx, addrTop, addrTopOfLoop, db, distFlag, distFlag1, eDist, eDist1, groupBySort, i, iAMem, iAbortFlag, iBMem, iBreak, iCont, iCsr, iDb, iDb1, iEnd, iOrderByCol, iRoot, iUseFlag, ii, isAgg, j, k, minMaxFlag, nCol, nGroupBy, onceAddr, orderByGrp, p0, pAggInfo, pBase, pBest, pCol, pCteUse, pCteUse1, pDistinct, pDistinct1, pEList, pExpr, pF, pF1, pGroupBy, pHaving, pI2, pIdx, pItem, pItem1, pItem2, pKeyInfo, pKeyInfo1, pKeyInfo2, pPrior, pPriorSubq, pSub, pSub1, pSubq, pTab, pTab1, pTabList, pWInfo, pWhere, pWin, pX, rc, regAcc, regBase, regGosub, regOutputRow, regRecord, regReset, sortOut, sortPTab, topAddr, v, wctrlFlags, zDb, zSavedAuthContext, v1, v12, v15, v3 /* True for select lists like "count(*)" */
	pEList = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        /* The HAVING clause.  May be NULL */
	pAggInfo = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      /* Aggregate information */
	rc = int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* The database connection */
	**(**uintptr)(__ccgo_up(bp + 64)) = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             /* Flag for min/max queries */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	v = _sqlite3GetVdbe(tls, pParse)
	if p == uintptr(0) || (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return int32(1)
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_SELECT), uintptr(0), uintptr(0), uintptr(0)) != 0 {
		return int32(1)
	}
	/* tag-select-0100 */
	if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= int32(SRT_DistQueue) {
		/* All of these destinations are also able to ignore the ORDER BY clause */
		if (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 {
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
			(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		}
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Distinct)
	}
	_sqlite3SelectPrep(tls, pParse, p, uintptr(0))
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto select_end
	}
	/* If the SF_UFSrcCheck flag is set, then this function is being called
	 ** as part of populating the temp table for an UPDATE...FROM statement.
	 ** In this case, it is an error if the target object (pSrc->a[0]) name
	 ** or alias is duplicated within FROM clause (pSrc->a[1..n]).
	 **
	 ** Postgres disallows this case too. The reason is that some other
	 ** systems handle this case differently, and not all the same way,
	 ** which is just confusing. To avoid this, we follow PG's lead and
	 ** disallow it altogether.  */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_UFSrcCheck) != 0 {
		p0 = (*TSelect)(unsafe.Pointer(p)).FpSrc + 8
		if _sameSrcAlias(tls, p0, (*TSelect)(unsafe.Pointer(p)).FpSrc) != 0 {
			if (*TSrcItem)(unsafe.Pointer(p0)).FzAlias != 0 {
				v1 = (*TSrcItem)(unsafe.Pointer(p0)).FzAlias
			} else {
				v1 = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(p0)).FpSTab)).FzName
			}
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21632, libc.VaList(bp+176, v1))
			goto select_end
		}
		/* Clear the SF_UFSrcCheck flag. The check has already been performed,
		 ** and leaving this flag set can cause errors if a compound sub-query
		 ** in p->pSrc is flattened into this query and this function called
		 ** again as part of compound SELECT processing.  */
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_UFSrcCheck)
	}
	if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_Output) {
		_sqlite3GenerateColumnNames(tls, pParse, p)
	}
	if _sqlite3WindowRewrite(tls, pParse, p) != 0 {
		goto select_end
	}
	pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	isAgg = libc.BoolInt32((*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) != uint32(0))
	libc.Xmemset(tls, bp+16, 0, uint64(48))
	(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
	/* Try to do various optimizations (flattening subqueries, and strength
	 ** reduction of join operators) in the FROM clause up into the main query
	 ** tag-select-0200
	 */
	i = 0
	for {
		if !(!((*TSelect)(unsafe.Pointer(p)).FpPrior != 0) && i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pItem = pTabList + 8 + uintptr(i)*80
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
			v1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
		} else {
			v1 = uintptr(0)
		}
		pSub = v1
		pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
		/* The expander should have already created transient Table objects
		 ** even for FROM clause elements such as subqueries that do not correspond
		 ** to a real table */
		/* Try to simplify joins:
		 **
		 **      LEFT JOIN  ->  JOIN
		 **     RIGHT JOIN  ->  JOIN
		 **      FULL JOIN  ->  RIGHT JOIN
		 **
		 ** If terms of the i-th table are used in the WHERE clause in such a
		 ** way that the i-th table cannot be the NULL row of a join, then
		 ** perform the appropriate simplification. This is called
		 ** "OUTER JOIN strength reduction" in the SQLite documentation.
		 ** tag-select-0220
		 */
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)) != 0 && _sqlite3ExprImpliesNonNullRow(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LTORJ)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_SimplifyJoin)) == uint32(0) {
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
				if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
					v1 = pItem + 24
					*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(JT_LEFT))
				} else {
					v1 = pItem + 24
					*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(JT_LEFT) | libc.Int32FromInt32(JT_OUTER)))
					_unsetJoinExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, 0)
				}
			}
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
				j = i + int32(1)
				for {
					if !(j < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
						break
					}
					pI2 = pTabList + 8 + uintptr(j)*80
					if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pI2)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
						if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pI2)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
							v1 = pI2 + 24
							*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(JT_RIGHT))
						} else {
							v1 = pI2 + 24
							*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(JT_RIGHT) | libc.Int32FromInt32(JT_OUTER)))
							_unsetJoinExpr(tls, (*TSelect)(unsafe.Pointer(p)).FpWhere, (*TSrcItem)(unsafe.Pointer(pI2)).FiCursor, int32(1))
						}
					}
					goto _6
				_6:
					;
					j = j + 1
				}
				j = (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc - int32(1)
				for {
					if !(j >= 0) {
						break
					}
					v1 = pTabList + 8 + uintptr(j)*80 + 24
					*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(JT_LTORJ))
					if libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*80))).Ffg.Fjointype)&int32(JT_RIGHT) != 0 {
						break
					}
					goto _9
				_9:
					;
					j = j - 1
				}
			}
		}
		/* No further action if this term of the FROM clause is not a subquery */
		if pSub == uintptr(0) {
			goto _2
		}
		/* Catch mismatch in the declared columns of a view and the number of
		 ** columns in the SELECT on the RHS */
		if int32((*TTable)(unsafe.Pointer(pTab)).FnCol) != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpEList)).FnExpr {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+21686, libc.VaList(bp+176, int32((*TTable)(unsafe.Pointer(pTab)).FnCol), (*TTable)(unsafe.Pointer(pTab)).FzName, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSub)).FpEList)).FnExpr))
			goto select_end
		}
		/* Do not attempt the usual optimizations (flattening and ORDER BY
		 ** elimination) on a MATERIALIZED common table expression because
		 ** a MATERIALIZED common table expression is an optimization fence.
		 */
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x400000>>22) != 0 && libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 56)))).FeM10d) == M10d_Yes {
			goto _2
		}
		/* Do not try to flatten an aggregate subquery.
		 **
		 ** Flattening an aggregate subquery is only possible if the outer query
		 ** is not a join.  But if the outer query is not a join, then the subquery
		 ** will be implemented as a co-routine and there is no advantage to
		 ** flattening in that case.
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FselFlags&uint32(SF_Aggregate) != uint32(0) {
			goto _2
		}
		/* tag-select-0230:
		 ** If a FROM-clause subquery has an ORDER BY clause that is not
		 ** really doing anything, then delete it now so that it does not
		 ** interfere with query flattening.  See the discussion at
		 ** https://sqlite.org/forum/forumpost/2d76f2bcf65d256a
		 **
		 ** Beware of these cases where the ORDER BY clause may not be safely
		 ** omitted:
		 **
		 **    (1)   There is also a LIMIT clause
		 **    (2)   The subquery was added to help with window-function
		 **          processing
		 **    (3)   The subquery is in the FROM clause of an UPDATE
		 **    (4)   The outer query uses an aggregate function other than
		 **          the built-in count(), min(), or max().
		 **    (5)   The ORDER BY isn't going to accomplish anything because
		 **          one of:
		 **            (a)  The outer query has a different ORDER BY clause
		 **            (b)  The subquery is part of a join
		 **          See forum post 062d576715d277c8
		 **    (6)   The subquery is not a recursive CTE.  ORDER BY has a different
		 **          meaning for recursive CTEs and this optimization does not
		 **          apply.
		 **
		 ** Also retain the ORDER BY if the OmitOrderBy optimization is disabled.
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != uintptr(0) && ((*TSelect)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) || (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1)) && (*TSelect)(unsafe.Pointer(pSub)).FpLimit == uintptr(0) && (*TSelect)(unsafe.Pointer(pSub)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_OrderByReqd)|libc.Int32FromInt32(SF_Recursive)) == uint32(0) && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_OrderByReqd) == uint32(0) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OmitOrderBy)) == uint32(0) {
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3ExprListDeleteGeneric), (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy)
			(*TSelect)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
		}
		/* If the outer query contains a "complex" result set (that is,
		 ** if the result set of the outer query uses functions or subqueries)
		 ** and if the subquery contains an ORDER BY clause and if
		 ** it will be implemented as a co-routine, then do not flatten.  This
		 ** restriction allows SQL constructs like this:
		 **
		 **  SELECT expensive_function(x)
		 **    FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
		 **
		 ** The expensive_function() is only computed on the 10 rows that
		 ** are output, rather than every row of the table.
		 **
		 ** The requirement that the outer query have a complex result set
		 ** means that flattening does occur on simpler SQL constraints without
		 ** the expensive_function() like:
		 **
		 **  SELECT x FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
		 */
		if (*TSelect)(unsafe.Pointer(pSub)).FpOrderBy != uintptr(0) && i == 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_ComplexResult) != uint32(0) && ((*TSrcList)(unsafe.Pointer(pTabList)).FnSrc == int32(1) || libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + 1*80))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0) {
			goto _2
		}
		/* tag-select-0240 */
		if _flattenSubquery(tls, pParse, p, i, isAgg) != 0 {
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				goto select_end
			}
			/* This subquery can be absorbed into its parent. */
			i = -int32(1)
		}
		pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		if !(libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= libc.Int32FromInt32(SRT_Fifo)) {
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = (*TSelect)(unsafe.Pointer(p)).FpOrderBy
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	/* Handle compound SELECT statements using the separate multiSelect()
	 ** procedure.  tag-select-0300
	 */
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		rc = _multiSelect(tls, pParse, p, pDest)
		if (*TSelect)(unsafe.Pointer(p)).FpNext == uintptr(0) {
			_sqlite3VdbeExplainPop(tls, pParse)
		}
		return rc
	}
	/* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
	 ** to change it into a join.  */
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x800>>11)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_ExistsToJoin)) == uint32(0) {
		_existsToJoin(tls, pParse, p, (*TSelect)(unsafe.Pointer(p)).FpWhere)
		pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	}
	/* Do the WHERE-clause constant propagation optimization if this is
	 ** a join.  No need to spend time on this operation for non-join queries
	 ** as the equivalent optimization will be handled by query planner in
	 ** sqlite3WhereBegin().  tag-select-0330
	 */
	if (*TSelect)(unsafe.Pointer(p)).FpWhere != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpWhere)).Fop) == int32(TK_AND) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_PropagateConst)) == uint32(0) && _propagateConstants(tls, pParse, p) != 0 {
	} else {
	}
	/* tag-select-0350 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_QueryFlattener)|libc.Int32FromInt32(SQLITE_CountOfView)) == uint32(0) && _countOfViewOptimization(tls, pParse, p) != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		pTabList = (*TSelect)(unsafe.Pointer(p)).FpSrc
	}
	/* Loop over all terms in the FROM clause and do two things for each term:
	 **
	 **   (1) Authorize unreferenced tables
	 **   (2) Generate code for all sub-queries
	 **
	 ** tag-select-0400
	 */
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
			break
		}
		pItem1 = pTabList + 8 + uintptr(i)*80
		/* Authorized unreferenced tables.  tag-select-0410
		 **
		 ** Issue SQLITE_READ authorizations with a fake column name for any
		 ** tables that are referenced but from which no values are extracted.
		 ** Examples of where these kinds of null SQLITE_READ authorizations
		 ** would occur:
		 **
		 **     SELECT count(*) FROM t1;   -- SQLITE_READ t1.""
		 **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2.""
		 **
		 ** The fake column name is an empty string.  It is possible for a table to
		 ** have a column named by the empty string, in which case there is no way to
		 ** distinguish between an unreferenced table and an actual reference to the
		 ** "" column. The original design was for the fake column name to be a NULL,
		 ** which would be unambiguous.  But legacy authorization callbacks might
		 ** assume the column name is non-NULL and segfault.  The use of an empty
		 ** string for the fake column name seems safer.
		 */
		if (*TSrcItem)(unsafe.Pointer(pItem1)).FcolUsed == uint64(0) && (*TSrcItem)(unsafe.Pointer(pItem1)).FzName != uintptr(0) {
			if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x8000>>15) != 0 {
				iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pItem1 + 72)))
				zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
			} else {
				if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x20000000>>29) != 0 {
					zDb = uintptr(0)
				} else {
					zDb = *(*uintptr)(unsafe.Pointer(pItem1 + 72))
				}
			}
			_sqlite3AuthCheck(tls, pParse, int32(SQLITE_READ), (*TSrcItem)(unsafe.Pointer(pItem1)).FzName, __ccgo_ts+1704, zDb)
		}
		/* Generate code for all sub-queries in the FROM clause
		 */
		if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x20000000>>29) == 0 {
			goto _11
		}
		pSubq = *(*uintptr)(unsafe.Pointer(pItem1 + 72))
		pSub1 = (*TSubquery)(unsafe.Pointer(pSubq)).FpSelect
		/* The code for a subquery should only be generated once. */
		if (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub != 0 {
			goto _11
		}
		/* Increment Parse.nHeight by the height of the largest expression
		 ** tree referred to by this, the parent select. The child select
		 ** may contain expression trees of at most
		 ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit
		 ** more conservative than necessary, but much easier than enforcing
		 ** an exact limit.
		 */
		**(**int32)(__ccgo_up(pParse + 316)) += _sqlite3SelectExprHeight(tls, p)
		/* Make copies of constant WHERE-clause terms in the outer query down
		 ** inside the subquery.  This can help the subquery to run more efficiently.
		 ** This is the "predicate push-down optimization".  tag-select-0420
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_PushDown)) == uint32(0) && (int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x400000>>22) == 0 || libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 56)))).FeM10d) != M10d_Yes && (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 56)))).FnUse < int32(2)) && _pushDownWhereTerms(tls, pParse, pSub1, (*TSelect)(unsafe.Pointer(p)).FpWhere, pTabList, i) != 0 {
		} else {
		}
		/* Convert unused result columns of the subquery into simple NULL
		 ** expressions, to avoid unneeded searching and computation.
		 ** tag-select-0440
		 */
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_NullUnusedCols)) == uint32(0) && _disableUnusedSubqueryResultColumns(tls, pItem1) != 0 {
		}
		zSavedAuthContext = (*TParse)(unsafe.Pointer(pParse)).FzAuthContext
		(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = (*TSrcItem)(unsafe.Pointer(pItem1)).FzName
		/* Generate byte-code to implement the subquery  tag-select-0480
		 */
		if _fromClauseTermCanBeCoroutine(tls, pParse, pTabList, i, libc.Int32FromUint32((*TSelect)(unsafe.Pointer(p)).FselFlags)) != 0 {
			/* Implement a co-routine that will return a single row of the result
			 ** set on each invocation.  tag-select-0482
			 */
			addrTop = _sqlite3VdbeCurrentAddr(tls, v) + int32(1)
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			(*TSubquery)(unsafe.Pointer(pSubq)).FregReturn = v12
			_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, 0, addrTop)
			(*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub = addrTop
			_sqlite3SelectDestInit(tls, bp+72, int32(SRT_Coroutine), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn)
			_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21726, libc.VaList(bp+176, pItem1))
			_sqlite3Select(tls, pParse, pSub1, bp+72)
			(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem1)).FpSTab)).FnRowLogEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
			libc.SetBitFieldPtr32Uint32(pItem1+24+4, libc.Uint32FromInt32(1), 25, 0x2000000)
			(*TSubquery)(unsafe.Pointer(pSubq)).FregResult = (**(**TSelectDest)(__ccgo_up(bp + 72))).FiSdst
			_sqlite3VdbeEndCoroutine(tls, v, (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn)
			_sqlite3VdbeJumpHere(tls, v, addrTop-int32(1))
			_sqlite3ClearTempRegCache(tls, pParse)
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x400000>>22) != 0 && (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 56)))).FaddrM9e > 0 {
				/* This is a CTE for which materialization code has already been
				 ** generated.  Invoke the subroutine to compute the materialization,
				 ** then make the pItem->iCursor be a copy of the ephemeral table that
				 ** holds the result of the materialization. tag-select-0484 */
				pCteUse = *(*uintptr)(unsafe.Pointer(pItem1 + 56))
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TCteUse)(unsafe.Pointer(pCteUse)).FregRtn, (*TCteUse)(unsafe.Pointer(pCteUse)).FaddrM9e)
				if (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor != (*TCteUse)(unsafe.Pointer(pCteUse)).FiCur {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor, (*TCteUse)(unsafe.Pointer(pCteUse)).FiCur)
				}
				(*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow = (*TCteUse)(unsafe.Pointer(pCteUse)).FnRowEst
			} else {
				v1 = _isSelfJoinView(tls, pTabList, pItem1, 0, i)
				pPrior = v1
				if v1 != uintptr(0) {
					pPriorSubq = *(*uintptr)(unsafe.Pointer(pPrior + 72))
					if (*TSubquery)(unsafe.Pointer(pPriorSubq)).FaddrFillSub != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSubquery)(unsafe.Pointer(pPriorSubq)).FregReturn, (*TSubquery)(unsafe.Pointer(pPriorSubq)).FaddrFillSub)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenDup), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor, (*TSrcItem)(unsafe.Pointer(pPrior)).FiCursor)
					(*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pPriorSubq)).FpSelect)).FnSelectRow
				} else {
					onceAddr = 0
					v1 = pParse + 60
					*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
					v12 = *(*int32)(unsafe.Pointer(v1))
					(*TSubquery)(unsafe.Pointer(pSubq)).FregReturn = v12
					topAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
					(*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub = topAddr + int32(1)
					libc.SetBitFieldPtr32Uint32(pItem1+24+4, libc.Uint32FromInt32(1), 26, 0x4000000)
					if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x8000000>>27) == 0 {
						/* If the subquery is not correlated and if we are not inside of
						 ** a trigger, then we only need to compute the value of the subquery
						 ** once. */
						onceAddr = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
					} else {
					}
					_sqlite3SelectDestInit(tls, bp+72, int32(SRT_EphemTab), (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor)
					_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+21741, libc.VaList(bp+176, pItem1))
					_sqlite3Select(tls, pParse, pSub1, bp+72)
					(*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem1)).FpSTab)).FnRowLogEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
					if onceAddr != 0 {
						_sqlite3VdbeJumpHere(tls, v, onceAddr)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Return), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, topAddr+int32(1))
					_sqlite3VdbeJumpHere(tls, v, topAddr)
					_sqlite3ClearTempRegCache(tls, pParse)
					if int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x400000>>22) != 0 && int32(*(*uint32)(unsafe.Pointer(pItem1 + 24 + 4))&0x8000000>>27) == 0 {
						pCteUse1 = *(*uintptr)(unsafe.Pointer(pItem1 + 56))
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FaddrM9e = (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FregRtn = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FiCur = (*TSrcItem)(unsafe.Pointer(pItem1)).FiCursor
						(*TCteUse)(unsafe.Pointer(pCteUse1)).FnRowEst = (*TSelect)(unsafe.Pointer(pSub1)).FnSelectRow
					}
				}
			}
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		**(**int32)(__ccgo_up(pParse + 316)) -= _sqlite3SelectExprHeight(tls, p)
		(*TParse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext
		goto _11
	_11:
		;
		i = i + 1
	}
	/* Various elements of the SELECT copied into local variables for
	 ** convenience */
	pEList = (*TSelect)(unsafe.Pointer(p)).FpEList
	pWhere = (*TSelect)(unsafe.Pointer(p)).FpWhere
	pGroupBy = (*TSelect)(unsafe.Pointer(p)).FpGroupBy
	pHaving = (*TSelect)(unsafe.Pointer(p)).FpHaving
	(**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct = libc.BoolUint8((*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != uint32(0))
	/* tag-select-0500
	 **
	 ** If the query is DISTINCT with an ORDER BY but is not an aggregate, and
	 ** if the select-list is the same as the ORDER BY list, then this query
	 ** can be rewritten as a GROUP BY. In other words, this:
	 **
	 **     SELECT DISTINCT xyz FROM ... ORDER BY xyz
	 **
	 ** is transformed to:
	 **
	 **     SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
	 **
	 ** The second form is preferred as a single index (or temp-table) may be
	 ** used for both the ORDER BY and DISTINCT processing. As originally
	 ** written the query must use a temp-table for at least one of the ORDER
	 ** BY and DISTINCT, and an index or separate temp-table for the other.
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SF_Distinct)|libc.Int32FromInt32(SF_Aggregate)) == uint32(SF_Distinct) && _sqlite3CopySortOrder(tls, pEList, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy) != 0 && _sqlite3ExprListCompare(tls, pEList, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, -int32(1)) == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_GroupByOrder)) == uint32(0) && (*TSelect)(unsafe.Pointer(p)).FpWin == uintptr(0) {
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Distinct)
		v1 = _sqlite3ExprListDup(tls, db, pEList, 0)
		(*TSelect)(unsafe.Pointer(p)).FpGroupBy = v1
		pGroupBy = v1
		if pGroupBy != 0 {
			i = 0
			for {
				if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
					break
				}
				*(*Tu16)(unsafe.Pointer(pGroupBy + 8 + uintptr(i)*32 + 24)) = libc.Uint16FromInt32(i + int32(1))
				goto _18
			_18:
				;
				i = i + 1
			}
		}
		**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_Aggregate)
		/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
		 ** the sDistinct.isTnct is still set.  Hence, isTnct represents the
		 ** original setting of the SF_Distinct flag, not the current setting */
		(**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct = uint8(2)
	}
	/* If there is an ORDER BY clause, then create an ephemeral index to
	 ** do the sorting.  But this sorting ephemeral index might end up
	 ** being unused if the data can be extracted in pre-sorted order.
	 ** If that is the case, then the OP_OpenEphemeral instruction will be
	 ** changed to an OP_Noop once we figure out that the sorting index is
	 ** not needed.  The sSort.addrSortIndex variable is used to facilitate
	 ** that change.  tag-select-0600
	 */
	if (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy != 0 {
		pKeyInfo = _sqlite3KeyInfoFromExprList(tls, pParse, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, 0, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
		v1 = pParse + 56
		v12 = *(*int32)(unsafe.Pointer(v1))
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		(**(**TSortCtx)(__ccgo_up(bp + 16))).FiECursor = v12
		(**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (**(**TSortCtx)(__ccgo_up(bp + 16))).FiECursor, (*TExprList)(unsafe.Pointer((**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy)).FnExpr+int32(1)+(*TExprList)(unsafe.Pointer(pEList)).FnExpr, 0, pKeyInfo, -int32(9))
	} else {
		(**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex = -int32(1)
	}
	/* If the output is destined for a temporary table, open that table.
	 ** tag-select-0630
	 */
	if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) == int32(SRT_EphemTab) {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TSelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*TExprList)(unsafe.Pointer(pEList)).FnExpr)
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_NestedFrom) != 0 {
			ii = (*TExprList)(unsafe.Pointer(pEList)).FnExpr - int32(1)
			for {
				if !(ii > 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32 + 16 + 4))&0x200>>9)) == 0) {
					break
				}
				_sqlite3ExprDelete(tls, db, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FpExpr)
				_sqlite3DbFree(tls, db, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FzEName)
				(*TExprList)(unsafe.Pointer(pEList)).FnExpr = (*TExprList)(unsafe.Pointer(pEList)).FnExpr - 1
				goto _21
			_21:
				;
				ii = ii - 1
			}
			ii = 0
			for {
				if !(ii < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
					break
				}
				if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32 + 16 + 4))&0x200>>9)) == 0 {
					(*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32))).FpExpr)).Fop = uint8(TK_NULL)
				}
				goto _22
			_22:
				;
				ii = ii + 1
			}
		}
	}
	/* Set the limiter.  tag-select-0650
	 */
	iEnd = _sqlite3VdbeMakeLabel(tls, pParse)
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_FixedLimit) == uint32(0) {
		(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(320) /* 4 billion rows */
	}
	if (*TSelect)(unsafe.Pointer(p)).FpLimit != 0 {
		_computeLimitRegisters(tls, pParse, p, iEnd)
	}
	if (*TSelect)(unsafe.Pointer(p)).FiLimit == 0 && (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex >= 0 {
		_sqlite3VdbeChangeOpcode(tls, v, (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex, uint8(OP_SorterOpen))
		v1 = bp + 16 + 36
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(SORTFLAG_UseSorter))
	}
	/* Open an ephemeral index to use for the distinct set. tag-select-0680
	 */
	if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) != 0 {
		v1 = pParse + 56
		v12 = *(*int32)(unsafe.Pointer(v1))
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		(**(**TDistinctCtx)(__ccgo_up(bp))).FtabTnct = v12
		(**(**TDistinctCtx)(__ccgo_up(bp))).FaddrTnct = _sqlite3VdbeAddOp4(tls, v, int32(OP_OpenEphemeral), (**(**TDistinctCtx)(__ccgo_up(bp))).FtabTnct, 0, 0, _sqlite3KeyInfoFromExprList(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpEList, 0, 0), -int32(9))
		_sqlite3VdbeChangeP5(tls, v, uint16(BTREE_UNORDERED))
		(**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType = uint8(WHERE_DISTINCT_UNORDERED)
	} else {
		(**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType = uint8(WHERE_DISTINCT_NOOP)
	}
	if !(isAgg != 0) && pGroupBy == uintptr(0) {
		if (**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct != 0 {
			v12 = int32(WHERE_WANT_DISTINCT)
		} else {
			v12 = 0
		}
		/* No aggregate functions and no GROUP BY clause.  tag-select-0700 */
		wctrlFlags = uint16(libc.Uint32FromInt32(v12) | (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_FixedLimit))
		pWin = (*TSelect)(unsafe.Pointer(p)).FpWin /* Main window object (or NULL) */
		if pWin != 0 {
			_sqlite3WindowCodeInit(tls, pParse, p)
		}
		/* Begin the database scan. */
		pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, (*TSelect)(unsafe.Pointer(p)).FpEList, p, wctrlFlags, int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow))
		if pWInfo == uintptr(0) {
			goto select_end
		}
		if int32(_sqlite3WhereOutputRowCount(tls, pWInfo)) < int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) {
			(*TSelect)(unsafe.Pointer(p)).FnSelectRow = _sqlite3WhereOutputRowCount(tls, pWInfo)
			if libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) <= int32(SRT_DistQueue) && libc.Int32FromUint8((*TSelectDest)(unsafe.Pointer(pDest)).FeDest) >= int32(SRT_DistFifo) {
				/* TUNING: For a UNION CTE, because UNION is implies DISTINCT,
				 ** reduce the estimated output row count by 8 (LogEst 30).
				 ** Search for tag-20250414a to see other cases */
				v1 = p + 2
				*(*TLogEst)(unsafe.Pointer(v1)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v1))) - libc.Int32FromInt32(30))
			}
		}
		if (**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct != 0 && _sqlite3WhereIsDistinct(tls, pWInfo) != 0 {
			(**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType = libc.Uint8FromInt32(_sqlite3WhereIsDistinct(tls, pWInfo))
		}
		if (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy != 0 {
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FnOBSat = _sqlite3WhereIsOrdered(tls, pWInfo)
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FlabelOBLopt = _sqlite3WhereOrderByLimitOptLabel(tls, pWInfo)
			if (**(**TSortCtx)(__ccgo_up(bp + 16))).FnOBSat == (*TExprList)(unsafe.Pointer((**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy)).FnExpr {
				(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = uintptr(0)
			}
		}
		/* If sorting index that was created by a prior OP_OpenEphemeral
		 ** instruction ended up not being needed, then change the OP_OpenEphemeral
		 ** into an OP_Noop.
		 */
		if (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex >= 0 && (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy == uintptr(0) {
			_sqlite3VdbeChangeToNoop(tls, v, (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex)
		}
		if pWin != 0 {
			addrGosub = _sqlite3VdbeMakeLabel(tls, pParse)
			iCont = _sqlite3VdbeMakeLabel(tls, pParse)
			iBreak = _sqlite3VdbeMakeLabel(tls, pParse)
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			regGosub = v12
			_sqlite3WindowCodeStep(tls, pParse, p, pWInfo, regGosub, addrGosub)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, iBreak)
			_sqlite3VdbeResolveLabel(tls, v, addrGosub)
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FlabelOBLopt = 0
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+16, bp, pDest, iCont, iBreak)
			_sqlite3VdbeResolveLabel(tls, v, iCont)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regGosub)
			_sqlite3VdbeResolveLabel(tls, v, iBreak)
		} else {
			/* Use the standard inner loop. */
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+16, bp, pDest, _sqlite3WhereContinueLabel(tls, pWInfo), _sqlite3WhereBreakLabel(tls, pWInfo))
			/* End the database scan loop.
			 */
			_sqlite3WhereEnd(tls, pWInfo)
		}
	} else { /* End of processing for this SELECT */
		sortPTab = 0   /* Pseudotable used to decode sorting results */
		sortOut = 0    /* Output register from the sorter */
		orderByGrp = 0 /* True if the GROUP BY and ORDER BY are the same */
		/* Remove any and all aliases between the result set and the
		 ** GROUP BY clause.
		 */
		if pGroupBy != 0 { /* For looping over expression in a list */
			k = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr
			pItem2 = (*TSelect)(unsafe.Pointer(p)).FpEList + 8
			for {
				if !(k > 0) {
					break
				}
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem2 + 24))).FiAlias = uint16(0)
				goto _30
			_30:
				;
				k = k - 1
				pItem2 += 32
			}
			k = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			pItem2 = pGroupBy + 8
			for {
				if !(k > 0) {
					break
				}
				(*(*struct {
					FiOrderByCol Tu16
					FiAlias      Tu16
				})(unsafe.Pointer(pItem2 + 24))).FiAlias = uint16(0)
				goto _31
			_31:
				;
				k = k - 1
				pItem2 += 32
			}
			if int32((*TSelect)(unsafe.Pointer(p)).FnSelectRow) > int32(66) {
				(*TSelect)(unsafe.Pointer(p)).FnSelectRow = int16(66)
			}
			/* If there is both a GROUP BY and an ORDER BY clause and they are
			 ** identical, then it may be possible to disable the ORDER BY clause
			 ** on the grounds that the GROUP BY will cause elements to come out
			 ** in the correct order. It also may not - the GROUP BY might use a
			 ** database index that causes rows to be grouped together as required
			 ** but not actually sorted. Either way, record the fact that the
			 ** ORDER BY and GROUP BY clauses are the same by setting the orderByGrp
			 ** variable.  */
			if _sqlite3CopySortOrder(tls, pGroupBy, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy) != 0 && _sqlite3ExprListCompare(tls, pGroupBy, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy, -int32(1)) == 0 {
				orderByGrp = int32(1)
			}
		} else {
			(*TSelect)(unsafe.Pointer(p)).FnSelectRow = 0
		}
		/* Create a label to jump to when we want to abort the query */
		addrEnd = _sqlite3VdbeMakeLabel(tls, pParse)
		/* Convert TK_COLUMN nodes into TK_AGG_COLUMN and make entries in
		 ** sAggInfo for all TK_AGG_FUNCTION nodes in expressions of the
		 ** SELECT statement.
		 */
		pAggInfo = _sqlite3DbMallocZero(tls, db, uint64(64))
		if pAggInfo != 0 {
			_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_agginfoFree), pAggInfo)
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FselId = (*TSelect)(unsafe.Pointer(p)).FselId
		libc.Xmemset(tls, bp+112, 0, uint64(56))
		(**(**TNameContext)(__ccgo_up(bp + 112))).FpParse = pParse
		(**(**TNameContext)(__ccgo_up(bp + 112))).FpSrcList = pTabList
		*(*uintptr)(unsafe.Pointer(bp + 112 + 16)) = pAggInfo
		if pGroupBy != 0 {
			v12 = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
		} else {
			v12 = 0
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = libc.Uint32FromInt32(v12)
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy = pGroupBy
		_sqlite3ExprAnalyzeAggList(tls, bp+112, pEList)
		_sqlite3ExprAnalyzeAggList(tls, bp+112, (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy)
		if pHaving != 0 {
			if pGroupBy != 0 {
				_havingToWhere(tls, pParse, p)
				pWhere = (*TSelect)(unsafe.Pointer(p)).FpWhere
			}
			_sqlite3ExprAnalyzeAggregates(tls, bp+112, pHaving)
		}
		(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn
		if (*TSelect)(unsafe.Pointer(p)).FpGroupBy == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FpHaving == uintptr(0) && (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) {
			minMaxFlag = _minMaxQuery(tls, db, (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr, bp+64)
		} else {
			minMaxFlag = uint8(WHERE_ORDERBY_NORMAL)
		}
		_analyzeAggFuncArgs(tls, pAggInfo, bp+112)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto select_end
		}
		/* Processing for aggregates with GROUP BY is very different and
		 ** much more complex than aggregates without a GROUP BY.  tag-select-0810
		 */
		if pGroupBy != 0 { /* Return address register for reset subroutine */
			pDistinct = uintptr(0)
			distFlag = uint16(0)
			eDist = WHERE_DISTINCT_NOOP
			if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) && (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FiDistinct >= 0 && (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr != uintptr(0) && (*TExpr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr)).Fflags&uint32(EP_xIsSelect) == uint32(0) && *(*uintptr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 32)) != uintptr(0) {
				pExpr = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 32)) + 8))).FpExpr
				pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
				pDistinct = _sqlite3ExprListDup(tls, db, pGroupBy, 0)
				pDistinct = _sqlite3ExprListAppend(tls, pParse, pDistinct, pExpr)
				if pDistinct != 0 {
					v12 = libc.Int32FromInt32(WHERE_WANT_DISTINCT) | libc.Int32FromInt32(WHERE_AGG_DISTINCT)
				} else {
					v12 = 0
				}
				distFlag = libc.Uint16FromInt32(v12)
			}
			/* If there is a GROUP BY clause we might need a sorting index to
			 ** implement it.  Allocate that sorting index now.  If it turns out
			 ** that we do not need it after all, the OP_SorterOpen instruction
			 ** will be converted into a Noop.
			 */
			v1 = pParse + 56
			v12 = *(*int32)(unsafe.Pointer(v1))
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			(*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx = v12
			pKeyInfo1 = _sqlite3KeyInfoFromExprList(tls, pParse, pGroupBy, 0, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn)
			addrSortingIdx = _sqlite3VdbeAddOp4(tls, v, int32(OP_SorterOpen), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, libc.Int32FromUint32((*TAggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn), 0, pKeyInfo1, -int32(9))
			/* Initialize memory locations used by GROUP BY aggregate processing
			 */
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			iUseFlag = v12
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			iAbortFlag = v12
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			regOutputRow = v12
			addrOutputRow = _sqlite3VdbeMakeLabel(tls, pParse)
			v1 = pParse + 60
			*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
			v12 = *(*int32)(unsafe.Pointer(v1))
			regReset = v12
			addrReset = _sqlite3VdbeMakeLabel(tls, pParse)
			iAMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			iBMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, iAbortFlag)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, iAMem, iAMem+(*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr-int32(1))
			_sqlite3ExprNullRegisterRange(tls, pParse, iAMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
			/* Begin a loop that will extract all source rows in GROUP BY order.
			 ** This might involve two separate loops with an OP_Sort in between, or
			 ** it might be a single loop that uses an index to extract information
			 ** in the right order to begin with.
			 */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regReset, addrReset)
			if libc.Int32FromUint8((**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct) == int32(2) {
				v12 = int32(WHERE_DISTINCTBY)
			} else {
				v12 = int32(WHERE_GROUPBY)
			}
			if orderByGrp != 0 {
				v15 = int32(WHERE_SORTBYGROUP)
			} else {
				v15 = 0
			}
			pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, pGroupBy, pDistinct, p, libc.Uint16FromInt32(v12|v15|libc.Int32FromUint16(distFlag)), 0)
			if pWInfo == uintptr(0) {
				_sqlite3ExprListDelete(tls, db, pDistinct)
				goto select_end
			}
			if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr != 0 {
				_optimizeAggregateUseOfIndexedExpr(tls, pParse, p, pAggInfo, bp+112)
			}
			_assignAggregateRegisters(tls, pParse, pAggInfo)
			eDist = _sqlite3WhereIsDistinct(tls, pWInfo)
			if _sqlite3WhereIsOrdered(tls, pWInfo) == (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr {
				/* The optimizer is able to deliver rows in group by order so
				 ** we do not have to sort.  The OP_OpenEphemeral table will be
				 ** cancelled later because we still need to use the pKeyInfo
				 */
				groupBySort = 0
			} else {
				if (**(**TDistinctCtx)(__ccgo_up(bp))).FisTnct != 0 && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Distinct) == uint32(0) {
					v1 = __ccgo_ts + 21757
				} else {
					v1 = __ccgo_ts + 21766
				}
				_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+20522, libc.VaList(bp+176, v1))
				groupBySort = int32(1)
				nGroupBy = (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr
				nCol = nGroupBy
				j = nGroupBy
				i = 0
				for {
					if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
						break
					}
					if (**(**TAggInfo_col)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(i)*32))).FiSorterColumn >= j {
						nCol = nCol + 1
						j = j + 1
					}
					goto _47
				_47:
					;
					i = i + 1
				}
				regBase = _sqlite3GetTempRange(tls, pParse, nCol)
				_sqlite3ExprCodeExprList(tls, pParse, pGroupBy, regBase, 0, uint8(0))
				j = nGroupBy
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(1)
				i = 0
				for {
					if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
						break
					}
					pCol = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(i)*32
					if (*TAggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn >= j {
						_sqlite3ExprCode(tls, pParse, (*TAggInfo_col)(unsafe.Pointer(pCol)).FpCExpr, j+regBase)
						j = j + 1
					}
					goto _48
				_48:
					;
					i = i + 1
				}
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(0)
				regRecord = _sqlite3GetTempReg(tls, pParse)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regBase, nCol, regRecord)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterInsert), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, regRecord)
				_sqlite3ReleaseTempReg(tls, pParse, regRecord)
				_sqlite3ReleaseTempRange(tls, pParse, regBase, nCol)
				_sqlite3WhereEnd(tls, pWInfo)
				v1 = pParse + 56
				v15 = *(*int32)(unsafe.Pointer(v1))
				*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
				v12 = v15
				sortPTab = v12
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab = v12
				sortOut = _sqlite3GetTempReg(tls, pParse)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenPseudo), sortPTab, sortOut, nCol)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterSort), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, addrEnd)
				(*TAggInfo)(unsafe.Pointer(pAggInfo)).FuseSortingIdx = uint8(1)
			}
			/* If there are entries in pAgggInfo->aFunc[] that contain subexpressions
			 ** that are indexed (and that were previously identified and tagged
			 ** in optimizeAggregateUseOfIndexedExpr()) then those subexpressions
			 ** must now be converted into a TK_AGG_COLUMN node so that the value
			 ** is correctly pulled from the index rather than being recomputed. */
			if (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr != 0 {
				_aggregateConvertIndexedExprRefToColumn(tls, pAggInfo)
			}
			/* If the index or temporary table used by the GROUP BY sort
			 ** will naturally deliver rows in the order required by the ORDER BY
			 ** clause, cancel the ephemeral table open coded earlier.
			 **
			 ** This is an optimization - the correct answer should result regardless.
			 ** Use the SQLITE_GroupByOrder flag with SQLITE_TESTCTRL_OPTIMIZER to
			 ** disable this optimization for testing purposes.  */
			if orderByGrp != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_GroupByOrder)) == uint32(0) && (groupBySort != 0 || _sqlite3WhereIsSorted(tls, pWInfo) != 0) {
				(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = uintptr(0)
				_sqlite3VdbeChangeToNoop(tls, v, (**(**TSortCtx)(__ccgo_up(bp + 16))).FaddrSortIndex)
			}
			/* Evaluate the current GROUP BY terms and store in b0, b1, b2...
			 ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
			 ** Then compare the current GROUP BY terms against the GROUP BY terms
			 ** from the previous row currently stored in a0, a1, a2...
			 */
			addrTopOfLoop = _sqlite3VdbeCurrentAddr(tls, v)
			if groupBySort != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_SorterData), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, sortOut, sortPTab)
			}
			j = 0
			for {
				if !(j < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
					break
				}
				iOrderByCol = libc.Int32FromUint16(*(*Tu16)(unsafe.Pointer(pGroupBy + 8 + uintptr(j)*32 + 24)))
				if groupBySort != 0 {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), sortPTab, j, iBMem+j)
				} else {
					(*TAggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = uint8(1)
					_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(j)*32))).FpExpr, iBMem+j)
				}
				if iOrderByCol != 0 {
					pX = (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(iOrderByCol-int32(1))*32))).FpExpr
					pBase = _sqlite3ExprSkipCollateAndLikely(tls, pX)
					for pBase != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pBase)).Fop) == int32(TK_IF_NULL_ROW) {
						pX = (*TExpr)(unsafe.Pointer(pBase)).FpLeft
						pBase = _sqlite3ExprSkipCollateAndLikely(tls, pX)
					}
					if pBase != uintptr(0) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pBase)).Fop) != int32(TK_AGG_COLUMN) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pBase)).Fop) != int32(TK_REGISTER) {
						_sqlite3ExprToRegister(tls, pX, iAMem+j)
					}
				}
				goto _52
			_52:
				;
				j = j + 1
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_Compare), iAMem, iBMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr, _sqlite3KeyInfoRef(tls, pKeyInfo1), -int32(9))
			addr1 = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Jump), addr1+int32(1), 0, addr1+int32(1))
			/* Generate code that runs whenever the GROUP BY changes.
			 ** Changes in the GROUP BY are detected by the previous code
			 ** block.  If there were no changes, this block is skipped.
			 **
			 ** This code copies current group by terms in b0,b1,b2,...
			 ** over to a0,a1,a2.  It then calls the output subroutine
			 ** and resets the aggregate accumulator registers in preparation
			 ** for the next GROUP BY batch.
			 */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutputRow, addrOutputRow)
			_sqlite3ExprCodeMove(tls, pParse, iBMem, iAMem, (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), iAbortFlag, addrEnd)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regReset, addrReset)
			/* Update the aggregate accumulators based on the content of
			 ** the current row
			 */
			_sqlite3VdbeJumpHere(tls, v, addr1)
			_updateAccumulator(tls, pParse, iUseFlag, pAggInfo, eDist)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iUseFlag)
			/* End of the loop
			 */
			if groupBySort != 0 {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_SorterNext), (*TAggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, addrTopOfLoop)
			} else {
				_sqlite3WhereEnd(tls, pWInfo)
				_sqlite3VdbeChangeToNoop(tls, v, addrSortingIdx)
			}
			_sqlite3ExprListDelete(tls, db, pDistinct)
			/* Output the final row of result
			 */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regOutputRow, addrOutputRow)
			/* Jump over the subroutines
			 */
			_sqlite3VdbeGoto(tls, v, addrEnd)
			/* Generate a subroutine that outputs a single row of the result
			 ** set.  This subroutine first looks at the iUseFlag.  If iUseFlag
			 ** is less than or equal to zero, the subroutine is a no-op.  If
			 ** the processing calls for the query to abort, this subroutine
			 ** increments the iAbortFlag memory location before returning in
			 ** order to signal the caller to abort.
			 */
			addrSetAbort = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), iAbortFlag)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regOutputRow)
			_sqlite3VdbeResolveLabel(tls, v, addrOutputRow)
			addrOutputRow = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IfPos), iUseFlag, addrOutputRow+int32(2))
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regOutputRow)
			_finalizeAggFunctions(tls, pParse, pAggInfo)
			_sqlite3ExprIfFalse(tls, pParse, pHaving, addrOutputRow+int32(1), int32(SQLITE_JUMPIFNULL))
			_selectInnerLoop(tls, pParse, p, -int32(1), bp+16, bp, pDest, addrOutputRow+int32(1), addrSetAbort)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regOutputRow)
			/* Generate a subroutine that will reset the group-by accumulator
			 */
			_sqlite3VdbeResolveLabel(tls, v, addrReset)
			_resetAccumulator(tls, pParse, pAggInfo)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, iUseFlag)
			_sqlite3VdbeAddOp1(tls, v, int32(OP_Return), regReset)
			if libc.Int32FromUint16(distFlag) != 0 && eDist != WHERE_DISTINCT_NOOP {
				pF = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
				_fixDistinctOpenEph(tls, pParse, eDist, (*TAggInfo_func)(unsafe.Pointer(pF)).FiDistinct, (*TAggInfo_func)(unsafe.Pointer(pF)).FiDistAddr)
			}
		} else {
			v1 = _isSimpleCount(tls, p, pAggInfo)
			pTab1 = v1
			if v1 != uintptr(0) {
				/* tag-select-0821
				 **
				 ** If isSimpleCount() returns a pointer to a Table structure, then
				 ** the SQL statement is of the form:
				 **
				 **   SELECT count(*) FROM <tbl>
				 **
				 ** where the Table structure returned represents table <tbl>.
				 **
				 ** This statement is so common that it is optimized specially. The
				 ** OP_Count instruction is executed either on the intkey table that
				 ** contains the data for table <tbl> or on one of its indexes. It
				 ** is better to execute the op on an index, as indexes are almost
				 ** always spread across less pages than their corresponding tables.
				 */
				iDb1 = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab1)).FpSchema)
				v3 = pParse + 56
				v12 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				iCsr = v12                                     /* Iterator variable */
				pKeyInfo2 = uintptr(0)                         /* Keyinfo for scanned index */
				pBest = uintptr(0)                             /* Best index found so far */
				iRoot = (*TTable)(unsafe.Pointer(pTab1)).Ftnum /* Root page of scanned b-tree */
				_sqlite3CodeVerifySchema(tls, pParse, iDb1)
				_sqlite3TableLock(tls, pParse, iDb1, (*TTable)(unsafe.Pointer(pTab1)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab1)).FzName)
				/* Search for the index that has the lowest scan cost.
				 **
				 ** (2011-04-15) Do not do a full scan of an unordered index.
				 **
				 ** (2013-10-03) Do not count the entries in a partial index.
				 **
				 ** In practice the KeyInfo structure will not be used. It is only
				 ** passed to keep OP_OpenRead happy.
				 */
				if !((*TTable)(unsafe.Pointer(pTab1)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
					pBest = _sqlite3PrimaryKeyIndex(tls, pTab1)
				}
				if !(int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8 + 24 + 4))&0x80000000>>31) != 0) {
					pIdx = (*TTable)(unsafe.Pointer(pTab1)).FpIndex
					for {
						if !(pIdx != 0) {
							break
						}
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x2000>>13)) == 0 && int32((*TIndex)(unsafe.Pointer(pIdx)).FszIdxRow) < int32((*TTable)(unsafe.Pointer(pTab1)).FszTabRow) && (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) && (!(pBest != 0) || int32((*TIndex)(unsafe.Pointer(pIdx)).FszIdxRow) < int32((*TIndex)(unsafe.Pointer(pBest)).FszIdxRow)) {
							pBest = pIdx
						}
						goto _56
					_56:
						;
						pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
					}
				}
				if pBest != 0 {
					iRoot = (*TIndex)(unsafe.Pointer(pBest)).Ftnum
					pKeyInfo2 = _sqlite3KeyInfoOfIndex(tls, pParse, pBest)
				}
				/* Open a read-only cursor, execute the OP_Count, close the cursor. */
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_OpenRead), iCsr, libc.Int32FromUint32(iRoot), iDb1, int32(1))
				if pKeyInfo2 != 0 {
					_sqlite3VdbeChangeP4(tls, v, -int32(1), pKeyInfo2, -int32(9))
				}
				_assignAggregateRegisters(tls, pParse, pAggInfo)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Count), iCsr, (*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+(*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn+0)
				_sqlite3VdbeAddOp1(tls, v, int32(OP_Close), iCsr)
				_explainSimpleCount(tls, pParse, pTab1, pBest)
			} else {
				/* The general case of an aggregate query without GROUP BY
				 ** tag-select-0822 */
				regAcc = 0 /* "populate accumulators" flag */
				pDistinct1 = uintptr(0)
				distFlag1 = uint16(0)
				/* If there are accumulator registers but no min() or max() functions
				 ** without FILTER clauses, allocate register regAcc. Register regAcc
				 ** will contain 0 the first time the inner loop runs, and 1 thereafter.
				 ** The code generated by updateAccumulator() uses this to ensure
				 ** that the accumulator registers are (a) updated only once if
				 ** there are no min() or max functions or (b) always updated for the
				 ** first row visited by the aggregate, so that they are updated at
				 ** least once even if the FILTER clause means the min() or max()
				 ** function visits zero rows.  */
				if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 {
					i = 0
					for {
						if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
							break
						}
						if (*TExpr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32))).FpFExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_WinFunc)) != uint32(0) {
							goto _57
						}
						if (*TFuncDef)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*32))).FpFunc)).FfuncFlags&uint32(SQLITE_FUNC_NEEDCOLL) != 0 {
							break
						}
						goto _57
					_57:
						;
						i = i + 1
					}
					if i == (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
						v1 = pParse + 60
						*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
						v12 = *(*int32)(unsafe.Pointer(v1))
						regAcc = v12
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regAcc)
					}
				} else {
					if (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == int32(1) && (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FiDistinct >= 0 {
						pDistinct1 = *(*uintptr)(unsafe.Pointer((**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc))).FpFExpr + 32))
						if pDistinct1 != 0 {
							v12 = libc.Int32FromInt32(WHERE_WANT_DISTINCT) | libc.Int32FromInt32(WHERE_AGG_DISTINCT)
						} else {
							v12 = 0
						}
						distFlag1 = libc.Uint16FromInt32(v12)
					}
				}
				_assignAggregateRegisters(tls, pParse, pAggInfo)
				/* This case runs if the aggregate has no GROUP BY clause.  The
				 ** processing is much simpler since there is only a single row
				 ** of output.
				 */
				_resetAccumulator(tls, pParse, pAggInfo)
				/* If this query is a candidate for the min/max optimization, then
				 ** minMaxFlag will have been previously set to either
				 ** WHERE_ORDERBY_MIN or WHERE_ORDERBY_MAX and pMinMaxOrderBy will
				 ** be an appropriate ORDER BY expression for the optimization.
				 */
				pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, **(**uintptr)(__ccgo_up(bp + 64)), pDistinct1, p, libc.Uint16FromInt32(libc.Int32FromUint8(minMaxFlag)|libc.Int32FromUint16(distFlag1)), 0)
				if pWInfo == uintptr(0) {
					goto select_end
				}
				eDist1 = _sqlite3WhereIsDistinct(tls, pWInfo)
				_updateAccumulator(tls, pParse, regAcc, pAggInfo, eDist1)
				if eDist1 != WHERE_DISTINCT_NOOP {
					pF1 = (*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
					if pF1 != 0 {
						_fixDistinctOpenEph(tls, pParse, eDist1, (*TAggInfo_func)(unsafe.Pointer(pF1)).FiDistinct, (*TAggInfo_func)(unsafe.Pointer(pF1)).FiDistAddr)
					}
				}
				if regAcc != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regAcc)
				}
				if minMaxFlag != 0 {
					_sqlite3WhereMinMaxOptEarlyOut(tls, v, pWInfo)
				}
				_sqlite3WhereEnd(tls, pWInfo)
				_finalizeAggFunctions(tls, pParse, pAggInfo)
			}
			(**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy = uintptr(0)
			_sqlite3ExprIfFalse(tls, pParse, pHaving, addrEnd, int32(SQLITE_JUMPIFNULL))
			_selectInnerLoop(tls, pParse, p, -int32(1), uintptr(0), uintptr(0), pDest, addrEnd, addrEnd)
		}
		_sqlite3VdbeResolveLabel(tls, v, addrEnd)
	} /* endif aggregate query */
	if libc.Int32FromUint8((**(**TDistinctCtx)(__ccgo_up(bp))).FeTnctType) == int32(WHERE_DISTINCT_UNORDERED) {
		_explainTempTable(tls, pParse, __ccgo_ts+21757)
	}
	/* If there is an ORDER BY clause, then we need to sort the results
	 ** and send them to the callback one by one.  tag-select-0900
	 */
	if (**(**TSortCtx)(__ccgo_up(bp + 16))).FpOrderBy != 0 {
		_generateSortTail(tls, pParse, p, bp+16, (*TExprList)(unsafe.Pointer(pEList)).FnExpr, pDest)
	}
	/* Jump here to skip this query
	 */
	_sqlite3VdbeResolveLabel(tls, v, iEnd)
	/* The SELECT has been coded. If there is an error in the Parse structure,
	 ** set the return code to 1. Otherwise 0. */
	rc = libc.BoolInt32((*TParse)(unsafe.Pointer(pParse)).FnErr > 0)
	/* Control jumps to here if an error is encountered above, or upon
	 ** successful coding of the SELECT.
	 */
	goto select_end
select_end:
	;
	_sqlite3ExprListDelete(tls, db, **(**uintptr)(__ccgo_up(bp + 64)))
	_sqlite3VdbeExplainPop(tls, pParse)
	return rc
}

/************** End of select.c **********************************************/
/************** Begin file table.c *******************************************/
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the sqlite3_get_table() and sqlite3_free_table()
** interface routines.  These are just wrappers around the main
** interface routine of sqlite3_exec().
**
** These routines are in a separate files so that they will not be linked
** if they are not used.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Check all ON clauses in pSelect to verify that they do not reference
//	** columns to the right.
//	*/
func _sqlite3SelectCheckOnClauses(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var ii int32
	var pItem uintptr
	var _ /* sCtx at bp+48 */ TCheckOnCtx
	var _ /* w at bp+0 */ TWalker
	_, _ = ii, pItem
	libc.Xmemset(tls, bp, 0, uint64(48))
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_selectCheckOnClausesExpr)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_selectCheckOnClausesSelect)
	*(*uintptr)(unsafe.Pointer(bp + 40)) = bp + 48
	libc.Xmemset(tls, bp+48, 0, uint64(24))
	(**(**TCheckOnCtx)(__ccgo_up(bp + 48))).FpSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	_sqlite3WalkExpr(tls, bp, (*TSelect)(unsafe.Pointer(pSelect)).FpWhere)
	**(**Tu32)(__ccgo_up(pSelect + 4)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(SF_OnToWhere))
	/* Check for any table-function args that are attached to virtual tables
	 ** on the RHS of an outer join. They are subject to the same constraints
	 ** as ON clauses. */
	(**(**TCheckOnCtx)(__ccgo_up(bp + 48))).FbFuncArg = int32(1)
	ii = 0
	for {
		if !(ii < (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc)).FnSrc) {
			break
		}
		pItem = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8 + uintptr(ii)*80
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000000>>28) != 0 && libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_OUTER) != 0 {
			(**(**TCheckOnCtx)(__ccgo_up(bp + 48))).FiJoin = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
			_sqlite3WalkExprList(tls, bp, *(*uintptr)(unsafe.Pointer(pItem + 48)))
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
}

// C documentation
//
//	/*
//	** This routine "expands" a SELECT statement and all of its subqueries.
//	** For additional information on what it means to "expand" a SELECT
//	** statement, see the comment on the selectExpand worker callback above.
//	**
//	** Expanding a SELECT statement is the first step in processing a
//	** SELECT statement.  The SELECT statement must be expanded before
//	** name resolution is performed.
//	**
//	** If anything goes wrong, an error message is written into pParse.
//	** The calling function can detect the problem by looking at pParse->nErr
//	** and/or pParse->db->mallocFailed.
//	*/
func _sqlite3SelectExpand(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* w at bp+0 */ TWalker
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x2000>>13)) != 0 {
		(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_convertCompoundSelectToSubquery)
		(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = uintptr(0)
		_sqlite3WalkSelect(tls, bp, pSelect)
	}
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_selectExpander)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = __ccgo_fp(_sqlite3SelectPopWith)
	(**(**TWalker)(__ccgo_up(bp))).FeCode = uint16(0)
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// C documentation
//
//	/*
//	** Attach a Subquery object to pItem->uv.pSubq.  Set the
//	** pSelect value but leave all the other values initialized
//	** to zero.
//	**
//	** A copy of the Select object is made if dupSelect is true, and the
//	** SrcItem takes responsibility for deleting the copy.  If dupSelect is
//	** false, ownership of the Select passes to the SrcItem.  Either way,
//	** the SrcItem will take responsibility for deleting the Select.
//	**
//	** When dupSelect is zero, that means the Select might get deleted right
//	** away if there is an OOM error.  Beware.
//	**
//	** Return non-zero on success.  Return zero on an OOM error.
//	*/
func _sqlite3SrcItemAttachSubquery(tls *libc.TLS, pParse uintptr, pItem uintptr, pSelect uintptr, dupSelect int32) (r int32) {
	var p, v1 uintptr
	_, _ = p, v1
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8000>>15) != 0 {
		*(*uintptr)(unsafe.Pointer(pItem + 72)) = uintptr(0)
		libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(0), 15, 0x8000)
	} else {
		if *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pItem + 72)))
			*(*uintptr)(unsafe.Pointer(pItem + 72)) = uintptr(0)
		}
	}
	if dupSelect != 0 {
		pSelect = _sqlite3SelectDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect, 0)
		if pSelect == uintptr(0) {
			return 0
		}
	}
	v1 = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(24))
	*(*uintptr)(unsafe.Pointer(pItem + 72)) = v1
	p = v1
	if p == uintptr(0) {
		_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect)
		return 0
	}
	libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 29, 0x20000000)
	(*TSubquery)(unsafe.Pointer(p)).FpSelect = pSelect
	libc.Xmemset(tls, p+uintptr(8), 0, libc.Uint64FromInt64(24)-libc.Uint64FromInt64(8))
	return int32(1)
}

// C documentation
//
//	/*
//	** Mark a subquery result column as having been used.
//	*/
func _sqlite3SrcItemColumnUsed(tls *libc.TLS, pItem uintptr, iCol int32) {
	var pResults uintptr
	_ = pResults
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000>>17) != 0 {
		pResults = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect)).FpEList
		libc.SetBitFieldPtr16Uint32(pResults+8+uintptr(iCol)*32+16+4, libc.Uint32FromInt32(1), 9, 0x200)
	}
}

// C documentation
//
//	/*
//	** This routine is called by the parser to add a new term to the
//	** end of a growing FROM clause.  The "p" parameter is the part of
//	** the FROM clause that has already been constructed.  "p" is NULL
//	** if this is the first term of the FROM clause.  pTable and pDatabase
//	** are the name of the table and database named in the FROM clause term.
//	** pDatabase is NULL if the database name qualifier is missing - the
//	** usual case.  If the term has an alias, then pAlias points to the
//	** alias token.  If the term is a subquery, then pSubquery is the
//	** SELECT statement that the subquery encodes.  The pTable and
//	** pDatabase parameters are NULL for subqueries.  The pOn and pUsing
//	** parameters are the content of the ON and USING clauses.
//	**
//	** Return a new SrcList which encodes is the FROM with the new
//	** term added.
//	*/
func _sqlite3SrcListAppendFromTerm(tls *libc.TLS, pParse uintptr, p uintptr, pTable uintptr, pDatabase uintptr, pAlias uintptr, pSubquery uintptr, pOnUsing uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pItem, pToken, v1 uintptr
	_, _, _, _ = db, pItem, pToken, v1
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if !(p != 0) && pOnUsing != uintptr(0) && ((*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn != 0 || (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0) {
		if (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn != 0 {
			v1 = __ccgo_ts + 16062
		} else {
			v1 = __ccgo_ts + 16065
		}
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+16071, libc.VaList(bp+8, v1))
		goto append_from_error
	}
	p = _sqlite3SrcListAppend(tls, pParse, p, pTable, pDatabase)
	if p == uintptr(0) {
		goto append_from_error
	}
	pItem = p + 8 + uintptr((*TSrcList)(unsafe.Pointer(p)).FnSrc-int32(1))*80
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
		if pDatabase != 0 && (*TToken)(unsafe.Pointer(pDatabase)).Fz != 0 {
			v1 = pDatabase
		} else {
			v1 = pTable
		}
		pToken = v1
		_sqlite3RenameTokenMap(tls, pParse, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, pToken)
	}
	if (*TToken)(unsafe.Pointer(pAlias)).Fn != 0 {
		(*TSrcItem)(unsafe.Pointer(pItem)).FzAlias = _sqlite3NameFromToken(tls, db, pAlias)
	}
	if pSubquery != 0 {
		if _sqlite3SrcItemAttachSubquery(tls, pParse, pItem, pSubquery, 0) != 0 {
			if (*TSelect)(unsafe.Pointer(pSubquery)).FselFlags&uint32(SF_NestedFrom) != 0 {
				libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 17, 0x20000)
			}
		}
	}
	if pOnUsing == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pItem + 64)) = uintptr(0)
	} else {
		if (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0 {
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 20, 0x100000)
			*(*uintptr)(unsafe.Pointer(pItem + 64)) = (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 64)) = (*TOnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn
		}
	}
	return p
	goto append_from_error
append_from_error:
	;
	_sqlite3ClearOnOrUsing(tls, db, pOnUsing)
	_sqlite3SelectDelete(tls, db, pSubquery)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Assign VdbeCursor index numbers to all tables in a SrcList
//	*/
func _sqlite3SrcListAssignCursors(tls *libc.TLS, pParse uintptr, pList uintptr) {
	var i, v2 int32
	var pItem, v3 uintptr
	_, _, _, _ = i, pItem, v2, v3
	if pList != 0 {
		i = 0
		pItem = pList + 8
		for {
			if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
				break
			}
			if (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor >= 0 {
				goto _1
			}
			v3 = pParse + 56
			v2 = *(*int32)(unsafe.Pointer(v3))
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = v2
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
				_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect)).FpSrc)
			}
			goto _1
		_1:
			;
			i = i + 1
			pItem += 80
		}
	}
}

// C documentation
//
//	/*
//	** Delete an entire SrcList including all its substructure.
//	*/
func _sqlite3SrcListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32
	var pItem uintptr
	_, _ = i, pItem
	if pList == uintptr(0) {
		return
	}
	pItem = pList + 8
	i = libc.Int32FromInt32(0)
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
			break
		}
		/* Check invariants on SrcItem */
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
		}
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias)
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
			_sqlite3SubqueryDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x8000>>15) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 72)) != uintptr(0) {
				_sqlite3DbNNFreeNN(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
			}
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x40000000>>30) != 0 {
			_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 48)))
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000000>>28) != 0 {
			_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 48)))
		}
		_sqlite3DeleteTable(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x100000>>20) != 0 {
			_sqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 64)))
		} else {
			if *(*uintptr)(unsafe.Pointer(pItem + 64)) != 0 {
				_sqlite3ExprDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 64)))
			}
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 80
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

// C documentation
//
//	/*
//	** If cursors, triggers, views and subqueries are all omitted from
//	** the build, then none of the following routines, except for
//	** sqlite3SelectDup(), can be called. sqlite3SelectDup() is sometimes
//	** called with a NULL argument.
//	*/
func _sqlite3SrcListDup(tls *libc.TLS, db uintptr, p uintptr, flags int32) (r uintptr) {
	var i int32
	var pNew, pNewItem, pNewSubq, pOldItem, pTab, v3 uintptr
	var v1 Tu32
	_, _, _, _, _, _, _, _ = i, pNew, pNewItem, pNewSubq, pOldItem, pTab, v1, v3
	if p == uintptr(0) {
		return uintptr(0)
	}
	pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt32((*TSrcList)(unsafe.Pointer(p)).FnSrc)*libc.Uint64FromInt64(80)))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	v1 = libc.Uint32FromInt32((*TSrcList)(unsafe.Pointer(p)).FnSrc)
	(*TSrcList)(unsafe.Pointer(pNew)).FnAlloc = v1
	(*TSrcList)(unsafe.Pointer(pNew)).FnSrc = libc.Int32FromUint32(v1)
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(p)).FnSrc) {
			break
		}
		pNewItem = pNew + 8 + uintptr(i)*80
		pOldItem = p + 8 + uintptr(i)*80
		(*TSrcItem)(unsafe.Pointer(pNewItem)).Ffg = (*TSrcItem)(unsafe.Pointer(pOldItem)).Ffg
		if int32(*(*uint32)(unsafe.Pointer(pOldItem + 24 + 4))&0x20000000>>29) != 0 {
			pNewSubq = _sqlite3DbMallocRaw(tls, db, uint64(24))
			if pNewSubq == uintptr(0) {
				libc.SetBitFieldPtr32Uint32(pNewItem+24+4, libc.Uint32FromInt32(0), 29, 0x20000000)
			} else {
				libc.Xmemcpy(tls, pNewSubq, *(*uintptr)(unsafe.Pointer(pOldItem + 72)), uint64(24))
				(*TSubquery)(unsafe.Pointer(pNewSubq)).FpSelect = _sqlite3SelectDup(tls, db, (*TSubquery)(unsafe.Pointer(pNewSubq)).FpSelect, flags)
				if (*TSubquery)(unsafe.Pointer(pNewSubq)).FpSelect == uintptr(0) {
					_sqlite3DbFree(tls, db, pNewSubq)
					pNewSubq = uintptr(0)
					libc.SetBitFieldPtr32Uint32(pNewItem+24+4, libc.Uint32FromInt32(0), 29, 0x20000000)
				}
			}
			*(*uintptr)(unsafe.Pointer(pNewItem + 72)) = pNewSubq
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pOldItem + 24 + 4))&0x8000>>15) != 0 {
				*(*uintptr)(unsafe.Pointer(pNewItem + 72)) = *(*uintptr)(unsafe.Pointer(pOldItem + 72))
			} else {
				*(*uintptr)(unsafe.Pointer(pNewItem + 72)) = _sqlite3DbStrDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 72)))
			}
		}
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FzName = _sqlite3DbStrDup(tls, db, (*TSrcItem)(unsafe.Pointer(pOldItem)).FzName)
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FzAlias = _sqlite3DbStrDup(tls, db, (*TSrcItem)(unsafe.Pointer(pOldItem)).FzAlias)
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FiCursor = (*TSrcItem)(unsafe.Pointer(pOldItem)).FiCursor
		if int32(*(*uint32)(unsafe.Pointer(pNewItem + 24 + 4))&0x40000000>>30) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 48)) = _sqlite3DbStrDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 48)))
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pNewItem + 24 + 4))&0x10000000>>28) != 0 {
				*(*uintptr)(unsafe.Pointer(pNewItem + 48)) = _sqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 48)), flags)
			} else {
				*(*Tu32)(unsafe.Pointer(&(*TSrcItem)(unsafe.Pointer(pNewItem)).Fu1)) = *(*Tu32)(unsafe.Pointer(&(*TSrcItem)(unsafe.Pointer(pOldItem)).Fu1))
			}
		}
		(*TSrcItem)(unsafe.Pointer(pNewItem)).Fu2 = (*TSrcItem)(unsafe.Pointer(pOldItem)).Fu2
		if int32(*(*uint32)(unsafe.Pointer(pNewItem + 24 + 4))&0x400000>>22) != 0 {
			(*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNewItem + 56)))).FnUse = (*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNewItem + 56)))).FnUse + 1
		}
		v3 = (*TSrcItem)(unsafe.Pointer(pOldItem)).FpSTab
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FpSTab = v3
		pTab = v3
		if pTab != 0 {
			(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
		}
		if int32(*(*uint32)(unsafe.Pointer(pOldItem + 24 + 4))&0x100000>>20) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 64)) = _sqlite3IdListDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 64)))
		} else {
			*(*uintptr)(unsafe.Pointer(pNewItem + 64)) = _sqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 64)), flags)
		}
		(*TSrcItem)(unsafe.Pointer(pNewItem)).FcolUsed = (*TSrcItem)(unsafe.Pointer(pOldItem)).FcolUsed
		goto _2
	_2:
		;
		i = i + 1
	}
	return pNew
}

// C documentation
//
//	/*
//	** Add the list of function arguments to the SrcList entry for a
//	** table-valued-function.
//	*/
func _sqlite3SrcListFuncArgs(tls *libc.TLS, pParse uintptr, p uintptr, pList uintptr) {
	var pItem uintptr
	_ = pItem
	if p != 0 {
		pItem = p + 8 + uintptr((*TSrcList)(unsafe.Pointer(p)).FnSrc-int32(1))*80
		*(*uintptr)(unsafe.Pointer(pItem + 48)) = pList
		libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 28, 0x10000000)
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	}
}

// C documentation
//
//	/*
//	** Add an INDEXED BY or NOT INDEXED clause to the most recently added
//	** element of the source-list passed as the second argument.
//	*/
func _sqlite3SrcListIndexedBy(tls *libc.TLS, pParse uintptr, p uintptr, pIndexedBy uintptr) {
	var pItem uintptr
	_ = pItem
	if p != 0 && (*TToken)(unsafe.Pointer(pIndexedBy)).Fn > uint32(0) {
		pItem = p + 8 + uintptr((*TSrcList)(unsafe.Pointer(p)).FnSrc-int32(1))*80
		if (*TToken)(unsafe.Pointer(pIndexedBy)).Fn == uint32(1) && !((*TToken)(unsafe.Pointer(pIndexedBy)).Fz != 0) {
			/* A "NOT INDEXED" clause was supplied. See parse.y
			 ** construct "indexed_opt" for details. */
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 31, 0x80000000)
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 48)) = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIndexedBy)
			libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 30, 0x40000000)
			/* No collision on union u2 */
		}
	}
}

// C documentation
//
//	/*
//	** While a SrcList can in general represent multiple tables and subqueries
//	** (as in the FROM clause of a SELECT statement) in this case it contains
//	** the name of a single table, as one might find in an INSERT, DELETE,
//	** or UPDATE statement.  Look up that table in the symbol table and
//	** return a pointer.  Set an error message and return NULL if the table
//	** name is not found or if any other error occurs.
//	**
//	** The following fields are initialized appropriate in pSrc:
//	**
//	**    pSrc->a[0].spTab        Pointer to the Table object
//	**    pSrc->a[0].u2.pIBIndex  Pointer to the INDEXED BY index, if there is one
//	**
//	*/
func _sqlite3SrcListLookup(tls *libc.TLS, pParse uintptr, pSrc uintptr) (r uintptr) {
	var pItem, pTab uintptr
	_, _ = pItem, pTab
	pItem = pSrc + 8
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pItem)
	if (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab != 0 {
		_sqlite3DeleteTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)
	}
	(*TSrcItem)(unsafe.Pointer(pItem)).FpSTab = pTab
	libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(1), 21, 0x200000)
	if pTab != 0 {
		(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x40000000>>30) != 0 && _sqlite3IndexedByLookup(tls, pParse, pItem) != 0 {
			pTab = uintptr(0)
		}
	}
	return pTab
}

// C documentation
//
//	/*
//	** Begin constructing a new table representation in memory.  This is
//	** the first of several action routines that get called in response
//	** to a CREATE TABLE statement.  In particular, this routine is called
//	** after seeing tokens "CREATE" and "TABLE" and the table name. The isTemp
//	** flag is true if the table should be stored in the auxiliary database
//	** file instead of in the main database file.  This is normally the case
//	** when the "TEMP" or "TEMPORARY" keyword occurs in between
//	** CREATE and TABLE.
//	**
//	** The new table record is initialized and put in pParse->pNewTable.
//	** As more of the CREATE TABLE statement is parsed, additional action
//	** routines will be called to add more information to this record.
//	** At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
//	** is called to complete the construction of the new table record.
//	*/
func _sqlite3StartTable(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, isTemp int32, isView int32, isVirtual int32, noErr int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var addr1, fileFormat, iDb, reg1, reg2, reg3, v7, v8 int32
	var db, pTable, v, zDb, zDb1, zName, v1 uintptr
	var v6 bool
	var _ /* pName at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, db, fileFormat, iDb, pTable, reg1, reg2, reg3, v, zDb, zDb1, zName, v1, v6, v7, v8
	zName = uintptr(0)                         /* The name of the new table */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Unqualified name of the table to create */
	if (*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Finit1.FnewTnum == uint32(1) {
		/* Special case:  Parsing the sqlite_schema or sqlite_temp_schema schema */
		iDb = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb)
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			v1 = __ccgo_ts + 6768
		} else {
			v1 = __ccgo_ts + 6288
		}
		zName = _sqlite3DbStrDup(tls, db, v1)
		**(**uintptr)(__ccgo_up(bp)) = pName1
	} else {
		/* The common case */
		iDb = _sqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
		if iDb < 0 {
			return
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp != 0 && (*TToken)(unsafe.Pointer(pName2)).Fn > uint32(0) && iDb != int32(1) {
			/* If creating a temp table, the name may not be qualified. Unless
			 ** the database name is "temp" anyway.  */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13809, 0)
			return
		}
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp != 0 {
			iDb = int32(1)
		}
		zName = _sqlite3NameFromToken(tls, db, **(**uintptr)(__ccgo_up(bp)))
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenMap(tls, pParse, zName, **(**uintptr)(__ccgo_up(bp)))
		}
	}
	(*TParse)(unsafe.Pointer(pParse)).FsNameToken = **(**TToken)(__ccgo_up(**(**uintptr)(__ccgo_up(bp))))
	if zName == uintptr(0) {
		return
	}
	if isView != 0 {
		v1 = __ccgo_ts + 11119
	} else {
		v1 = __ccgo_ts + 9381
	}
	if _sqlite3CheckObjectName(tls, pParse, zName, v1, zName) != 0 {
		goto begin_table_error
	}
	if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Finit1.FiDb) == int32(1) {
		isTemp = int32(1)
	}
	zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
	if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && isTemp == int32(1) {
		v1 = __ccgo_ts + 6768
	} else {
		v1 = __ccgo_ts + 6288
	}
	if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_INSERT), v1, uintptr(0), zDb) != 0 {
		goto begin_table_error
	}
	if !(isVirtual != 0) && _sqlite3AuthCheck(tls, pParse, libc.Int32FromUint8(_aCode[isTemp+int32(2)*isView]), zName, uintptr(0), zDb) != 0 {
		goto begin_table_error
	}
	/* Make sure the new table name does not collide with an existing
	 ** index or table name in the same database.  Issue an error message if
	 ** it does. The exception is if the statement being parsed was passed
	 ** to an sqlite3_declare_vtab() call. In that case only the column names
	 ** and types will be used, so there is no need to test for namespace
	 ** collisions.
	 */
	if !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) != libc.Int32FromInt32(PARSE_MODE_NORMAL)) {
		zDb1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName
		if SQLITE_OK != _sqlite3ReadSchema(tls, pParse) {
			goto begin_table_error
		}
		pTable = _sqlite3FindTable(tls, db, zName, zDb1)
		if pTable != 0 {
			if !(noErr != 0) {
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTable)).FeTabType) == int32(TABTYP_VIEW) {
					v1 = __ccgo_ts + 11119
				} else {
					v1 = __ccgo_ts + 9381
				}
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13850, libc.VaList(bp+16, v1, **(**uintptr)(__ccgo_up(bp))))
			} else {
				_sqlite3CodeVerifySchema(tls, pParse, iDb)
				_sqlite3ForceNotReadOnly(tls, pParse)
			}
			goto begin_table_error
		}
		if _sqlite3FindIndex(tls, db, zName, zDb1) != uintptr(0) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+13871, libc.VaList(bp+16, zName))
			goto begin_table_error
		}
	}
	pTable = _sqlite3DbMallocZero(tls, db, uint64(120))
	if pTable == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_NOMEM)
		(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
		goto begin_table_error
	}
	(*TTable)(unsafe.Pointer(pTable)).FzName = zName
	(*TTable)(unsafe.Pointer(pTable)).FiPKey = int16(-int32(1))
	(*TTable)(unsafe.Pointer(pTable)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpSchema
	(*TTable)(unsafe.Pointer(pTable)).FnTabRef = uint32(1)
	(*TTable)(unsafe.Pointer(pTable)).FnRowLogEst = int16(200)
	(*TParse)(unsafe.Pointer(pParse)).FpNewTable = pTable
	/* Begin generating the code that will insert the table record into
	 ** the schema table.  Note in particular that we must go ahead
	 ** and allocate the record number for the table entry now.  Before any
	 ** PRIMARY KEY or UNIQUE keywords are parsed.  Those keywords will cause
	 ** indices to be created and the table record must come before the
	 ** indices.  Hence, the record number for the table must be allocated
	 ** now.
	 */
	if v6 = !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0); v6 {
		v1 = _sqlite3GetVdbe(tls, pParse)
		v = v1
	}
	if v6 && v1 != uintptr(0) {
		_sqlite3BeginWriteOperation(tls, pParse, int32(1), iDb)
		if isVirtual != 0 {
			_sqlite3VdbeAddOp0(tls, v, int32(OP_VBegin))
		}
		/* If the file format and encoding in the database have not been set,
		 ** set them now.
		 */
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v8 = *(*int32)(unsafe.Pointer(v1))
		v7 = v8
		(*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRowid = v7
		reg1 = v7
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v8 = *(*int32)(unsafe.Pointer(v1))
		v7 = v8
		(*(*struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		})(unsafe.Pointer(pParse + 256))).FregRoot = v7
		reg2 = v7
		v1 = pParse + 60
		*(*int32)(unsafe.Pointer(v1)) = *(*int32)(unsafe.Pointer(v1)) + 1
		v7 = *(*int32)(unsafe.Pointer(v1))
		reg3 = v7
		_sqlite3VdbeAddOp3(tls, v, int32(OP_ReadCookie), iDb, reg3, int32(BTREE_FILE_FORMAT))
		_sqlite3VdbeUsesBtree(tls, v, iDb)
		addr1 = _sqlite3VdbeAddOp1(tls, v, int32(OP_If), reg3)
		if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LegacyFileFmt) != uint64(0) {
			v7 = int32(1)
		} else {
			v7 = int32(SQLITE_MAX_FILE_FORMAT)
		}
		fileFormat = v7
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_FILE_FORMAT), fileFormat)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_SetCookie), iDb, int32(BTREE_TEXT_ENCODING), libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).Fenc))
		_sqlite3VdbeJumpHere(tls, v, addr1)
		/* This just creates a place-holder record in the sqlite_schema table.
		 ** The record created does not contain anything yet.  It will be replaced
		 ** by the real entry in code generated at sqlite3EndTable().
		 **
		 ** The rowid for the new entry is left in register pParse->u1.cr.regRowid.
		 ** The root page of the new table is left in reg pParse->u1.cr.regRoot.
		 ** The rowid and root page number values are needed by the code that
		 ** sqlite3EndTable will generate.
		 */
		if isView != 0 || isVirtual != 0 {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, reg2)
		} else {
			(*(*struct {
				FaddrCrTab      int32
				FregRowid       int32
				FregRoot        int32
				FconstraintName TToken
			})(unsafe.Pointer(pParse + 256))).FaddrCrTab = _sqlite3VdbeAddOp3(tls, v, int32(OP_CreateBtree), iDb, reg2, int32(BTREE_INTKEY))
		}
		_sqlite3OpenSchemaTable(tls, pParse, iDb)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), 0, reg1)
		_sqlite3VdbeAddOp4(tls, v, int32(OP_Blob), int32(6), reg3, 0, uintptr(unsafe.Pointer(&_nullRow)), -int32(1))
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), 0, reg3, reg1)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		_sqlite3VdbeAddOp0(tls, v, int32(OP_Close))
	} else {
		if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x60>>5)) != 0 {
			**(**Tu32)(__ccgo_up(pTable + 48)) |= uint32(TF_Imposter)
			if int32(uint32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x60>>5)) >= int32(2) {
				**(**Tu32)(__ccgo_up(pTable + 48)) |= uint32(TF_Readonly)
			}
		}
	}
	/* Normal (non-error) return. */
	return
	/* If an error occurs, we jump here */
	goto begin_table_error
begin_table_error:
	;
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
	_sqlite3DbFree(tls, db, zName)
	return
}

// C documentation
//
//	/*
//	** Execute the statement pStmt, either until a row of data is ready, the
//	** statement is completely executed or an error occurs.
//	**
//	** This routine implements the bulk of the logic behind the sqlite_step()
//	** API.  The only thing omitted is the automatic recompile if a
//	** schema change has occurred.  That detail is handled by the
//	** outer sqlite3_step() wrapper procedure.
//	*/
func _sqlite3Step(tls *libc.TLS, p uintptr) (r int32) {
	var db uintptr
	var rc int32
	_, _ = db, rc
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) != int32(VDBE_RUN_STATE) {
		goto restart_step
	restart_step:
		;
		if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_READY_STATE) {
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0xc000>>14)) != 0 {
				(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_SCHEMA)
				rc = int32(SQLITE_ERROR)
				if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) != 0 {
					/* If this statement was prepared using saved SQL and an
					 ** error has occurred, then return the error code in p->rc to the
					 ** caller. Set the error code in the database handle to the same
					 ** value.
					 */
					rc = _sqlite3VdbeTransferError(tls, p)
				}
				goto end_of_step
			}
			/* If there are no other statements currently running, then
			 ** reset the interrupt flag.  This prevents a call to sqlite3_interrupt
			 ** from interrupting a statement that has not yet started.
			 */
			if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
				libc.AtomicStoreNInt32(db+432, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
			}
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&(libc.Int32FromInt32(SQLITE_TRACE_PROFILE)|libc.Int32FromInt32(SQLITE_TRACE_XPROFILE)) != 0 && !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) && (*TVdbe)(unsafe.Pointer(p)).FzSql != 0 {
				_sqlite3OsCurrentTimeInt64(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, p+184)
			} else {
			}
			(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive + 1
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x200>>9)) == 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite + 1
			}
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x100>>8)) != 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead + 1
			}
			(*TVdbe)(unsafe.Pointer(p)).Fpc = 0
			(*TVdbe)(unsafe.Pointer(p)).FeVdbeState = uint8(VDBE_RUN_STATE)
		} else {
			if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_HALT_STATE) {
				/* We used to require that sqlite3_reset() be called before retrying
				 ** sqlite3_step() after any error or after SQLITE_DONE.  But beginning
				 ** with version 3.7.0, we changed this so that sqlite3_reset() would
				 ** be called automatically instead of throwing the SQLITE_MISUSE error.
				 ** This "automatic-reset" change is not technically an incompatibility,
				 ** since any application that receives an SQLITE_MISUSE is broken by
				 ** definition.
				 **
				 ** Nevertheless, some published applications that were originally written
				 ** for version 3.6.23 or earlier do in fact depend on SQLITE_MISUSE
				 ** returns, and those were broken by the automatic-reset change.  As a
				 ** a work-around, the SQLITE_OMIT_AUTORESET compile-time restores the
				 ** legacy behavior of returning SQLITE_MISUSE for cases where the
				 ** previous sqlite3_step() returned something other than a SQLITE_LOCKED
				 ** or SQLITE_BUSY error.
				 */
				Xsqlite3_reset(tls, p)
				goto restart_step
			}
		}
	}
	if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)) != 0 {
		rc = _sqlite3VdbeList(tls, p)
	} else {
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec + 1
		rc = _sqlite3VdbeExec(tls, p)
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec - 1
	}
	if rc == int32(SQLITE_ROW) {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = int32(SQLITE_ROW)
		return int32(SQLITE_ROW)
	} else {
		/* If the statement completed successfully, invoke the profile callback */
		if (*TVdbe)(unsafe.Pointer(p)).FstartTime > 0 {
			_invokeProfileCallback(tls, db, p)
		}
		(*TVdbe)(unsafe.Pointer(p)).FpResultRow = uintptr(0)
		if rc == int32(SQLITE_DONE) && (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
			(*TVdbe)(unsafe.Pointer(p)).Frc = _doWalCallbacks(tls, db)
			if (*TVdbe)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				rc = int32(SQLITE_ERROR)
			}
		} else {
			if rc != int32(SQLITE_DONE) && libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) != 0 {
				/* If this statement was prepared using saved SQL and an
				 ** error has occurred, then return the error code in p->rc to the
				 ** caller. Set the error code in the database handle to the same value.
				 */
				rc = _sqlite3VdbeTransferError(tls, p)
			}
		}
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FerrCode = rc
	if int32(SQLITE_NOMEM) == _sqlite3ApiExit(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, (*TVdbe)(unsafe.Pointer(p)).Frc) {
		(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FprepFlags)&int32(SQLITE_PREPARE_SAVESQL) != 0 {
			rc = (*TVdbe)(unsafe.Pointer(p)).Frc
		}
	}
	goto end_of_step
end_of_step:
	;
	/* There are only a limited number of result codes allowed from the
	 ** statements prepared using the legacy sqlite3_prepare() interface */
	return rc & (*Tsqlite3)(unsafe.Pointer(db)).FerrMask
}

// C documentation
//
//	/*
//	** Remove a Subquery from a SrcItem.  Return the associated Select object.
//	** The returned Select becomes the responsibility of the caller.
//	*/
func _sqlite3SubqueryDetach(tls *libc.TLS, db uintptr, pItem uintptr) (r uintptr) {
	var pSel uintptr
	_ = pSel
	pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
	_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
	*(*uintptr)(unsafe.Pointer(pItem + 72)) = uintptr(0)
	libc.SetBitFieldPtr32Uint32(pItem+24+4, libc.Uint32FromInt32(0), 29, 0x20000000)
	return pSel
}

func _sqlite3TriggersExist(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, pChanges uintptr, pMask uintptr) (r uintptr) {
	if (*TTable)(unsafe.Pointer(pTab)).FpTrigger == uintptr(0) && !(_tempTriggersExist(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb) != 0) || int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x8000>>15)) != 0 {
		if pMask != 0 {
			**(**int32)(__ccgo_up(pMask)) = 0
		}
		return uintptr(0)
	}
	return _triggersReallyExist(tls, pParse, pTab, op, pChanges, pMask)
}

// C documentation
//
//	/*
//	** Code an OP_Halt due to UNIQUE or PRIMARY KEY constraint violation.
//	*/
func _sqlite3UniqueConstraint(tls *libc.TLS, pParse uintptr, onError int32, pIdx uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var j, v2 int32
	var pTab, zCol, zErr uintptr
	var _ /* errMsg at bp+0 */ TStrAccum
	_, _, _, _, _ = j, pTab, zCol, zErr, v2
	pTab = (*TIndex)(unsafe.Pointer(pIdx)).FpTable
	_sqlite3StrAccumInit(tls, bp, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), 0, **(**int32)(__ccgo_up((*TParse)(unsafe.Pointer(pParse)).Fdb + 136)))
	if (*TIndex)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+16207, libc.VaList(bp+40, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
	} else {
		j = 0
		for {
			if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
				break
			}
			zCol = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))*16))).FzCnName
			if j != 0 {
				Xsqlite3_str_append(tls, bp, __ccgo_ts+16218, int32(2))
			}
			Xsqlite3_str_appendall(tls, bp, (*TTable)(unsafe.Pointer(pTab)).FzName)
			Xsqlite3_str_append(tls, bp, __ccgo_ts+1743, int32(1))
			Xsqlite3_str_appendall(tls, bp, zCol)
			goto _1
		_1:
			;
			j = j + 1
		}
	}
	zErr = _sqlite3StrAccumFinish(tls, bp)
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
		v2 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(6)<<libc.Int32FromInt32(8)
	} else {
		v2 = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(8)<<libc.Int32FromInt32(8)
	}
	_sqlite3HaltConstraint(tls, pParse, v2, onError, zErr, int8(-libc.Int32FromInt32(7)), uint8(P5_ConstraintUnique))
}

// C documentation
//
//	/*
//	** Process an UPDATE statement.
//	**
//	**   UPDATE OR IGNORE tbl SET a=b, c=d FROM tbl2... WHERE e<5 AND f NOT NULL;
//	**          \_______/ \_/     \______/      \_____/       \________________/
//	**           onError   |      pChanges         |                pWhere
//	**                     \_______________________/
//	**                               pTabList
//	*/
func _sqlite3Update(tls *libc.TLS, pParse uintptr, pTabList uintptr, pChanges uintptr, pWhere uintptr, onError int32, pOrderBy uintptr, pLimit uintptr, pUpsert uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var aRegIdx, aToOpen, aXRef, db, pIdx, pKeyInfo, pPk, pRowidExpr, pTab, pTrigger, pWInfo, v, v4 uintptr
	var addrOnce, addrOpen, addrTop, bFinishSeek, bProgress, eOnePass, flags, hasFK, i, iBaseCur, iCur, iDataCur, iDb, iEph, iIdxCur, iPk, iRowidExpr, isView, j, k, labelBreak, labelContinue, nAllIdx, nChangeFrom, nEphCol, nIdx, nKey, nOff, newmask, rc, reg, regKey, regNew, regNewRowid, regOld, regOldRowid, regRowCount, regRowSet, v1, v2 int32
	var chngKey, chngPk, chngRowid, v8 Tu8
	var colFlags, oldmask Tu32
	var nPk Ti16
	var v12 uint64
	var v42 uint32
	var _ /* aiCurOnePass at bp+80 */ [2]int32
	var _ /* bReplace at bp+88 */ int32
	var _ /* iNotUsed1 at bp+92 */ int32
	var _ /* iNotUsed2 at bp+96 */ int32
	var _ /* sContext at bp+0 */ TAuthContext
	var _ /* sNC at bp+16 */ TNameContext
	var _ /* tmask at bp+72 */ int32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aRegIdx, aToOpen, aXRef, addrOnce, addrOpen, addrTop, bFinishSeek, bProgress, chngKey, chngPk, chngRowid, colFlags, db, eOnePass, flags, hasFK, i, iBaseCur, iCur, iDataCur, iDb, iEph, iIdxCur, iPk, iRowidExpr, isView, j, k, labelBreak, labelContinue, nAllIdx, nChangeFrom, nEphCol, nIdx, nKey, nOff, nPk, newmask, oldmask, pIdx, pKeyInfo, pPk, pRowidExpr, pTab, pTrigger, pWInfo, rc, reg, regKey, regNew, regNewRowid, regOld, regOldRowid, regRowCount, regRowSet, v, v1, v12, v2, v4, v42, v8 /* The table to be updated */
	addrTop = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           /* VDBE instruction address of the start of the loop */
	pWInfo = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* The database structure */
	aRegIdx = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  /* Registers for to each index and the main table */
	aXRef = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    /* Either chngPk or chngRowid */
	pRowidExpr = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Expression defining the new record number */
	iRowidExpr = -int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* Mask of NEW.* columns accessed by BEFORE triggers */
	iEph = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* Ephemeral table holding all primary key values */
	nKey = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              /* The write cursors opened by WHERE_ONEPASS */
	addrOpen = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          /* Address of OP_OpenEphemeral */
	iPk = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* First of nPk cells holding PRIMARY KEY value */
	nPk = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* Number of components of the PRIMARY KEY */
	**(**int32)(__ccgo_up(bp + 88)) = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* True if REPLACE conflict resolution might happen */
	bFinishSeek = int32(1)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                /* The OP_FinishSeek opcode is needed */
	nChangeFrom = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       /* If there is a FROM, pChanges->nExpr, else 0 */
	/* Register Allocations */
	regRowCount = 0 /* A count of rows changed */
	regOldRowid = 0 /* The old rowid */
	regNewRowid = 0 /* The new rowid */
	regNew = 0      /* Content of the NEW.* table in triggers */
	regOld = 0      /* Content of OLD.* table in triggers */
	regRowSet = 0   /* Rowset of rows to be updated */
	regKey = 0      /* composite PRIMARY KEY value */
	libc.Xmemset(tls, bp, 0, uint64(16))
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto update_cleanup
	}
	/* Locate the table which we want to update.
	 */
	pTab = _sqlite3SrcListLookup(tls, pParse, pTabList)
	if pTab == uintptr(0) {
		goto update_cleanup
	}
	iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
	/* Figure out if we have any triggers and if the table being
	 ** updated is a view.
	 */
	pTrigger = _sqlite3TriggersExist(tls, pParse, pTab, int32(TK_UPDATE), pChanges, bp+72)
	isView = libc.BoolInt32(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW))
	/* If there was a FROM clause, set nChangeFrom to the number of expressions
	 ** in the change-list. Otherwise, set it to 0. There cannot be a FROM
	 ** clause if this function is being called to generate code for part of
	 ** an UPSERT statement.  */
	if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(1) {
		v1 = (*TExprList)(unsafe.Pointer(pChanges)).FnExpr
	} else {
		v1 = 0
	}
	nChangeFrom = v1
	if _sqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
		goto update_cleanup
	}
	if _sqlite3IsReadOnly(tls, pParse, pTab, pTrigger) != 0 {
		goto update_cleanup
	}
	/* Allocate a cursors for the main database table and for all indices.
	 ** The index cursors might not be used, but if they are used they
	 ** need to occur right after the database cursor.  So go ahead and
	 ** allocate enough space, just in case.
	 */
	v4 = pParse + 56
	v2 = *(*int32)(unsafe.Pointer(v4))
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	v1 = v2
	iDataCur = v1
	iBaseCur = v1
	iIdxCur = iDataCur + int32(1)
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		v4 = uintptr(0)
	} else {
		v4 = _sqlite3PrimaryKeyIndex(tls, pTab)
	}
	pPk = v4
	nIdx = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if pPk == pIdx {
			iDataCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
		}
		(*TParse)(unsafe.Pointer(pParse)).FnTab = (*TParse)(unsafe.Pointer(pParse)).FnTab + 1
		goto _6
	_6:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nIdx = nIdx + 1
	}
	if pUpsert != 0 {
		/* On an UPSERT, reuse the same cursors already opened by INSERT */
		iDataCur = (*TUpsert)(unsafe.Pointer(pUpsert)).FiDataCur
		iIdxCur = (*TUpsert)(unsafe.Pointer(pUpsert)).FiIdxCur
		(*TParse)(unsafe.Pointer(pParse)).FnTab = iBaseCur
	}
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FiCursor = iDataCur
	/* Allocate space for aXRef[], aRegIdx[], and aToOpen[].
	 ** Initialize aXRef[] and aToOpen[] to their default values.
	 */
	aXRef = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(4)*libc.Uint64FromInt32(int32((*TTable)(unsafe.Pointer(pTab)).FnCol)+nIdx+libc.Int32FromInt32(1))+libc.Uint64FromInt32(nIdx)+uint64(2)))
	if aXRef == uintptr(0) {
		goto update_cleanup
	}
	aRegIdx = aXRef + uintptr((*TTable)(unsafe.Pointer(pTab)).FnCol)*4
	aToOpen = aRegIdx + uintptr(nIdx)*4 + libc.UintptrFromInt32(1)*4
	libc.Xmemset(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)))
	**(**Tu8)(__ccgo_up(aToOpen + uintptr(nIdx+int32(1)))) = uint8(0)
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		**(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) = -int32(1)
		goto _7
	_7:
		;
		i = i + 1
	}
	/* Initialize the name-context */
	libc.Xmemset(tls, bp+16, 0, uint64(56))
	(**(**TNameContext)(__ccgo_up(bp + 16))).FpParse = pParse
	(**(**TNameContext)(__ccgo_up(bp + 16))).FpSrcList = pTabList
	*(*uintptr)(unsafe.Pointer(bp + 16 + 16)) = pUpsert
	(**(**TNameContext)(__ccgo_up(bp + 16))).FncFlags = int32(NC_UUpsert)
	/* Begin generating code. */
	v = _sqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		goto update_cleanup
	}
	/* Resolve the column names in all the expressions of the
	 ** of the UPDATE statement.  Also find the column index
	 ** for each column to be updated in the pChanges array.  For each
	 ** column to be updated, make sure we have authorization to change
	 ** that column.
	 */
	v8 = libc.Uint8FromInt32(0)
	chngPk = v8
	chngRowid = v8
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pChanges)).FnExpr) {
			break
		}
		/* If this is an UPDATE with a FROM clause, do not resolve expressions
		 ** here. The call to sqlite3Select() below will do that. */
		if nChangeFrom == 0 && _sqlite3ResolveExprNames(tls, bp+16, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FpExpr) != 0 {
			goto update_cleanup
		}
		j = _sqlite3ColumnIndex(tls, pTab, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FzEName)
		if j >= 0 {
			if j == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
				chngRowid = uint8(1)
				pRowidExpr = (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FpExpr
				iRowidExpr = i
			} else {
				if pPk != 0 && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_PRIMKEY) != 0 {
					chngPk = uint8(1)
				} else {
					if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
						_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+22607, libc.VaList(bp+112, (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FzCnName))
						goto update_cleanup
					}
				}
			}
			**(**int32)(__ccgo_up(aXRef + uintptr(j)*4)) = i
		} else {
			if pPk == uintptr(0) && _sqlite3IsRowid(tls, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FzEName) != 0 {
				j = -int32(1)
				chngRowid = uint8(1)
				pRowidExpr = (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FpExpr
				iRowidExpr = i
			} else {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+11910, libc.VaList(bp+112, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32))).FzEName))
				libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 7, 0x80)
				goto update_cleanup
			}
		}
		if j < 0 {
			v4 = __ccgo_ts + 8201
		} else {
			v4 = (**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*16))).FzCnName
		}
		rc = _sqlite3AuthCheck(tls, pParse, int32(SQLITE_UPDATE), (*TTable)(unsafe.Pointer(pTab)).FzName, v4, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FzDbSName)
		if rc == int32(SQLITE_DENY) {
			goto update_cleanup
		} else {
			if rc == int32(SQLITE_IGNORE) {
				**(**int32)(__ccgo_up(aXRef + uintptr(j)*4)) = -int32(1)
			}
		}
		goto _9
	_9:
		;
		i = i + 1
	}
	chngKey = libc.Uint8FromInt32(libc.Int32FromUint8(chngRowid) + libc.Int32FromUint8(chngPk))
	/* Mark generated columns as changing if their generator expressions
	 ** reference any changing column.  The actual aXRef[] value for
	 ** generated expressions is not used, other than to check to see that it
	 ** is non-negative, so the value of aXRef[] for generated columns can be
	 ** set to any non-negative number.  We use 99999 so that the value is
	 ** obvious when looking at aXRef[] in a symbolic debugger.
	 */
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
		for cond := true; cond; cond = bProgress != 0 {
			bProgress = 0
			i = 0
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if **(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) >= 0 {
					goto _11
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) == 0 {
					goto _11
				}
				if _sqlite3ExprReferencesUpdatedColumn(tls, _sqlite3ColumnExpr(tls, pTab, (*TTable)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*16), aXRef, libc.Int32FromUint8(chngRowid)) != 0 {
					**(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) = int32(99999)
					bProgress = int32(1)
				}
				goto _11
			_11:
				;
				i = i + 1
			}
		}
	}
	/* The SET expressions are not actually used inside the WHERE loop.
	 ** So reset the colUsed mask. Unless this is a virtual table. In that
	 ** case, set all bits of the colUsed mask (to ensure that the virtual
	 ** table implementation makes all columns available).
	 */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		v12 = libc.Uint64FromInt32(-libc.Int32FromInt32(1))
	} else {
		v12 = uint64(0)
	}
	(*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FcolUsed = v12
	hasFK = _sqlite3FkRequired(tls, pParse, pTab, aXRef, libc.Int32FromUint8(chngKey))
	/* There is one entry in the aRegIdx[] array for each index on the table
	 ** being updated.  Fill in aRegIdx[] with a register number that will hold
	 ** the key for accessing each index.
	 */
	if onError == int32(OE_Replace) {
		**(**int32)(__ccgo_up(bp + 88)) = int32(1)
	}
	nAllIdx = 0
	pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(pIdx != 0) {
			break
		}
		if chngKey != 0 || hasFK > int32(1) || pIdx == pPk || _indexWhereClauseMightChange(tls, pIdx, aXRef, libc.Int32FromUint8(chngRowid)) != 0 {
			v4 = pParse + 60
			*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
			v1 = *(*int32)(unsafe.Pointer(v4))
			reg = v1
			**(**int32)(__ccgo_up(pParse + 60)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
		} else {
			reg = 0
			i = 0
			for {
				if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				if _indexColumnIsBeingUpdated(tls, pIdx, i, aXRef, libc.Int32FromUint8(chngRowid)) != 0 {
					v4 = pParse + 60
					*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
					v1 = *(*int32)(unsafe.Pointer(v4))
					reg = v1
					**(**int32)(__ccgo_up(pParse + 60)) += libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
					if onError == int32(OE_Default) && libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) == int32(OE_Replace) {
						**(**int32)(__ccgo_up(bp + 88)) = int32(1)
					}
					break
				}
				goto _16
			_16:
				;
				i = i + 1
			}
		}
		if reg == 0 {
			**(**Tu8)(__ccgo_up(aToOpen + uintptr(nAllIdx+int32(1)))) = uint8(0)
		}
		**(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4)) = reg
		goto _13
	_13:
		;
		pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		nAllIdx = nAllIdx + 1
	}
	v4 = pParse + 60
	*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
	v1 = *(*int32)(unsafe.Pointer(v4))
	**(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4)) = v1 /* Register storing the table record */
	if **(**int32)(__ccgo_up(bp + 88)) != 0 {
		/* If REPLACE conflict resolution might be invoked, open cursors on all
		 ** indexes in case they are needed to delete records.  */
		libc.Xmemset(tls, aToOpen, int32(1), libc.Uint64FromInt32(nIdx+int32(1)))
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
		_sqlite3VdbeCountChanges(tls, v)
	}
	_sqlite3BeginWriteOperation(tls, pParse, libc.BoolInt32(pTrigger != 0 || hasFK != 0), iDb)
	/* Allocate required registers. */
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) {
		/* For now, regRowSet and aRegIdx[nAllIdx] share the same register.
		 ** If regRowSet turns out to be needed, then aRegIdx[nAllIdx] will be
		 ** reallocated.  aRegIdx[nAllIdx] is the register in which the main
		 ** table record is written.  regRowSet holds the RowSet for the
		 ** two-pass update algorithm. */
		regRowSet = **(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4))
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v2 = *(*int32)(unsafe.Pointer(v4))
		v1 = v2
		regNewRowid = v1
		regOldRowid = v1
		if chngPk != 0 || pTrigger != 0 || hasFK != 0 {
			regOld = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
			**(**int32)(__ccgo_up(pParse + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		}
		if chngKey != 0 || pTrigger != 0 || hasFK != 0 {
			v4 = pParse + 60
			*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
			v1 = *(*int32)(unsafe.Pointer(v4))
			regNewRowid = v1
		}
		regNew = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	}
	/* Start the view context. */
	if isView != 0 {
		_sqlite3AuthContextPush(tls, pParse, bp, (*TTable)(unsafe.Pointer(pTab)).FzName)
	}
	/* If we are trying to update a view, realize that view into
	 ** an ephemeral table.
	 */
	if nChangeFrom == 0 && isView != 0 {
		_sqlite3MaterializeView(tls, pParse, pTab, pWhere, pOrderBy, pLimit, iDataCur)
		pOrderBy = uintptr(0)
		pLimit = uintptr(0)
	}
	/* Resolve the column names in all the expressions in the
	 ** WHERE clause.
	 */
	if nChangeFrom == 0 && _sqlite3ResolveExprNames(tls, bp+16, pWhere) != 0 {
		goto update_cleanup
	}
	/* Virtual tables must be handled separately */
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		_updateVirtualTable(tls, pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef, pWhere, onError)
		goto update_cleanup
	}
	/* Jump to labelBreak to abandon further processing of this UPDATE */
	v1 = _sqlite3VdbeMakeLabel(tls, pParse)
	labelBreak = v1
	labelContinue = v1
	/* Not an UPSERT.  Normal processing.  Begin by
	 ** initialize the count of updated rows */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) && !((*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0) && !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !(int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x1000>>12)) != 0) && pUpsert == uintptr(0) {
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v1 = *(*int32)(unsafe.Pointer(v4))
		regRowCount = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regRowCount)
	}
	if nChangeFrom == 0 && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, regRowSet, regOldRowid)
		v4 = pParse + 56
		v1 = *(*int32)(unsafe.Pointer(v4))
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		iEph = v1
		addrOpen = _sqlite3VdbeAddOp3(tls, v, int32(OP_OpenEphemeral), iEph, 0, regRowSet)
	} else {
		if pPk != 0 {
			v1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
		} else {
			v1 = 0
		}
		nPk = int16(v1)
		iPk = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 60)) += int32(nPk)
		**(**int32)(__ccgo_up(pParse + 60)) += nChangeFrom
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v1 = *(*int32)(unsafe.Pointer(v4))
		regKey = v1
		if pUpsert == uintptr(0) {
			if isView != 0 {
				v1 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
			} else {
				v1 = 0
			}
			nEphCol = int32(nPk) + nChangeFrom + v1
			v4 = pParse + 56
			v2 = *(*int32)(unsafe.Pointer(v4))
			*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
			iEph = v2
			if pPk != 0 {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, iPk, iPk+int32(nPk)-int32(1))
			}
			addrOpen = _sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), iEph, nEphCol)
			if pPk != 0 {
				pKeyInfo = _sqlite3KeyInfoOfIndex(tls, pParse, pPk)
				if pKeyInfo != 0 {
					(*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField = libc.Uint16FromInt32(nEphCol)
					_sqlite3VdbeAppendP4(tls, v, pKeyInfo, -int32(9))
				}
			}
			if nChangeFrom != 0 {
				_updateFromSelect(tls, pParse, iEph, pPk, pChanges, pTabList, pWhere, pOrderBy, pLimit)
				if isView != 0 {
					iDataCur = iEph
				}
			}
		}
	}
	if nChangeFrom != 0 {
		_sqlite3MultiWrite(tls, pParse)
		eOnePass = ONEPASS_OFF
		nKey = int32(nPk)
		regKey = iPk
	} else {
		if pUpsert != 0 {
			/* If this is an UPSERT, then all cursors have already been opened by
			 ** the outer INSERT and the data cursor should be pointing at the row
			 ** that is to be updated.  So bypass the code that searches for the
			 ** row(s) to be updated.
			 */
			pWInfo = uintptr(0)
			eOnePass = int32(ONEPASS_SINGLE)
			_sqlite3ExprIfFalse(tls, pParse, pWhere, labelBreak, int32(SQLITE_JUMPIFNULL))
			bFinishSeek = 0
		} else {
			/* Begin the database scan.
			 **
			 ** Do not consider a single-pass strategy for a multi-row update if
			 ** there is anything that might disrupt the cursor being used to do
			 ** the UPDATE:
			 **   (1) This is a nested UPDATE
			 **   (2) There are triggers
			 **   (3) There are FOREIGN KEY constraints
			 **   (4) There are REPLACE conflict handlers
			 **   (5) There are subqueries in the WHERE clause
			 */
			flags = int32(WHERE_ONEPASS_DESIRED)
			if !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) && !(pTrigger != 0) && !(hasFK != 0) && !(chngKey != 0) && !(**(**int32)(__ccgo_up(bp + 88)) != 0) && (pWhere == uintptr(0) || !((*TExpr)(unsafe.Pointer(pWhere)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != libc.Uint32FromInt32(0))) {
				flags = flags | int32(WHERE_ONEPASS_MULTIROW)
			}
			pWInfo = _sqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), libc.Uint16FromInt32(flags), iIdxCur)
			if pWInfo == uintptr(0) {
				goto update_cleanup
			}
			/* A one-pass strategy that might update more than one row may not
			 ** be used if any column of the index used for the scan is being
			 ** updated. Otherwise, if there is an index on "b", statements like
			 ** the following could create an infinite loop:
			 **
			 **   UPDATE t1 SET b=b+1 WHERE b>?
			 **
			 ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
			 ** strategy that uses an index for which one or more columns are being
			 ** updated.  */
			eOnePass = _sqlite3WhereOkOnePass(tls, pWInfo, bp+80)
			bFinishSeek = _sqlite3WhereUsesDeferredSeek(tls, pWInfo)
			if eOnePass != int32(ONEPASS_SINGLE) {
				_sqlite3MultiWrite(tls, pParse)
				if eOnePass == int32(ONEPASS_MULTI) {
					iCur = (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]
					if iCur >= 0 && iCur != iDataCur && **(**Tu8)(__ccgo_up(aToOpen + uintptr(iCur-iBaseCur))) != 0 {
						eOnePass = ONEPASS_OFF
					}
				}
			}
		}
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			/* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
			 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
			 ** leave it in register regOldRowid.  */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iDataCur, regOldRowid)
			if eOnePass == ONEPASS_OFF {
				v4 = pParse + 60
				*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
				v1 = *(*int32)(unsafe.Pointer(v4))
				**(**int32)(__ccgo_up(aRegIdx + uintptr(nAllIdx)*4)) = v1
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iEph, regRowSet, regOldRowid)
			} else {
				if addrOpen != 0 {
					_sqlite3VdbeChangeToNoop(tls, v, addrOpen)
				}
			}
		} else {
			/* Read the PK of the current row into an array of registers. In
			 ** ONEPASS_OFF mode, serialize the array into a record and store it in
			 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
			 ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table
			 ** is not required) and leave the PK fields in the array of registers.  */
			i = 0
			for {
				if !(i < int32(nPk)) {
					break
				}
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
				goto _39
			_39:
				;
				i = i + 1
			}
			if eOnePass != 0 {
				if addrOpen != 0 {
					_sqlite3VdbeChangeToNoop(tls, v, addrOpen)
				}
				nKey = int32(nPk)
				regKey = iPk
			} else {
				_sqlite3VdbeAddOp4(tls, v, int32(OP_MakeRecord), iPk, int32(nPk), regKey, _sqlite3IndexAffinityStr(tls, db, pPk), int32(nPk))
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iEph, regKey, iPk, int32(nPk))
			}
		}
	}
	if pUpsert == uintptr(0) {
		if nChangeFrom == 0 && eOnePass != int32(ONEPASS_MULTI) {
			_sqlite3WhereEnd(tls, pWInfo)
		}
		if !(isView != 0) {
			addrOnce = 0
			**(**int32)(__ccgo_up(bp + 92)) = 0
			**(**int32)(__ccgo_up(bp + 96)) = 0
			/* Open every index that needs updating. */
			if eOnePass != ONEPASS_OFF {
				if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] >= 0 {
					**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[0]-iBaseCur))) = uint8(0)
				}
				if (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0 {
					**(**Tu8)(__ccgo_up(aToOpen + uintptr((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)]-iBaseCur))) = uint8(0)
				}
			}
			if eOnePass == int32(ONEPASS_MULTI) && nIdx-libc.BoolInt32((**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] >= 0) > 0 {
				addrOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			}
			_sqlite3OpenTableAndIndices(tls, pParse, pTab, int32(OP_OpenWrite), uint8(0), iBaseCur, aToOpen, bp+92, bp+96)
			if addrOnce != 0 {
				_sqlite3VdbeJumpHereOrPopInst(tls, v, addrOnce)
			}
		}
		/* Top of the update loop */
		if eOnePass != ONEPASS_OFF {
			if (**(**[2]int32)(__ccgo_up(bp + 80)))[0] != iDataCur && (**(**[2]int32)(__ccgo_up(bp + 80)))[int32(1)] != iDataCur {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelBreak, regKey, nKey)
			}
			if eOnePass != int32(ONEPASS_SINGLE) {
				labelContinue = _sqlite3VdbeMakeLabel(tls, pParse)
			}
			if pPk != 0 {
				v1 = regKey
			} else {
				v1 = regOldRowid
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), v1, labelBreak)
		} else {
			if pPk != 0 || nChangeFrom != 0 {
				labelContinue = _sqlite3VdbeMakeLabel(tls, pParse)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iEph, labelBreak)
				addrTop = _sqlite3VdbeCurrentAddr(tls, v)
				if nChangeFrom != 0 {
					if !(isView != 0) {
						if pPk != 0 {
							i = 0
							for {
								if !(i < int32(nPk)) {
									break
								}
								_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, i, iPk+i)
								goto _41
							_41:
								;
								i = i + 1
							}
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, iPk, int32(nPk))
						} else {
							_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iEph, regOldRowid)
							_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
						}
					}
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_RowData), iEph, regKey)
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, regKey, 0)
				}
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iEph, labelBreak)
				labelContinue = _sqlite3VdbeMakeLabel(tls, pParse)
				addrTop = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iEph, regOldRowid)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
			}
		}
	}
	/* If the rowid value will change, set register regNewRowid to
	 ** contain the new value. If the rowid is not being modified,
	 ** then regNewRowid is the same register as regOldRowid, which is
	 ** already populated.  */
	if chngRowid != 0 {
		if nChangeFrom == 0 {
			_sqlite3ExprCode(tls, pParse, pRowidExpr, regNewRowid)
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, iRowidExpr, regNewRowid)
		}
		_sqlite3VdbeAddOp1(tls, v, int32(OP_MustBeInt), regNewRowid)
	}
	/* Compute the old pre-UPDATE content of the row being changed, if that
	 ** information is needed */
	if chngPk != 0 || hasFK != 0 || pTrigger != 0 {
		if hasFK != 0 {
			v42 = _sqlite3FkOldmask(tls, pParse, pTab)
		} else {
			v42 = uint32(0)
		}
		oldmask = v42
		oldmask = oldmask | _sqlite3TriggerColmask(tls, pParse, pTrigger, pChanges, 0, libc.Int32FromInt32(TRIGGER_BEFORE)|libc.Int32FromInt32(TRIGGER_AFTER), pTab, onError)
		i = 0
		for {
			if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
				break
			}
			colFlags = uint32((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)
			k = int32(_sqlite3TableColumnToStorage(tls, pTab, int16(i))) + regOld
			if oldmask == uint32(0xffffffff) || i < int32(32) && oldmask&(libc.Uint32FromInt32(1)<<i) != uint32(0) || colFlags&uint32(COLFLAG_PRIMKEY) != uint32(0) {
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
			} else {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, k)
			}
			goto _43
		_43:
			;
			i = i + 1
		}
		if libc.Int32FromUint8(chngRowid) == 0 && pPk == uintptr(0) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Copy), regOldRowid, regNewRowid)
		}
	}
	/* Populate the array of registers beginning at regNew with the new
	 ** row data. This array is used to check constants, create the new
	 ** table and index records, and as the values for any new.* references
	 ** made by triggers.
	 **
	 ** If there are one or more BEFORE triggers, then do not populate the
	 ** registers associated with columns that are (a) not modified by
	 ** this UPDATE statement and (b) not accessed by new.* references. The
	 ** values for registers not modified by the UPDATE must be reloaded from
	 ** the database after the BEFORE triggers are fired anyway (as the trigger
	 ** may have modified them). So not loading those that are not going to
	 ** be used eliminates some redundant opcodes.
	 */
	newmask = libc.Int32FromUint32(_sqlite3TriggerColmask(tls, pParse, pTrigger, pChanges, int32(1), int32(TRIGGER_BEFORE), pTab, onError))
	i = 0
	k = regNew
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
			break
		}
		if i == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, k)
		} else {
			if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					k = k - 1
				}
			} else {
				j = **(**int32)(__ccgo_up(aXRef + uintptr(i)*4))
				if j >= 0 {
					if nChangeFrom != 0 {
						if isView != 0 {
							v1 = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
						} else {
							v1 = int32(nPk)
						}
						nOff = v1
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, nOff+j, k)
					} else {
						_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(j)*32))).FpExpr, k)
					}
				} else {
					if 0 == **(**int32)(__ccgo_up(bp + 72))&int32(TRIGGER_BEFORE) || i > int32(31) || libc.Uint32FromInt32(newmask)&(libc.Uint32FromInt32(1)<<i) != 0 {
						/* This branch loads the value of a column that will not be changed
						 ** into a register. This is done if there are no BEFORE triggers, or
						 ** if there are one or more BEFORE triggers that use this value via
						 ** a new.* reference in a trigger program.
						 */
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
						bFinishSeek = 0
					} else {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, k)
					}
				}
			}
		}
		goto _44
	_44:
		;
		i = i + 1
		k = k + 1
	}
	if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
		_sqlite3ComputeGeneratedColumns(tls, pParse, regNew, pTab)
	}
	/* Fire any BEFORE UPDATE triggers. This happens before constraints are
	 ** verified. One could argue that this is wrong.
	 */
	if **(**int32)(__ccgo_up(bp + 72))&int32(TRIGGER_BEFORE) != 0 {
		_sqlite3TableAffinity(tls, v, pTab, regNew)
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_UPDATE), pChanges, int32(TRIGGER_BEFORE), pTab, regOldRowid, onError, labelContinue)
		if !(isView != 0) {
			/* The row-trigger may have deleted the row being updated. In this
			 ** case, jump to the next row. No updates or AFTER triggers are
			 ** required. This behavior - what happens when the row being updated
			 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
			 ** documentation.
			 */
			if pPk != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, regKey, nKey)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
			}
			/* After-BEFORE-trigger-reload-loop:
			 ** If it did not delete it, the BEFORE trigger may still have modified
			 ** some of the columns of the row being updated. Load the values for
			 ** all columns not modified by the update statement into their registers
			 ** in case this has happened. Only unmodified columns are reloaded.
			 ** The values computed for modified columns use the values before the
			 ** BEFORE trigger runs.  See test case trigger1-18.0 (added 2018-04-26)
			 ** for an example.
			 */
			i = 0
			k = regNew
			for {
				if !(i < int32((*TTable)(unsafe.Pointer(pTab)).FnCol)) {
					break
				}
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
					if libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
						k = k - 1
					}
				} else {
					if **(**int32)(__ccgo_up(aXRef + uintptr(i)*4)) < 0 && i != int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) {
						_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
					}
				}
				goto _46
			_46:
				;
				i = i + 1
				k = k + 1
			}
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasGenerated) != 0 {
				_sqlite3ComputeGeneratedColumns(tls, pParse, regNew, pTab)
			}
		}
	}
	if !(isView != 0) {
		/* Do constraint checks. */
		_sqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, iDataCur, iIdxCur, regNewRowid, regOldRowid, chngKey, libc.Uint8FromInt32(onError), labelContinue, bp+88, aXRef, uintptr(0))
		/* If REPLACE conflict handling may have been used, or if the PK of the
		 ** row is changing, then the GenerateConstraintChecks() above may have
		 ** moved cursor iDataCur. Reseek it. */
		if **(**int32)(__ccgo_up(bp + 88)) != 0 || chngKey != 0 {
			if pPk != 0 {
				_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iDataCur, labelContinue, regKey, nKey)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDataCur, labelContinue, regOldRowid)
			}
		}
		/* Do FK constraint checks. */
		if hasFK != 0 {
			_sqlite3FkCheck(tls, pParse, pTab, regOldRowid, 0, aXRef, libc.Int32FromUint8(chngKey))
		}
		/* Delete the index entries associated with the current record.  */
		_sqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, aRegIdx, -int32(1))
		/* We must run the OP_FinishSeek opcode to resolve a prior
		 ** OP_DeferredSeek if there is any possibility that there have been
		 ** no OP_Column opcodes since the OP_DeferredSeek was issued.  But
		 ** we want to avoid the OP_FinishSeek if possible, as running it
		 ** costs CPU cycles. */
		if bFinishSeek != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_FinishSeek), iDataCur)
		}
		/* If changing the rowid value, or if there are foreign key constraints
		 ** to process, delete the old record. Otherwise, add a noop OP_Delete
		 ** to invoke the pre-update hook.
		 **
		 ** That (regNew==regnewRowid+1) is true is also important for the
		 ** pre-update hook. If the caller invokes preupdate_new(), the returned
		 ** value is copied from memory cell (regNewRowid+1+iCol), where iCol
		 ** is the column index supplied by the user.
		 */
		if hasFK > int32(1) || chngKey != 0 {
			v1 = 0
		} else {
			v1 = int32(OPFLAG_ISNOOP)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Delete), iDataCur, int32(OPFLAG_ISUPDATE)|v1, regNewRowid)
		if eOnePass == int32(ONEPASS_MULTI) {
			_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
		}
		if !((*TParse)(unsafe.Pointer(pParse)).Fnested != 0) {
			_sqlite3VdbeAppendP4(tls, v, pTab, -int32(5))
		}
		if hasFK != 0 {
			_sqlite3FkCheck(tls, pParse, pTab, 0, regNewRowid, aXRef, libc.Int32FromUint8(chngKey))
		}
		/* Insert the new index entries and the new record. */
		if eOnePass == int32(ONEPASS_MULTI) {
			v1 = int32(OPFLAG_SAVEPOSITION)
		} else {
			v1 = 0
		}
		_sqlite3CompleteInsertion(tls, pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx, int32(OPFLAG_ISUPDATE)|v1, 0, 0)
		/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
		 ** handle rows (possibly in other tables) that refer via a foreign key
		 ** to the row just updated. */
		if hasFK != 0 {
			_sqlite3FkActions(tls, pParse, pTab, pChanges, regOldRowid, aXRef, libc.Int32FromUint8(chngKey))
		}
	}
	/* Increment the row counter
	 */
	if regRowCount != 0 {
		_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), regRowCount, int32(1))
	}
	if pTrigger != 0 {
		_sqlite3CodeRowTrigger(tls, pParse, pTrigger, int32(TK_UPDATE), pChanges, int32(TRIGGER_AFTER), pTab, regOldRowid, onError, labelContinue)
	}
	/* Repeat the above with the next record to be updated, until
	 ** all record selected by the WHERE clause have been updated.
	 */
	if eOnePass == int32(ONEPASS_SINGLE) {
		/* Nothing to do at end-of-loop for a single-pass */
	} else {
		if eOnePass == int32(ONEPASS_MULTI) {
			_sqlite3VdbeResolveLabel(tls, v, labelContinue)
			_sqlite3WhereEnd(tls, pWInfo)
		} else {
			_sqlite3VdbeResolveLabel(tls, v, labelContinue)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iEph, addrTop)
		}
	}
	_sqlite3VdbeResolveLabel(tls, v, labelBreak)
	/* Update the sqlite_sequence table by storing the content of the
	 ** maximum rowid counter values recorded while inserting into
	 ** autoincrement tables.
	 */
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) && pUpsert == uintptr(0) {
		_sqlite3AutoincrementEnd(tls, pParse)
	}
	/*
	 ** Return the number of rows that were changed, if we are tracking
	 ** that information.
	 */
	if regRowCount != 0 {
		_sqlite3CodeChangeCount(tls, v, regRowCount, __ccgo_ts+22643)
	}
	goto update_cleanup
update_cleanup:
	;
	_sqlite3AuthContextPop(tls, bp)
	_sqlite3DbFree(tls, db, aXRef) /* Also frees aRegIdx[] and aToOpen[] */
	_sqlite3SrcListDelete(tls, db, pTabList)
	_sqlite3ExprListDelete(tls, db, pChanges)
	_sqlite3ExprDelete(tls, db, pWhere)
	return
}

/* Make sure "isView" and other macros defined above are undefined. Otherwise
** they may interfere with compilation of other functions in this file
** (or in another file, if this file becomes part of the amalgamation).  */

// C documentation
//
//	/*
//	** zIn is a UTF-16 encoded unicode string at least nByte bytes long.
//	** Return the number of bytes in the first nChar unicode characters
//	** in pZ.  nChar must be non-negative.  Surrogate pairs count as a single
//	** character.
//	*/
func _sqlite3Utf16ByteLen(tls *libc.TLS, zIn uintptr, nByte int32, nChar int32) (r int32) {
	var c, n int32
	var z, zEnd uintptr
	_, _, _, _ = c, n, z, zEnd
	z = zIn
	zEnd = z + uintptr(nByte-int32(1))
	n = 0
	if false {
		z = z + 1
	}
	for n < nChar && z <= zEnd {
		c = libc.Int32FromUint8(**(**uint8)(__ccgo_up(z)))
		z = z + uintptr(2)
		if c >= int32(0xd8) && c < int32(0xdc) && z <= zEnd && libc.Int32FromUint8(**(**uint8)(__ccgo_up(z))) >= int32(0xdc) && libc.Int32FromUint8(**(**uint8)(__ccgo_up(z))) < int32(0xe0) {
			z = z + uintptr(2)
		}
		n = n + 1
	}
	return int32(int64(z)-int64(zIn)) - libc.BoolInt32(false)
}

// C documentation
//
//	/*
//	** Set a flag in the vdbe to update the change counter when it is finalised
//	** or reset.
//	*/
func _sqlite3VdbeCountChanges(tls *libc.TLS, v uintptr) {
	libc.SetBitFieldPtr16Uint32(v+200, libc.Uint32FromInt32(1), 11, 0x800)
}

// C documentation
//
//	/*
//	** Execute as much of a VDBE program as we can.
//	** This is the core of sqlite3_step().
//	*/
func _sqlite3VdbeExec(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(1024)
	defer tls.Free(1024)
	var aCol, aMem, aOffset, aOp, aPermute, aRoot, apArg, apArg1, db, pArgc, pBt, pBt1, pBt2, pBt3, pC, pC1, pC10, pC11, pC12, pC13, pC14, pC15, pC16, pC17, pC18, pC19, pC2, pC20, pC21, pC22, pC23, pC24, pC25, pC26, pC27, pC28, pC29, pC3, pC30, pC31, pC32, pC33, pC34, pC4, pC5, pC6, pC7, pC8, pC9, pCaller, pColl, pCrsr, pCrsr1, pCrsr2, pCrsr3, pCrsr4, pCrsr5, pCrsr6, pCrsr7, pCrsr8, pCtx, pCtx1, pCtx2, pCur, pCur1, pCur2, pCur3, pCur4, pCur5, pCur6, pCx, pCx1, pCx2, pCx3, pData, pData0, pDb, pDb1, pDb2, pDb3, pDest, pDest1, pDest2, pEnd, pFrame, pFrame1, pFrame2, pFrame3, pFrame4, pIdxKey, pIn, pIn1, pIn2, pIn3, pKey, pKeyInfo, pKeyInfo1, pKeyInfo2, pLast, pMem, pMem1, pMem2, pMem3, pMem4, pModule, pModule1, pModule2, pModule3, pModule4, pModule5, pModule6, pName, pNew, pOp, pOrig, pOut, pPager, pProgram, pQuery, pRec, pReg, pRhs, pRt, pSavepoint, pSrc, pTab, pTab1, pTab2, pTab3, pTabCur, pTmp, pVCur1, pVTab, pVar, pVtab, pVtab1, pVtab2, pVtab3, pVtab4, pVtab5, pVtab6, pVtab7, pX, pX1, pnErr, t1, z1, z2, z3, zAffinity, zAffinity1, zData, zDb, zDb1, zEndHdr, zErr, zFilename, zHdr, zHdr1, zName, zPayload, zSchema, zSql, zTab, zTrace, v191, v194 uintptr
	var affinity uint8
	var alreadyExists, bRev, c, c1, c2, cnt, cnt1, desiredAutoCommit, eNew, eOld, eqOnly, exists, i, i1, i2, i4, i5, i6, i7, i8, i9, iCompare, iCookie, iDb, iDb1, iDb2, iDb3, iQuery, iRollback, iSavepoint, iSet, ii, ii1, isLegacy, isSchemaChange, isTransaction, len1, n, n1, n2, n4, nArg, nArg1, nCol, nField, nField1, nField2, nHdr, nKeyCol, nMem, nName, nRoot, nStep, nVarint, oc, opflags, p1, p11, p12, p13, p2, p21, pcDest, pcx, rc, res, res11, res13, res14, res21, savedAnalysisLimit, seekResult, v11, v21, wrFlag, v190, v193 int32
	var colCacheCtr, iAddr, iMap, iPrior, idx, len11, n3, p22, p23, serialType, serial_type, v215, v216 Tu32
	var encoding, isWriteLock, mTrace, op, p5, resetSchemaOnFault, vtabOnConflict, v227 Tu8
	var flags1, flags11, flags2, flags3, flags31, newType, nullFlag, type1, type2, typeMask, v192 Tu16
	var h, h1, iKey1, nAlloc, nData, nProgressLimit, nVmStep, offset64, uu Tu64
	var i3, iA, iB1, iKey, iKey2, nByte, nByte1, nByte2, nCellKey, nZero, sz, v256 Ti64
	var newMax, v213 uint32
	var rA, rB float64
	var xAuth Tsqlite3_xauth
	var v206 int64
	var v217 bool
	var _ /* aRes at bp+760 */ [3]int32
	var _ /* iA at bp+8 */ Ti64
	var _ /* iB at bp+0 */ Ti64
	var _ /* iMeta at bp+104 */ int32
	var _ /* iMeta at bp+108 */ int32
	var _ /* iMoved at bp+608 */ int32
	var _ /* initData at bp+640 */ TInitData
	var _ /* m at bp+552 */ TMem
	var _ /* nChange at bp+616 */ Ti64
	var _ /* nEntry at bp+96 */ Ti64
	var _ /* nErr at bp+680 */ int32
	var _ /* nullFunc at bp+896 */ TFuncDef
	var _ /* pVCur at bp+832 */ uintptr
	var _ /* pgno at bp+624 */ TPgno
	var _ /* r at bp+120 */ TUnpackedRecord
	var _ /* r at bp+168 */ TUnpackedRecord
	var _ /* r at bp+208 */ TUnpackedRecord
	var _ /* r at bp+464 */ TUnpackedRecord
	var _ /* r at bp+512 */ TUnpackedRecord
	var _ /* r at bp+704 */ TUnpackedRecord
	var _ /* res at bp+112 */ int32
	var _ /* res at bp+160 */ int32
	var _ /* res at bp+248 */ int32
	var _ /* res at bp+320 */ int32
	var _ /* res at bp+376 */ int32
	var _ /* res at bp+392 */ int32
	var _ /* res at bp+396 */ int32
	var _ /* res at bp+400 */ int32
	var _ /* res at bp+404 */ int32
	var _ /* res at bp+456 */ int32
	var _ /* res at bp+696 */ int32
	var _ /* rowid at bp+504 */ Ti64
	var _ /* rowid at bp+968 */ Tsqlite_int64
	var _ /* sContext at bp+848 */ Tsqlite3_context
	var _ /* sMem at bp+24 */ TMem
	var _ /* sMem at bp+776 */ TMem
	var _ /* t at bp+80 */ Tu32
	var _ /* uA at bp+16 */ Tu64
	var _ /* v at bp+312 */ Ti64
	var _ /* v at bp+384 */ Ti64
	var _ /* v at bp+88 */ Tu64
	var _ /* val at bp+744 */ Ti64
	var _ /* x at bp+256 */ TMem
	var _ /* x at bp+328 */ TBtreePayload
	var _ /* x at bp+408 */ TBtreePayload
	var _ /* x at bp+752 */ Ti64
	var _ /* z at bp+688 */ uintptr
	var _ /* zErr at bp+632 */ uintptr
	var _ /* zErr at bp+840 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aCol, aMem, aOffset, aOp, aPermute, aRoot, affinity, alreadyExists, apArg, apArg1, bRev, c, c1, c2, cnt, cnt1, colCacheCtr, db, desiredAutoCommit, eNew, eOld, encoding, eqOnly, exists, flags1, flags11, flags2, flags3, flags31, h, h1, i, i1, i2, i3, i4, i5, i6, i7, i8, i9, iA, iAddr, iB1, iCompare, iCookie, iDb, iDb1, iDb2, iDb3, iKey, iKey1, iKey2, iMap, iPrior, iQuery, iRollback, iSavepoint, iSet, idx, ii, ii1, isLegacy, isSchemaChange, isTransaction, isWriteLock, len1, len11, mTrace, n, n1, n2, n3, n4, nAlloc, nArg, nArg1, nByte, nByte1, nByte2, nCellKey, nCol, nData, nField, nField1, nField2, nHdr, nKeyCol, nMem, nName, nProgressLimit, nRoot, nStep, nVarint, nVmStep, nZero, newMax, newType, nullFlag, oc, offset64, op, opflags, p1, p11, p12, p13, p2, p21, p22, p23, p5, pArgc, pBt, pBt1, pBt2, pBt3, pC, pC1, pC10, pC11, pC12, pC13, pC14, pC15, pC16, pC17, pC18, pC19, pC2, pC20, pC21, pC22, pC23, pC24, pC25, pC26, pC27, pC28, pC29, pC3, pC30, pC31, pC32, pC33, pC34, pC4, pC5, pC6, pC7, pC8, pC9, pCaller, pColl, pCrsr, pCrsr1, pCrsr2, pCrsr3, pCrsr4, pCrsr5, pCrsr6, pCrsr7, pCrsr8, pCtx, pCtx1, pCtx2, pCur, pCur1, pCur2, pCur3, pCur4, pCur5, pCur6, pCx, pCx1, pCx2, pCx3, pData, pData0, pDb, pDb1, pDb2, pDb3, pDest, pDest1, pDest2, pEnd, pFrame, pFrame1, pFrame2, pFrame3, pFrame4, pIdxKey, pIn, pIn1, pIn2, pIn3, pKey, pKeyInfo, pKeyInfo1, pKeyInfo2, pLast, pMem, pMem1, pMem2, pMem3, pMem4, pModule, pModule1, pModule2, pModule3, pModule4, pModule5, pModule6, pName, pNew, pOp, pOrig, pOut, pPager, pProgram, pQuery, pRec, pReg, pRhs, pRt, pSavepoint, pSrc, pTab, pTab1, pTab2, pTab3, pTabCur, pTmp, pVCur1, pVTab, pVar, pVtab, pVtab1, pVtab2, pVtab3, pVtab4, pVtab5, pVtab6, pVtab7, pX, pX1, pcDest, pcx, pnErr, rA, rB, rc, res, res11, res13, res14, res21, resetSchemaOnFault, savedAnalysisLimit, seekResult, serialType, serial_type, sz, t1, type1, type2, typeMask, uu, v11, v21, vtabOnConflict, wrFlag, xAuth, z1, z2, z3, zAffinity, zAffinity1, zData, zDb, zDb1, zEndHdr, zErr, zFilename, zHdr, zHdr1, zName, zPayload, zSchema, zSql, zTab, zTrace, v190, v191, v192, v193, v194, v206, v213, v215, v216, v217, v227, v256
	aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp          /* Copy of p->aOp */
	pOp = aOp                                       /* Current operation */
	rc = SQLITE_OK                                  /* Value to return */
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb            /* The database */
	resetSchemaOnFault = uint8(0)                   /* Reset schema after an error if positive */
	encoding = (*Tsqlite3)(unsafe.Pointer(db)).Fenc /* The database encoding */
	iCompare = 0                                    /* Result of last comparison */
	nVmStep = uint64(0)                             /* Invoke xProgress() when nVmStep reaches this */
	aMem = (*TVdbe)(unsafe.Pointer(p)).FaMem        /* Copy of p->aMem */
	pIn1 = uintptr(0)                               /* 1st input operand */
	pIn2 = uintptr(0)                               /* 2nd input operand */
	pIn3 = uintptr(0)                               /* 3rd input operand */
	pOut = uintptr(0)                               /* Output operand */
	colCacheCtr = uint32(0)                         /* Column cache counter */
	/*** INSERT STACK UNION HERE ***/
	/* sqlite3_step() verifies this */
	if (*TVdbe)(unsafe.Pointer(p)).FlockMask != uint32(0) {
		_sqlite3VdbeEnter(tls, p)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != 0 {
		iPrior = **(**Tu32)(__ccgo_up(p + 212 + 4*4))
		nProgressLimit = uint64((*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps - iPrior%(*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps)
	} else {
		nProgressLimit = libc.Uint64FromUint32(0xffffffff) | libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)
	}
	if (*TVdbe)(unsafe.Pointer(p)).Frc == int32(SQLITE_NOMEM) {
		/* This happens if a malloc() inside a call to sqlite3_column_text() or
		 ** sqlite3_column_text16() failed.  */
		goto no_mem
	}
	(*TVdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
	(*TVdbe)(unsafe.Pointer(p)).FiCurrentTime = 0
	(*Tsqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	if libc.AtomicLoadNInt32(db+432, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
		goto abort_due_to_interrupt
	}
	pOp = aOp + uintptr((*TVdbe)(unsafe.Pointer(p)).Fpc)*24
	for {
		if !(int32(1) != 0) {
			break
		}
		/* Errors are detected by individual opcodes, with an immediate
		 ** jumps to abort_due_to_error. */
		nVmStep = nVmStep + 1
		/* Only allow tracing if SQLITE_DEBUG is defined.
		 */
		/* Check to see if we need to simulate an interrupt.  This only happens
		 ** if we have a special test build.
		 */
		/* Sanity checking on other operands */
		switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
		case int32(OP_Goto):
			goto _2
		case int32(OP_Gosub):
			goto _3
		case int32(OP_Return):
			goto _4
		case int32(OP_InitCoroutine):
			goto _5
		case int32(OP_EndCoroutine):
			goto _6
		case int32(OP_Yield):
			goto _7
		case int32(OP_HaltIfNull):
			goto _8
		case int32(OP_Halt):
			goto _9
		case int32(OP_Integer):
			goto _10
		case int32(OP_Int64):
			goto _11
		case int32(OP_Real):
			goto _12
		case int32(OP_String8):
			goto _13
		case int32(OP_String):
			goto _14
		case int32(OP_Null):
			goto _15
		case int32(OP_BeginSubrtn):
			goto _16
		case int32(OP_SoftNull):
			goto _17
		case int32(OP_Blob):
			goto _18
		case int32(OP_Variable):
			goto _19
		case int32(OP_Move):
			goto _20
		case int32(OP_Copy):
			goto _21
		case int32(OP_SCopy):
			goto _22
		case int32(OP_IntCopy):
			goto _23
		case int32(OP_FkCheck):
			goto _24
		case int32(OP_ResultRow):
			goto _25
		case int32(OP_Concat):
			goto _26
		case int32(OP_Remainder):
			goto _27
		case int32(OP_Divide):
			goto _28
		case int32(OP_Multiply):
			goto _29
		case int32(OP_Subtract):
			goto _30
		case int32(OP_Add):
			goto _31
		case int32(OP_CollSeq):
			goto _32
		case int32(OP_ShiftRight):
			goto _33
		case int32(OP_ShiftLeft):
			goto _34
		case int32(OP_BitOr):
			goto _35
		case int32(OP_BitAnd):
			goto _36
		case int32(OP_AddImm):
			goto _37
		case int32(OP_MustBeInt):
			goto _38
		case int32(OP_RealAffinity):
			goto _39
		case int32(OP_Cast):
			goto _40
		case int32(OP_Ge):
			goto _41
		case int32(OP_Gt):
			goto _42
		case int32(OP_Le):
			goto _43
		case int32(OP_Lt):
			goto _44
		case int32(OP_Ne):
			goto _45
		case int32(OP_Eq):
			goto _46
		case int32(OP_ElseEq):
			goto _47
		case int32(OP_Permutation):
			goto _48
		case int32(OP_Compare):
			goto _49
		case int32(OP_Jump):
			goto _50
		case int32(OP_Or):
			goto _51
		case int32(OP_And):
			goto _52
		case int32(OP_IsTrue):
			goto _53
		case int32(OP_Not):
			goto _54
		case int32(OP_BitNot):
			goto _55
		case int32(OP_Once):
			goto _56
		case int32(OP_If):
			goto _57
		case int32(OP_IfNot):
			goto _58
		case int32(OP_IsNull):
			goto _59
		case int32(OP_IsType):
			goto _60
		case int32(OP_ZeroOrNull):
			goto _61
		case int32(OP_NotNull):
			goto _62
		case int32(OP_IfNullRow):
			goto _63
		case int32(OP_Offset):
			goto _64
		case int32(OP_Column):
			goto _65
		case int32(OP_TypeCheck):
			goto _66
		case int32(OP_Affinity):
			goto _67
		case int32(OP_MakeRecord):
			goto _68
		case int32(OP_Count):
			goto _69
		case OP_Savepoint:
			goto _70
		case int32(OP_AutoCommit):
			goto _71
		case int32(OP_Transaction):
			goto _72
		case int32(OP_ReadCookie):
			goto _73
		case int32(OP_SetCookie):
			goto _74
		case int32(OP_OpenWrite):
			goto _75
		case int32(OP_OpenRead):
			goto _76
		case int32(OP_ReopenIdx):
			goto _77
		case int32(OP_OpenDup):
			goto _78
		case int32(OP_OpenEphemeral):
			goto _79
		case int32(OP_OpenAutoindex):
			goto _80
		case int32(OP_SorterOpen):
			goto _81
		case int32(OP_SequenceTest):
			goto _82
		case int32(OP_OpenPseudo):
			goto _83
		case int32(OP_Close):
			goto _84
		case int32(OP_SeekGT):
			goto _85
		case int32(OP_SeekGE):
			goto _86
		case int32(OP_SeekLE):
			goto _87
		case int32(OP_SeekLT):
			goto _88
		case int32(OP_SeekScan):
			goto _89
		case int32(OP_SeekHit):
			goto _90
		case int32(OP_IfNotOpen):
			goto _91
		case int32(OP_IfNoHope):
			goto _92
		case int32(OP_Found):
			goto _93
		case int32(OP_NotFound):
			goto _94
		case int32(OP_NoConflict):
			goto _95
		case int32(OP_NotExists):
			goto _96
		case int32(OP_SeekRowid):
			goto _97
		case int32(OP_Sequence):
			goto _98
		case int32(OP_NewRowid):
			goto _99
		case int32(OP_Insert):
			goto _100
		case int32(OP_RowCell):
			goto _101
		case int32(OP_Delete):
			goto _102
		case int32(OP_ResetCount):
			goto _103
		case int32(OP_SorterCompare):
			goto _104
		case int32(OP_SorterData):
			goto _105
		case int32(OP_RowData):
			goto _106
		case int32(OP_Rowid):
			goto _107
		case int32(OP_NullRow):
			goto _108
		case int32(OP_Last):
			goto _109
		case int32(OP_SeekEnd):
			goto _110
		case int32(OP_IfSizeBetween):
			goto _111
		case int32(OP_Sort):
			goto _112
		case int32(OP_SorterSort):
			goto _113
		case int32(OP_Rewind):
			goto _114
		case int32(OP_IfEmpty):
			goto _115
		case int32(OP_Prev):
			goto _116
		case int32(OP_Next):
			goto _117
		case int32(OP_SorterNext):
			goto _118
		case int32(OP_IdxInsert):
			goto _119
		case int32(OP_SorterInsert):
			goto _120
		case int32(OP_IdxDelete):
			goto _121
		case int32(OP_IdxRowid):
			goto _122
		case int32(OP_DeferredSeek):
			goto _123
		case int32(OP_FinishSeek):
			goto _124
		case int32(OP_IdxGE):
			goto _125
		case int32(OP_IdxLT):
			goto _126
		case int32(OP_IdxGT):
			goto _127
		case int32(OP_IdxLE):
			goto _128
		case int32(OP_Destroy):
			goto _129
		case int32(OP_Clear):
			goto _130
		case int32(OP_ResetSorter):
			goto _131
		case int32(OP_CreateBtree):
			goto _132
		case int32(OP_SqlExec):
			goto _133
		case int32(OP_ParseSchema):
			goto _134
		case int32(OP_LoadAnalysis):
			goto _135
		case int32(OP_DropTable):
			goto _136
		case int32(OP_DropIndex):
			goto _137
		case int32(OP_DropTrigger):
			goto _138
		case int32(OP_IntegrityCk):
			goto _139
		case int32(OP_IFindKey):
			goto _140
		case int32(OP_RowSetAdd):
			goto _141
		case int32(OP_RowSetRead):
			goto _142
		case int32(OP_RowSetTest):
			goto _143
		case int32(OP_Program):
			goto _144
		case int32(OP_Param):
			goto _145
		case int32(OP_FkCounter):
			goto _146
		case int32(OP_FkIfZero):
			goto _147
		case int32(OP_MemMax):
			goto _148
		case int32(OP_IfPos):
			goto _149
		case int32(OP_OffsetLimit):
			goto _150
		case int32(OP_IfNotZero):
			goto _151
		case int32(OP_DecrJumpZero):
			goto _152
		case int32(OP_AggStep):
			goto _153
		case int32(OP_AggInverse):
			goto _154
		case int32(OP_AggStep1):
			goto _155
		case int32(OP_AggFinal):
			goto _156
		case int32(OP_AggValue):
			goto _157
		case int32(OP_Checkpoint):
			goto _158
		case int32(OP_JournalMode):
			goto _159
		case int32(OP_Vacuum):
			goto _160
		case int32(OP_IncrVacuum):
			goto _161
		case int32(OP_Expire):
			goto _162
		case int32(OP_CursorLock):
			goto _163
		case int32(OP_CursorUnlock):
			goto _164
		case int32(OP_TableLock):
			goto _165
		case int32(OP_VBegin):
			goto _166
		case int32(OP_VCreate):
			goto _167
		case int32(OP_VDestroy):
			goto _168
		case int32(OP_VOpen):
			goto _169
		case int32(OP_VCheck):
			goto _170
		case int32(OP_VInitIn):
			goto _171
		case int32(OP_VFilter):
			goto _172
		case int32(OP_VColumn):
			goto _173
		case int32(OP_VNext):
			goto _174
		case int32(OP_VRename):
			goto _175
		case int32(OP_VUpdate):
			goto _176
		case int32(OP_Pagecount):
			goto _177
		case int32(OP_MaxPgcnt):
			goto _178
		case int32(OP_Function):
			goto _179
		case int32(OP_PureFunc):
			goto _180
		case int32(OP_ClrSubtype):
			goto _181
		case int32(OP_GetSubtype):
			goto _182
		case int32(OP_SetSubtype):
			goto _183
		case int32(OP_FilterAdd):
			goto _184
		case int32(OP_Filter):
			goto _185
		case int32(OP_Init):
			goto _186
		case int32(OP_Trace):
			goto _187
		default:
			goto _188
		}
		goto _189
		/*****************************************************************************
		 ** What follows is a massive switch statement where each case implements a
		 ** separate instruction in the virtual machine.  If we follow the usual
		 ** indentation conventions, each case should be indented by 6 spaces.  But
		 ** that is a lot of wasted space on the left margin.  So the code within
		 ** the switch statement will break with convention and be flush-left. Another
		 ** big comment (similar to this one) will mark the point in the code where
		 ** we transition back to normal indentation.
		 **
		 ** The formatting of each case is important.  The makefile for SQLite
		 ** generates two C files "opcodes.h" and "opcodes.c" by scanning this
		 ** file looking for lines that begin with "case OP_".  The opcodes.h files
		 ** will be filled with #defines that give unique integer values to each
		 ** opcode and the opcodes.c file is filled with an array of strings where
		 ** each string is the symbolic name for the corresponding opcode.  If the
		 ** case statement is followed by a comment of the form "/# same as ... #/"
		 ** that comment is used to determine the particular value of the opcode.
		 **
		 ** Other keywords in the comment that follows each case are used to
		 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[].
		 ** Keywords include: in1, in2, in3, out2, out3.  See
		 ** the mkopcodeh.awk script for additional information.
		 **
		 ** Documentation about VDBE opcodes is generated by scanning this file
		 ** for lines of that contain "Opcode:".  That line and all subsequent
		 ** comment lines are used in the generation of the opcode.html documentation
		 ** file.
		 **
		 ** SUMMARY:
		 **
		 **     Formatting is important to scripts that scan this file.
		 **     Do not deviate from the formatting style currently in use.
		 **
		 *****************************************************************************/
		/* Opcode:  Goto * P2 * * *
		 **
		 ** An unconditional jump to address P2.
		 ** The next instruction executed will be
		 ** the one at index P2 from the beginning of
		 ** the program.
		 **
		 ** The P1 parameter is not actually used by this opcode.  However, it
		 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell
		 ** that this Goto is the bottom of a loop and that the lines from P2 down
		 ** to the current line should be indented for EXPLAIN output.
		 */
	_2:
		; /* jump */
		goto jump_to_p2_and_check_for_interrupt
	jump_to_p2_and_check_for_interrupt:
		;
		pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*24
		/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
		 ** OP_VNext, or OP_SorterNext) all jump here upon
		 ** completion.  Check to see if sqlite3_interrupt() has been called
		 ** or if the progress callback needs to be invoked.
		 **
		 ** This code uses unstructured "goto" statements and does not look clean.
		 ** But that is not due to sloppy coding habits. The code is written this
		 ** way for performance, to avoid having to run the interrupt and progress
		 ** checks on every opcode.  This helps sqlite3_step() to run about 1.5%
		 ** faster according to "valgrind --tool=cachegrind" */
		goto check_for_interrupt
	check_for_interrupt:
		;
		if libc.AtomicLoadNInt32(db+432, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
			goto abort_due_to_interrupt
		}
		/* Call the progress callback if it is configured and the required number
		 ** of VDBE ops have been executed (either since this invocation of
		 ** sqlite3VdbeExec() or since last time the progress callback was called).
		 ** If the progress callback returns non-zero, exit the virtual machine with
		 ** a return code SQLITE_ABORT.
		 */
		for nVmStep >= nProgressLimit && (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != uintptr(0) {
			nProgressLimit = nProgressLimit + uint64((*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps)
			if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxProgress})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
				nProgressLimit = libc.Uint64FromUint32(0xffffffff) | libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)
				rc = int32(SQLITE_INTERRUPT)
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode:  Gosub P1 P2 * * *
		 **
		 ** Write the current address onto register P1
		 ** and then jump to address P2.
		 */
	_3:
		; /* jump */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = uint16(MEM_Int)
		*(*Ti64)(unsafe.Pointer(pIn1)) = int64(int32((int64(pOp) - int64(aOp)) / 24))
		goto jump_to_p2_and_check_for_interrupt
		/* Opcode:  Return P1 P2 P3 * *
		 **
		 ** Jump to the address stored in register P1.  If P1 is a return address
		 ** register, then this accomplishes a return from a subroutine.
		 **
		 ** If P3 is 1, then the jump is only taken if register P1 holds an integer
		 ** values, otherwise execution falls through to the next opcode, and the
		 ** OP_Return becomes a no-op. If P3 is 0, then register P1 must hold an
		 ** integer or else an assert() is raised.  P3 should be set to 1 when
		 ** this opcode is used in combination with OP_BeginSubrtn, and set to 0
		 ** otherwise.
		 **
		 ** The value in register P1 is unchanged by this opcode.
		 **
		 ** P2 is not used by the byte-code engine.  However, if P2 is positive
		 ** and also less than the current address, then the "EXPLAIN" output
		 ** formatter in the CLI will indent all opcodes from the P2 opcode up
		 ** to be not including the current Return.   P2 should be the first opcode
		 ** in the subroutine from which this opcode is returning.  Thus the P2
		 ** value is a byte-code indentation hint.  See tag-20220407a in
		 ** wherecode.c and shell.c.
		 */
	_4:
		; /* in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			}
			pOp = aOp + uintptr(*(*Ti64)(unsafe.Pointer(pIn1)))*24
		} else {
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			}
		}
		goto _189
		/* Opcode: InitCoroutine P1 P2 P3 * *
		 **
		 ** Set up register P1 so that it will Yield to the coroutine
		 ** located at address P3.
		 **
		 ** If P2!=0 then the coroutine implementation immediately follows
		 ** this opcode.  So jump over the coroutine implementation to
		 ** address P2.
		 **
		 ** See also: EndCoroutine
		 */
	_5:
		; /* jump0 */
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		*(*Ti64)(unsafe.Pointer(pOut)) = int64((*TOp)(unsafe.Pointer(pOp)).Fp3 - int32(1))
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
			goto _189
		}
		/* Most jump operations do a goto to this spot in order to update
		 ** the pOp pointer. */
		goto jump_to_p2
	jump_to_p2:
		;
		/* There are never any jumps to instruction 0 */
		/* Jumps must be in range */
		pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*24
		goto _189
		/* Opcode:  EndCoroutine P1 * * * *
		 **
		 ** The instruction at the address in register P1 is a Yield.
		 ** Jump to the P2 parameter of that Yield.
		 ** After the jump, the value register P1 is left with a value
		 ** such that subsequent OP_Yields go back to the this same
		 ** OP_EndCoroutine instruction.
		 **
		 ** See also: InitCoroutine
		 */
	_6:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pCaller = aOp + uintptr(*(*Ti64)(unsafe.Pointer(pIn1)))*24
		*(*Ti64)(unsafe.Pointer(pIn1)) = int64(int32((int64(pOp)-int64((*TVdbe)(unsafe.Pointer(p)).FaOp))/24) - int32(1))
		pOp = aOp + uintptr((*TVdbeOp)(unsafe.Pointer(pCaller)).Fp2-int32(1))*24
		goto _189
		/* Opcode:  Yield P1 P2 * * *
		 **
		 ** Swap the program counter with the value in register P1.  This
		 ** has the effect of yielding to a coroutine.
		 **
		 ** If the coroutine that is launched by this instruction ends with
		 ** Yield or Return then continue to the next instruction.  But if
		 ** the coroutine launched by this instruction ends with
		 ** EndCoroutine, then jump to P2 rather than continuing with the
		 ** next instruction.
		 **
		 ** See also: InitCoroutine
		 */
	_7:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = uint16(MEM_Int)
		pcDest = int32(*(*Ti64)(unsafe.Pointer(pIn1)))
		*(*Ti64)(unsafe.Pointer(pIn1)) = int64(int32((int64(pOp) - int64(aOp)) / 24))
		pOp = aOp + uintptr(pcDest)*24
		goto _189
		/* Opcode:  HaltIfNull  P1 P2 P3 P4 P5
		 ** Synopsis: if r[P3]=null halt
		 **
		 ** Check the value in register P3.  If it is NULL then Halt using
		 ** parameter P1, P2, and P4 as if this were a Halt instruction.  If the
		 ** value in register P3 is not NULL, then this routine is a no-op.
		 ** The P5 parameter should be 1.
		 */
	_8:
		; /* in3 */
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn3)).Fflags)&int32(MEM_Null) == 0 {
			goto _189
		}
		/* Fall through into OP_Halt */
		/* Opcode:  Halt P1 P2 P3 P4 P5
		 **
		 ** Exit immediately.  All open cursors, etc are closed
		 ** automatically.
		 **
		 ** P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
		 ** or sqlite3_finalize().  For a normal halt, this should be SQLITE_OK (0).
		 ** For errors, it can be some other value.  If P1!=0 then P2 will determine
		 ** whether or not to rollback the current transaction.  Do not rollback
		 ** if P2==OE_Fail. Do the rollback if P2==OE_Rollback.  If P2==OE_Abort,
		 ** then back out all changes that have occurred during this execution of the
		 ** VDBE, but do not rollback the transaction.
		 **
		 ** If P3 is not zero and P4 is NULL, then P3 is a register that holds the
		 ** text of an error message.
		 **
		 ** If P3 is zero and P4 is not null then the error message string is held
		 ** in P4.
		 **
		 ** P5 is a value between 1 and 4, inclusive, then the P4 error message
		 ** string is modified as follows:
		 **
		 **    1:  NOT NULL constraint failed: P4
		 **    2:  UNIQUE constraint failed: P4
		 **    3:  CHECK constraint failed: P4
		 **    4:  FOREIGN KEY constraint failed: P4
		 **
		 ** If P3 is zero and P5 is not zero and P4 is NULL, then everything after
		 ** the ":" is omitted.
		 **
		 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
		 ** every program.  So a jump past the last instruction of the program
		 ** is the same as executing Halt.
		 */
	_9:
		;
		/* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
		 ** something is wrong with the code generator.  Raise an assertion in order
		 ** to bring this to the attention of fuzzers and other testing tools. */
		if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp1 == SQLITE_OK {
			/* Halt the sub-program. Return control to the parent frame. */
			pFrame = (*TVdbe)(unsafe.Pointer(p)).FpFrame
			(*TVdbe)(unsafe.Pointer(p)).FpFrame = (*TVdbeFrame)(unsafe.Pointer(pFrame)).FpParent
			(*TVdbe)(unsafe.Pointer(p)).FnFrame = (*TVdbe)(unsafe.Pointer(p)).FnFrame - 1
			_sqlite3VdbeSetChanges(tls, db, (*TVdbe)(unsafe.Pointer(p)).FnChange)
			pcx = _sqlite3VdbeFrameRestore(tls, pFrame)
			if (*TOp)(unsafe.Pointer(pOp)).Fp2 == int32(OE_Ignore) {
				/* Instruction pcx is the OP_Program that invoked the sub-program
				 ** currently being halted. If the p2 instruction of this OP_Halt
				 ** instruction is set to OE_Ignore, then the sub-program is throwing
				 ** an IGNORE exception. In this case jump to the address specified
				 ** as the p2 of the calling OP_Program.  */
				pcx = (**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(pcx)*24))).Fp2 - int32(1)
			}
			aOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
			aMem = (*TVdbe)(unsafe.Pointer(p)).FaMem
			pOp = aOp + uintptr(pcx)*24
			goto _189
		}
		(*TVdbe)(unsafe.Pointer(p)).Frc = (*TOp)(unsafe.Pointer(pOp)).Fp1
		(*TVdbe)(unsafe.Pointer(p)).FerrorAction = libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
		if (*TVdbe)(unsafe.Pointer(p)).Frc != 0 {
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 && int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == P4_NOTUSED {
				zErr = _sqlite3ValueText(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56, uint8(SQLITE_UTF8))
				_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, zErr))
			} else {
				if (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 {
					_sqlite3VdbeError(tls, p, __ccgo_ts+5860, libc.VaList(bp+984, _azType[libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)-int32(1)]))
					if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
						(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3MPrintf(tls, db, __ccgo_ts+5881, libc.VaList(bp+984, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg, *(*uintptr)(unsafe.Pointer(pOp + 16))))
					}
				} else {
					_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, *(*uintptr)(unsafe.Pointer(pOp + 16))))
				}
			}
			_sqlite3VdbeLogAbort(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, pOp, aOp)
		}
		rc = _sqlite3VdbeHalt(tls, p)
		if rc == int32(SQLITE_BUSY) {
			(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_BUSY)
		} else {
			if (*TVdbe)(unsafe.Pointer(p)).Frc != 0 {
				v190 = int32(SQLITE_ERROR)
			} else {
				v190 = int32(SQLITE_DONE)
			}
			rc = v190
		}
		goto vdbe_return
		/* Opcode: Integer P1 P2 * * *
		 ** Synopsis: r[P2]=P1
		 **
		 ** The 32-bit integer value P1 is written into register P2.
		 */
	_10:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = int64((*TOp)(unsafe.Pointer(pOp)).Fp1)
		goto _189
		/* Opcode: Int64 * P2 * P4 *
		 ** Synopsis: r[P2]=P4
		 **
		 ** P4 is a pointer to a 64-bit integer value.
		 ** Write that value into register P2.
		 */
	_11:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pOp + 16))))
		goto _189
		/* Opcode: Real * P2 * P4 *
		 ** Synopsis: r[P2]=P4
		 **
		 ** P4 is a pointer to a 64-bit floating point value.
		 ** Write that value into register P2.
		 */
	_12:
		; /* same as TK_FLOAT, out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Real)
		*(*float64)(unsafe.Pointer(pOut)) = **(**float64)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pOp + 16))))
		goto _189
		/* Opcode: String8 * P2 * P4 *
		 ** Synopsis: r[P2]='P4'
		 **
		 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
		 ** into a String opcode before it is executed for the first time.  During
		 ** this transformation, the length of string P4 is computed and stored
		 ** as the P1 parameter.
		 */
	_13:
		; /* same as TK_STRING, out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		(*TOp)(unsafe.Pointer(pOp)).Fp1 = _sqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		if libc.Int32FromUint8(encoding) != int32(SQLITE_UTF8) {
			rc = _sqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(pOp + 16)), int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
			if rc != 0 {
				goto too_big
			}
			if SQLITE_OK != _sqlite3VdbeChangeEncoding(tls, pOut, libc.Int32FromUint8(encoding)) {
				goto no_mem
			}
			(*TMem)(unsafe.Pointer(pOut)).FszMalloc = 0
			v191 = pOut + 20
			*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Static))
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(7) {
				_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)))
			}
			(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(7))
			*(*uintptr)(unsafe.Pointer(pOp + 16)) = (*TMem)(unsafe.Pointer(pOut)).Fz
			(*TOp)(unsafe.Pointer(pOp)).Fp1 = (*TMem)(unsafe.Pointer(pOut)).Fn
		}
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 > **(**int32)(__ccgo_up(db + 136)) {
			goto too_big
		}
		(*TOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_String)
		/* Fall through to the next case, OP_String */
		/* Opcode: String P1 P2 P3 P4 P5
		 ** Synopsis: r[P2]='P4' (len=P1)
		 **
		 ** The string value P4 of length P1 (bytes) is stored in register P2.
		 **
		 ** If P3 is not zero and the content of register P3 is equal to P5, then
		 ** the datatype of the register P2 is converted to BLOB.  The content is
		 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
		 ** of a string, as if it had been CAST.  In other words:
		 **
		 ** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
		 */
	_14:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Term))
		(*TMem)(unsafe.Pointer(pOut)).Fz = *(*uintptr)(unsafe.Pointer(pOp + 16))
		(*TMem)(unsafe.Pointer(pOut)).Fn = (*TOp)(unsafe.Pointer(pOp)).Fp1
		(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
		goto _189
		/* Opcode: BeginSubrtn * P2 * * *
		 ** Synopsis: r[P2]=NULL
		 **
		 ** Mark the beginning of a subroutine that can be entered in-line
		 ** or that can be called using OP_Gosub.  The subroutine should
		 ** be terminated by an OP_Return instruction that has a P1 operand that
		 ** is the same as the P2 operand to this opcode and that has P3 set to 1.
		 ** If the subroutine is entered in-line, then the OP_Return will simply
		 ** fall through.  But if the subroutine is entered using OP_Gosub, then
		 ** the OP_Return will jump back to the first instruction after the OP_Gosub.
		 **
		 ** This routine works by loading a NULL into the P2 register.  When the
		 ** return address register contains a NULL, the OP_Return instruction is
		 ** a no-op that simply falls through to the next instruction (assuming that
		 ** the OP_Return opcode has a P3 value of 1).  Thus if the subroutine is
		 ** entered in-line, then the OP_Return will cause in-line execution to
		 ** continue.  But if the subroutine is entered via OP_Gosub, then the
		 ** OP_Return will cause a return to the address following the OP_Gosub.
		 **
		 ** This opcode is identical to OP_Null.  It has a different name
		 ** only to make the byte code easier to read and verify.
		 */
		/* Opcode: Null P1 P2 P3 * *
		 ** Synopsis: r[P2..P3]=NULL
		 **
		 ** Write a NULL into registers P2.  If P3 greater than P2, then also write
		 ** NULL into register P3 and every register in between P2 and P3.  If P3
		 ** is less than P2 (typically P3 is zero) then only register P2 is
		 ** set to NULL.
		 **
		 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
		 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
		 ** OP_Ne or OP_Eq.
		 */
	_16:
		;
	_15:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		cnt = (*TOp)(unsafe.Pointer(pOp)).Fp3 - (*TOp)(unsafe.Pointer(pOp)).Fp2
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
			v190 = libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Cleared)
		} else {
			v190 = int32(MEM_Null)
		}
		v192 = libc.Uint16FromInt32(v190)
		nullFlag = v192
		(*TMem)(unsafe.Pointer(pOut)).Fflags = v192
		(*TMem)(unsafe.Pointer(pOut)).Fn = 0
		for cnt > 0 {
			pOut += 56
			_sqlite3VdbeMemSetNull(tls, pOut)
			(*TMem)(unsafe.Pointer(pOut)).Fflags = nullFlag
			(*TMem)(unsafe.Pointer(pOut)).Fn = 0
			cnt = cnt - 1
		}
		goto _189
		/* Opcode: SoftNull P1 * * * *
		 ** Synopsis: r[P1]=NULL
		 **
		 ** Set register P1 to have the value NULL as seen by the OP_MakeRecord
		 ** instruction, but do not free any string or blob memory associated with
		 ** the register, so that if the value was a string or blob that was
		 ** previously copied using OP_SCopy, the copies will continue to be valid.
		 */
	_17:
		;
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_Undefined)|libc.Int32FromInt32(MEM_AffMask)) | int32(MEM_Null))
		goto _189
		/* Opcode: Blob P1 P2 * P4 *
		 ** Synopsis: r[P2]=P4 (len=P1)
		 **
		 ** P4 points to a blob of data P1 bytes long.  Store this
		 ** blob in register P2.  If P4 is a NULL pointer, then construct
		 ** a zero-filled blob that is P1 bytes long in P2.
		 */
	_18:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		if *(*uintptr)(unsafe.Pointer(pOp + 16)) == uintptr(0) {
			_sqlite3VdbeMemSetZeroBlob(tls, pOut, (*TOp)(unsafe.Pointer(pOp)).Fp1)
			if _sqlite3VdbeMemExpandBlob(tls, pOut) != 0 {
				goto no_mem
			}
		} else {
			_sqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(pOp + 16)), int64((*TOp)(unsafe.Pointer(pOp)).Fp1), uint8(0), uintptr(0))
		}
		(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
		goto _189
		/* Opcode: Variable P1 P2 * * *
		 ** Synopsis: r[P2]=parameter(P1)
		 **
		 ** Transfer the values of bound parameter P1 into register P2
		 */
	_19:
		; /* Value being transferred */
		pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1-int32(1))*56
		if _sqlite3VdbeMemTooBig(tls, pVar) != 0 {
			goto too_big
		}
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
			_sqlite3VdbeMemSetNull(tls, pOut)
		}
		libc.Xmemcpy(tls, pOut, pVar, uint64(libc.UintptrFromInt32(0)+24))
		v191 = pOut + 20
		*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Dyn) | libc.Int32FromInt32(MEM_Ephem)))
		v191 = pOut + 20
		*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | (libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_FromBind)))
		goto _189
		/* Opcode: Move P1 P2 P3 * *
		 ** Synopsis: r[P2@P3]=r[P1@P3]
		 **
		 ** Move the P3 values in register P1..P1+P3-1 over into
		 ** registers P2..P2+P3-1.  Registers P1..P1+P3-1 are
		 ** left holding a NULL.  It is an error for register ranges
		 ** P1..P1+P3-1 and P2..P2+P3-1 to overlap.  It is an error
		 ** for P3 to be less than 1.
		 */
	_20:
		; /* Register to copy to */
		n = (*TOp)(unsafe.Pointer(pOp)).Fp3
		p1 = (*TOp)(unsafe.Pointer(pOp)).Fp1
		p2 = (*TOp)(unsafe.Pointer(pOp)).Fp2
		pIn1 = aMem + uintptr(p1)*56
		pOut = aMem + uintptr(p2)*56
		for {
			_sqlite3VdbeMemMove(tls, pOut, pIn1)
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				goto no_mem
			}
			pIn1 += 56
			pOut += 56
			goto _197
		_197:
			;
			n = n - 1
			v190 = n
			if !(v190 != 0) {
				break
			}
		}
		goto _189
		/* Opcode: Copy P1 P2 P3 * P5
		 ** Synopsis: r[P2@P3+1]=r[P1@P3+1]
		 **
		 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
		 **
		 ** If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
		 ** destination.  The 0x0001 bit of P5 indicates that this Copy opcode cannot
		 ** be merged.  The 0x0001 bit is used by the query planner and does not
		 ** come into play during query execution.
		 **
		 ** This instruction makes a deep copy of the value.  A duplicate
		 ** is made of any string or blob constant.  See also OP_SCopy.
		 */
	_21:
		;
		n1 = (*TOp)(unsafe.Pointer(pOp)).Fp3
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		for int32(1) != 0 {
			_sqlite3VdbeMemShallowCopy(tls, pOut, pIn1, int32(MEM_Ephem))
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				goto no_mem
			}
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Subtype) != 0 && libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(0x0002) != 0 {
				v191 = pOut + 20
				*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Subtype))
			}
			v190 = n1
			n1 = n1 - 1
			if v190 == 0 {
				break
			}
			pOut += 56
			pIn1 += 56
		}
		goto _189
		/* Opcode: SCopy P1 P2 * * *
		 ** Synopsis: r[P2]=r[P1]
		 **
		 ** Make a shallow copy of register P1 into register P2.
		 **
		 ** This instruction makes a shallow copy of the value.  If the value
		 ** is a string or blob, then the copy is only a pointer to the
		 ** original and hence if the original changes so will the copy.
		 ** Worse, if the original is deallocated, the copy becomes invalid.
		 ** Thus the program must guarantee that the original will not change
		 ** during the lifetime of the copy.  Use OP_Copy to make a complete
		 ** copy.
		 */
	_22:
		; /* out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		_sqlite3VdbeMemShallowCopy(tls, pOut, pIn1, int32(MEM_Ephem))
		goto _189
		/* Opcode: IntCopy P1 P2 * * *
		 ** Synopsis: r[P2]=r[P1]
		 **
		 ** Transfer the integer value held in register P1 into register P2.
		 **
		 ** This is an optimized version of SCopy that works only for integer
		 ** values.
		 */
	_23:
		; /* out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		_sqlite3VdbeMemSetInt64(tls, pOut, *(*Ti64)(unsafe.Pointer(pIn1)))
		goto _189
		/* Opcode: FkCheck * * * * *
		 **
		 ** Halt with an SQLITE_CONSTRAINT error if there are any unresolved
		 ** foreign key constraint violations.  If there are no foreign key
		 ** constraint violations, this is a no-op.
		 **
		 ** FK constraint violations are also checked when the prepared statement
		 ** exits.  This opcode is used to raise foreign key constraint errors prior
		 ** to returning results such as a row change count or the result of a
		 ** RETURNING clause.
		 */
	_24:
		;
		v190 = _sqlite3VdbeCheckFkImmediate(tls, p)
		rc = v190
		if v190 != SQLITE_OK {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: ResultRow P1 P2 * * *
		 ** Synopsis: output=r[P1@P2]
		 **
		 ** The registers P1 through P1+P2-1 contain a single row of
		 ** results. This opcode causes the sqlite3_step() call to terminate
		 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
		 ** structure to provide access to the r(P1)..r(P1+P2-1) values as
		 ** the result row.
		 */
	_25:
		;
		(*TVdbe)(unsafe.Pointer(p)).FcacheCtr = (*TVdbe)(unsafe.Pointer(p)).FcacheCtr + uint32(2) | uint32(1)
		(*TVdbe)(unsafe.Pointer(p)).FpResultRow = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto no_mem
		}
		if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_ROW) != 0 {
			(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_ROW), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, uintptr(0))
		}
		(*TVdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp)-int64(aOp))/24) + int32(1)
		rc = int32(SQLITE_ROW)
		goto vdbe_return
		/* Opcode: Concat P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P2]+r[P1]
		 **
		 ** Add the text in register P1 onto the end of the text in
		 ** register P2 and store the result in register P3.
		 ** If either the P1 or P2 text are NULL then store NULL in P3.
		 **
		 **   P3 = P2 || P1
		 **
		 ** It is illegal for P1 and P3 to be the same register. Sometimes,
		 ** if P3 is the same register as P2, the implementation is able
		 ** to avoid a memcpy().
		 */
	_26:
		; /* Initial flags for P2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		flags1 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
		if (libc.Int32FromUint16(flags1)|libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags))&int32(MEM_Null) != 0 {
			_sqlite3VdbeMemSetNull(tls, pOut)
			goto _189
		}
		if libc.Int32FromUint16(flags1)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) == 0 {
			if _sqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(0)) != 0 {
				goto no_mem
			}
			flags1 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
		} else {
			if libc.Int32FromUint16(flags1)&int32(MEM_Zero) != 0 {
				if _sqlite3VdbeMemExpandBlob(tls, pIn1) != 0 {
					goto no_mem
				}
				flags1 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
			}
		}
		flags2 = (*TMem)(unsafe.Pointer(pIn2)).Fflags
		if libc.Int32FromUint16(flags2)&(libc.Int32FromInt32(MEM_Str)|libc.Int32FromInt32(MEM_Blob)) == 0 {
			if _sqlite3VdbeMemStringify(tls, pIn2, encoding, uint8(0)) != 0 {
				goto no_mem
			}
			flags2 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
		} else {
			if libc.Int32FromUint16(flags2)&int32(MEM_Zero) != 0 {
				if _sqlite3VdbeMemExpandBlob(tls, pIn2) != 0 {
					goto no_mem
				}
				flags2 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags) & ^libc.Int32FromInt32(MEM_Str))
			}
		}
		nByte = int64((*TMem)(unsafe.Pointer(pIn1)).Fn)
		nByte = nByte + int64((*TMem)(unsafe.Pointer(pIn2)).Fn)
		if nByte > int64(**(**int32)(__ccgo_up(db + 136))) {
			goto too_big
		}
		if _sqlite3VdbeMemGrow(tls, pOut, int32(nByte)+int32(2), libc.BoolInt32(pOut == pIn2)) != 0 {
			goto no_mem
		}
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Str))
		if pOut != pIn2 {
			libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pOut)).Fz, (*TMem)(unsafe.Pointer(pIn2)).Fz, libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pIn2)).Fn))
			(*TMem)(unsafe.Pointer(pIn2)).Fflags = flags2
		}
		libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pOut)).Fz+uintptr((*TMem)(unsafe.Pointer(pIn2)).Fn), (*TMem)(unsafe.Pointer(pIn1)).Fz, libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pIn1)).Fn))
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = flags1
		if libc.Int32FromUint8(encoding) > int32(SQLITE_UTF8) {
			nByte = nByte & int64(^libc.Int32FromInt32(1))
		}
		**(**uint8)(__ccgo_up((*TMem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte))) = uint8(0)
		**(**uint8)(__ccgo_up((*TMem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte+int64(1)))) = uint8(0)
		v191 = pOut + 20
		*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Term))
		(*TMem)(unsafe.Pointer(pOut)).Fn = int32(nByte)
		(*TMem)(unsafe.Pointer(pOut)).Fenc = encoding
		goto _189
		/* Opcode: Add P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P1]+r[P2]
		 **
		 ** Add the value in register P1 to the value in register P2
		 ** and store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
		/* Opcode: Multiply P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P1]*r[P2]
		 **
		 **
		 ** Multiply the value in register P1 by the value in register P2
		 ** and store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
		/* Opcode: Subtract P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P2]-r[P1]
		 **
		 ** Subtract the value in register P1 from the value in register P2
		 ** and store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
		/* Opcode: Divide P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P2]/r[P1]
		 **
		 ** Divide the value in register P1 by the value in register P2
		 ** and store the result in register P3 (P3=P2/P1). If the value in
		 ** register P1 is zero, then the result is NULL. If either input is
		 ** NULL, the result is NULL.
		 */
		/* Opcode: Remainder P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P2]%r[P1]
		 **
		 ** Compute the remainder after integer register P2 is divided by
		 ** register P1 and store the result in register P3.
		 ** If the value in register P1 is zero the result is NULL.
		 ** If either operand is NULL, the result is NULL.
		 */
	_31:
		; /* same as TK_PLUS, in1, in2, out3 */
	_30:
		; /* same as TK_MINUS, in1, in2, out3 */
	_29:
		; /* same as TK_STAR, in1, in2, out3 */
	_28:
		; /* same as TK_SLASH, in1, in2, out3 */
	_27:
		; /* Real value of right operand */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		type1 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		type2 = (*TMem)(unsafe.Pointer(pIn2)).Fflags
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if !(libc.Int32FromUint16(type1)&libc.Int32FromUint16(type2)&int32(MEM_Int) != 0) {
			goto _202
		}
		goto int_math
	int_math:
		;
		iA = *(*Ti64)(unsafe.Pointer(pIn1))
		**(**Ti64)(__ccgo_up(bp)) = *(*Ti64)(unsafe.Pointer(pIn2))
		switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
		case int32(OP_Add):
			if _sqlite3AddInt64(tls, bp, iA) != 0 {
				goto fp_math
			}
		case int32(OP_Subtract):
			if _sqlite3SubInt64(tls, bp, iA) != 0 {
				goto fp_math
			}
		case int32(OP_Multiply):
			if _sqlite3MulInt64(tls, bp, iA) != 0 {
				goto fp_math
			}
		case int32(OP_Divide):
			if iA == 0 {
				goto arithmetic_result_is_null
			}
			if iA == int64(-int32(1)) && **(**Ti64)(__ccgo_up(bp)) == int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
				goto fp_math
			}
			**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) / iA
		default:
			if iA == 0 {
				goto arithmetic_result_is_null
			}
			if iA == int64(-int32(1)) {
				iA = int64(1)
			}
			**(**Ti64)(__ccgo_up(bp)) = **(**Ti64)(__ccgo_up(bp)) % iA
			break
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp))
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		goto _203
	_202:
		;
		if !((libc.Int32FromUint16(type1)|libc.Int32FromUint16(type2))&int32(MEM_Null) != 0) {
			goto _204
		}
		goto arithmetic_result_is_null
		goto _205
	_204:
		;
		type1 = _numericType(tls, pIn1)
		type2 = _numericType(tls, pIn2)
		if libc.Int32FromUint16(type1)&libc.Int32FromUint16(type2)&int32(MEM_Int) != 0 {
			goto int_math
		}
		goto fp_math
	fp_math:
		;
		rA = _sqlite3VdbeRealValue(tls, pIn1)
		rB = _sqlite3VdbeRealValue(tls, pIn2)
		switch libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) {
		case int32(OP_Add):
			rB = rB + rA
		case int32(OP_Subtract):
			rB = rB - rA
		case int32(OP_Multiply):
			rB = rB * rA
		case int32(OP_Divide):
			/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
			if rA == libc.Float64FromInt32(0) {
				goto arithmetic_result_is_null
			}
			rB = rB / rA
		default:
			iA = _sqlite3VdbeIntValue(tls, pIn1)
			**(**Ti64)(__ccgo_up(bp)) = _sqlite3VdbeIntValue(tls, pIn2)
			if iA == 0 {
				goto arithmetic_result_is_null
			}
			if iA == int64(-int32(1)) {
				iA = int64(1)
			}
			rB = float64(**(**Ti64)(__ccgo_up(bp)) % iA)
			break
		}
		if _sqlite3IsNaN(tls, rB) != 0 {
			goto arithmetic_result_is_null
		}
		*(*float64)(unsafe.Pointer(pOut)) = rB
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Real))
	_205:
		;
	_203:
		;
		goto _189
		goto arithmetic_result_is_null
	arithmetic_result_is_null:
		;
		_sqlite3VdbeMemSetNull(tls, pOut)
		goto _189
		/* Opcode: CollSeq P1 * * P4
		 **
		 ** P4 is a pointer to a CollSeq object. If the next call to a user function
		 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
		 ** be returned. This is used by the built-in min(), max() and nullif()
		 ** functions.
		 **
		 ** If P1 is not zero, then it is a register that a subsequent min() or
		 ** max() aggregate will set to 1 if the current row is not the minimum or
		 ** maximum.  The P1 register is initialized to 0 by this instruction.
		 **
		 ** The interface used by the implementation of the aforementioned functions
		 ** to retrieve the collation sequence set by this opcode is not available
		 ** publicly.  Only built-in functions have access to this feature.
		 */
	_32:
		;
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
			_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56, 0)
		}
		goto _189
		/* Opcode: BitAnd P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P1]&r[P2]
		 **
		 ** Take the bit-wise AND of the values in register P1 and P2 and
		 ** store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
		/* Opcode: BitOr P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P1]|r[P2]
		 **
		 ** Take the bit-wise OR of the values in register P1 and P2 and
		 ** store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
		/* Opcode: ShiftLeft P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P2]<<r[P1]
		 **
		 ** Shift the integer value in register P2 to the left by the
		 ** number of bits specified by the integer in register P1.
		 ** Store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
		/* Opcode: ShiftRight P1 P2 P3 * *
		 ** Synopsis: r[P3]=r[P2]>>r[P1]
		 **
		 ** Shift the integer value in register P2 to the right by the
		 ** number of bits specified by the integer in register P1.
		 ** Store the result in register P3.
		 ** If either input is NULL, the result is NULL.
		 */
	_36:
		; /* same as TK_BITAND, in1, in2, out3 */
	_35:
		; /* same as TK_BITOR, in1, in2, out3 */
	_34:
		; /* same as TK_LSHIFT, in1, in2, out3 */
	_33:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if (libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)|libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags))&int32(MEM_Null) != 0 {
			_sqlite3VdbeMemSetNull(tls, pOut)
			goto _189
		}
		**(**Ti64)(__ccgo_up(bp + 8)) = _sqlite3VdbeIntValue(tls, pIn2)
		iB1 = _sqlite3VdbeIntValue(tls, pIn1)
		op = (*TOp)(unsafe.Pointer(pOp)).Fopcode
		if libc.Int32FromUint8(op) == int32(OP_BitAnd) {
			**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) & iB1
		} else {
			if libc.Int32FromUint8(op) == int32(OP_BitOr) {
				**(**Ti64)(__ccgo_up(bp + 8)) = **(**Ti64)(__ccgo_up(bp + 8)) | iB1
			} else {
				if iB1 != 0 {
					/* If shifting by a negative amount, shift in the other direction */
					if iB1 < 0 {
						op = libc.Uint8FromInt32(libc.Int32FromInt32(2)*libc.Int32FromInt32(OP_ShiftLeft) + libc.Int32FromInt32(1) - libc.Int32FromUint8(op))
						if iB1 > int64(-libc.Int32FromInt32(64)) {
							v206 = -iB1
						} else {
							v206 = int64(64)
						}
						iB1 = v206
					}
					if iB1 >= int64(64) {
						if **(**Ti64)(__ccgo_up(bp + 8)) >= 0 || libc.Int32FromUint8(op) == int32(OP_ShiftLeft) {
							v190 = 0
						} else {
							v190 = -int32(1)
						}
						**(**Ti64)(__ccgo_up(bp + 8)) = int64(v190)
					} else {
						libc.Xmemcpy(tls, bp+16, bp+8, uint64(8))
						if libc.Int32FromUint8(op) == int32(OP_ShiftLeft) {
							**(**Tu64)(__ccgo_up(bp + 16)) = **(**Tu64)(__ccgo_up(bp + 16)) << libc.Uint64FromInt64(iB1)
						} else {
							**(**Tu64)(__ccgo_up(bp + 16)) = **(**Tu64)(__ccgo_up(bp + 16)) >> libc.Uint64FromInt64(iB1)
							/* Sign-extend on a right shift of a negative number */
							if **(**Ti64)(__ccgo_up(bp + 8)) < 0 {
								**(**Tu64)(__ccgo_up(bp + 16)) = **(**Tu64)(__ccgo_up(bp + 16)) | (libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff))<<(int64(64)-iB1)
							}
						}
						libc.Xmemcpy(tls, bp+8, bp+16, uint64(8))
					}
				}
			}
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 8))
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		goto _189
		/* Opcode: AddImm  P1 P2 * * *
		 ** Synopsis: r[P1]=r[P1]+P2
		 **
		 ** Add the constant P2 to the value in register P1.
		 ** The result is always an integer.
		 **
		 ** To force any register to be an integer, just add 0.
		 */
	_37:
		; /* in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		_sqlite3VdbeMemIntegerify(tls, pIn1)
		**(**Tu64)(__ccgo_up(pIn1)) += libc.Uint64FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
		goto _189
		/* Opcode: MustBeInt P1 P2 * * *
		 **
		 ** Force the value in register P1 to be an integer.  If the value
		 ** in P1 is not an integer and cannot be converted into an integer
		 ** without data loss, then jump immediately to P2, or if P2==0
		 ** raise an SQLITE_MISMATCH exception.
		 */
	_38:
		; /* jump0, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
			_applyAffinity(tls, pIn1, uint8(SQLITE_AFF_NUMERIC), encoding)
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
				if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
					rc = int32(SQLITE_MISMATCH)
					goto abort_due_to_error
				} else {
					goto jump_to_p2
				}
			}
		}
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		goto _189
		/* Opcode: RealAffinity P1 * * * *
		 **
		 ** If register P1 holds an integer convert it to a real value.
		 **
		 ** This opcode is used when extracting information from a column that
		 ** has REAL affinity.  Such column values may still be stored as
		 ** integers, for space efficiency, but after extraction we want them
		 ** to have only a real value.
		 */
	_39:
		; /* in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
			_sqlite3VdbeMemRealify(tls, pIn1)
		}
		goto _189
		/* Opcode: Cast P1 P2 * * *
		 ** Synopsis: affinity(r[P1])
		 **
		 ** Force the value in register P1 to be the type defined by P2.
		 **
		 ** <ul>
		 ** <li> P2=='A' &rarr; BLOB
		 ** <li> P2=='B' &rarr; TEXT
		 ** <li> P2=='C' &rarr; NUMERIC
		 ** <li> P2=='D' &rarr; INTEGER
		 ** <li> P2=='E' &rarr; REAL
		 ** </ul>
		 **
		 ** A NULL value is not changed by this routine.  It remains NULL.
		 */
	_40:
		; /* in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Zero) != 0 {
			v190 = _sqlite3VdbeMemExpandBlob(tls, pIn1)
		} else {
			v190 = 0
		}
		rc = v190
		if rc != 0 {
			goto abort_due_to_error
		}
		rc = _sqlite3VdbeMemCast(tls, pIn1, libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2), encoding)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: Eq P1 P2 P3 P4 P5
		 ** Synopsis: IF r[P3]==r[P1]
		 **
		 ** Compare the values in register P1 and P3.  If reg(P3)==reg(P1) then
		 ** jump to address P2.
		 **
		 ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
		 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
		 ** to coerce both inputs according to this affinity before the
		 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
		 ** affinity is used. Note that the affinity conversions are stored
		 ** back into the input registers P1 and P3.  So this opcode can cause
		 ** persistent changes to registers P1 and P3.
		 **
		 ** Once any conversions have taken place, and neither value is NULL,
		 ** the values are compared. If both values are blobs then memcmp() is
		 ** used to determine the results of the comparison.  If both values
		 ** are text, then the appropriate collating function specified in
		 ** P4 is used to do the comparison.  If P4 is not specified then
		 ** memcmp() is used to compare text string.  If both values are
		 ** numeric, then a numeric comparison is used. If the two values
		 ** are of different types, then numbers are considered less than
		 ** strings and strings are considered less than blobs.
		 **
		 ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
		 ** true or false and is never NULL.  If both operands are NULL then the result
		 ** of comparison is true.  If either operand is NULL then the result is false.
		 ** If neither operand is NULL the result is the same as it would be if
		 ** the SQLITE_NULLEQ flag were omitted from P5.
		 **
		 ** This opcode saves the result of comparison for use by the new
		 ** OP_Jump opcode.
		 */
		/* Opcode: Ne P1 P2 P3 P4 P5
		 ** Synopsis: IF r[P3]!=r[P1]
		 **
		 ** This works just like the Eq opcode except that the jump is taken if
		 ** the operands in registers P1 and P3 are not equal.  See the Eq opcode for
		 ** additional information.
		 */
		/* Opcode: Lt P1 P2 P3 P4 P5
		 ** Synopsis: IF r[P3]<r[P1]
		 **
		 ** Compare the values in register P1 and P3.  If reg(P3)<reg(P1) then
		 ** jump to address P2.
		 **
		 ** If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
		 ** reg(P3) is NULL then the take the jump.  If the SQLITE_JUMPIFNULL
		 ** bit is clear then fall through if either operand is NULL.
		 **
		 ** The SQLITE_AFF_MASK portion of P5 must be an affinity character -
		 ** SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
		 ** to coerce both inputs according to this affinity before the
		 ** comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
		 ** affinity is used. Note that the affinity conversions are stored
		 ** back into the input registers P1 and P3.  So this opcode can cause
		 ** persistent changes to registers P1 and P3.
		 **
		 ** Once any conversions have taken place, and neither value is NULL,
		 ** the values are compared. If both values are blobs then memcmp() is
		 ** used to determine the results of the comparison.  If both values
		 ** are text, then the appropriate collating function specified in
		 ** P4 is  used to do the comparison.  If P4 is not specified then
		 ** memcmp() is used to compare text string.  If both values are
		 ** numeric, then a numeric comparison is used. If the two values
		 ** are of different types, then numbers are considered less than
		 ** strings and strings are considered less than blobs.
		 **
		 ** This opcode saves the result of comparison for use by the new
		 ** OP_Jump opcode.
		 */
		/* Opcode: Le P1 P2 P3 P4 P5
		 ** Synopsis: IF r[P3]<=r[P1]
		 **
		 ** This works just like the Lt opcode except that the jump is taken if
		 ** the content of register P3 is less than or equal to the content of
		 ** register P1.  See the Lt opcode for additional information.
		 */
		/* Opcode: Gt P1 P2 P3 P4 P5
		 ** Synopsis: IF r[P3]>r[P1]
		 **
		 ** This works just like the Lt opcode except that the jump is taken if
		 ** the content of register P3 is greater than the content of
		 ** register P1.  See the Lt opcode for additional information.
		 */
		/* Opcode: Ge P1 P2 P3 P4 P5
		 ** Synopsis: IF r[P3]>=r[P1]
		 **
		 ** This works just like the Lt opcode except that the jump is taken if
		 ** the content of register P3 is greater than or equal to the content of
		 ** register P1.  See the Lt opcode for additional information.
		 */
	_46:
		; /* same as TK_EQ, jump, in1, in3 */
	_45:
		; /* same as TK_NE, jump, in1, in3 */
	_44:
		; /* same as TK_LT, jump, in1, in3 */
	_43:
		; /* same as TK_LE, jump, in1, in3 */
	_42:
		; /* same as TK_GT, jump, in1, in3 */
	_41:
		; /* Copy of initial value of pIn3->flags */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		flags11 = (*TMem)(unsafe.Pointer(pIn1)).Fflags
		flags3 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
		if libc.Int32FromUint16(flags11)&libc.Int32FromUint16(flags3)&int32(MEM_Int) != 0 {
			/* Common case of comparison of two integers */
			if *(*Ti64)(unsafe.Pointer(pIn3)) > *(*Ti64)(unsafe.Pointer(pIn1)) {
				if **(**uint8)(__ccgo_up(_sqlite3aGTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
					goto jump_to_p2
				}
				iCompare = +libc.Int32FromInt32(1)
			} else {
				if *(*Ti64)(unsafe.Pointer(pIn3)) < *(*Ti64)(unsafe.Pointer(pIn1)) {
					if **(**uint8)(__ccgo_up(_sqlite3aLTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
						goto jump_to_p2
					}
					iCompare = -int32(1)
				} else {
					if **(**uint8)(__ccgo_up(_sqlite3aEQb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))) != 0 {
						goto jump_to_p2
					}
					iCompare = 0
				}
			}
			goto _189
		}
		if (libc.Int32FromUint16(flags11)|libc.Int32FromUint16(flags3))&int32(MEM_Null) != 0 {
			/* One or both operands are NULL */
			if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(SQLITE_NULLEQ) != 0 {
				/* If SQLITE_NULLEQ is set (which will only happen if the operator is
				 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
				 ** or not both operands are null.
				 */
				if libc.Int32FromUint16(flags11)&libc.Int32FromUint16(flags3)&int32(MEM_Null) != 0 && libc.Int32FromUint16(flags3)&int32(MEM_Cleared) == 0 {
					res = 0 /* Operands are equal */
				} else {
					if libc.Int32FromUint16(flags3)&int32(MEM_Null) != 0 {
						v190 = -int32(1)
					} else {
						v190 = +libc.Int32FromInt32(1)
					}
					res = v190 /* Operands are not equal */
				}
			} else {
				/* SQLITE_NULLEQ is clear and at least one operand is NULL,
				 ** then the result is always NULL.
				 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
				 */
				if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(SQLITE_JUMPIFNULL) != 0 {
					goto jump_to_p2
				}
				iCompare = int32(1) /* Operands are not equal */
				goto _189
			}
		} else {
			/* Neither operand is NULL and we couldn't do the special high-speed
			 ** integer comparison case.  So do a general-case comparison. */
			affinity = libc.Uint8FromInt32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) & int32(SQLITE_AFF_MASK))
			if libc.Int32FromUint8(affinity) >= int32(SQLITE_AFF_NUMERIC) {
				if (libc.Int32FromUint16(flags11)|libc.Int32FromUint16(flags3))&int32(MEM_Str) != 0 {
					if libc.Int32FromUint16(flags11)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_Str)) == int32(MEM_Str) {
						_applyNumericAffinity(tls, pIn1, 0)
						flags3 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
					}
					if libc.Int32FromUint16(flags3)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_Str)) == int32(MEM_Str) {
						_applyNumericAffinity(tls, pIn3, 0)
					}
				}
			} else {
				if libc.Int32FromUint8(affinity) == int32(SQLITE_AFF_TEXT) && (libc.Int32FromUint16(flags11)|libc.Int32FromUint16(flags3))&int32(MEM_Str) != 0 {
					if libc.Int32FromUint16(flags11)&int32(MEM_Str) != 0 {
						v191 = pIn1 + 20
						*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
					} else {
						if libc.Int32FromUint16(flags11)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
							_sqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(1))
							flags11 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags) & ^libc.Int32FromInt32(MEM_TypeMask) | libc.Int32FromUint16(flags11)&int32(MEM_TypeMask))
							if pIn1 == pIn3 {
								flags3 = libc.Uint16FromInt32(libc.Int32FromUint16(flags11) | int32(MEM_Str))
							}
						}
					}
					if libc.Int32FromUint16(flags3)&int32(MEM_Str) != 0 {
						v191 = pIn3 + 20
						*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
					} else {
						if libc.Int32FromUint16(flags3)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
							_sqlite3VdbeMemStringify(tls, pIn3, encoding, uint8(1))
							flags3 = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn3)).Fflags) & ^libc.Int32FromInt32(MEM_TypeMask) | libc.Int32FromUint16(flags3)&int32(MEM_TypeMask))
						}
					}
				}
			}
			res = _sqlite3MemCompare(tls, pIn3, pIn1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		}
		/* At this point, res is negative, zero, or positive if reg[P1] is
		 ** less than, equal to, or greater than reg[P3], respectively.  Compute
		 ** the answer to this operator in res2, depending on what the comparison
		 ** operator actually is.  The next block of code depends on the fact
		 ** that the 6 comparison operators are consecutive integers in this
		 ** order:  NE, EQ, GT, LE, LT, GE */
		if res < 0 {
			res21 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(_sqlite3aLTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
		} else {
			if res == 0 {
				res21 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(_sqlite3aEQb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
			} else {
				res21 = libc.Int32FromUint8(**(**uint8)(__ccgo_up(_sqlite3aGTb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fopcode))))
			}
		}
		iCompare = res
		/* Undo any changes made by applyAffinity() to the input registers. */
		(*TMem)(unsafe.Pointer(pIn3)).Fflags = flags3
		(*TMem)(unsafe.Pointer(pIn1)).Fflags = flags11
		if res21 != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: ElseEq * P2 * * *
		 **
		 ** This opcode must follow an OP_Lt or OP_Gt comparison operator.  There
		 ** can be zero or more OP_ReleaseReg opcodes intervening, but no other
		 ** opcodes are allowed to occur between this instruction and the previous
		 ** OP_Lt or OP_Gt.
		 **
		 ** If the result of an OP_Eq comparison on the same two operands as
		 ** the prior OP_Lt or OP_Gt would have been true, then jump to P2.  If
		 ** the result of an OP_Eq comparison on the two previous operands
		 ** would have been false or NULL, then fall through.
		 */
	_47:
		; /* same as TK_ESCAPE, jump */
		if iCompare == 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: Permutation * * * P4 *
		 **
		 ** Set the permutation used by the OP_Compare operator in the next
		 ** instruction.  The permutation is stored in the P4 operand.
		 **
		 ** The permutation is only valid for the next opcode which must be
		 ** an OP_Compare that has the OPFLAG_PERMUTE bit set in P5.
		 **
		 ** The first integer in the P4 integer array is the length of the array
		 ** and does not become part of the permutation.
		 */
	_48:
		;
		goto _189
		/* Opcode: Compare P1 P2 P3 P4 P5
		 ** Synopsis: r[P1@P3] <-> r[P2@P3]
		 **
		 ** Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
		 ** vector "A") and in reg(P2)..reg(P2+P3-1) ("B").  Save the result of
		 ** the comparison for use by the next OP_Jump instruct.
		 **
		 ** If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is
		 ** determined by the most recent OP_Permutation operator.  If the
		 ** OPFLAG_PERMUTE bit is clear, then register are compared in sequential
		 ** order.
		 **
		 ** P4 is a KeyInfo structure that defines collating sequences and sort
		 ** orders for the comparison.  The permutation applies to registers
		 ** only.  The KeyInfo elements are used sequentially.
		 **
		 ** The comparison is a sort comparison, so NULLs compare equal,
		 ** NULLs are less than numbers, numbers are less than strings,
		 ** and strings are less than blobs.
		 **
		 ** This opcode must be immediately followed by an OP_Jump opcode.
		 */
	_49:
		; /* The permutation */
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_PERMUTE) == 0 {
			aPermute = uintptr(0)
		} else {
			aPermute = *(*uintptr)(unsafe.Pointer(pOp + uintptr(-libc.Int32FromInt32(1))*24 + 16)) + uintptr(1)*4
		}
		n2 = (*TOp)(unsafe.Pointer(pOp)).Fp3
		pKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))
		p11 = (*TOp)(unsafe.Pointer(pOp)).Fp1
		p21 = (*TOp)(unsafe.Pointer(pOp)).Fp2
		i = 0
		for {
			if !(i < n2) {
				break
			}
			if aPermute != 0 {
				v213 = **(**Tu32)(__ccgo_up(aPermute + uintptr(i)*4))
			} else {
				v213 = libc.Uint32FromInt32(i)
			}
			idx = v213
			pColl = *(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(i)*8))
			bRev = libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i)))) & int32(KEYINFO_ORDER_DESC)
			iCompare = _sqlite3MemCompare(tls, aMem+uintptr(libc.Uint32FromInt32(p11)+idx)*56, aMem+uintptr(libc.Uint32FromInt32(p21)+idx)*56, pColl)
			if iCompare != 0 {
				if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i))))&int32(KEYINFO_ORDER_BIGNULL) != 0 && (libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr(libc.Uint32FromInt32(p11)+idx)*56))).Fflags)&int32(MEM_Null) != 0 || libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr(libc.Uint32FromInt32(p21)+idx)*56))).Fflags)&int32(MEM_Null) != 0) {
					iCompare = -iCompare
				}
				if bRev != 0 {
					iCompare = -iCompare
				}
				break
			}
			goto _212
		_212:
			;
			i = i + 1
		}
		goto _189
		/* Opcode: Jump P1 P2 P3 * *
		 **
		 ** Jump to the instruction at address P1, P2, or P3 depending on whether
		 ** in the most recent OP_Compare instruction the P1 vector was less than,
		 ** equal to, or greater than the P2 vector, respectively.
		 **
		 ** This opcode must immediately follow an OP_Compare opcode.
		 */
	_50:
		; /* jump */
		if iCompare < 0 {
			pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1-int32(1))*24
		} else {
			if iCompare == 0 {
				pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2-int32(1))*24
			} else {
				pOp = aOp + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3-int32(1))*24
			}
		}
		goto _189
		/* Opcode: And P1 P2 P3 * *
		 ** Synopsis: r[P3]=(r[P1] && r[P2])
		 **
		 ** Take the logical AND of the values in registers P1 and P2 and
		 ** write the result into register P3.
		 **
		 ** If either P1 or P2 is 0 (false) then the result is 0 even if
		 ** the other input is NULL.  A NULL and true or two NULLs give
		 ** a NULL output.
		 */
		/* Opcode: Or P1 P2 P3 * *
		 ** Synopsis: r[P3]=(r[P1] || r[P2])
		 **
		 ** Take the logical OR of the values in register P1 and P2 and
		 ** store the answer in register P3.
		 **
		 ** If either P1 or P2 is nonzero (true) then the result is 1 (true)
		 ** even if the other input is NULL.  A NULL and false or two NULLs
		 ** give a NULL output.
		 */
	_52:
		; /* same as TK_AND, in1, in2, out3 */
	_51:
		; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
		v11 = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56, int32(2))
		v21 = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56, int32(2))
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_And) {
			v11 = libc.Int32FromUint8(_and_logic[v11*int32(3)+v21])
		} else {
			v11 = libc.Int32FromUint8(_or_logic[v11*int32(3)+v21])
		}
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if v11 == int32(2) {
			(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
		} else {
			*(*Ti64)(unsafe.Pointer(pOut)) = int64(v11)
			(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Int))
		}
		goto _189
		/* Opcode: IsTrue P1 P2 P3 P4 *
		 ** Synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4
		 **
		 ** This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and
		 ** IS NOT FALSE operators.
		 **
		 ** Interpret the value in register P1 as a boolean value.  Store that
		 ** boolean (a 0 or 1) in register P2.  Or if the value in register P1 is
		 ** NULL, then the P3 is stored in register P2.  Invert the answer if P4
		 ** is 1.
		 **
		 ** The logic is summarized like this:
		 **
		 ** <ul>
		 ** <li> If P3==0 and P4==0  then  r[P2] := r[P1] IS TRUE
		 ** <li> If P3==1 and P4==1  then  r[P2] := r[P1] IS FALSE
		 ** <li> If P3==0 and P4==1  then  r[P2] := r[P1] IS NOT TRUE
		 ** <li> If P3==1 and P4==0  then  r[P2] := r[P1] IS NOT FALSE
		 ** </ul>
		 */
	_53:
		; /* in1, out2 */
		_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56, int64(_sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56, (*TOp)(unsafe.Pointer(pOp)).Fp3)^(*TOp)(unsafe.Pointer(pOp)).Fp4.Fi))
		goto _189
		/* Opcode: Not P1 P2 * * *
		 ** Synopsis: r[P2]= !r[P1]
		 **
		 ** Interpret the value in register P1 as a boolean value.  Store the
		 ** boolean complement in register P2.  If the value in register P1 is
		 ** NULL, then a NULL is stored in P2.
		 */
	_54:
		; /* same as TK_NOT, in1, out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
			_sqlite3VdbeMemSetInt64(tls, pOut, libc.BoolInt64(!(_sqlite3VdbeBooleanValue(tls, pIn1, 0) != 0)))
		} else {
			_sqlite3VdbeMemSetNull(tls, pOut)
		}
		goto _189
		/* Opcode: BitNot P1 P2 * * *
		 ** Synopsis: r[P2]= ~r[P1]
		 **
		 ** Interpret the content of register P1 as an integer.  Store the
		 ** ones-complement of the P1 value into register P2.  If P1 holds
		 ** a NULL then store a NULL in P2.
		 */
	_55:
		; /* same as TK_BITNOT, in1, out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		_sqlite3VdbeMemSetNull(tls, pOut)
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
			*(*Ti64)(unsafe.Pointer(pOut)) = ^_sqlite3VdbeIntValue(tls, pIn1)
		}
		goto _189
		/* Opcode: Once P1 P2 P3 * *
		 **
		 ** Fall through to the next instruction the first time this opcode is
		 ** encountered on each invocation of the byte-code program.  Jump to P2
		 ** on the second and all subsequent encounters during the same invocation.
		 **
		 ** Top-level programs determine first invocation by comparing the P1
		 ** operand against the P1 operand on the OP_Init opcode at the beginning
		 ** of the program.  If the P1 values differ, then fall through and make
		 ** the P1 of this opcode equal to the P1 of OP_Init.  If P1 values are
		 ** the same then take the jump.
		 **
		 ** For subprograms, there is a bitmask in the VdbeFrame that determines
		 ** whether or not the jump should be taken.  The bitmask is necessary
		 ** because the self-altering code trick does not work for recursive
		 ** triggers.
		 **
		 ** The P3 operand is not used directly by this opcode.  However P3 is
		 ** used by the code generator as follows:  If this opcode is the start
		 ** of a subroutine and that subroutine uses a Bloom filter, then P3 will
		 ** be the register that holds that Bloom filter.  See tag-202407032019
		 ** in the source code for implementation details.
		 */
	_56:
		; /* Address of this instruction */
		if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
			iAddr = libc.Uint32FromInt32(int32((int64(pOp) - int64((*TVdbe)(unsafe.Pointer(p)).FaOp)) / 24))
			if libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TVdbeFrame)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/uint32(8)))))&(int32(1)<<(iAddr&uint32(7))) != 0 {
				goto jump_to_p2
			}
			v191 = (*TVdbeFrame)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/uint32(8))
			*(*Tu8)(unsafe.Pointer(v191)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v191))) | libc.Int32FromInt32(1)<<(iAddr&libc.Uint32FromInt32(7)))
		} else {
			if (**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp))).Fp1 == (*TOp)(unsafe.Pointer(pOp)).Fp1 {
				goto jump_to_p2
			}
		}
		(*TOp)(unsafe.Pointer(pOp)).Fp1 = (**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp))).Fp1
		goto _189
		/* Opcode: If P1 P2 P3 * *
		 **
		 ** Jump to P2 if the value in register P1 is true.  The value
		 ** is considered true if it is numeric and non-zero.  If the value
		 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
		 */
	_57:
		;
		c = _sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56, (*TOp)(unsafe.Pointer(pOp)).Fp3)
		if c != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: IfNot P1 P2 P3 * *
		 **
		 ** Jump to P2 if the value in register P1 is False.  The value
		 ** is considered false if it has a numeric value of zero.  If the value
		 ** in P1 is NULL then take the jump if and only if P3 is non-zero.
		 */
	_58:
		;
		c1 = libc.BoolInt32(!(_sqlite3VdbeBooleanValue(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56, libc.BoolInt32(!((*TOp)(unsafe.Pointer(pOp)).Fp3 != 0))) != 0))
		if c1 != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: IsNull P1 P2 * * *
		 ** Synopsis: if r[P1]==NULL goto P2
		 **
		 ** Jump to P2 if the value in register P1 is NULL.
		 */
	_59:
		; /* same as TK_ISNULL, jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: IsType P1 P2 P3 P4 P5
		 ** Synopsis: if typeof(P1.P3) in P5 goto P2
		 **
		 ** Jump to P2 if the type of a column in a btree is one of the types specified
		 ** by the P5 bitmask.
		 **
		 ** P1 is normally a cursor on a btree for which the row decode cache is
		 ** valid through at least column P3.  In other words, there should have been
		 ** a prior OP_Column for column P3 or greater.  If the cursor is not valid,
		 ** then this opcode might give spurious results.
		 ** The the btree row has fewer than P3 columns, then use P4 as the
		 ** datatype.
		 **
		 ** If P1 is -1, then P3 is a register number and the datatype is taken
		 ** from the value in that register.
		 **
		 ** P5 is a bitmask of data types.  SQLITE_INTEGER is the least significant
		 ** (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04.
		 ** SQLITE_BLOB is 0x08.  SQLITE_NULL is 0x10.
		 **
		 ** WARNING: This opcode does not reliably distinguish between NULL and REAL
		 ** when P1>=0.  If the database contains a NaN value, this opcode will think
		 ** that the datatype is REAL when it should be NULL.  When P1<0 and the value
		 ** is already stored in register P3, then this opcode does reliably
		 ** distinguish between NULL and REAL.  The problem only arises then P1>=0.
		 **
		 ** Take the jump to address P2 if and only if the datatype of the
		 ** value determined by P1 and P3 corresponds to one of the bits in the
		 ** P5 bitmask.
		 **
		 */
	_60:
		;
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 >= 0 {
			pC = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 < libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) {
				serialType = *(*Tu32)(unsafe.Pointer(pC + 120 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*4))
				if serialType >= uint32(12) {
					if serialType&uint32(1) != 0 {
						typeMask = uint16(0x04) /* SQLITE_TEXT */
					} else {
						typeMask = uint16(0x08) /* SQLITE_BLOB */
					}
				} else {
					typeMask = uint16(_aMask[serialType])
				}
			} else {
				typeMask = libc.Uint16FromInt32(int32(1) << ((*TOp)(unsafe.Pointer(pOp)).Fp4.Fi - int32(1)))
			}
		} else {
			typeMask = libc.Uint16FromInt32(int32(1) << (Xsqlite3_value_type(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56) - int32(1)))
		}
		if libc.Int32FromUint16(typeMask)&libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: ZeroOrNull P1 P2 P3 * *
		 ** Synopsis: r[P2] = 0 OR NULL
		 **
		 ** If both registers P1 and P3 are NOT NULL, then store a zero in
		 ** register P2.  If either registers P1 or P3 are NULL then put
		 ** a NULL in register P2.
		 */
	_61:
		; /* in1, in2, out2, in3 */
		if libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56))).Fflags)&int32(MEM_Null) != 0 || libc.Int32FromUint16((**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56))).Fflags)&int32(MEM_Null) != 0 {
			_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56)
		} else {
			_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56, 0)
		}
		goto _189
		/* Opcode: NotNull P1 P2 * * *
		 ** Synopsis: if r[P1]!=NULL goto P2
		 **
		 ** Jump to P2 if the value in register P1 is not NULL.
		 */
	_62:
		; /* same as TK_NOTNULL, jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: IfNullRow P1 P2 P3 * *
		 ** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
		 **
		 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
		 ** If it is, then set register P3 to NULL and jump immediately to P2.
		 ** If P1 is not on a NULL row, then fall through without making any
		 ** changes.
		 **
		 ** If P1 is not an open cursor, then this opcode is a no-op.
		 */
	_63:
		;
		pC1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if pC1 != 0 && (*TVdbeCursor)(unsafe.Pointer(pC1)).FnullRow != 0 {
			_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56)
			goto jump_to_p2
		}
		goto _189
		/* Opcode: Offset P1 P2 P3 * *
		 ** Synopsis: r[P3] = sqlite_offset(P1)
		 **
		 ** Store in register r[P3] the byte offset into the database file that is the
		 ** start of the payload for the record at which that cursor P1 is currently
		 ** pointing.
		 **
		 ** P2 is the column number for the argument to the sqlite_offset() function.
		 ** This opcode does not use P2 itself, but the P2 value is used by the
		 ** code generator.  The P1, P2, and P3 operands to this opcode are the
		 ** same as for OP_Column.
		 **
		 ** This opcode is only available if SQLite is compiled with the
		 ** -DSQLITE_ENABLE_OFFSET_SQL_FUNC option.
		 */
	_64:
		; /* The VDBE cursor */
		pC2 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pOut = (*TVdbe)(unsafe.Pointer(p)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if pC2 == uintptr(0) || libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC2)).FeCurType) != CURTYPE_BTREE {
			_sqlite3VdbeMemSetNull(tls, pOut)
		} else {
			if (*TVdbeCursor)(unsafe.Pointer(pC2)).FdeferredMoveto != 0 {
				rc = _sqlite3VdbeFinishMoveto(tls, pC2)
				if rc != 0 {
					goto abort_due_to_error
				}
			}
			if _sqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC2 + 48))) != 0 {
				_sqlite3VdbeMemSetNull(tls, pOut)
			} else {
				_sqlite3VdbeMemSetInt64(tls, pOut, _sqlite3BtreeOffset(tls, *(*uintptr)(unsafe.Pointer(pC2 + 48))))
			}
		}
		goto _189
		/* Opcode: Column P1 P2 P3 P4 P5
		 ** Synopsis: r[P3]=PX cursor P1 column P2
		 **
		 ** Interpret the data that cursor P1 points to as a structure built using
		 ** the MakeRecord instruction.  (See the MakeRecord opcode for additional
		 ** information about the format of the data.)  Extract the P2-th column
		 ** from this record.  If there are less than (P2+1)
		 ** values in the record, extract a NULL.
		 **
		 ** The value extracted is stored in register P3.
		 **
		 ** If the record contains fewer than P2 fields, then extract a NULL.  Or,
		 ** if the P4 argument is a P4_MEM use the value of the P4 argument as
		 ** the result.
		 **
		 ** If the OPFLAG_LENGTHARG bit is set in P5 then the result is guaranteed
		 ** to only be used by the length() function or the equivalent.  The content
		 ** of large blobs is not loaded, thus saving CPU cycles.  If the
		 ** OPFLAG_TYPEOFARG bit is set then the result will only be used by the
		 ** typeof() function or the IS NULL or IS NOT NULL operators or the
		 ** equivalent.  In this case, all content loading can be omitted.
		 */
	_65:
		; /* PseudoTable input register */
		pC3 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		p22 = libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
		goto op_column_restart
	op_column_restart:
		;
		aOffset = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaOffset
		if (*TVdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus != (*TVdbe)(unsafe.Pointer(p)).FcacheCtr { /*OPTIMIZATION-IF-FALSE*/
			if (*TVdbeCursor)(unsafe.Pointer(pC3)).FnullRow != 0 {
				if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC3)).FeCurType) == int32(CURTYPE_PSEUDO) && (*TVdbeCursor)(unsafe.Pointer(pC3)).FseekResult > 0 {
					/* For the special case of as pseudo-cursor, the seekResult field
					 ** identifies the register that holds the record */
					pReg = aMem + uintptr((*TVdbeCursor)(unsafe.Pointer(pC3)).FseekResult)*56
					v215 = libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pReg)).Fn)
					(*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow = v215
					(*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = v215
					(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = (*TMem)(unsafe.Pointer(pReg)).Fz
				} else {
					pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
					_sqlite3VdbeMemSetNull(tls, pDest)
					goto op_column_out
				}
			} else {
				pCrsr = *(*uintptr)(unsafe.Pointer(pC3 + 48))
				if (*TVdbeCursor)(unsafe.Pointer(pC3)).FdeferredMoveto != 0 {
					if v217 = *(*uintptr)(unsafe.Pointer(pC3 + 16)) != 0; v217 {
						v215 = **(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(pC3 + 16)) + uintptr(uint32(1)+p22)*4))
						iMap = v215
					}
					if v217 && v215 > uint32(0) {
						pC3 = (*TVdbeCursor)(unsafe.Pointer(pC3)).FpAltCursor
						p22 = iMap - uint32(1)
						goto op_column_restart
					}
					rc = _sqlite3VdbeFinishMoveto(tls, pC3)
					if rc != 0 {
						goto abort_due_to_error
					}
				} else {
					if _sqlite3BtreeCursorHasMoved(tls, pCrsr) != 0 {
						rc = _sqlite3VdbeHandleMovedCursor(tls, pC3)
						if rc != 0 {
							goto abort_due_to_error
						}
						goto op_column_restart
					}
				}
				(*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = _sqlite3BtreePayloadSize(tls, pCrsr)
				(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = _sqlite3BtreePayloadFetch(tls, pCrsr, pC3+108)
				/* Maximum page size is 64KiB */
			}
			(*TVdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus = (*TVdbe)(unsafe.Pointer(p)).FcacheCtr
			v215 = uint32(**(**Tu8)(__ccgo_up((*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow)))
			**(**Tu32)(__ccgo_up(aOffset)) = v215
			if v215 < uint32(0x80) {
				(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = uint32(1)
			} else {
				(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = uint32(_sqlite3GetVarint32(tls, (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow, aOffset))
			}
			(*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed = uint16(0)
			if (*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow < **(**Tu32)(__ccgo_up(aOffset)) { /*OPTIMIZATION-IF-FALSE*/
				/* pC->aRow does not have to hold the entire row, but it does at least
				 ** need to cover the header of the record.  If pC->aRow does not contain
				 ** the complete header, then set it to zero, forcing the header to be
				 ** dynamically allocated. */
				(*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow = uintptr(0)
				(*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow = uint32(0)
				/* Make sure a corrupt database has not given us an oversize header.
				 ** Do this now to avoid an oversize memory allocation.
				 **
				 ** Type entries can be between 1 and 5 bytes each.  But 4 and 5 byte
				 ** types use so much data space that there can only be 4096 and 32 of
				 ** them, respectively.  So the maximum header length results from a
				 ** 3-byte type for each of the maximum of 32768 columns plus three
				 ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
				 */
				if **(**Tu32)(__ccgo_up(aOffset)) > uint32(98307) || **(**Tu32)(__ccgo_up(aOffset)) > (*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize {
					goto op_column_corrupt
				}
			} else {
				/* This is an optimization.  By skipping over the first few tests
				 ** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
				 ** measurable performance gain.
				 **
				 ** This branch is taken even if aOffset[0]==0.  Such a record is never
				 ** generated by SQLite, and could be considered corruption, but we
				 ** accept it for historical reasons.  When aOffset[0]==0, the code this
				 ** branch jumps to reads past the end of the record, but never more
				 ** than a few bytes.  Even if the record occurs at the end of the page
				 ** content area, the "page header" comes after the page content and so
				 ** this overread is harmless.  Similar overreads can occur for a corrupt
				 ** database file.
				 */
				zData = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow
				/* Conditional skipped */
				goto op_column_read_header
			}
		} else {
			if _sqlite3BtreeCursorHasMoved(tls, *(*uintptr)(unsafe.Pointer(pC3 + 48))) != 0 {
				rc = _sqlite3VdbeHandleMovedCursor(tls, pC3)
				if rc != 0 {
					goto abort_due_to_error
				}
				goto op_column_restart
			}
		}
		/* Make sure at least the first p2+1 entries of the header have been
		 ** parsed and valid information is in aOffset[] and pC->aType[].
		 */
		if !(uint32((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed) <= p22) {
			goto _219
		}
		/* If there is more header available for parsing in the record, try
		 ** to extract additional fields up through the p2+1-th field
		 */
		if !((*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset < **(**Tu32)(__ccgo_up(aOffset))) {
			goto _221
		}
		/* Make sure zData points to enough of the record to cover the header. */
		if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
			libc.Xmemset(tls, bp+24, 0, uint64(56))
			rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, *(*uintptr)(unsafe.Pointer(pC3 + 48)), **(**Tu32)(__ccgo_up(aOffset)), bp+24)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			zData = (**(**TMem)(__ccgo_up(bp + 24))).Fz
		} else {
			zData = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow
		}
		/* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
		goto op_column_read_header
	op_column_read_header:
		;
		i1 = libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed)
		offset64 = uint64(**(**Tu32)(__ccgo_up(aOffset + uintptr(i1)*4)))
		zHdr = zData + uintptr((*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset)
		zEndHdr = zData + uintptr(**(**Tu32)(__ccgo_up(aOffset)))
		for cond := true; cond; cond = libc.Uint32FromInt32(i1) <= p22 && zHdr < zEndHdr {
			v216 = uint32(**(**Tu8)(__ccgo_up(zHdr)))
			**(**Tu32)(__ccgo_up(bp + 80)) = v216
			v215 = v216
			*(*Tu32)(unsafe.Pointer(pC3 + 120 + uintptr(i1)*4)) = v215
			if v215 < uint32(0x80) {
				zHdr = zHdr + 1
				offset64 = offset64 + uint64(_sqlite3VdbeOneByteSerialTypeLen(tls, uint8(**(**Tu32)(__ccgo_up(bp + 80)))))
			} else {
				zHdr = zHdr + uintptr(_sqlite3GetVarint32(tls, zHdr, bp+80))
				*(*Tu32)(unsafe.Pointer(pC3 + 120 + uintptr(i1)*4)) = **(**Tu32)(__ccgo_up(bp + 80))
				offset64 = offset64 + uint64(_sqlite3VdbeSerialTypeLen(tls, **(**Tu32)(__ccgo_up(bp + 80))))
			}
			i1 = i1 + 1
			v190 = i1
			**(**Tu32)(__ccgo_up(aOffset + uintptr(v190)*4)) = uint32(offset64 & libc.Uint64FromUint32(0xffffffff))
		}
		/* The record is corrupt if any of the following are true:
		 ** (1) the bytes of the header extend past the declared header size
		 ** (2) the entire header was used but not all data was used
		 ** (3) the end of the data extends beyond the end of the record.
		 */
		if zHdr >= zEndHdr && (zHdr > zEndHdr || offset64 != uint64((*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize)) || offset64 > uint64((*TVdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize) {
			if **(**Tu32)(__ccgo_up(aOffset)) == uint32(0) {
				i1 = 0
				zHdr = zEndHdr
			} else {
				if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
					_sqlite3VdbeMemRelease(tls, bp+24)
				}
				goto op_column_corrupt
			}
		}
		(*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed = libc.Uint16FromInt32(i1)
		(*TVdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = libc.Uint32FromInt64(int64(zHdr) - int64(zData))
		if (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0) {
			_sqlite3VdbeMemRelease(tls, bp+24)
		}
		goto _222
	_221:
		;
		**(**Tu32)(__ccgo_up(bp + 80)) = uint32(0)
	_222:
		;
		/* If after trying to extract new entries from the header, nHdrParsed is
		 ** still not up to p2, that means that the record has fewer than p2
		 ** columns.  So the result will be either the default value or a NULL.
		 */
		if uint32((*TVdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed) <= p22 {
			pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(11) {
				_sqlite3VdbeMemShallowCopy(tls, pDest, *(*uintptr)(unsafe.Pointer(pOp + 16)), int32(MEM_Static))
			} else {
				_sqlite3VdbeMemSetNull(tls, pDest)
			}
			goto op_column_out
		}
		goto _220
	_219:
		;
		**(**Tu32)(__ccgo_up(bp + 80)) = *(*Tu32)(unsafe.Pointer(pC3 + 120 + uintptr(p22)*4))
	_220:
		;
		/* Extract the content for the p2+1-th column.  Control can only
		 ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
		 ** all valid.
		 */
		pDest = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pDest)).Fflags)&(libc.Int32FromInt32(MEM_Agg)|libc.Int32FromInt32(MEM_Dyn)) != 0 {
			_sqlite3VdbeMemSetNull(tls, pDest)
		}
		if (*TVdbeCursor)(unsafe.Pointer(pC3)).FszRow >= **(**Tu32)(__ccgo_up(aOffset + uintptr(p22+uint32(1))*4)) {
			/* This is the common case where the desired content fits on the original
			 ** page - where the content is not on an overflow page */
			zData = (*TVdbeCursor)(unsafe.Pointer(pC3)).FaRow + uintptr(**(**Tu32)(__ccgo_up(aOffset + uintptr(p22)*4)))
			if **(**Tu32)(__ccgo_up(bp + 80)) < uint32(12) {
				_sqlite3VdbeSerialGet(tls, zData, **(**Tu32)(__ccgo_up(bp + 80)), pDest)
			} else {
				v190 = libc.Int32FromUint32((**(**Tu32)(__ccgo_up(bp + 80)) - libc.Uint32FromInt32(12)) / libc.Uint32FromInt32(2))
				len1 = v190
				(*TMem)(unsafe.Pointer(pDest)).Fn = v190
				(*TMem)(unsafe.Pointer(pDest)).Fenc = encoding
				if (*TMem)(unsafe.Pointer(pDest)).FszMalloc < len1+int32(2) {
					if len1 > **(**int32)(__ccgo_up(db + 136)) {
						goto too_big
					}
					(*TMem)(unsafe.Pointer(pDest)).Fflags = uint16(MEM_Null)
					if _sqlite3VdbeMemGrow(tls, pDest, len1+int32(2), 0) != 0 {
						goto no_mem
					}
				} else {
					(*TMem)(unsafe.Pointer(pDest)).Fz = (*TMem)(unsafe.Pointer(pDest)).FzMalloc
				}
				libc.Xmemcpy(tls, (*TMem)(unsafe.Pointer(pDest)).Fz, zData, libc.Uint64FromInt32(len1))
				**(**uint8)(__ccgo_up((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1))) = uint8(0)
				**(**uint8)(__ccgo_up((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1+int32(1)))) = uint8(0)
				(*TMem)(unsafe.Pointer(pDest)).Fflags = _aFlag1[**(**Tu32)(__ccgo_up(bp + 80))&uint32(1)]
			}
		} else {
			(*TMem)(unsafe.Pointer(pDest)).Fenc = encoding
			/* This branch happens only when content is on overflow pages */
			v227 = libc.Uint8FromInt32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) & libc.Int32FromInt32(OPFLAG_BYTELENARG))
			p5 = v227
			if libc.Int32FromUint8(v227) != 0 && (libc.Int32FromUint8(p5) == int32(OPFLAG_TYPEOFARG) || **(**Tu32)(__ccgo_up(bp + 80)) >= uint32(12) && (**(**Tu32)(__ccgo_up(bp + 80))&uint32(1) == uint32(0) || libc.Int32FromUint8(p5) == int32(OPFLAG_BYTELENARG))) || _sqlite3VdbeSerialTypeLen(tls, **(**Tu32)(__ccgo_up(bp + 80))) == uint32(0) {
				/* Content is irrelevant for
				 **    1. the typeof() function,
				 **    2. the length(X) function if X is a blob, and
				 **    3. if the content length is zero.
				 ** So we might as well use bogus content rather than reading
				 ** content from disk.
				 **
				 ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the
				 ** buffer passed to it, debugging function VdbeMemPrettyPrint() may
				 ** read more.  Use the global constant sqlite3CtypeMap[] as the array,
				 ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint())
				 ** and it begins with a bunch of zeros.
				 */
				_sqlite3VdbeSerialGet(tls, uintptr(unsafe.Pointer(&_sqlite3CtypeMap)), **(**Tu32)(__ccgo_up(bp + 80)), pDest)
			} else {
				rc = _vdbeColumnFromOverflow(tls, pC3, libc.Int32FromUint32(p22), **(**Tu32)(__ccgo_up(bp + 80)), libc.Int64FromUint32(**(**Tu32)(__ccgo_up(aOffset + uintptr(p22)*4))), (*TVdbe)(unsafe.Pointer(p)).FcacheCtr, colCacheCtr, pDest)
				if rc != 0 {
					if rc == int32(SQLITE_NOMEM) {
						goto no_mem
					}
					if rc == int32(SQLITE_TOOBIG) {
						goto too_big
					}
					goto abort_due_to_error
				}
			}
		}
		goto op_column_out
	op_column_out:
		;
		goto _189
		goto op_column_corrupt
	op_column_corrupt:
		;
		if (**(**TOp)(__ccgo_up(aOp))).Fp3 > 0 {
			pOp = aOp + uintptr((**(**TOp)(__ccgo_up(aOp))).Fp3-int32(1))*24
			goto _189
		} else {
			rc = _sqlite3CorruptError(tls, int32(99872))
			goto abort_due_to_error
		}
		/* Opcode: TypeCheck P1 P2 P3 P4 *
		 ** Synopsis: typecheck(r[P1@P2])
		 **
		 ** Apply affinities to the range of P2 registers beginning with P1.
		 ** Take the affinities from the Table object in P4.  If any value
		 ** cannot be coerced into the correct type, then raise an error.
		 **
		 ** If P3==0, then omit checking of VIRTUAL columns.
		 **
		 ** If P3==1, then omit checking of all generated column, both VIRTUAL
		 ** and STORED.
		 **
		 ** If P3>=2, then only check column number P3-2 in the table (which will
		 ** be a VIRTUAL column) against the value in reg[P1].  In this case,
		 ** P2 will be 1.
		 **
		 ** This opcode is similar to OP_Affinity except that this opcode
		 ** forces the register type to the Table column type.  This is used
		 ** to implement "strict affinity".
		 **
		 ** GENERATED ALWAYS AS ... STATIC columns are only checked if P3
		 ** is zero.  When P3 is non-zero, no type checking occurs for
		 ** static generated columns.  Virtual columns are computed at query time
		 ** and so they are never checked.
		 **
		 ** Preconditions:
		 **
		 ** <ul>
		 ** <li> P2 should be the number of non-virtual columns in the
		 **      table of P4 unless P3>1, in which case P2 will be 1.
		 ** <li> Table P4 is a STRICT table.
		 ** </ul>
		 **
		 ** If any precondition is false, an assertion fault occurs.
		 */
	_66:
		;
		pTab = *(*uintptr)(unsafe.Pointer(pOp + 16))
		aCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 < int32(2) {
			i2 = 0
			nCol = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
		} else {
			i2 = (*TOp)(unsafe.Pointer(pOp)).Fp3 - int32(2)
			nCol = i2 + int32(1)
		}
		for {
			if !(i2 < nCol) {
				break
			}
			if libc.Int32FromUint16((**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*16))).FcolFlags)&int32(COLFLAG_GENERATED) != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp3 < int32(2) {
				if libc.Int32FromUint16((**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*16))).FcolFlags)&int32(COLFLAG_VIRTUAL) != 0 {
					goto _228
				}
				if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
					pIn1 += 56
					goto _228
				}
			}
			_applyAffinity(tls, pIn1, (**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*16))).Faffinity, encoding)
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) == 0 {
				switch int32(uint32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*16 + 8)) & 0xf >> 0)) {
				case int32(COLTYPE_BLOB):
					if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
						goto vdbe_type_error
					}
				case int32(COLTYPE_INTEGER):
					fallthrough
				case int32(COLTYPE_INT):
					if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) == 0 {
						goto vdbe_type_error
					}
				case int32(COLTYPE_TEXT):
					if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Str) == 0 {
						goto vdbe_type_error
					}
				case int32(COLTYPE_REAL):
					if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
						/* When applying REAL affinity, if the result is still an MEM_Int
						 ** that will fit in 6 bytes, then change the type to MEM_IntReal
						 ** so that we keep the high-resolution integer value but know that
						 ** the type really wants to be REAL. */
						if *(*Ti64)(unsafe.Pointer(pIn1)) <= int64(140737488355327) && *(*Ti64)(unsafe.Pointer(pIn1)) >= -int64(140737488355328) {
							v191 = pIn1 + 20
							*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_IntReal))
							v191 = pIn1 + 20
							*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
						} else {
							*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*Ti64)(unsafe.Pointer(pIn1)))
							v191 = pIn1 + 20
							*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Real))
							v191 = pIn1 + 20
							*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
						}
					} else {
						if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&(libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
							goto vdbe_type_error
						}
					}
				default:
					/* COLTYPE_ANY.  Accept anything. */
					break
				}
			}
			pIn1 += 56
			goto _228
		_228:
			;
			i2 = i2 + 1
		}
		goto _189
		goto vdbe_type_error
	vdbe_type_error:
		;
		_sqlite3VdbeError(tls, p, __ccgo_ts+5888, libc.VaList(bp+984, _vdbeMemTypeName(tls, pIn1), _sqlite3StdType[int32(uint32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*16 + 8))&0xf>>0))-int32(1)], (*TTable)(unsafe.Pointer(pTab)).FzName, (**(**TColumn)(__ccgo_up(aCol + uintptr(i2)*16))).FzCnName))
		rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(12)<<libc.Int32FromInt32(8)
		goto abort_due_to_error
		/* Opcode: Affinity P1 P2 * P4 *
		 ** Synopsis: affinity(r[P1@P2])
		 **
		 ** Apply affinities to a range of P2 registers starting with P1.
		 **
		 ** P4 is a string that is P2 characters long. The N-th character of the
		 ** string indicates the column affinity that should be used for the N-th
		 ** memory cell in the range.
		 */
	_67:
		; /* The affinity to be applied */
		zAffinity = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		for int32(1) != 0 {
			_applyAffinity(tls, pIn1, **(**uint8)(__ccgo_up(zAffinity)), encoding)
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zAffinity))) == int32(SQLITE_AFF_REAL) && libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Int) != 0 {
				/* When applying REAL affinity, if the result is still an MEM_Int
				 ** that will fit in 6 bytes, then change the type to MEM_IntReal
				 ** so that we keep the high-resolution integer value but know that
				 ** the type really wants to be REAL. */
				if *(*Ti64)(unsafe.Pointer(pIn1)) <= int64(140737488355327) && *(*Ti64)(unsafe.Pointer(pIn1)) >= -int64(140737488355328) {
					v191 = pIn1 + 20
					*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_IntReal))
					v191 = pIn1 + 20
					*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
				} else {
					*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*Ti64)(unsafe.Pointer(pIn1)))
					v191 = pIn1 + 20
					*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Real))
					v191 = pIn1 + 20
					*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^(libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Str)))
				}
			}
			zAffinity = zAffinity + 1
			if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zAffinity))) == 0 {
				break
			}
			pIn1 += 56
		}
		goto _189
		/* Opcode: MakeRecord P1 P2 P3 P4 *
		 ** Synopsis: r[P3]=mkrec(r[P1@P2])
		 **
		 ** Convert P2 registers beginning with P1 into the [record format]
		 ** use as a data record in a database table or as a key
		 ** in an index.  The OP_Column opcode can decode the record later.
		 **
		 ** P4 may be a string that is P2 characters long.  The N-th character of the
		 ** string indicates the column affinity that should be used for the N-th
		 ** field of the index key.
		 **
		 ** The mapping from character to affinity is given by the SQLITE_AFF_
		 ** macros defined in sqliteInt.h.
		 **
		 ** If P4 is NULL then all index fields have the affinity BLOB.
		 **
		 ** The meaning of P5 depends on whether or not the SQLITE_ENABLE_NULL_TRIM
		 ** compile-time option is enabled:
		 **
		 **   * If SQLITE_ENABLE_NULL_TRIM is enabled, then the P5 is the index
		 **     of the right-most table that can be null-trimmed.
		 **
		 **   * If SQLITE_ENABLE_NULL_TRIM is omitted, then P5 has the value
		 **     OPFLAG_NOCHNG_MAGIC if the OP_MakeRecord opcode is allowed to
		 **     accept no-change records with serial_type 10.  This value is
		 **     only used inside an assert() and does not affect the end result.
		 */
	_68:
		; /* Where to write next byte of the payload */
		/* Assuming the record contains N fields, the record format looks
		 ** like this:
		 **
		 ** ------------------------------------------------------------------------
		 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
		 ** ------------------------------------------------------------------------
		 **
		 ** Data(0) is taken from register P1.  Data(1) comes from register P1+1
		 ** and so forth.
		 **
		 ** Each type field is a varint representing the serial type of the
		 ** corresponding data element (see sqlite3VdbeSerialType()). The
		 ** hdr-size field is also a varint which is the offset from the beginning
		 ** of the record to data0.
		 */
		nData = uint64(0) /* Number of bytes of data space */
		nHdr = 0          /* Number of bytes of header space */
		nZero = 0         /* Number of zero bytes at the end of the record */
		nField = (*TOp)(unsafe.Pointer(pOp)).Fp1
		zAffinity1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pData0 = aMem + uintptr(nField)*56
		nField = (*TOp)(unsafe.Pointer(pOp)).Fp2
		pLast = pData0 + uintptr(nField-int32(1))*56
		/* Identify the output register */
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		/* Apply the requested affinity to all inputs
		 */
		if zAffinity1 != 0 {
			pRec = pData0
			for cond := true; cond; cond = **(**uint8)(__ccgo_up(zAffinity1)) != 0 {
				_applyAffinity(tls, pRec, **(**uint8)(__ccgo_up(zAffinity1)), encoding)
				if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zAffinity1))) == int32(SQLITE_AFF_REAL) && libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Int) != 0 {
					v191 = pRec + 20
					*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_IntReal))
					v191 = pRec + 20
					*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Int))
				}
				zAffinity1 = zAffinity1 + 1
				pRec += 56
			}
		}
		/* Loop through the elements that will make up the record to figure
		 ** out how much space is required for the new record.  After this loop,
		 ** the Mem.uTemp field of each term should hold the serial-type that will
		 ** be used for that term in the generated record:
		 **
		 **   Mem.uTemp value    type
		 **   ---------------    ---------------
		 **      0               NULL
		 **      1               1-byte signed integer
		 **      2               2-byte signed integer
		 **      3               3-byte signed integer
		 **      4               4-byte signed integer
		 **      5               6-byte signed integer
		 **      6               8-byte signed integer
		 **      7               IEEE float
		 **      8               Integer constant 0
		 **      9               Integer constant 1
		 **     10,11            reserved for expansion
		 **    N>=12 and even    BLOB
		 **    N>=13 and odd     text
		 **
		 ** The following additional values are computed:
		 **     nHdr        Number of bytes needed for the record header
		 **     nData       Number of bytes of data space needed for the record
		 **     nZero       Zero bytes at the end of the record
		 */
		pRec = pLast
		for cond := true; cond; cond = int32(1) != 0 {
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Null) != 0 {
				if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Zero) != 0 {
					/* Values with MEM_Null and MEM_Zero are created by xColumn virtual
					 ** table methods that never invoke sqlite3_result_xxxxx() while
					 ** computing an unchanging column value in an UPDATE statement.
					 ** Give such values a special internal-use-only serial-type of 10
					 ** so that they can be passed through to xUpdate and have
					 ** a true sqlite3_value_nochange(). */
					(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(10)
				} else {
					(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(0)
				}
				nHdr = nHdr + 1
			} else {
				if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) != 0 {
					/* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
					i3 = *(*Ti64)(unsafe.Pointer(pRec))
					if i3 < 0 {
						uu = libc.Uint64FromInt64(^i3)
					} else {
						uu = libc.Uint64FromInt64(i3)
					}
					nHdr = nHdr + 1
					if uu <= uint64(127) {
						if i3&int64(1) == i3 && libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) >= int32(4) {
							(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(8) + uint32(uu)
						} else {
							nData = nData + 1
							(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(1)
						}
					} else {
						if uu <= uint64(32767) {
							nData = nData + uint64(2)
							(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(2)
						} else {
							if uu <= uint64(8388607) {
								nData = nData + uint64(3)
								(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(3)
							} else {
								if uu <= uint64(2147483647) {
									nData = nData + uint64(4)
									(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(4)
								} else {
									if uu <= uint64(140737488355327) {
										nData = nData + uint64(6)
										(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(5)
									} else {
										nData = nData + uint64(8)
										if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_IntReal) != 0 {
											/* If the value is IntReal and is going to take up 8 bytes to store
											 ** as an integer, then we might as well make it an 8-byte floating
											 ** point value */
											*(*float64)(unsafe.Pointer(pRec)) = float64(*(*Ti64)(unsafe.Pointer(pRec)))
											v191 = pRec + 20
											*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_IntReal))
											v191 = pRec + 20
											*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Real))
											(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(7)
										} else {
											(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(6)
										}
									}
								}
							}
						}
					}
				} else {
					if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Real) != 0 {
						nHdr = nHdr + 1
						nData = nData + uint64(8)
						(*TMem)(unsafe.Pointer(pRec)).FuTemp = uint32(7)
					} else {
						len11 = libc.Uint32FromInt32((*TMem)(unsafe.Pointer(pRec)).Fn)
						serial_type = len11*uint32(2) + uint32(12) + libc.BoolUint32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&libc.Int32FromInt32(MEM_Str) != libc.Int32FromInt32(0))
						if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRec)).Fflags)&int32(MEM_Zero) != 0 {
							serial_type = serial_type + libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))*uint32(2)
							if nData != 0 {
								if _sqlite3VdbeMemExpandBlob(tls, pRec) != 0 {
									goto no_mem
								}
								len11 = len11 + libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))
							} else {
								nZero = nZero + int64(*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pRec)).Fu)))
							}
						}
						nData = nData + uint64(len11)
						nHdr = nHdr + _sqlite3VarintLen(tls, uint64(serial_type))
						(*TMem)(unsafe.Pointer(pRec)).FuTemp = serial_type
					}
				}
			}
			if pRec == pData0 {
				break
			}
			pRec -= 56
		}
		/* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
		 ** which determines the total number of bytes in the header. The varint
		 ** value is the size of the header in bytes including the size varint
		 ** itself. */
		if nHdr <= int32(126) {
			/* The common case */
			nHdr = nHdr + int32(1)
		} else {
			/* Rare case of a really large header */
			nVarint = _sqlite3VarintLen(tls, libc.Uint64FromInt32(nHdr))
			nHdr = nHdr + nVarint
			if nVarint < _sqlite3VarintLen(tls, libc.Uint64FromInt32(nHdr)) {
				nHdr = nHdr + 1
			}
		}
		nByte1 = libc.Int64FromUint64(libc.Uint64FromInt32(nHdr) + nData)
		/* Make sure the output register has a buffer large enough to store
		 ** the new record. The output register (pOp->p3) is not allowed to
		 ** be one of the input registers (because the following call to
		 ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used).
		 */
		if nByte1+nZero <= int64((*TMem)(unsafe.Pointer(pOut)).FszMalloc) {
			/* The output register is already large enough to hold the record.
			 ** No error checks or buffer enlargement is required */
			(*TMem)(unsafe.Pointer(pOut)).Fz = (*TMem)(unsafe.Pointer(pOut)).FzMalloc
		} else {
			/* Need to make sure that the output is not too big and then enlarge
			 ** the output register to hold the full result */
			if nByte1+nZero > int64(**(**int32)(__ccgo_up(db + 136))) {
				goto too_big
			}
			if _sqlite3VdbeMemClearAndResize(tls, pOut, int32(nByte1)) != 0 {
				goto no_mem
			}
		}
		(*TMem)(unsafe.Pointer(pOut)).Fn = int32(nByte1)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Blob)
		if nZero != 0 {
			*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pOut)).Fu)) = int32(nZero)
			v191 = pOut + 20
			*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Zero))
		}
		zHdr1 = (*TMem)(unsafe.Pointer(pOut)).Fz
		zPayload = zHdr1 + uintptr(nHdr)
		/* Write the record */
		if nHdr < int32(0x80) {
			v191 = zHdr1
			zHdr1 = zHdr1 + 1
			**(**Tu8)(__ccgo_up(v191)) = libc.Uint8FromInt32(nHdr)
		} else {
			zHdr1 = zHdr1 + uintptr(_sqlite3PutVarint(tls, zHdr1, libc.Uint64FromInt32(nHdr)))
		}
		pRec = pData0
		for int32(1) != 0 {
			serial_type = (*TMem)(unsafe.Pointer(pRec)).FuTemp
			/* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
			 ** additional varints, one per column.
			 ** EVIDENCE-OF: R-64536-51728 The values for each column in the record
			 ** immediately follow the header. */
			if serial_type <= uint32(7) {
				v191 = zHdr1
				zHdr1 = zHdr1 + 1
				**(**Tu8)(__ccgo_up(v191)) = uint8(serial_type)
				if serial_type == uint32(0) {
					/* NULL value.  No change in zPayload */
				} else {
					if serial_type == uint32(7) {
						libc.Xmemcpy(tls, bp+88, pRec, uint64(8))
					} else {
						**(**Tu64)(__ccgo_up(bp + 88)) = libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(pRec)))
					}
					len11 = uint32(_sqlite3SmallTypeSizes[serial_type])
					switch len11 {
					default:
						**(**Tu8)(__ccgo_up(zPayload + 7)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						**(**Tu8)(__ccgo_up(zPayload + 6)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						fallthrough
					case uint32(6):
						**(**Tu8)(__ccgo_up(zPayload + 5)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						**(**Tu8)(__ccgo_up(zPayload + 4)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						fallthrough
					case uint32(4):
						**(**Tu8)(__ccgo_up(zPayload + 3)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						fallthrough
					case uint32(3):
						**(**Tu8)(__ccgo_up(zPayload + 2)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						fallthrough
					case uint32(2):
						**(**Tu8)(__ccgo_up(zPayload + 1)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
						**(**Tu64)(__ccgo_up(bp + 88)) = **(**Tu64)(__ccgo_up(bp + 88)) >> uint64(8)
						fallthrough
					case uint32(1):
						**(**Tu8)(__ccgo_up(zPayload)) = uint8(**(**Tu64)(__ccgo_up(bp + 88)) & libc.Uint64FromInt32(0xff))
					}
					zPayload = zPayload + uintptr(len11)
				}
			} else {
				if serial_type < uint32(0x80) {
					v191 = zHdr1
					zHdr1 = zHdr1 + 1
					**(**Tu8)(__ccgo_up(v191)) = uint8(serial_type)
					if serial_type >= uint32(14) && (*TMem)(unsafe.Pointer(pRec)).Fn > 0 {
						libc.Xmemcpy(tls, zPayload, (*TMem)(unsafe.Pointer(pRec)).Fz, libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pRec)).Fn))
						zPayload = zPayload + uintptr((*TMem)(unsafe.Pointer(pRec)).Fn)
					}
				} else {
					zHdr1 = zHdr1 + uintptr(_sqlite3PutVarint(tls, zHdr1, uint64(serial_type)))
					if (*TMem)(unsafe.Pointer(pRec)).Fn != 0 {
						libc.Xmemcpy(tls, zPayload, (*TMem)(unsafe.Pointer(pRec)).Fz, libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pRec)).Fn))
						zPayload = zPayload + uintptr((*TMem)(unsafe.Pointer(pRec)).Fn)
					}
				}
			}
			if pRec == pLast {
				break
			}
			pRec += 56
		}
		goto _189
		/* Opcode: Count P1 P2 P3 * *
		 ** Synopsis: r[P2]=count()
		 **
		 ** Store the number of entries (an integer value) in the table or index
		 ** opened by cursor P1 in register P2.
		 **
		 ** If P3==0, then an exact count is obtained, which involves visiting
		 ** every btree page of the table.  But if P3 is non-zero, an estimate
		 ** is returned based on the current cursor position.
		 */
	_69:
		;
		pCrsr1 = *(*uintptr)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8)) + 48))
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			**(**Ti64)(__ccgo_up(bp + 96)) = _sqlite3BtreeRowCountEst(tls, pCrsr1)
		} else {
			**(**Ti64)(__ccgo_up(bp + 96)) = 0 /* Not needed.  Only used to silence a warning. */
			rc = _sqlite3BtreeCount(tls, db, pCrsr1, bp+96)
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 96))
		goto check_for_interrupt
		/* Opcode: Savepoint P1 * * P4 *
		 **
		 ** Open, release or rollback the savepoint named by parameter P4, depending
		 ** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
		 ** To release (commit) an existing savepoint set P1==1 (SAVEPOINT_RELEASE).
		 ** To rollback an existing savepoint set P1==2 (SAVEPOINT_ROLLBACK).
		 */
	_70:
		;
		p12 = (*TOp)(unsafe.Pointer(pOp)).Fp1
		zName = *(*uintptr)(unsafe.Pointer(pOp + 16))
		/* Assert that the p1 parameter is valid. Also that if there is no open
		 ** transaction, then there cannot be any savepoints.
		 */
		if p12 == SAVEPOINT_BEGIN {
			if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 {
				/* A new savepoint cannot be created if there are active write
				 ** statements (i.e. open read/write incremental blob handles).
				 */
				_sqlite3VdbeError(tls, p, __ccgo_ts+5929, 0)
				rc = int32(SQLITE_BUSY)
			} else {
				nName = _sqlite3Strlen30(tls, zName)
				/* This call is Ok even if this savepoint is actually a transaction
				 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
				 ** If this is a transaction savepoint being opened, it is guaranteed
				 ** that the db->aVTrans[] array is empty.  */
				rc = _sqlite3VtabSavepoint(tls, db, SAVEPOINT_BEGIN, (*Tsqlite3)(unsafe.Pointer(db)).FnStatement+(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint)
				if rc != SQLITE_OK {
					goto abort_due_to_error
				}
				/* Create a new savepoint structure. */
				pNew = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(32)+libc.Uint64FromInt32(nName)+uint64(1)))
				if pNew != 0 {
					(*TSavepoint)(unsafe.Pointer(pNew)).FzName = pNew + 1*32
					libc.Xmemcpy(tls, (*TSavepoint)(unsafe.Pointer(pNew)).FzName, zName, libc.Uint64FromInt32(nName+int32(1)))
					/* If there is no open transaction, then mark this as a special
					 ** "transaction savepoint". */
					if (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
						(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
						(*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = uint8(1)
					} else {
						(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint + 1
					}
					/* Link the new savepoint into the database handle's list. */
					(*TSavepoint)(unsafe.Pointer(pNew)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint
					(*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint = pNew
					(*TSavepoint)(unsafe.Pointer(pNew)).FnDeferredCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons
					(*TSavepoint)(unsafe.Pointer(pNew)).FnDeferredImmCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons
				}
			}
		} else {
			iSavepoint = 0
			/* Find the named savepoint. If there is no such savepoint, then an
			 ** an error is returned to the user.  */
			pSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint
			for {
				if !(pSavepoint != 0 && _sqlite3StrICmp(tls, (*TSavepoint)(unsafe.Pointer(pSavepoint)).FzName, zName) != 0) {
					break
				}
				iSavepoint = iSavepoint + 1
				goto _245
			_245:
				;
				pSavepoint = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext
			}
			if !(pSavepoint != 0) {
				_sqlite3VdbeError(tls, p, __ccgo_ts+5980, libc.VaList(bp+984, zName))
				rc = int32(SQLITE_ERROR)
			} else {
				if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 && p12 == int32(SAVEPOINT_RELEASE) {
					/* It is not possible to release (commit) a savepoint if there are
					 ** active write statements.
					 */
					_sqlite3VdbeError(tls, p, __ccgo_ts+6002, 0)
					rc = int32(SQLITE_BUSY)
				} else {
					/* Determine whether or not this is a transaction savepoint. If so,
					 ** and this is a RELEASE command, then the current transaction
					 ** is committed.
					 */
					isTransaction = libc.BoolInt32((*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint != 0)
					if isTransaction != 0 && p12 == int32(SAVEPOINT_RELEASE) {
						v190 = _sqlite3VdbeCheckFkDeferred(tls, p)
						rc = v190
						if v190 != SQLITE_OK {
							goto vdbe_return
						}
						(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
						if _sqlite3VdbeHalt(tls, p) == int32(SQLITE_BUSY) {
							(*TVdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp) - int64(aOp)) / 24)
							(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
							v190 = libc.Int32FromInt32(SQLITE_BUSY)
							rc = v190
							(*TVdbe)(unsafe.Pointer(p)).Frc = v190
							goto vdbe_return
						}
						rc = (*TVdbe)(unsafe.Pointer(p)).Frc
						if rc != 0 {
							(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(0)
						} else {
							(*Tsqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = uint8(0)
						}
					} else {
						iSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint - iSavepoint - int32(1)
						if p12 == int32(SAVEPOINT_ROLLBACK) {
							isSchemaChange = libc.BoolInt32((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_SchemaChange) != uint32(0))
							ii = 0
							for {
								if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
									break
								}
								rc = _sqlite3BtreeTripAllCursors(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*32))).FpBt, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8), libc.BoolInt32(isSchemaChange == 0))
								if rc != SQLITE_OK {
									goto abort_due_to_error
								}
								goto _248
							_248:
								;
								ii = ii + 1
							}
						} else {
							isSchemaChange = 0
						}
						ii = 0
						for {
							if !(ii < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
								break
							}
							rc = _sqlite3BtreeSavepoint(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(ii)*32))).FpBt, p12, iSavepoint)
							if rc != SQLITE_OK {
								goto abort_due_to_error
							}
							goto _249
						_249:
							;
							ii = ii + 1
						}
						if isSchemaChange != 0 {
							_sqlite3ExpirePreparedStatements(tls, db, 0)
							_sqlite3ResetAllSchemasOfConnection(tls, db)
							**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_SchemaChange)
						}
					}
					if rc != 0 {
						goto abort_due_to_error
					}
					/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
					 ** savepoints nested inside of the savepoint being operated on. */
					for (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint != pSavepoint {
						pTmp = (*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint
						(*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint = (*TSavepoint)(unsafe.Pointer(pTmp)).FpNext
						_sqlite3DbFree(tls, db, pTmp)
						(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint - 1
					}
					/* If it is a RELEASE, then destroy the savepoint being operated on
					 ** too. If it is a ROLLBACK TO, then set the number of deferred
					 ** constraint violations present in the database to the value stored
					 ** when the savepoint was created.  */
					if p12 == int32(SAVEPOINT_RELEASE) {
						(*Tsqlite3)(unsafe.Pointer(db)).FpSavepoint = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FpNext
						_sqlite3DbFree(tls, db, pSavepoint)
						if !(isTransaction != 0) {
							(*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint - 1
						}
					} else {
						(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FnDeferredCons
						(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = (*TSavepoint)(unsafe.Pointer(pSavepoint)).FnDeferredImmCons
					}
					if !(isTransaction != 0) || p12 == int32(SAVEPOINT_ROLLBACK) {
						rc = _sqlite3VtabSavepoint(tls, db, p12, iSavepoint)
						if rc != SQLITE_OK {
							goto abort_due_to_error
						}
					}
				}
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_HALT_STATE) {
			rc = int32(SQLITE_DONE)
			goto vdbe_return
		}
		goto _189
		/* Opcode: AutoCommit P1 P2 * * *
		 **
		 ** Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
		 ** back any currently active btree transactions. If there are any active
		 ** VMs (apart from this one), then a ROLLBACK fails.  A COMMIT fails if
		 ** there are active writing VMs or active VMs that use shared cache.
		 **
		 ** This instruction causes the VM to halt.
		 */
	_71:
		;
		desiredAutoCommit = (*TOp)(unsafe.Pointer(pOp)).Fp1
		iRollback = (*TOp)(unsafe.Pointer(pOp)).Fp2
		/* At least this one VM is active */
		if desiredAutoCommit != libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) {
			if iRollback != 0 {
				_sqlite3RollbackAll(tls, db, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8))
				(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
			} else {
				if desiredAutoCommit != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 {
					/* If this instruction implements a COMMIT and other VMs are writing
					 ** return an error indicating that the other VMs must complete first.
					 */
					_sqlite3VdbeError(tls, p, __ccgo_ts+6056, 0)
					rc = int32(SQLITE_BUSY)
					goto abort_due_to_error
				} else {
					v190 = _sqlite3VdbeCheckFkDeferred(tls, p)
					rc = v190
					if v190 != SQLITE_OK {
						goto vdbe_return
					} else {
						(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = libc.Uint8FromInt32(desiredAutoCommit)
					}
				}
			}
			if _sqlite3VdbeHalt(tls, p) == int32(SQLITE_BUSY) {
				(*TVdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp) - int64(aOp)) / 24)
				(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = libc.Uint8FromInt32(libc.Int32FromInt32(1) - desiredAutoCommit)
				v190 = libc.Int32FromInt32(SQLITE_BUSY)
				rc = v190
				(*TVdbe)(unsafe.Pointer(p)).Frc = v190
				goto vdbe_return
			}
			_sqlite3CloseSavepoints(tls, db)
			if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				rc = int32(SQLITE_DONE)
			} else {
				rc = int32(SQLITE_ERROR)
			}
			goto vdbe_return
		} else {
			if !(desiredAutoCommit != 0) {
				v191 = __ccgo_ts + 6111
			} else {
				if iRollback != 0 {
					v194 = __ccgo_ts + 6159
				} else {
					v194 = __ccgo_ts + 6202
				}
				v191 = v194
			}
			_sqlite3VdbeError(tls, p, v191, 0)
			rc = int32(SQLITE_ERROR)
			goto abort_due_to_error
		}
		/* Opcode: Transaction P1 P2 P3 P4 P5
		 **
		 ** Begin a transaction on database P1 if a transaction is not already
		 ** active.
		 ** If P2 is non-zero, then a write-transaction is started, or if a
		 ** read-transaction is already active, it is upgraded to a write-transaction.
		 ** If P2 is zero, then a read-transaction is started.  If P2 is 2 or more
		 ** then an exclusive transaction is started.
		 **
		 ** P1 is the index of the database file on which the transaction is
		 ** started.  Index 0 is the main database file and index 1 is the
		 ** file used for temporary tables.  Indices of 2 or more are used for
		 ** attached databases.
		 **
		 ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
		 ** true (this flag is set if the Vdbe may modify more than one row and may
		 ** throw an ABORT exception), a statement transaction may also be opened.
		 ** More specifically, a statement transaction is opened iff the database
		 ** connection is currently not in autocommit mode, or if there are other
		 ** active statements. A statement transaction allows the changes made by this
		 ** VDBE to be rolled back after an error without having to roll back the
		 ** entire transaction. If no error is encountered, the statement transaction
		 ** will automatically commit when the VDBE halts.
		 **
		 ** If P5!=0 then this opcode also checks the schema cookie against P3
		 ** and the schema generation counter against P4.
		 ** The cookie changes its value whenever the database schema changes.
		 ** This operation is used to detect when that the cookie has changed
		 ** and that the current process needs to reread the schema.  If the schema
		 ** cookie in P3 differs from the schema cookie in the database header or
		 ** if the schema generation counter in P4 differs from the current
		 ** generation counter, then an SQLITE_SCHEMA error is raised and execution
		 ** halts.  The sqlite3_step() wrapper function might then reprepare the
		 ** statement and rerun it from the beginning.
		 */
	_72:
		;
		**(**int32)(__ccgo_up(bp + 104)) = 0
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(SQLITE_QueryOnly)|libc.Uint64FromInt32(libc.Int32FromInt32(0x00002))<<libc.Int32FromInt32(32)) != uint64(0) {
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_QueryOnly) != 0 {
				/* Writes prohibited by the "PRAGMA query_only=TRUE" statement */
				rc = int32(SQLITE_READONLY)
			} else {
				/* Writes prohibited due to a prior SQLITE_CORRUPT in the current
				 ** transaction */
				rc = int32(SQLITE_CORRUPT)
			}
			goto abort_due_to_error
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32
		pBt = (*TDb)(unsafe.Pointer(pDb)).FpBt
		if pBt != 0 {
			rc = _sqlite3BtreeBeginTrans(tls, pBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, bp+104)
			if rc != SQLITE_OK {
				if rc&int32(0xff) == int32(SQLITE_BUSY) {
					(*TVdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp) - int64(aOp)) / 24)
					(*TVdbe)(unsafe.Pointer(p)).Frc = rc
					goto vdbe_return
				}
				goto abort_due_to_error
			}
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x400>>10)) != 0 && (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 && (libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 || (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > int32(1)) {
				if (*TVdbe)(unsafe.Pointer(p)).FiStatement == 0 {
					(*Tsqlite3)(unsafe.Pointer(db)).FnStatement = (*Tsqlite3)(unsafe.Pointer(db)).FnStatement + 1
					(*TVdbe)(unsafe.Pointer(p)).FiStatement = (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint + (*Tsqlite3)(unsafe.Pointer(db)).FnStatement
				}
				rc = _sqlite3VtabSavepoint(tls, db, SAVEPOINT_BEGIN, (*TVdbe)(unsafe.Pointer(p)).FiStatement-int32(1))
				if rc == SQLITE_OK {
					rc = _sqlite3BtreeBeginStmt(tls, pBt, (*TVdbe)(unsafe.Pointer(p)).FiStatement)
				}
				/* Store the current value of the database handles deferred constraint
				 ** counter. If the statement transaction needs to be rolled back,
				 ** the value of this counter needs to be restored too.  */
				(*TVdbe)(unsafe.Pointer(p)).FnStmtDefCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons
				(*TVdbe)(unsafe.Pointer(p)).FnStmtDefImmCons = (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons
			}
		}
		if rc == SQLITE_OK && (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 && (**(**int32)(__ccgo_up(bp + 104)) != (*TOp)(unsafe.Pointer(pOp)).Fp3 || (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb)).FpSchema)).FiGeneration != (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi) {
			/*
			 ** IMPLEMENTATION-OF: R-03189-51135 As each SQL statement runs, the schema
			 ** version is checked to ensure that the schema has not changed since the
			 ** SQL statement was prepared.
			 */
			_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg)
			(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = _sqlite3DbStrDup(tls, db, __ccgo_ts+6243)
			/* If the schema-cookie from the database file matches the cookie
			 ** stored with the in-memory representation of the schema, do
			 ** not reload the schema from the database file.
			 **
			 ** If virtual-tables are in use, this is not just an optimization.
			 ** Often, v-tables store their data in other SQLite tables, which
			 ** are queried from within xNext() and other v-table methods using
			 ** prepared queries. If such a query is out-of-date, we do not want to
			 ** discard the database schema, as the user code implementing the
			 ** v-table would have to be ready for the sqlite3_vtab structure itself
			 ** to be invalidated whenever sqlite3_step() is called from within
			 ** a v-table method.
			 */
			if (*TSchema)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32))).FpSchema)).Fschema_cookie != **(**int32)(__ccgo_up(bp + 104)) {
				_sqlite3ResetOneSchema(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
			}
			libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 14, 0xc000)
			rc = int32(SQLITE_SCHEMA)
			/* Set changeCntOn to 0 to prevent the value returned by sqlite3_changes()
			 ** from being modified in sqlite3VdbeHalt(). If this statement is
			 ** reprepared, changeCntOn will be set again. */
			libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 11, 0x800)
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: ReadCookie P1 P2 P3 * *
		 **
		 ** Read cookie number P3 from database P1 and write it into register P2.
		 ** P3==1 is the schema version.  P3==2 is the database format.
		 ** P3==3 is the recommended pager cache size, and so forth.  P1==0 is
		 ** the main database file and P1==1 is the database file used to store
		 ** temporary tables.
		 **
		 ** There must be a read-lock on the database (either a transaction
		 ** must be started or there must be an open cursor) before
		 ** executing this instruction.
		 */
	_73:
		;
		iDb = (*TOp)(unsafe.Pointer(pOp)).Fp1
		iCookie = (*TOp)(unsafe.Pointer(pOp)).Fp3
		_sqlite3BtreeGetMeta(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32))).FpBt, iCookie, bp+108)
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = int64(**(**int32)(__ccgo_up(bp + 108)))
		goto _189
		/* Opcode: SetCookie P1 P2 P3 * P5
		 **
		 ** Write the integer value P3 into cookie number P2 of database P1.
		 ** P2==1 is the schema version.  P2==2 is the database format.
		 ** P2==3 is the recommended pager cache
		 ** size, and so forth.  P1==0 is the main database file and P1==1 is the
		 ** database file used to store temporary tables.
		 **
		 ** A transaction must be started before executing this opcode.
		 **
		 ** If P2 is the SCHEMA_VERSION cookie (cookie number 1) then the internal
		 ** schema version is set to P3-P5.  The "PRAGMA schema_version=N" statement
		 ** has P5 set to 1, so that the internal schema version will be different
		 ** from the database schema version, resulting in a schema reset.
		 */
	_74:
		;
		pDb1 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32
		/* See note about index shifting on OP_ReadCookie */
		rc = _sqlite3BtreeUpdateMeta(tls, (*TDb)(unsafe.Pointer(pDb1)).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3))
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 == int32(BTREE_SCHEMA_VERSION) {
			/* When the schema cookie changes, record the new cookie internally */
			**(**Tu32)(__ccgo_up((*TDb)(unsafe.Pointer(pDb1)).FpSchema)) = **(**Tu32)(__ccgo_up(pOp + 12)) - uint32((*TOp)(unsafe.Pointer(pOp)).Fp5)
			**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_SchemaChange)
			_sqlite3FkClearTriggerCache(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
		} else {
			if (*TOp)(unsafe.Pointer(pOp)).Fp2 == int32(BTREE_FILE_FORMAT) {
				/* Record changes in the file format */
				(*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb1)).FpSchema)).Ffile_format = libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
			}
		}
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 == int32(1) {
			/* Invalidate all prepared statements whenever the TEMP database
			 ** schema is changed.  Ticket #1644 */
			_sqlite3ExpirePreparedStatements(tls, db, 0)
			libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 14, 0xc000)
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: OpenRead P1 P2 P3 P4 P5
		 ** Synopsis: root=P2 iDb=P3
		 **
		 ** Open a read-only cursor for the database table whose root page is
		 ** P2 in a database file.  The database file is determined by P3.
		 ** P3==0 means the main database, P3==1 means the database used for
		 ** temporary tables, and P3>1 means used the corresponding attached
		 ** database.  Give the new cursor an identifier of P1.  The P1
		 ** values need not be contiguous but all P1 values should be small integers.
		 ** It is an error for P1 to be negative.
		 **
		 ** Allowed P5 bits:
		 ** <ul>
		 ** <li>  <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
		 **       equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
		 **       of OP_SeekLE/OP_IdxLT)
		 ** </ul>
		 **
		 ** The P4 value may be either an integer (P4_INT32) or a pointer to
		 ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
		 ** object, then table being opened must be an [index b-tree] where the
		 ** KeyInfo object defines the content and collating
		 ** sequence of that index b-tree. Otherwise, if P4 is an integer
		 ** value, then the table being opened must be a [table b-tree] with a
		 ** number of columns no less than the value of P4.
		 **
		 ** See also: OpenWrite, ReopenIdx
		 */
		/* Opcode: ReopenIdx P1 P2 P3 P4 P5
		 ** Synopsis: root=P2 iDb=P3
		 **
		 ** The ReopenIdx opcode works like OP_OpenRead except that it first
		 ** checks to see if the cursor on P1 is already open on the same
		 ** b-tree and if it is this opcode becomes a no-op.  In other words,
		 ** if the cursor is already open, do not reopen it.
		 **
		 ** The ReopenIdx opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
		 ** and with P4 being a P4_KEYINFO object.  Furthermore, the P3 value must
		 ** be the same as every other ReopenIdx or OpenRead for the same cursor
		 ** number.
		 **
		 ** Allowed P5 bits:
		 ** <ul>
		 ** <li>  <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
		 **       equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
		 **       of OP_SeekLE/OP_IdxLT)
		 ** </ul>
		 **
		 ** See also: OP_OpenRead, OP_OpenWrite
		 */
		/* Opcode: OpenWrite P1 P2 P3 P4 P5
		 ** Synopsis: root=P2 iDb=P3
		 **
		 ** Open a read/write cursor named P1 on the table or index whose root
		 ** page is P2 (or whose root page is held in register P2 if the
		 ** OPFLAG_P2ISREG bit is set in P5 - see below).
		 **
		 ** The P4 value may be either an integer (P4_INT32) or a pointer to
		 ** a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
		 ** object, then table being opened must be an [index b-tree] where the
		 ** KeyInfo object defines the content and collating
		 ** sequence of that index b-tree. Otherwise, if P4 is an integer
		 ** value, then the table being opened must be a [table b-tree] with a
		 ** number of columns no less than the value of P4.
		 **
		 ** Allowed P5 bits:
		 ** <ul>
		 ** <li>  <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
		 **       equality lookups (implemented as a pair of opcodes OP_SeekGE/OP_IdxGT
		 **       of OP_SeekLE/OP_IdxLT)
		 ** <li>  <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
		 **       and subsequently delete entries in an index btree.  This is a
		 **       hint to the storage engine that the storage engine is allowed to
		 **       ignore.  The hint is not used by the official SQLite b*tree storage
		 **       engine, but is used by COMDB2.
		 ** <li>  <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
		 **       as the root page, not the value of P2 itself.
		 ** </ul>
		 **
		 ** This instruction works like OpenRead except that it opens the cursor
		 ** in read/write mode.
		 **
		 ** See also: OP_OpenRead, OP_ReopenIdx
		 */
	_77:
		;
		pCur = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if pCur != 0 && (*TVdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot == libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2) {
			/* Guaranteed by the code generator */
			_sqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pCur + 48)))
			goto open_cursor_set_hints
		}
		/* If the cursor is not currently open or is open on a different
		 ** index, then fall through into OP_OpenRead to force a reopen */
	_76:
		; /* ncycle */
	_75:
		;
		if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0xc000>>14)) == int32(1) {
			rc = libc.Int32FromInt32(SQLITE_ABORT) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
			goto abort_due_to_error
		}
		nField1 = 0
		pKeyInfo1 = uintptr(0)
		p23 = libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
		iDb1 = (*TOp)(unsafe.Pointer(pOp)).Fp3
		pDb2 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb1)*32
		pX = (*TDb)(unsafe.Pointer(pDb2)).FpBt
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_OpenWrite) {
			wrFlag = int32(BTREE_WRCSR) | libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_FORDELETE)
			if libc.Int32FromUint8((*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format) < libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) {
				(*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat = (*TSchema)(unsafe.Pointer((*TDb)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format
			}
			if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_P2ISREG) != 0 {
				pIn2 = aMem + uintptr(p23)*56
				_sqlite3VdbeMemIntegerify(tls, pIn2)
				p23 = libc.Uint32FromInt32(int32(*(*Ti64)(unsafe.Pointer(pIn2))))
				/* The p2 value always comes from a prior OP_CreateBtree opcode and
				 ** that opcode will always set the p2 value to 2 or more or else fail.
				 ** If there were a failure, the prepared statement would have halted
				 ** before reaching this instruction. */
			}
		} else {
			wrFlag = 0
		}
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(9) {
			pKeyInfo1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			nField1 = libc.Int32FromUint16((*TKeyInfo)(unsafe.Pointer(pKeyInfo1)).FnAllField)
		} else {
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(3) {
				nField1 = (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi
			}
		}
		/* Table with INTEGER PRIMARY KEY and nothing else */
		pCur = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, nField1, uint8(CURTYPE_BTREE))
		if pCur == uintptr(0) {
			goto no_mem
		}
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FiDb = int8(iDb1)
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FnullRow = uint8(1)
		libc.SetBitFieldPtr8Uint32(pCur+8, libc.Uint32FromInt32(1), 5, 0x20)
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot = p23
		rc = _sqlite3BtreeCursor(tls, pX, p23, wrFlag, pKeyInfo1, *(*uintptr)(unsafe.Pointer(pCur + 48)))
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FpKeyInfo = pKeyInfo1
		/* Set the VdbeCursor.isTable variable. Previous versions of
		 ** SQLite used to check if the root-page flags were sane at this point
		 ** and report database corruption if they were not, but this check has
		 ** since moved into the btree layer.  */
		(*TVdbeCursor)(unsafe.Pointer(pCur)).FisTable = libc.BoolUint8(int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) != -int32(9))
		goto open_cursor_set_hints
	open_cursor_set_hints:
		;
		_sqlite3BtreeCursorHintFlags(tls, *(*uintptr)(unsafe.Pointer(pCur + 48)), libc.Uint32FromInt32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_BULKCSR)|libc.Int32FromInt32(OPFLAG_SEEKEQ))))
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: OpenDup P1 P2 * * *
		 **
		 ** Open a new cursor P1 that points to the same ephemeral table as
		 ** cursor P2.  The P2 cursor must have been opened by a prior OP_OpenEphemeral
		 ** opcode.  Only ephemeral cursors may be duplicated.
		 **
		 ** Duplicate ephemeral cursors are used for self-joins of materialized views.
		 */
	_78:
		; /* The new cursor */
		pOrig = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*8))
		/* Only ephemeral cursors can be duplicated */
		pCx = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, int32((*TVdbeCursor)(unsafe.Pointer(pOrig)).FnField), uint8(CURTYPE_BTREE))
		if pCx == uintptr(0) {
			goto no_mem
		}
		(*TVdbeCursor)(unsafe.Pointer(pCx)).FnullRow = uint8(1)
		libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(1), 7, 0x80)
		(*TVdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pOrig)).FpKeyInfo
		(*TVdbeCursor)(unsafe.Pointer(pCx)).FisTable = (*TVdbeCursor)(unsafe.Pointer(pOrig)).FisTable
		(*TVdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot = (*TVdbeCursor)(unsafe.Pointer(pOrig)).FpgnoRoot
		libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(int32(TBool(*(*uint8)(unsafe.Pointer(pOrig + 8))&0x20>>5))), 5, 0x20)
		*(*uintptr)(unsafe.Pointer(pCx + 16)) = *(*uintptr)(unsafe.Pointer(pOrig + 16))
		libc.SetBitFieldPtr8Uint32(pCx+8, libc.Uint32FromInt32(1), 4, 0x10)
		libc.SetBitFieldPtr8Uint32(pOrig+8, libc.Uint32FromInt32(1), 4, 0x10)
		rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx + 16)), (*TVdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot, int32(BTREE_WRCSR), (*TVdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo, *(*uintptr)(unsafe.Pointer(pCx + 48)))
		/* The sqlite3BtreeCursor() routine can only fail for the first cursor
		 ** opened for a database.  Since there is already an open cursor when this
		 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
		goto _189
		/* Opcode: OpenEphemeral P1 P2 P3 P4 P5
		 ** Synopsis: nColumn=P2
		 **
		 ** Open a new cursor P1 to a transient table.
		 ** The cursor is always opened read/write even if
		 ** the main database is read-only.  The ephemeral
		 ** table is deleted automatically when the cursor is closed.
		 **
		 ** If the cursor P1 is already opened on an ephemeral table, the table
		 ** is cleared (all content is erased).
		 **
		 ** P2 is the number of columns in the ephemeral table.
		 ** The cursor points to a BTree table if P4==0 and to a BTree index
		 ** if P4 is not 0.  If P4 is not NULL, it points to a KeyInfo structure
		 ** that defines the format of keys in the index.
		 **
		 ** The P5 parameter can be a mask of the BTREE_* flags defined
		 ** in btree.h.  These flags control aspects of the operation of
		 ** the btree.  The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
		 ** added automatically.
		 **
		 ** If P3 is positive, then reg[P3] is modified slightly so that it
		 ** can be used as zero-length data for OP_Insert.  This is an optimization
		 ** that avoids an extra OP_Blob opcode to initialize that register.
		 */
		/* Opcode: OpenAutoindex P1 P2 * P4 *
		 ** Synopsis: nColumn=P2
		 **
		 ** This opcode works the same as OP_OpenEphemeral.  It has a
		 ** different name to distinguish its use.  Tables created using
		 ** by this opcode will be used for automatically created transient
		 ** indices in joins.
		 */
	_80:
		; /* ncycle */
	_79:
		;
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 {
			/* Make register reg[P3] into a value that can be used as the data
			 ** form sqlite3BtreeInsert() where the length of the data is zero. */
			/* Only used when number of columns is zero */
			(**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56))).Fn = 0
			(**(**TMem)(__ccgo_up(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56))).Fz = __ccgo_ts + 1704
		}
		pCx1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if pCx1 != 0 && !(int32(TBool(*(*uint8)(unsafe.Pointer(pCx1 + 8))&0x10>>4)) != 0) && (*TOp)(unsafe.Pointer(pOp)).Fp2 <= int32((*TVdbeCursor)(unsafe.Pointer(pCx1)).FnField) {
			/* If the ephemeral table is already open and has no duplicates from
			 ** OP_OpenDup, then erase all existing content so that the table is
			 ** empty again, rather than creating a new table. */
			(*TVdbeCursor)(unsafe.Pointer(pCx1)).FseqCount = 0
			(*TVdbeCursor)(unsafe.Pointer(pCx1)).FcacheStatus = uint32(CACHE_STALE)
			rc = _sqlite3BtreeClearTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), libc.Int32FromUint32((*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot), uintptr(0))
		} else {
			pCx1 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, uint8(CURTYPE_BTREE))
			if pCx1 == uintptr(0) {
				goto no_mem
			}
			libc.SetBitFieldPtr8Uint32(pCx1+8, libc.Uint32FromInt32(1), 7, 0x80)
			rc = _sqlite3BtreeOpen(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, pCx1+16, libc.Int32FromInt32(BTREE_OMIT_JOURNAL)|libc.Int32FromInt32(BTREE_SINGLE)|libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5), _vfsFlags)
			if rc == SQLITE_OK {
				rc = _sqlite3BtreeBeginTrans(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), int32(1), uintptr(0))
				if rc == SQLITE_OK {
					/* If a transient index is required, create it by calling
					 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
					 ** opening it. If a transient table is required, just use the
					 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
					 */
					v194 = *(*uintptr)(unsafe.Pointer(pOp + 16))
					pKeyInfo2 = v194
					v191 = v194
					(*TVdbeCursor)(unsafe.Pointer(pCx1)).FpKeyInfo = v191
					if v191 != uintptr(0) {
						rc = _sqlite3BtreeCreateTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), pCx1+68, int32(BTREE_BLOBKEY)|libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5))
						if rc == SQLITE_OK {
							rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), (*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot, int32(BTREE_WRCSR), pKeyInfo2, *(*uintptr)(unsafe.Pointer(pCx1 + 48)))
						}
						(*TVdbeCursor)(unsafe.Pointer(pCx1)).FisTable = uint8(0)
					} else {
						(*TVdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot = uint32(SCHEMA_ROOT)
						rc = _sqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), uint32(SCHEMA_ROOT), int32(BTREE_WRCSR), uintptr(0), *(*uintptr)(unsafe.Pointer(pCx1 + 48)))
						(*TVdbeCursor)(unsafe.Pointer(pCx1)).FisTable = uint8(1)
					}
				}
				libc.SetBitFieldPtr8Uint32(pCx1+8, libc.BoolUint32(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) != libc.Int32FromInt32(BTREE_UNORDERED)), 5, 0x20)
				if rc != 0 {
					_sqlite3BtreeClose(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)))
					**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8)) = uintptr(0) /* Not required; helps with static analysis */
				} else {
				}
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		(*TVdbeCursor)(unsafe.Pointer(pCx1)).FnullRow = uint8(1)
		goto _189
		/* Opcode: SorterOpen P1 P2 P3 P4 *
		 **
		 ** This opcode works like OP_OpenEphemeral except that it opens
		 ** a transient index that is specifically designed to sort large
		 ** tables using an external merge-sort algorithm.
		 **
		 ** If argument P3 is non-zero, then it indicates that the sorter may
		 ** assume that a stable sort considering the first P3 fields of each
		 ** key is sufficient to produce the required results.
		 */
	_81:
		;
		pCx2 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, uint8(CURTYPE_SORTER))
		if pCx2 == uintptr(0) {
			goto no_mem
		}
		(*TVdbeCursor)(unsafe.Pointer(pCx2)).FpKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))
		rc = _sqlite3VdbeSorterInit(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp3, pCx2)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: SequenceTest P1 P2 * * *
		 ** Synopsis: if( cursor[P1].ctr++ ) pc = P2
		 **
		 ** P1 is a sorter cursor. If the sequence counter is currently zero, jump
		 ** to P2. Regardless of whether or not the jump is taken, increment the
		 ** the sequence value.
		 */
	_82:
		;
		pC4 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		v191 = pC4 + 24
		v256 = *(*Ti64)(unsafe.Pointer(v191))
		*(*Ti64)(unsafe.Pointer(v191)) = *(*Ti64)(unsafe.Pointer(v191)) + 1
		if v256 == 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: OpenPseudo P1 P2 P3 * *
		 ** Synopsis: P3 columns in r[P2]
		 **
		 ** Open a new cursor that points to a fake table that contains a single
		 ** row of data.  The content of that one row is the content of memory
		 ** register P2.  In other words, cursor P1 becomes an alias for the
		 ** MEM_Blob content contained in register P2.
		 **
		 ** A pseudo-table created by this opcode is used to hold a single
		 ** row output from the sorter so that the row can be decomposed into
		 ** individual columns using the OP_Column opcode.  The OP_Column opcode
		 ** is the only cursor opcode that works with a pseudo-table.
		 **
		 ** P3 is the number of fields in the records that will be stored by
		 ** the pseudo-table.  If P2 is 0 or negative then the pseudo-cursor
		 ** will return NULL for every column.
		 */
	_83:
		;
		pCx3 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp3, uint8(CURTYPE_PSEUDO))
		if pCx3 == uintptr(0) {
			goto no_mem
		}
		(*TVdbeCursor)(unsafe.Pointer(pCx3)).FnullRow = uint8(1)
		(*TVdbeCursor)(unsafe.Pointer(pCx3)).FseekResult = (*TOp)(unsafe.Pointer(pOp)).Fp2
		(*TVdbeCursor)(unsafe.Pointer(pCx3)).FisTable = uint8(1)
		/* Give this pseudo-cursor a fake BtCursor pointer so that pCx
		 ** can be safely passed to sqlite3VdbeCursorMoveto().  This avoids a test
		 ** for pCx->eCurType==CURTYPE_BTREE inside of sqlite3VdbeCursorMoveto()
		 ** which is a performance optimization */
		*(*uintptr)(unsafe.Pointer(pCx3 + 48)) = _sqlite3BtreeFakeValidCursor(tls)
		goto _189
		/* Opcode: Close P1 * * * *
		 **
		 ** Close a cursor previously opened as P1.  If P1 is not
		 ** currently open, this instruction is a no-op.
		 */
	_84:
		; /* ncycle */
		_sqlite3VdbeFreeCursor(tls, p, **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8)))
		**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8)) = uintptr(0)
		goto _189
		/* Opcode: SeekGE P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
		 ** use the value in register P3 as the key.  If cursor P1 refers
		 ** to an SQL index, then P3 is the first in an array of P4 registers
		 ** that are used as an unpacked index key.
		 **
		 ** Reposition cursor P1 so that  it points to the smallest entry that
		 ** is greater than or equal to the key value. If there are no records
		 ** greater than or equal to the key and P2 is not zero, then jump to P2.
		 **
		 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
		 ** opcode will either land on a record that exactly matches the key, or
		 ** else it will cause a jump to P2.  When the cursor is OPFLAG_SEEKEQ,
		 ** this opcode must be followed by an IdxLE opcode with the same arguments.
		 ** The IdxGT opcode will be skipped if this opcode succeeds, but the
		 ** IdxGT opcode will be used on subsequent loop iterations.  The
		 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
		 ** is an equality search.
		 **
		 ** This opcode leaves the cursor configured to move in forward order,
		 ** from the beginning toward the end.  In other words, the cursor is
		 ** configured to use Next, not Prev.
		 **
		 ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
		 */
		/* Opcode: SeekGT P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
		 ** use the value in register P3 as a key. If cursor P1 refers
		 ** to an SQL index, then P3 is the first in an array of P4 registers
		 ** that are used as an unpacked index key.
		 **
		 ** Reposition cursor P1 so that it points to the smallest entry that
		 ** is greater than the key value. If there are no records greater than
		 ** the key and P2 is not zero, then jump to P2.
		 **
		 ** This opcode leaves the cursor configured to move in forward order,
		 ** from the beginning toward the end.  In other words, the cursor is
		 ** configured to use Next, not Prev.
		 **
		 ** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
		 */
		/* Opcode: SeekLT P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
		 ** use the value in register P3 as a key. If cursor P1 refers
		 ** to an SQL index, then P3 is the first in an array of P4 registers
		 ** that are used as an unpacked index key.
		 **
		 ** Reposition cursor P1 so that  it points to the largest entry that
		 ** is less than the key value. If there are no records less than
		 ** the key and P2 is not zero, then jump to P2.
		 **
		 ** This opcode leaves the cursor configured to move in reverse order,
		 ** from the end toward the beginning.  In other words, the cursor is
		 ** configured to use Prev, not Next.
		 **
		 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
		 */
		/* Opcode: SeekLE P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
		 ** use the value in register P3 as a key. If cursor P1 refers
		 ** to an SQL index, then P3 is the first in an array of P4 registers
		 ** that are used as an unpacked index key.
		 **
		 ** Reposition cursor P1 so that it points to the largest entry that
		 ** is less than or equal to the key value. If there are no records
		 ** less than or equal to the key and P2 is not zero, then jump to P2.
		 **
		 ** This opcode leaves the cursor configured to move in reverse order,
		 ** from the end toward the beginning.  In other words, the cursor is
		 ** configured to use Prev, not Next.
		 **
		 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
		 ** opcode will either land on a record that exactly matches the key, or
		 ** else it will cause a jump to P2.  When the cursor is OPFLAG_SEEKEQ,
		 ** this opcode must be followed by an IdxLE opcode with the same arguments.
		 ** The IdxGE opcode will be skipped if this opcode succeeds, but the
		 ** IdxGE opcode will be used on subsequent loop iterations.  The
		 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
		 ** is an equality search.
		 **
		 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
		 */
	_88:
		; /* jump0, in3, group, ncycle */
	_87:
		; /* jump0, in3, group, ncycle */
	_86:
		; /* jump0, in3, group, ncycle */
	_85:
		; /* Only interested in == results */
		pC5 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		oc = libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode)
		eqOnly = 0
		(*TVdbeCursor)(unsafe.Pointer(pC5)).FnullRow = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC5)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC5)).FcacheStatus = uint32(CACHE_STALE)
		if (*TVdbeCursor)(unsafe.Pointer(pC5)).FisTable != 0 {
			/* The OPFLAG_SEEKEQ/BTREE_SEEK_EQ flag is only set on index cursors */
			/* The input value in P3 might be of any type: integer, real, string,
			 ** blob, or NULL.  But it needs to be an integer before we can do
			 ** the seek, so convert it. */
			pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
			flags31 = (*TMem)(unsafe.Pointer(pIn3)).Fflags
			if libc.Int32FromUint16(flags31)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_Real)|libc.Int32FromInt32(MEM_IntReal)|libc.Int32FromInt32(MEM_Str)) == int32(MEM_Str) {
				_applyNumericAffinity(tls, pIn3, 0)
			}
			iKey = _sqlite3VdbeIntValue(tls, pIn3)         /* Get the integer key value */
			newType = (*TMem)(unsafe.Pointer(pIn3)).Fflags /* Record the type after applying numeric affinity */
			(*TMem)(unsafe.Pointer(pIn3)).Fflags = flags31 /* But convert the type back to its original */
			/* If the P3 value could not be converted into an integer without
			 ** loss of information, then special processing is required... */
			if libc.Int32FromUint16(newType)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
				if libc.Int32FromUint16(newType)&int32(MEM_Real) == 0 {
					if libc.Int32FromUint16(newType)&int32(MEM_Null) != 0 || oc >= int32(OP_SeekGE) {
						goto jump_to_p2
					} else {
						rc = _sqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), bp+112)
						if rc != SQLITE_OK {
							goto abort_due_to_error
						}
						goto seek_not_found
					}
				}
				c2 = _sqlite3IntFloatCompare(tls, iKey, *(*float64)(unsafe.Pointer(pIn3)))
				/* If the approximation iKey is larger than the actual real search
				 ** term, substitute >= for > and < for <=. e.g. if the search term
				 ** is 4.9 and the integer approximation 5:
				 **
				 **        (x >  4.9)    ->     (x >= 5)
				 **        (x <= 4.9)    ->     (x <  5)
				 */
				if c2 > 0 {
					if oc&int32(0x0001) == libc.Int32FromInt32(OP_SeekGT)&libc.Int32FromInt32(0x0001) {
						oc = oc - 1
					}
				} else {
					if c2 < 0 {
						if oc&int32(0x0001) == libc.Int32FromInt32(OP_SeekLT)&libc.Int32FromInt32(0x0001) {
							oc = oc + 1
						}
					}
				}
			}
			rc = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), libc.Int64FromUint64(libc.Uint64FromInt64(iKey)), 0, bp+112)
			(*TVdbeCursor)(unsafe.Pointer(pC5)).FmovetoTarget = iKey /* Used by OP_Delete */
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
		} else {
			/* For a cursor with the OPFLAG_SEEKEQ/BTREE_SEEK_EQ hint, only the
			 ** OP_SeekGE and OP_SeekLE opcodes are allowed, and these must be
			 ** immediately followed by an OP_IdxGT or OP_IdxLT opcode, respectively,
			 ** with the same key.
			 */
			if _sqlite3BtreeCursorHasHint(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), uint32(BTREE_SEEK_EQ)) != 0 {
				eqOnly = int32(1)
			}
			nField2 = (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi
			(**(**TUnpackedRecord)(__ccgo_up(bp + 120))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC5)).FpKeyInfo
			(**(**TUnpackedRecord)(__ccgo_up(bp + 120))).FnField = libc.Uint16FromInt32(nField2)
			/* The next line of code computes as follows, only faster:
			 **   if( oc==OP_SeekGT || oc==OP_SeekLE ){
			 **     r.default_rc = -1;
			 **   }else{
			 **     r.default_rc = +1;
			 **   }
			 */
			if int32(1)&(oc-int32(OP_SeekLT)) != 0 {
				v190 = -int32(1)
			} else {
				v190 = +libc.Int32FromInt32(1)
			}
			(**(**TUnpackedRecord)(__ccgo_up(bp + 120))).Fdefault_rc = int8(v190)
			(**(**TUnpackedRecord)(__ccgo_up(bp + 120))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
			(**(**TUnpackedRecord)(__ccgo_up(bp + 120))).FeqSeen = uint8(0)
			rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), bp+120, bp+112)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if eqOnly != 0 && libc.Int32FromUint8((**(**TUnpackedRecord)(__ccgo_up(bp + 120))).FeqSeen) == 0 {
				goto seek_not_found
			}
		}
		if oc >= int32(OP_SeekGE) {
			if **(**int32)(__ccgo_up(bp + 112)) < 0 || **(**int32)(__ccgo_up(bp + 112)) == 0 && oc == int32(OP_SeekGT) {
				**(**int32)(__ccgo_up(bp + 112)) = 0
				rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), 0)
				if rc != SQLITE_OK {
					if rc == int32(SQLITE_DONE) {
						rc = SQLITE_OK
						**(**int32)(__ccgo_up(bp + 112)) = int32(1)
					} else {
						goto abort_due_to_error
					}
				}
			} else {
				**(**int32)(__ccgo_up(bp + 112)) = 0
			}
		} else {
			if **(**int32)(__ccgo_up(bp + 112)) > 0 || **(**int32)(__ccgo_up(bp + 112)) == 0 && oc == int32(OP_SeekLT) {
				**(**int32)(__ccgo_up(bp + 112)) = 0
				rc = _sqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), 0)
				if rc != SQLITE_OK {
					if rc == int32(SQLITE_DONE) {
						rc = SQLITE_OK
						**(**int32)(__ccgo_up(bp + 112)) = int32(1)
					} else {
						goto abort_due_to_error
					}
				}
			} else {
				/* res might be negative because the table is empty.  Check to
				 ** see if this is the case.
				 */
				**(**int32)(__ccgo_up(bp + 112)) = _sqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)))
			}
		}
		goto seek_not_found
	seek_not_found:
		;
		if **(**int32)(__ccgo_up(bp + 112)) != 0 {
			goto jump_to_p2
		} else {
			if eqOnly != 0 {
				pOp += 24 /* Skip the OP_IdxLt or OP_IdxGT that follows */
			}
		}
		goto _189
		/* Opcode: SeekScan  P1 P2 * * P5
		 ** Synopsis: Scan-ahead up to P1 rows
		 **
		 ** This opcode is a prefix opcode to OP_SeekGE.  In other words, this
		 ** opcode must be immediately followed by OP_SeekGE. This constraint is
		 ** checked by assert() statements.
		 **
		 ** This opcode uses the P1 through P4 operands of the subsequent
		 ** OP_SeekGE.  In the text that follows, the operands of the subsequent
		 ** OP_SeekGE opcode are denoted as SeekOP.P1 through SeekOP.P4.   Only
		 ** the P1, P2 and P5 operands of this opcode are also used, and  are called
		 ** This.P1, This.P2 and This.P5.
		 **
		 ** This opcode helps to optimize IN operators on a multi-column index
		 ** where the IN operator is on the later terms of the index by avoiding
		 ** unnecessary seeks on the btree, substituting steps to the next row
		 ** of the b-tree instead.  A correct answer is obtained if this opcode
		 ** is omitted or is a no-op.
		 **
		 ** The SeekGE.P3 and SeekGE.P4 operands identify an unpacked key which
		 ** is the desired entry that we want the cursor SeekGE.P1 to be pointing
		 ** to.  Call this SeekGE.P3/P4 row the "target".
		 **
		 ** If the SeekGE.P1 cursor is not currently pointing to a valid row,
		 ** then this opcode is a no-op and control passes through into the OP_SeekGE.
		 **
		 ** If the SeekGE.P1 cursor is pointing to a valid row, then that row
		 ** might be the target row, or it might be near and slightly before the
		 ** target row, or it might be after the target row.  If the cursor is
		 ** currently before the target row, then this opcode attempts to position
		 ** the cursor on or after the target row by invoking sqlite3BtreeStep()
		 ** on the cursor between 1 and This.P1 times.
		 **
		 ** The This.P5 parameter is a flag that indicates what to do if the
		 ** cursor ends up pointing at a valid row that is past the target
		 ** row.  If This.P5 is false (0) then a jump is made to SeekGE.P2.  If
		 ** This.P5 is true (non-zero) then a jump is made to This.P2.  The P5==0
		 ** case occurs when there are no inequality constraints to the right of
		 ** the IN constraint.  The jump to SeekGE.P2 ends the loop.  The P5!=0 case
		 ** occurs when there are inequality constraints to the right of the IN
		 ** operator.  In that case, the This.P2 will point either directly to or
		 ** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for
		 ** loop terminate.
		 **
		 ** Possible outcomes from this opcode:<ol>
		 **
		 ** <li> If the cursor is initially not pointed to any valid row, then
		 **      fall through into the subsequent OP_SeekGE opcode.
		 **
		 ** <li> If the cursor is left pointing to a row that is before the target
		 **      row, even after making as many as This.P1 calls to
		 **      sqlite3BtreeNext(), then also fall through into OP_SeekGE.
		 **
		 ** <li> If the cursor is left pointing at the target row, either because it
		 **      was at the target row to begin with or because one or more
		 **      sqlite3BtreeNext() calls moved the cursor to the target row,
		 **      then jump to This.P2..,
		 **
		 ** <li> If the cursor started out before the target row and a call to
		 **      to sqlite3BtreeNext() moved the cursor off the end of the index
		 **      (indicating that the target row definitely does not exist in the
		 **      btree) then jump to SeekGE.P2, ending the loop.
		 **
		 ** <li> If the cursor ends up on a valid row that is past the target row
		 **      (indicating that the target row does not exist in the btree) then
		 **      jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
		 ** </ol>
		 */
	_89:
		;
		/* If pOp->p5 is clear, then pOp->p2 points to the first instruction past the
		 ** OP_IdxGT that follows the OP_SeekGE. Otherwise, it points to the first
		 ** opcode past the OP_SeekGE itself.  */
		pC6 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((**(**TOp)(__ccgo_up(pOp + 1*24))).Fp1)*8))
		if !(_sqlite3BtreeCursorIsValidNN(tls, *(*uintptr)(unsafe.Pointer(pC6 + 48))) != 0) {
			goto _189
		}
		nStep = (*TOp)(unsafe.Pointer(pOp)).Fp1
		(**(**TUnpackedRecord)(__ccgo_up(bp + 168))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC6)).FpKeyInfo
		(**(**TUnpackedRecord)(__ccgo_up(bp + 168))).FnField = libc.Uint16FromInt32(*(*int32)(unsafe.Pointer(pOp + 1*24 + 16)))
		(**(**TUnpackedRecord)(__ccgo_up(bp + 168))).Fdefault_rc = 0
		(**(**TUnpackedRecord)(__ccgo_up(bp + 168))).FaMem = aMem + uintptr((**(**TOp)(__ccgo_up(pOp + 1*24))).Fp3)*56
		**(**int32)(__ccgo_up(bp + 160)) = 0 /* Not needed.  Only used to silence a warning. */
	_260:
		;
		if !(int32(1) != 0) {
			goto _259
		}
		rc = _sqlite3VdbeIdxKeyCompare(tls, db, pC6, bp+168, bp+160)
		if rc != 0 {
			goto abort_due_to_error
		}
		if !(**(**int32)(__ccgo_up(bp + 160)) > 0 && libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) == 0) {
			goto _261
		}
		goto seekscan_search_fail
	seekscan_search_fail:
		;
		/* Jump to SeekGE.P2, ending the loop */
		pOp += 24
		goto jump_to_p2
	_261:
		;
		if **(**int32)(__ccgo_up(bp + 160)) >= 0 {
			/* Jump to This.P2, bypassing the OP_SeekGE opcode */
			goto jump_to_p2
			goto _259
		}
		if nStep <= 0 {
			goto _259
		}
		nStep = nStep - 1
		(*TVdbeCursor)(unsafe.Pointer(pC6)).FcacheStatus = uint32(CACHE_STALE)
		rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC6 + 48)), 0)
		if rc != 0 {
			if rc == int32(SQLITE_DONE) {
				rc = SQLITE_OK
				goto seekscan_search_fail
			} else {
				goto abort_due_to_error
			}
		}
		goto _260
	_259:
		;
		goto _189
		/* Opcode: SeekHit P1 P2 P3 * *
		 ** Synopsis: set P2<=seekHit<=P3
		 **
		 ** Increase or decrease the seekHit value for cursor P1, if necessary,
		 ** so that it is no less than P2 and no greater than P3.
		 **
		 ** The seekHit integer represents the maximum of terms in an index for which
		 ** there is known to be at least one match.  If the seekHit value is smaller
		 ** than the total number of equality terms in an index lookup, then the
		 ** OP_IfNoHope opcode might run to see if the IN loop can be abandoned
		 ** early, thus saving work.  This is part of the IN-early-out optimization.
		 **
		 ** P1 must be a valid b-tree cursor.
		 */
	_90:
		;
		pC7 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit) < (*TOp)(unsafe.Pointer(pOp)).Fp2 {
			(*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2)
		} else {
			if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit) > (*TOp)(unsafe.Pointer(pOp)).Fp3 {
				(*TVdbeCursor)(unsafe.Pointer(pC7)).FseekHit = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
			}
		}
		goto _189
		/* Opcode: IfNotOpen P1 P2 * * *
		 ** Synopsis: if( !csr[P1] ) goto P2
		 **
		 ** If cursor P1 is not open or if P1 is set to a NULL row using the
		 ** OP_NullRow opcode, then jump to instruction P2. Otherwise, fall through.
		 */
	_91:
		;
		pCur1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if pCur1 == uintptr(0) || (*TVdbeCursor)(unsafe.Pointer(pCur1)).FnullRow != 0 {
			goto jump_to_p2_and_check_for_interrupt
		}
		goto _189
		/* Opcode: Found P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If P4==0 then register P3 holds a blob constructed by MakeRecord.  If
		 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
		 ** record.
		 **
		 ** Cursor P1 is on an index btree.  If the record identified by P3 and P4
		 ** is a prefix of any entry in P1 then a jump is made to P2 and
		 ** P1 is left pointing at the matching entry.
		 **
		 ** This operation leaves the cursor in a state where it can be
		 ** advanced in the forward direction.  The Next instruction will work,
		 ** but not the Prev instruction.
		 **
		 ** See also: NotFound, NoConflict, NotExists. SeekGe
		 */
		/* Opcode: NotFound P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If P4==0 then register P3 holds a blob constructed by MakeRecord.  If
		 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
		 ** record.
		 **
		 ** Cursor P1 is on an index btree.  If the record identified by P3 and P4
		 ** is not the prefix of any entry in P1 then a jump is made to P2.  If P1
		 ** does contain an entry whose prefix matches the P3/P4 record then control
		 ** falls through to the next instruction and P1 is left pointing at the
		 ** matching entry.
		 **
		 ** This operation leaves the cursor in a state where it cannot be
		 ** advanced in either direction.  In other words, the Next and Prev
		 ** opcodes do not work after this operation.
		 **
		 ** See also: Found, NotExists, NoConflict, IfNoHope
		 */
		/* Opcode: IfNoHope P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** Register P3 is the first of P4 registers that form an unpacked
		 ** record.  Cursor P1 is an index btree.  P2 is a jump destination.
		 ** In other words, the operands to this opcode are the same as the
		 ** operands to OP_NotFound and OP_IdxGT.
		 **
		 ** This opcode is an optimization attempt only.  If this opcode always
		 ** falls through, the correct answer is still obtained, but extra work
		 ** is performed.
		 **
		 ** A value of N in the seekHit flag of cursor P1 means that there exists
		 ** a key P3:N that will match some record in the index.  We want to know
		 ** if it is possible for a record P3:P4 to match some record in the
		 ** index.  If it is not possible, we can skip some work.  So if seekHit
		 ** is less than P4, attempt to find out if a match is possible by running
		 ** OP_NotFound.
		 **
		 ** This opcode is used in IN clause processing for a multi-column key.
		 ** If an IN clause is attached to an element of the key other than the
		 ** left-most element, and if there are no matches on the most recent
		 ** seek over the whole key, then it might be that one of the key element
		 ** to the left is prohibiting a match, and hence there is "no hope" of
		 ** any match regardless of how many IN clause elements are checked.
		 ** In such a case, we abandon the IN clause search early, using this
		 ** opcode.  The opcode name comes from the fact that the
		 ** jump is taken if there is "no hope" of achieving a match.
		 **
		 ** See also: NotFound, SeekHit
		 */
		/* Opcode: NoConflict P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** If P4==0 then register P3 holds a blob constructed by MakeRecord.  If
		 ** P4>0 then register P3 is the first of P4 registers that form an unpacked
		 ** record.
		 **
		 ** Cursor P1 is on an index btree.  If the record identified by P3 and P4
		 ** contains any NULL value, jump immediately to P2.  If all terms of the
		 ** record are not-NULL then a check is done to determine if any row in the
		 ** P1 index btree has a matching key prefix.  If there are no matches, jump
		 ** immediately to P2.  If there is a match, fall through and leave the P1
		 ** cursor pointing to the matching row.
		 **
		 ** This opcode is similar to OP_NotFound with the exceptions that the
		 ** branch is always taken if any part of the search key input is NULL.
		 **
		 ** This operation leaves the cursor in a state where it cannot be
		 ** advanced in either direction.  In other words, the Next and Prev
		 ** opcodes do not work after this operation.
		 **
		 ** See also: NotFound, Found, NotExists
		 */
	_92:
		;
		pC8 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if libc.Int32FromUint16((*TVdbeCursor)(unsafe.Pointer(pC8)).FseekHit) >= (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi {
			goto _189
		}
		/* Fall through into OP_NotFound */
	_95:
		; /* jump, in3, ncycle */
	_94:
		; /* jump, in3, ncycle */
	_93:
		;
		pC9 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		(**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		(**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FnField = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp4.Fi)
		if libc.Int32FromUint16((**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FnField) > 0 {
			/* Key values in an array of registers */
			(**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo
			(**(**TUnpackedRecord)(__ccgo_up(bp + 208))).Fdefault_rc = 0
			rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 48)), bp+208, pC9+36)
		} else {
			/* Composite key generated by OP_MakeRecord */
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer((**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FaMem)).Fflags)&int32(MEM_Zero) != 0 {
				v190 = _sqlite3VdbeMemExpandBlob(tls, (**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FaMem)
			} else {
				v190 = 0
			}
			rc = v190
			if rc != 0 {
				goto no_mem
			}
			pIdxKey = _sqlite3VdbeAllocUnpackedRecord(tls, (*TVdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo)
			if pIdxKey == uintptr(0) {
				goto no_mem
			}
			_sqlite3VdbeRecordUnpack(tls, (*TMem)(unsafe.Pointer((**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FaMem)).Fn, (*TMem)(unsafe.Pointer((**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FaMem)).Fz, pIdxKey)
			(*TUnpackedRecord)(unsafe.Pointer(pIdxKey)).Fdefault_rc = 0
			rc = _sqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 48)), pIdxKey, pC9+36)
			_sqlite3DbFreeNN(tls, db, pIdxKey)
		}
		if rc != SQLITE_OK {
			goto abort_due_to_error
		}
		alreadyExists = libc.BoolInt32((*TVdbeCursor)(unsafe.Pointer(pC9)).FseekResult == 0)
		(*TVdbeCursor)(unsafe.Pointer(pC9)).FnullRow = libc.Uint8FromInt32(int32(1) - alreadyExists)
		(*TVdbeCursor)(unsafe.Pointer(pC9)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC9)).FcacheStatus = uint32(CACHE_STALE)
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Found) {
			if alreadyExists != 0 {
				goto jump_to_p2
			}
		} else {
			if !(alreadyExists != 0) {
				goto jump_to_p2
			}
			if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_NoConflict) {
				/* For the OP_NoConflict opcode, take the jump if any of the
				 ** input fields are NULL, since any key with a NULL will not
				 ** conflict */
				ii1 = 0
				for {
					if !(ii1 < libc.Int32FromUint16((**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FnField)) {
						break
					}
					if libc.Int32FromUint16((**(**TMem)(__ccgo_up((**(**TUnpackedRecord)(__ccgo_up(bp + 208))).FaMem + uintptr(ii1)*56))).Fflags)&int32(MEM_Null) != 0 {
						goto jump_to_p2
					}
					goto _263
				_263:
					;
					ii1 = ii1 + 1
				}
			}
			if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_IfNoHope) {
				(*TVdbeCursor)(unsafe.Pointer(pC9)).FseekHit = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp4.Fi)
			}
		}
		goto _189
		/* Opcode: SeekRowid P1 P2 P3 * *
		 ** Synopsis: intkey=r[P3]
		 **
		 ** P1 is the index of a cursor open on an SQL table btree (with integer
		 ** keys).  If register P3 does not contain an integer or if P1 does not
		 ** contain a record with rowid P3 then jump immediately to P2.
		 ** Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
		 ** a record with rowid P3 then
		 ** leave the cursor pointing at that record and fall through to the next
		 ** instruction.
		 **
		 ** The OP_NotExists opcode performs the same operation, but with OP_NotExists
		 ** the P3 register must be guaranteed to contain an integer value.  With this
		 ** opcode, register P3 might not contain an integer.
		 **
		 ** The OP_NotFound opcode performs the same operation on index btrees
		 ** (with arbitrary multi-value keys).
		 **
		 ** This opcode leaves the cursor in a state where it cannot be advanced
		 ** in either direction.  In other words, the Next and Prev opcodes will
		 ** not work following this opcode.
		 **
		 ** See also: Found, NotFound, NoConflict, SeekRowid
		 */
		/* Opcode: NotExists P1 P2 P3 * *
		 ** Synopsis: intkey=r[P3]
		 **
		 ** P1 is the index of a cursor open on an SQL table btree (with integer
		 ** keys).  P3 is an integer rowid.  If P1 does not contain a record with
		 ** rowid P3 then jump immediately to P2.  Or, if P2 is 0, raise an
		 ** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then
		 ** leave the cursor pointing at that record and fall through to the next
		 ** instruction.
		 **
		 ** The OP_SeekRowid opcode performs the same operation but also allows the
		 ** P3 register to contain a non-integer value, in which case the jump is
		 ** always taken.  This opcode requires that P3 always contain an integer.
		 **
		 ** The OP_NotFound opcode performs the same operation on index btrees
		 ** (with arbitrary multi-value keys).
		 **
		 ** This opcode leaves the cursor in a state where it cannot be advanced
		 ** in either direction.  In other words, the Next and Prev opcodes will
		 ** not work following this opcode.
		 **
		 ** See also: Found, NotFound, NoConflict, SeekRowid
		 */
	_97:
		;
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn3)).Fflags)&(libc.Int32FromInt32(MEM_Int)|libc.Int32FromInt32(MEM_IntReal)) == 0 {
			/* If pIn3->u.i does not contain an integer, compute iKey as the
			 ** integer value of pIn3.  Jump to P2 if pIn3 cannot be converted
			 ** into an integer without loss of information.  Take care to avoid
			 ** changing the datatype of pIn3, however, as it is used by other
			 ** parts of the prepared statement. */
			*(*TMem)(unsafe.Pointer(bp + 256)) = TMem{}
			/* If pIn3->u.i does not contain an integer, compute iKey as the
			 ** integer value of pIn3.  Jump to P2 if pIn3 cannot be converted
			 ** into an integer without loss of information.  Take care to avoid
			 ** changing the datatype of pIn3, however, as it is used by other
			 ** parts of the prepared statement. */
			*(*Tsqlite3_value)(unsafe.Pointer(bp + 256)) = **(**TMem)(__ccgo_up(pIn3))
			_applyAffinity(tls, bp+256, uint8(SQLITE_AFF_NUMERIC), encoding)
			if libc.Int32FromUint16((**(**TMem)(__ccgo_up(bp + 256))).Fflags)&int32(MEM_Int) == 0 {
				goto jump_to_p2
			}
			iKey1 = libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(bp + 256)))
			goto notExistsWithKey
		}
		/* Fall through into OP_NotExists */
	_96:
		; /* jump, in3, ncycle */
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		iKey1 = libc.Uint64FromInt64(*(*Ti64)(unsafe.Pointer(pIn3)))
		goto notExistsWithKey
	notExistsWithKey:
		;
		pC10 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pCrsr2 = *(*uintptr)(unsafe.Pointer(pC10 + 48))
		**(**int32)(__ccgo_up(bp + 248)) = 0
		rc = _sqlite3BtreeTableMoveto(tls, pCrsr2, libc.Int64FromUint64(iKey1), 0, bp+248)
		(*TVdbeCursor)(unsafe.Pointer(pC10)).FmovetoTarget = libc.Int64FromUint64(iKey1) /* Used by OP_Delete */
		(*TVdbeCursor)(unsafe.Pointer(pC10)).FnullRow = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC10)).FcacheStatus = uint32(CACHE_STALE)
		(*TVdbeCursor)(unsafe.Pointer(pC10)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC10)).FseekResult = **(**int32)(__ccgo_up(bp + 248))
		if **(**int32)(__ccgo_up(bp + 248)) != 0 {
			if (*TOp)(unsafe.Pointer(pOp)).Fp2 == 0 {
				rc = _sqlite3CorruptError(tls, int32(102154))
			} else {
				goto jump_to_p2
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: Sequence P1 P2 * * *
		 ** Synopsis: r[P2]=cursor[P1].ctr++
		 **
		 ** Find the next available sequence number for cursor P1.
		 ** Write the sequence number into register P2.
		 ** The sequence number on the cursor is incremented after this
		 ** instruction.
		 */
	_98:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		v191 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8)) + 24
		v256 = *(*Ti64)(unsafe.Pointer(v191))
		*(*Ti64)(unsafe.Pointer(v191)) = *(*Ti64)(unsafe.Pointer(v191)) + 1
		*(*Ti64)(unsafe.Pointer(pOut)) = v256
		goto _189
		/* Opcode: NewRowid P1 P2 P3 * *
		 ** Synopsis: r[P2]=rowid
		 **
		 ** Get a new integer record number (a.k.a "rowid") used as the key to a table.
		 ** The record number is not previously used as a key in the database
		 ** table that cursor P1 points to.  The new record number is written
		 ** written to register P2.
		 **
		 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds
		 ** the largest previously generated record number. No new record numbers are
		 ** allowed to be less than this value. When this value reaches its maximum,
		 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
		 ** generated record number. This P3 mechanism is used to help implement the
		 ** AUTOINCREMENT feature.
		 */
	_99:
		; /* Root frame of VDBE */
		**(**Ti64)(__ccgo_up(bp + 312)) = 0
		**(**int32)(__ccgo_up(bp + 320)) = 0
		pOut = _out2Prerelease(tls, p, pOp)
		pC11 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		/* The next rowid or record number (different terms for the same
		 ** thing) is obtained in a two-step algorithm.
		 **
		 ** First we attempt to find the largest existing rowid and add one
		 ** to that.  But if the largest existing rowid is already the maximum
		 ** positive integer, we have to fall through to the second
		 ** probabilistic algorithm
		 **
		 ** The second algorithm is to select a rowid at random and see if
		 ** it already exists in the table.  If it does not exist, we have
		 ** succeeded.  If the random rowid does exist, we select a new one
		 ** and try again, up to 100 times.
		 */
		/* Some compilers complain about constants of the form 0x7fffffffffffffff.
		 ** Others complain about 0x7ffffffffffffffffLL.  The following macro seems
		 ** to provide the constant while making all compilers happy.
		 */
		if !(int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x40>>6)) != 0) {
			rc = _sqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC11 + 48)), bp+320)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if **(**int32)(__ccgo_up(bp + 320)) != 0 {
				**(**Ti64)(__ccgo_up(bp + 312)) = int64(1) /* IMP: R-61914-48074 */
			} else {
				**(**Ti64)(__ccgo_up(bp + 312)) = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC11 + 48)))
				if **(**Ti64)(__ccgo_up(bp + 312)) >= libc.Int64FromUint64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) {
					libc.SetBitFieldPtr8Uint32(pC11+8, libc.Uint32FromInt32(1), 6, 0x40)
				} else {
					**(**Ti64)(__ccgo_up(bp + 312)) = **(**Ti64)(__ccgo_up(bp + 312)) + 1 /* IMP: R-29538-34987 */
				}
			}
		}
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			/* Assert that P3 is a valid memory cell. */
			if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
				pFrame1 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
				for {
					if !((*TVdbeFrame)(unsafe.Pointer(pFrame1)).FpParent != 0) {
						break
					}
					goto _266
				_266:
					;
					pFrame1 = (*TVdbeFrame)(unsafe.Pointer(pFrame1)).FpParent
				}
				/* Assert that P3 is a valid memory cell. */
				pMem = (*TVdbeFrame)(unsafe.Pointer(pFrame1)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
			} else {
				/* Assert that P3 is a valid memory cell. */
				pMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
			}
			_sqlite3VdbeMemIntegerify(tls, pMem)
			/* mem(P3) holds an integer */
			if *(*Ti64)(unsafe.Pointer(pMem)) == libc.Int64FromUint64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) || int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x40>>6)) != 0 {
				rc = int32(SQLITE_FULL) /* IMP: R-17817-00630 */
				goto abort_due_to_error
			}
			if **(**Ti64)(__ccgo_up(bp + 312)) < *(*Ti64)(unsafe.Pointer(pMem))+int64(1) {
				**(**Ti64)(__ccgo_up(bp + 312)) = *(*Ti64)(unsafe.Pointer(pMem)) + int64(1)
			}
			*(*Ti64)(unsafe.Pointer(pMem)) = **(**Ti64)(__ccgo_up(bp + 312))
		}
		if int32(TBool(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x40>>6)) != 0 {
			/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
			 ** largest possible integer (9223372036854775807) then the database
			 ** engine starts picking positive candidate ROWIDs at random until
			 ** it finds one that is not previously used. */
			/* We cannot be in random rowid mode if this is
			 ** an AUTOINCREMENT table. */
			cnt1 = 0
			for {
				Xsqlite3_randomness(tls, int32(8), bp+312)
				**(**Ti64)(__ccgo_up(bp + 312)) = **(**Ti64)(__ccgo_up(bp + 312)) & (libc.Int64FromUint64(libc.Uint64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)|libc.Uint64FromUint32(0xffffffff)) >> libc.Int32FromInt32(1))
				**(**Ti64)(__ccgo_up(bp + 312)) = **(**Ti64)(__ccgo_up(bp + 312)) + 1 /* Ensure that v is greater than zero */
				goto _270
			_270:
				;
				v190 = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC11 + 48)), libc.Int64FromUint64(libc.Uint64FromInt64(**(**Ti64)(__ccgo_up(bp + 312)))), 0, bp+320)
				rc = v190
				if v217 = v190 == SQLITE_OK && **(**int32)(__ccgo_up(bp + 320)) == 0; v217 {
					cnt1 = cnt1 + 1
					v193 = cnt1
				}
				if !(v217 && v193 < int32(100)) {
					break
				}
			}
			if rc != 0 {
				goto abort_due_to_error
			}
			if **(**int32)(__ccgo_up(bp + 320)) == 0 {
				rc = int32(SQLITE_FULL) /* IMP: R-38219-53002 */
				goto abort_due_to_error
			}
			/* EV: R-40812-03570 */
		}
		(*TVdbeCursor)(unsafe.Pointer(pC11)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC11)).FcacheStatus = uint32(CACHE_STALE)
		*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 312))
		goto _189
		/* Opcode: Insert P1 P2 P3 P4 P5
		 ** Synopsis: intkey=r[P3] data=r[P2]
		 **
		 ** Write an entry into the table of cursor P1.  A new entry is
		 ** created if it doesn't already exist or the data for an existing
		 ** entry is overwritten.  The data is the value MEM_Blob stored in register
		 ** number P2. The key is stored in register P3. The key must
		 ** be a MEM_Int.
		 **
		 ** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
		 ** incremented (otherwise not).  If the OPFLAG_LASTROWID flag of P5 is set,
		 ** then rowid is stored for subsequent return by the
		 ** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
		 **
		 ** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
		 ** run faster by avoiding an unnecessary seek on cursor P1.  However,
		 ** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
		 ** seeks on the cursor or if the most recent seek used a key equal to P3.
		 **
		 ** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
		 ** UPDATE operation.  Otherwise (if the flag is clear) then this opcode
		 ** is part of an INSERT operation.  The difference is only important to
		 ** the update hook.
		 **
		 ** Parameter P4 may point to a Table structure, or may be NULL. If it is
		 ** not NULL, then the update-hook (sqlite3.xUpdateCallback) is invoked
		 ** following a successful insert.
		 **
		 ** (WARNING/TODO: If P1 is a pseudo-cursor and P2 is dynamically
		 ** allocated, then ownership of P2 is transferred to the pseudo-cursor
		 ** and register P2 becomes ephemeral.  If the cursor is changed, the
		 ** value of register P2 will then change.  Make sure this does not
		 ** cause any problems.)
		 **
		 ** This instruction only works on tables.  The equivalent instruction
		 ** for indices is OP_IdxInsert.
		 */
	_100:
		; /* Payload to be inserted */
		pData = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		pC12 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pKey = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		(**(**TBtreePayload)(__ccgo_up(bp + 328))).FnKey = *(*Ti64)(unsafe.Pointer(pKey))
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(5) && ((*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0) {
			zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TVdbeCursor)(unsafe.Pointer(pC12)).FiDb)*32))).FzDbSName
			pTab1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		} else {
			pTab1 = uintptr(0)
			zDb = uintptr(0)
		}
		/* Invoke the pre-update hook, if any */
		if pTab1 != 0 {
			if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 && !(libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&libc.Int32FromInt32(OPFLAG_ISUPDATE) != 0) {
				_sqlite3VdbePreUpdateHook(tls, p, pC12, int32(SQLITE_INSERT), zDb, pTab1, (**(**TBtreePayload)(__ccgo_up(bp + 328))).FnKey, (*TOp)(unsafe.Pointer(pOp)).Fp2, -int32(1))
			}
			if (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback == uintptr(0) || (*TTable)(unsafe.Pointer(pTab1)).FaCol == uintptr(0) {
				/* Prevent post-update hook from running in cases when it should not */
				pTab1 = uintptr(0)
			}
		}
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_ISNOOP) != 0 {
			goto _189
		}
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NCHANGE) != 0 {
			(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
			if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_LASTROWID) != 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FlastRowid = (**(**TBtreePayload)(__ccgo_up(bp + 328))).FnKey
			}
		}
		(**(**TBtreePayload)(__ccgo_up(bp + 328))).FpData = (*TMem)(unsafe.Pointer(pData)).Fz
		(**(**TBtreePayload)(__ccgo_up(bp + 328))).FnData = (*TMem)(unsafe.Pointer(pData)).Fn
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_USESEEKRESULT) != 0 {
			v190 = (*TVdbeCursor)(unsafe.Pointer(pC12)).FseekResult
		} else {
			v190 = 0
		}
		seekResult = v190
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pData)).Fflags)&int32(MEM_Zero) != 0 {
			(**(**TBtreePayload)(__ccgo_up(bp + 328))).FnZero = *(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pData)).Fu))
		} else {
			(**(**TBtreePayload)(__ccgo_up(bp + 328))).FnZero = 0
		}
		(**(**TBtreePayload)(__ccgo_up(bp + 328))).FpKey = uintptr(0)
		rc = _sqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC12 + 48)), bp+328, libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_APPEND)|libc.Int32FromInt32(OPFLAG_SAVEPOSITION)|libc.Int32FromInt32(OPFLAG_PREFORMAT)), seekResult)
		(*TVdbeCursor)(unsafe.Pointer(pC12)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC12)).FcacheStatus = uint32(CACHE_STALE)
		colCacheCtr = colCacheCtr + 1
		/* Invoke the update-hook if required. */
		if rc != 0 {
			goto abort_due_to_error
		}
		if pTab1 != 0 {
			if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_ISUPDATE) != 0 {
				v190 = int32(SQLITE_UPDATE)
			} else {
				v190 = int32(SQLITE_INSERT)
			}
			(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, Tsqlite_int64))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpUpdateArg, v190, zDb, (*TTable)(unsafe.Pointer(pTab1)).FzName, (**(**TBtreePayload)(__ccgo_up(bp + 328))).FnKey)
		}
		goto _189
		/* Opcode: RowCell P1 P2 P3 * *
		 **
		 ** P1 and P2 are both open cursors. Both must be opened on the same type
		 ** of table - intkey or index. This opcode is used as part of copying
		 ** the current row from P2 into P1. If the cursors are opened on intkey
		 ** tables, register P3 contains the rowid to use with the new record in
		 ** P1. If they are opened on index tables, P3 is not used.
		 **
		 ** This opcode must be followed by either an Insert or InsertIdx opcode
		 ** with the OPFLAG_PREFORMAT flag set to complete the insert operation.
		 */
	_101:
		; /* Rowid value to insert with */
		pDest1 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pSrc = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*8))
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			v206 = *(*Ti64)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56))
		} else {
			v206 = 0
		}
		iKey2 = v206
		rc = _sqlite3BtreeTransferRow(tls, *(*uintptr)(unsafe.Pointer(pDest1 + 48)), *(*uintptr)(unsafe.Pointer(pSrc + 48)), iKey2)
		if rc != SQLITE_OK {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: Delete P1 P2 P3 P4 P5
		 **
		 ** Delete the record at which the P1 cursor is currently pointing.
		 **
		 ** If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then
		 ** the cursor will be left pointing at  either the next or the previous
		 ** record in the table. If it is left pointing at the next record, then
		 ** the next Next instruction will be a no-op. As a result, in this case
		 ** it is ok to delete a record from within a Next loop. If
		 ** OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
		 ** left in an undefined state.
		 **
		 ** If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
		 ** delete is one of several associated with deleting a table row and
		 ** all its associated index entries.  Exactly one of those deletes is
		 ** the "primary" delete.  The others are all on OPFLAG_FORDELETE
		 ** cursors or else are marked with the AUXDELETE flag.
		 **
		 ** If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then
		 ** the row change count is incremented (otherwise not).
		 **
		 ** If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the
		 ** pre-update-hook for deletes is run, but the btree is otherwise unchanged.
		 ** This happens when the OP_Delete is to be shortly followed by an OP_Insert
		 ** with the same key, causing the btree entry to be overwritten.
		 **
		 ** P1 must not be pseudo-table.  It has to be a real table with
		 ** multiple rows.
		 **
		 ** If P4 is not NULL then it points to a Table object. In this case either
		 ** the update or pre-update hook, or both, may be invoked. The P1 cursor must
		 ** have been positioned using OP_NotFound prior to invoking this opcode in
		 ** this case. Specifically, if one is configured, the pre-update hook is
		 ** invoked if P4 is not NULL. The update-hook is invoked if one is configured,
		 ** P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.
		 **
		 ** If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address
		 ** of the memory cell that contains the value that the rowid of the row will
		 ** be set to by the update.
		 */
	_102:
		;
		opflags = (*TOp)(unsafe.Pointer(pOp)).Fp2
		pC13 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		/* If the update-hook or pre-update-hook will be invoked, set zDb to
		 ** the name of the db to pass as to it. Also set local pTab to a copy
		 ** of p4.pTab. Finally, if p5 is true, indicating that this cursor was
		 ** last moved with OP_Next or OP_Prev, not Seek or NotFound, set
		 ** VdbeCursor.movetoTarget to the current rowid.  */
		if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) == -int32(5) && ((*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0) {
			zDb1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TVdbeCursor)(unsafe.Pointer(pC13)).FiDb)*32))).FzDbSName
			pTab2 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_SAVEPOSITION) != 0 && (*TVdbeCursor)(unsafe.Pointer(pC13)).FisTable != 0 {
				(*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC13 + 48)))
			}
		} else {
			zDb1 = uintptr(0)
			pTab2 = uintptr(0)
		}
		/* Invoke the pre-update-hook if required. */
		if (*Tsqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 && pTab2 != 0 {
			if opflags&int32(OPFLAG_ISUPDATE) != 0 {
				v190 = int32(SQLITE_UPDATE)
			} else {
				v190 = int32(SQLITE_DELETE)
			}
			_sqlite3VdbePreUpdateHook(tls, p, pC13, v190, zDb1, pTab2, (*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget, (*TOp)(unsafe.Pointer(pOp)).Fp3, -int32(1))
		}
		if opflags&int32(OPFLAG_ISNOOP) != 0 {
			goto _189
		}
		/* Only flags that can be set are SAVEPOISTION and AUXDELETE */
		rc = _sqlite3BtreeDelete(tls, *(*uintptr)(unsafe.Pointer(pC13 + 48)), uint8((*TOp)(unsafe.Pointer(pOp)).Fp5))
		(*TVdbeCursor)(unsafe.Pointer(pC13)).FcacheStatus = uint32(CACHE_STALE)
		colCacheCtr = colCacheCtr + 1
		(*TVdbeCursor)(unsafe.Pointer(pC13)).FseekResult = 0
		if rc != 0 {
			goto abort_due_to_error
		}
		/* Invoke the update-hook if required. */
		if opflags&int32(OPFLAG_NCHANGE) != 0 {
			(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
			if (*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0 && pTab2 != uintptr(0) && (*TTable)(unsafe.Pointer(pTab2)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				(*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, Tsqlite_int64))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxUpdateCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpUpdateArg, int32(SQLITE_DELETE), zDb1, (*TTable)(unsafe.Pointer(pTab2)).FzName, (*TVdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget)
			}
		}
		goto _189
		/* Opcode: ResetCount * * * * *
		 **
		 ** The value of the change counter is copied to the database handle
		 ** change counter (returned by subsequent calls to sqlite3_changes()).
		 ** Then the VMs internal change counter resets to 0.
		 ** This is used by trigger programs.
		 */
	_103:
		;
		_sqlite3VdbeSetChanges(tls, db, (*TVdbe)(unsafe.Pointer(p)).FnChange)
		(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
		goto _189
		/* Opcode: SorterCompare P1 P2 P3 P4
		 ** Synopsis: if key(P1)!=trim(r[P3],P4) goto P2
		 **
		 ** P1 is a sorter cursor. This instruction compares a prefix of the
		 ** record blob in register P3 against a prefix of the entry that
		 ** the sorter cursor currently points to.  Only the first P4 fields
		 ** of r[P3] and the sorter record are compared.
		 **
		 ** If either P3 or the sorter contains a NULL in one of their significant
		 ** fields (not counting the P4 fields at the end which are ignored) then
		 ** the comparison is assumed to be equal.
		 **
		 ** Fall through to next instruction if the two records compare equal to
		 ** each other.  Jump to P2 if they are different.
		 */
	_104:
		;
		pC14 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		nKeyCol = (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi
		**(**int32)(__ccgo_up(bp + 376)) = 0
		rc = _sqlite3VdbeSorterCompare(tls, pC14, pIn3, nKeyCol, bp+376)
		if rc != 0 {
			goto abort_due_to_error
		}
		if **(**int32)(__ccgo_up(bp + 376)) != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: SorterData P1 P2 P3 * *
		 ** Synopsis: r[P2]=data
		 **
		 ** Write into register P2 the current sorter data for sorter cursor P1.
		 ** Then clear the column header cache on cursor P3.
		 **
		 ** This opcode is normally used to move a record out of the sorter and into
		 ** a register that is the source for a pseudo-table cursor created using
		 ** OpenPseudo.  That pseudo-table cursor is the one that is identified by
		 ** parameter P3.  Clearing the P3 column cache as part of this opcode saves
		 ** us from having to issue a separate NullRow instruction to clear that cache.
		 */
	_105:
		;
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		pC15 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		rc = _sqlite3VdbeSorterRowkey(tls, pC15, pOut)
		if rc != 0 {
			goto abort_due_to_error
		}
		(*TVdbeCursor)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*8)))).FcacheStatus = uint32(CACHE_STALE)
		goto _189
		/* Opcode: RowData P1 P2 P3 * *
		 ** Synopsis: r[P2]=data
		 **
		 ** Write into register P2 the complete row content for the row at
		 ** which cursor P1 is currently pointing.
		 ** There is no interpretation of the data.
		 ** It is just copied onto the P2 register exactly as
		 ** it is found in the database file.
		 **
		 ** If cursor P1 is an index, then the content is the key of the row.
		 ** If cursor P2 is a table, then the content extracted is the data.
		 **
		 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
		 ** of a real table, not a pseudo-table.
		 **
		 ** If P3!=0 then this opcode is allowed to make an ephemeral pointer
		 ** into the database page.  That means that the content of the output
		 ** register will be invalidated as soon as the cursor moves - including
		 ** moves caused by other cursors that "save" the current cursors
		 ** position in order that they can write to the same table.  If P3==0
		 ** then a copy of the data is made into memory.  P3!=0 is faster, but
		 ** P3==0 is safer.
		 **
		 ** If P3!=0 then the content of the P2 register is unsuitable for use
		 ** in OP_Result and any OP_Result will invalidate the P2 register content.
		 ** The P2 register content is invalidated by opcodes like OP_Function or
		 ** by any use of another cursor pointing to the same table.
		 */
	_106:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		pC16 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pCrsr3 = *(*uintptr)(unsafe.Pointer(pC16 + 48))
		/* The OP_RowData opcodes always follow OP_NotExists or
		 ** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions
		 ** that might invalidate the cursor.
		 ** If this were not the case, one of the following assert()s
		 ** would fail.  Should this ever change (because of changes in the code
		 ** generator) then the fix would be to insert a call to
		 ** sqlite3VdbeCursorMoveto().
		 */
		n3 = _sqlite3BtreePayloadSize(tls, pCrsr3)
		if n3 > libc.Uint32FromInt32(**(**int32)(__ccgo_up(db + 136))) {
			goto too_big
		}
		rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCrsr3, n3, pOut)
		if rc != 0 {
			goto abort_due_to_error
		}
		if !((*TOp)(unsafe.Pointer(pOp)).Fp3 != 0) {
			if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags)&int32(MEM_Ephem) != 0 && _sqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				goto no_mem
			}
		}
		goto _189
		/* Opcode: Rowid P1 P2 * * *
		 ** Synopsis: r[P2]=PX rowid of P1
		 **
		 ** Store in register P2 an integer which is the key of the table entry that
		 ** P1 is currently point to.
		 **
		 ** P1 can be either an ordinary table or a virtual table.  There used to
		 ** be a separate OP_VRowid opcode for use with virtual tables, but this
		 ** one opcode now works for both table types.
		 */
	_107:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		pC17 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if (*TVdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0 {
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
			goto _189
		} else {
			if (*TVdbeCursor)(unsafe.Pointer(pC17)).FdeferredMoveto != 0 {
				**(**Ti64)(__ccgo_up(bp + 384)) = (*TVdbeCursor)(unsafe.Pointer(pC17)).FmovetoTarget
			} else {
				if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC17)).FeCurType) == int32(CURTYPE_VTAB) {
					pVtab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pC17 + 48)))).FpVtab
					pModule = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule
					rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxRowid})))(tls, *(*uintptr)(unsafe.Pointer(pC17 + 48)), bp+384)
					_sqlite3VtabImportErrmsg(tls, p, pVtab)
					if rc != 0 {
						goto abort_due_to_error
					}
				} else {
					rc = _sqlite3VdbeCursorRestore(tls, pC17)
					if rc != 0 {
						goto abort_due_to_error
					}
					if (*TVdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0 {
						(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
						goto _189
					}
					**(**Ti64)(__ccgo_up(bp + 384)) = _sqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC17 + 48)))
				}
			}
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 384))
		goto _189
		/* Opcode: NullRow P1 * * * *
		 **
		 ** Move the cursor P1 to a null row.  Any OP_Column operations
		 ** that occur while the cursor is on the null row will always
		 ** write a NULL.
		 **
		 ** If cursor P1 is not previously opened, open it now to a special
		 ** pseudo-cursor that always returns NULL for every column.
		 */
	_108:
		;
		pC18 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if pC18 == uintptr(0) {
			/* If the cursor is not already open, create a special kind of
			 ** pseudo-cursor that always gives null rows. */
			pC18 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, int32(1), uint8(CURTYPE_PSEUDO))
			if pC18 == uintptr(0) {
				goto no_mem
			}
			(*TVdbeCursor)(unsafe.Pointer(pC18)).FseekResult = 0
			(*TVdbeCursor)(unsafe.Pointer(pC18)).FisTable = uint8(1)
			libc.SetBitFieldPtr8Uint32(pC18+8, libc.Uint32FromInt32(1), 4, 0x10)
			*(*uintptr)(unsafe.Pointer(pC18 + 48)) = _sqlite3BtreeFakeValidCursor(tls)
		}
		(*TVdbeCursor)(unsafe.Pointer(pC18)).FnullRow = uint8(1)
		(*TVdbeCursor)(unsafe.Pointer(pC18)).FcacheStatus = uint32(CACHE_STALE)
		if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC18)).FeCurType) == CURTYPE_BTREE {
			_sqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pC18 + 48)))
		}
		goto _189
		/* Opcode: SeekEnd P1 * * * *
		 **
		 ** Position cursor P1 at the end of the btree for the purpose of
		 ** appending a new entry onto the btree.
		 **
		 ** It is assumed that the cursor is used only for appending and so
		 ** if the cursor is valid, then the cursor must already be pointing
		 ** at the end of the btree and so no changes are made to
		 ** the cursor.
		 */
		/* Opcode: Last P1 P2 * * *
		 **
		 ** The next use of the Rowid or Column or Prev instruction for P1
		 ** will refer to the last entry in the database table or index.
		 ** If the table or index is empty and P2>0, then jump immediately to P2.
		 ** If P2 is 0 or if the table or index is not empty, fall through
		 ** to the following instruction.
		 **
		 ** This opcode leaves the cursor configured to move in reverse order,
		 ** from the end toward the beginning.  In other words, the cursor is
		 ** configured to use Prev, not Next.
		 */
	_110:
		; /* ncycle */
	_109:
		;
		pC19 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pCrsr4 = *(*uintptr)(unsafe.Pointer(pC19 + 48))
		**(**int32)(__ccgo_up(bp + 392)) = 0
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_SeekEnd) {
			(*TVdbeCursor)(unsafe.Pointer(pC19)).FseekResult = -int32(1)
			if _sqlite3BtreeCursorIsValidNN(tls, pCrsr4) != 0 {
				goto _189
			}
		}
		rc = _sqlite3BtreeLast(tls, pCrsr4, bp+392)
		(*TVdbeCursor)(unsafe.Pointer(pC19)).FnullRow = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp + 392)))
		(*TVdbeCursor)(unsafe.Pointer(pC19)).FdeferredMoveto = uint8(0)
		(*TVdbeCursor)(unsafe.Pointer(pC19)).FcacheStatus = uint32(CACHE_STALE)
		if rc != 0 {
			goto abort_due_to_error
		}
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 > 0 {
			if **(**int32)(__ccgo_up(bp + 392)) != 0 {
				goto jump_to_p2
			}
		}
		goto _189
		/* Opcode: IfSizeBetween P1 P2 P3 P4 *
		 **
		 ** Let N be the approximate number of rows in the table or index
		 ** with cursor P1 and let X be 10*log2(N) if N is positive or -1
		 ** if N is zero.
		 **
		 ** Jump to P2 if X is in between P3 and P4, inclusive.
		 */
	_111:
		;
		pC20 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pCrsr5 = *(*uintptr)(unsafe.Pointer(pC20 + 48))
		rc = _sqlite3BtreeFirst(tls, pCrsr5, bp+396)
		if rc != 0 {
			goto abort_due_to_error
		}
		if **(**int32)(__ccgo_up(bp + 396)) != 0 {
			sz = int64(-int32(1)) /* -Infinity encoding */
		} else {
			sz = _sqlite3BtreeRowCountEst(tls, pCrsr5)
			sz = int64(_sqlite3LogEst(tls, libc.Uint64FromInt64(sz)))
		}
		**(**int32)(__ccgo_up(bp + 396)) = libc.BoolInt32(sz >= int64((*TOp)(unsafe.Pointer(pOp)).Fp3) && sz <= int64((*TOp)(unsafe.Pointer(pOp)).Fp4.Fi))
		if **(**int32)(__ccgo_up(bp + 396)) != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: SorterSort P1 P2 * * *
		 **
		 ** After all records have been inserted into the Sorter object
		 ** identified by P1, invoke this opcode to actually do the sorting.
		 ** Jump to P2 if there are no records to be sorted.
		 **
		 ** This opcode is an alias for OP_Sort and OP_Rewind that is used
		 ** for Sorter objects.
		 */
		/* Opcode: Sort P1 P2 * * *
		 **
		 ** This opcode does exactly the same thing as OP_Rewind except that
		 ** it increments an undocumented global variable used for testing.
		 **
		 ** Sorting is accomplished by writing records into a sorting index,
		 ** then rewinding that index and playing it back from beginning to
		 ** end.  We use the OP_Sort opcode instead of OP_Rewind to do the
		 ** rewinding so that the global variable will be incremented and
		 ** regression tests can determine whether or not the optimizer is
		 ** correctly optimizing out sorts.
		 */
	_113:
		; /* jump ncycle */
	_112:
		; /* jump ncycle */
		**(**Tu32)(__ccgo_up(p + 212 + 2*4)) = **(**Tu32)(__ccgo_up(p + 212 + 2*4)) + 1
		/* Fall through into OP_Rewind */
		/* Opcode: Rewind P1 P2 * * *
		 **
		 ** The next use of the Rowid or Column or Next instruction for P1
		 ** will refer to the first entry in the database table or index.
		 ** If the table or index is empty, jump immediately to P2.
		 ** If the table or index is not empty, fall through to the following
		 ** instruction.
		 **
		 ** If P2 is zero, that is an assertion that the P1 table is never
		 ** empty and hence the jump will never be taken.
		 **
		 ** This opcode leaves the cursor configured to move in forward order,
		 ** from the beginning toward the end.  In other words, the cursor is
		 ** configured to use Next, not Prev.
		 */
	_114:
		;
		pC21 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		**(**int32)(__ccgo_up(bp + 400)) = int32(1)
		if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC21)).FeCurType) == int32(CURTYPE_SORTER) {
			rc = _sqlite3VdbeSorterRewind(tls, pC21, bp+400)
		} else {
			pCrsr6 = *(*uintptr)(unsafe.Pointer(pC21 + 48))
			rc = _sqlite3BtreeFirst(tls, pCrsr6, bp+400)
			(*TVdbeCursor)(unsafe.Pointer(pC21)).FdeferredMoveto = uint8(0)
			(*TVdbeCursor)(unsafe.Pointer(pC21)).FcacheStatus = uint32(CACHE_STALE)
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		(*TVdbeCursor)(unsafe.Pointer(pC21)).FnullRow = libc.Uint8FromInt32(**(**int32)(__ccgo_up(bp + 400)))
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 > 0 {
			if **(**int32)(__ccgo_up(bp + 400)) != 0 {
				goto jump_to_p2
			}
		}
		goto _189
		/* Opcode: IfEmpty P1 P2 * * *
		 ** Synopsis: if( empty(P1) ) goto P2
		 **
		 ** Check to see if the b-tree table that cursor P1 references is empty
		 ** and jump to P2 if it is.
		 */
	_115:
		;
		pC22 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pCrsr7 = *(*uintptr)(unsafe.Pointer(pC22 + 48))
		rc = _sqlite3BtreeIsEmpty(tls, pCrsr7, bp+404)
		if rc != 0 {
			goto abort_due_to_error
		}
		if **(**int32)(__ccgo_up(bp + 404)) != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: Next P1 P2 P3 * P5
		 **
		 ** Advance cursor P1 so that it points to the next key/data pair in its
		 ** table or index.  If there are no more key/value pairs then fall through
		 ** to the following instruction.  But if the cursor advance was successful,
		 ** jump immediately to P2.
		 **
		 ** The Next opcode is only valid following an SeekGT, SeekGE, or
		 ** OP_Rewind opcode used to position the cursor.  Next is not allowed
		 ** to follow SeekLT, SeekLE, or OP_Last.
		 **
		 ** The P1 cursor must be for a real table, not a pseudo-table.  P1 must have
		 ** been opened prior to this opcode or the program will segfault.
		 **
		 ** The P3 value is a hint to the btree implementation. If P3==1, that
		 ** means P1 is an SQL index and that this instruction could have been
		 ** omitted if that index had been unique.  P3 is usually 0.  P3 is
		 ** always either 0 or 1.
		 **
		 ** If P5 is positive and the jump is taken, then event counter
		 ** number P5-1 in the prepared statement is incremented.
		 **
		 ** See also: Prev
		 */
		/* Opcode: Prev P1 P2 P3 * P5
		 **
		 ** Back up cursor P1 so that it points to the previous key/data pair in its
		 ** table or index.  If there is no previous key/value pairs then fall through
		 ** to the following instruction.  But if the cursor backup was successful,
		 ** jump immediately to P2.
		 **
		 **
		 ** The Prev opcode is only valid following an SeekLT, SeekLE, or
		 ** OP_Last opcode used to position the cursor.  Prev is not allowed
		 ** to follow SeekGT, SeekGE, or OP_Rewind.
		 **
		 ** The P1 cursor must be for a real table, not a pseudo-table.  If P1 is
		 ** not open then the behavior is undefined.
		 **
		 ** The P3 value is a hint to the btree implementation. If P3==1, that
		 ** means P1 is an SQL index and that this instruction could have been
		 ** omitted if that index had been unique.  P3 is usually 0.  P3 is
		 ** always either 0 or 1.
		 **
		 ** If P5 is positive and the jump is taken, then event counter
		 ** number P5-1 in the prepared statement is incremented.
		 */
		/* Opcode: SorterNext P1 P2 * * P5
		 **
		 ** This opcode works just like OP_Next except that P1 must be a
		 ** sorter object for which the OP_SorterSort opcode has been
		 ** invoked.  This opcode advances the cursor to the next sorted
		 ** record, or jumps to P2 if there are no more sorted records.
		 */
	_118:
		;
		pC23 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		rc = _sqlite3VdbeSorterNext(tls, db, pC23)
		goto next_tail
	_116:
		; /* jump, ncycle */
		pC23 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		rc = _sqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC23 + 48)), (*TOp)(unsafe.Pointer(pOp)).Fp3)
		goto next_tail
	_117:
		; /* jump, ncycle */
		pC23 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		rc = _sqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC23 + 48)), (*TOp)(unsafe.Pointer(pOp)).Fp3)
		goto next_tail
	next_tail:
		;
		(*TVdbeCursor)(unsafe.Pointer(pC23)).FcacheStatus = uint32(CACHE_STALE)
		if rc == SQLITE_OK {
			(*TVdbeCursor)(unsafe.Pointer(pC23)).FnullRow = uint8(0)
			**(**Tu32)(__ccgo_up(p + 212 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*4)) = **(**Tu32)(__ccgo_up(p + 212 + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*4)) + 1
			goto jump_to_p2_and_check_for_interrupt
		}
		if rc != int32(SQLITE_DONE) {
			goto abort_due_to_error
		}
		rc = SQLITE_OK
		(*TVdbeCursor)(unsafe.Pointer(pC23)).FnullRow = uint8(1)
		goto check_for_interrupt
		/* Opcode: IdxInsert P1 P2 P3 P4 P5
		 ** Synopsis: key=r[P2]
		 **
		 ** Register P2 holds an SQL index key made using the
		 ** MakeRecord instructions.  This opcode writes that key
		 ** into the index P1.  Data for the entry is nil.
		 **
		 ** If P4 is not zero, then it is the number of values in the unpacked
		 ** key of reg(P2).  In that case, P3 is the index of the first register
		 ** for the unpacked key.  The availability of the unpacked key can sometimes
		 ** be an optimization.
		 **
		 ** If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
		 ** that this insert is likely to be an append.
		 **
		 ** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
		 ** incremented by this instruction.  If the OPFLAG_NCHANGE bit is clear,
		 ** then the change counter is unchanged.
		 **
		 ** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
		 ** run faster by avoiding an unnecessary seek on cursor P1.  However,
		 ** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
		 ** seeks on the cursor or if the most recent seek used a key equivalent
		 ** to P2.
		 **
		 ** This instruction only works for indices.  The equivalent instruction
		 ** for tables is OP_Insert.
		 */
	_119:
		;
		pC24 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NCHANGE) != 0 {
			(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
		}
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags)&int32(MEM_Zero) != 0 {
			v190 = _sqlite3VdbeMemExpandBlob(tls, pIn2)
		} else {
			v190 = 0
		}
		rc = v190
		if rc != 0 {
			goto abort_due_to_error
		}
		(**(**TBtreePayload)(__ccgo_up(bp + 408))).FnKey = int64((*TMem)(unsafe.Pointer(pIn2)).Fn)
		(**(**TBtreePayload)(__ccgo_up(bp + 408))).FpKey = (*TMem)(unsafe.Pointer(pIn2)).Fz
		(**(**TBtreePayload)(__ccgo_up(bp + 408))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		(**(**TBtreePayload)(__ccgo_up(bp + 408))).FnMem = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp4.Fi)
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_USESEEKRESULT) != 0 {
			v190 = (*TVdbeCursor)(unsafe.Pointer(pC24)).FseekResult
		} else {
			v190 = 0
		}
		rc = _sqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC24 + 48)), bp+408, libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&(libc.Int32FromInt32(OPFLAG_APPEND)|libc.Int32FromInt32(OPFLAG_SAVEPOSITION)|libc.Int32FromInt32(OPFLAG_PREFORMAT)), v190)
		(*TVdbeCursor)(unsafe.Pointer(pC24)).FcacheStatus = uint32(CACHE_STALE)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: SorterInsert P1 P2 * * *
		 ** Synopsis: key=r[P2]
		 **
		 ** Register P2 holds an SQL index key made using the
		 ** MakeRecord instructions.  This opcode writes that key
		 ** into the sorter P1.  Data for the entry is nil.
		 */
	_120:
		;
		pC25 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn2)).Fflags)&int32(MEM_Zero) != 0 {
			v190 = _sqlite3VdbeMemExpandBlob(tls, pIn2)
		} else {
			v190 = 0
		}
		rc = v190
		if rc != 0 {
			goto abort_due_to_error
		}
		rc = _sqlite3VdbeSorterWrite(tls, pC25, pIn2)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: IdxDelete P1 P2 P3 P4 *
		 ** Synopsis: key=r[P2@P3]
		 **
		 ** The content of P3 registers starting at register P2 form
		 ** an unpacked index key. This opcode removes that entry from the
		 ** index opened by cursor P1.
		 **
		 ** P4 is a pointer to an Index structure.
		 **
		 ** Raise an SQLITE_CORRUPT_INDEX error if no matching index entry is found
		 ** and not in writable_schema mode.
		 */
	_121:
		;
		pC26 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pCrsr8 = *(*uintptr)(unsafe.Pointer(pC26 + 48))
		(**(**TUnpackedRecord)(__ccgo_up(bp + 464))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC26)).FpKeyInfo
		(**(**TUnpackedRecord)(__ccgo_up(bp + 464))).FnField = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
		(**(**TUnpackedRecord)(__ccgo_up(bp + 464))).Fdefault_rc = 0
		(**(**TUnpackedRecord)(__ccgo_up(bp + 464))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		rc = _sqlite3BtreeIndexMoveto(tls, pCrsr8, bp+464, bp+456)
		if rc != 0 {
			goto abort_due_to_error
		}
		if **(**int32)(__ccgo_up(bp + 456)) != 0 {
			rc = _sqlite3VdbeFindIndexKey(tls, pCrsr8, *(*uintptr)(unsafe.Pointer(pOp + 16)), bp+464, bp+456, 0)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if **(**int32)(__ccgo_up(bp + 456)) != 0 {
				if !(_sqlite3WritableSchema(tls, db) != 0) {
					rc = _sqlite3ReportError(tls, libc.Int32FromInt32(SQLITE_CORRUPT)|libc.Int32FromInt32(3)<<libc.Int32FromInt32(8), int32(103271), __ccgo_ts+6271)
					goto abort_due_to_error
				}
				(*TVdbeCursor)(unsafe.Pointer(pC26)).FcacheStatus = uint32(CACHE_STALE)
				(*TVdbeCursor)(unsafe.Pointer(pC26)).FseekResult = 0
				goto _189
			}
		}
		rc = _sqlite3BtreeDelete(tls, pCrsr8, uint8(BTREE_AUXDELETE))
		if rc != 0 {
			goto abort_due_to_error
		}
		(*TVdbeCursor)(unsafe.Pointer(pC26)).FcacheStatus = uint32(CACHE_STALE)
		(*TVdbeCursor)(unsafe.Pointer(pC26)).FseekResult = 0
		goto _189
		/* Opcode: DeferredSeek P1 * P3 P4 *
		 ** Synopsis: Move P3 to P1.rowid if needed
		 **
		 ** P1 is an open index cursor and P3 is a cursor on the corresponding
		 ** table.  This opcode does a deferred seek of the P3 table cursor
		 ** to the row that corresponds to the current row of P1.
		 **
		 ** This is a deferred seek.  Nothing actually happens until
		 ** the cursor is used to read a record.  That way, if no reads
		 ** occur, no unnecessary I/O happens.
		 **
		 ** P4 may be an array of integers (type P4_INTARRAY) containing
		 ** one entry for each column in the P3 table.  If array entry a(i)
		 ** is non-zero, then reading column a(i)-1 from cursor P3 is
		 ** equivalent to performing the deferred seek and then reading column i
		 ** from P1.  This information is stored in P3 and used to redirect
		 ** reads against P3 over to P1, thus possibly avoiding the need to
		 ** seek and read cursor P3.
		 */
		/* Opcode: IdxRowid P1 P2 * * *
		 ** Synopsis: r[P2]=rowid
		 **
		 ** Write into register P2 an integer which is the last entry in the record at
		 ** the end of the index key pointed to by cursor P1.  This integer should be
		 ** the rowid of the table entry to which this index entry points.
		 **
		 ** See also: Rowid, MakeRecord.
		 */
	_123:
		; /* ncycle */
	_122:
		; /* Rowid that P1 current points to */
		pC27 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		/* The IdxRowid and Seek opcodes are combined because of the commonality
		 ** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
		rc = _sqlite3VdbeCursorRestore(tls, pC27)
		/* sqlite3VdbeCursorRestore() may fail if the cursor has been disturbed
		 ** since it was last positioned and an error (e.g. OOM or an IO error)
		 ** occurs while trying to reposition it. */
		if rc != SQLITE_OK {
			goto abort_due_to_error
		}
		if !((*TVdbeCursor)(unsafe.Pointer(pC27)).FnullRow != 0) {
			**(**Ti64)(__ccgo_up(bp + 504)) = 0 /* Not needed.  Only used to silence a warning. */
			rc = _sqlite3VdbeIdxRowid(tls, db, *(*uintptr)(unsafe.Pointer(pC27 + 48)), bp+504)
			if rc != SQLITE_OK {
				goto abort_due_to_error
			}
			if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_DeferredSeek) {
				pTabCur = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*8))
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FnullRow = uint8(0)
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FmovetoTarget = **(**Ti64)(__ccgo_up(bp + 504))
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FdeferredMoveto = uint8(1)
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FcacheStatus = uint32(CACHE_STALE)
				*(*uintptr)(unsafe.Pointer(pTabCur + 16)) = *(*uintptr)(unsafe.Pointer(pOp + 16))
				(*TVdbeCursor)(unsafe.Pointer(pTabCur)).FpAltCursor = pC27
			} else {
				pOut = _out2Prerelease(tls, p, pOp)
				*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 504))
			}
		} else {
			_sqlite3VdbeMemSetNull(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56)
		}
		goto _189
		/* Opcode: FinishSeek P1 * * * *
		 **
		 ** If cursor P1 was previously moved via OP_DeferredSeek, complete that
		 ** seek operation now, without further delay.  If the cursor seek has
		 ** already occurred, this instruction is a no-op.
		 */
	_124:
		; /* The P1 index cursor */
		pC28 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if (*TVdbeCursor)(unsafe.Pointer(pC28)).FdeferredMoveto != 0 {
			rc = _sqlite3VdbeFinishMoveto(tls, pC28)
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode: IdxGE P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** The P4 register values beginning with P3 form an unpacked index
		 ** key that omits the PRIMARY KEY.  Compare this key value against the index
		 ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
		 ** fields at the end.
		 **
		 ** If the P1 index entry is greater than or equal to the key value
		 ** then jump to P2.  Otherwise fall through to the next instruction.
		 */
		/* Opcode: IdxGT P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** The P4 register values beginning with P3 form an unpacked index
		 ** key that omits the PRIMARY KEY.  Compare this key value against the index
		 ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
		 ** fields at the end.
		 **
		 ** If the P1 index entry is greater than the key value
		 ** then jump to P2.  Otherwise fall through to the next instruction.
		 */
		/* Opcode: IdxLT P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** The P4 register values beginning with P3 form an unpacked index
		 ** key that omits the PRIMARY KEY or ROWID.  Compare this key value against
		 ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
		 ** ROWID on the P1 index.
		 **
		 ** If the P1 index entry is less than the key value then jump to P2.
		 ** Otherwise fall through to the next instruction.
		 */
		/* Opcode: IdxLE P1 P2 P3 P4 *
		 ** Synopsis: key=r[P3@P4]
		 **
		 ** The P4 register values beginning with P3 form an unpacked index
		 ** key that omits the PRIMARY KEY or ROWID.  Compare this key value against
		 ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
		 ** ROWID on the P1 index.
		 **
		 ** If the P1 index entry is less than or equal to the key value then jump
		 ** to P2. Otherwise fall through to the next instruction.
		 */
	_128:
		; /* jump, ncycle */
	_127:
		; /* jump, ncycle */
	_126:
		; /* jump, ncycle */
	_125:
		;
		pC29 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		(**(**TUnpackedRecord)(__ccgo_up(bp + 512))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC29)).FpKeyInfo
		(**(**TUnpackedRecord)(__ccgo_up(bp + 512))).FnField = libc.Uint16FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp4.Fi)
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) < int32(OP_IdxLT) {
			(**(**TUnpackedRecord)(__ccgo_up(bp + 512))).Fdefault_rc = int8(-int32(1))
		} else {
			(**(**TUnpackedRecord)(__ccgo_up(bp + 512))).Fdefault_rc = 0
		}
		(**(**TUnpackedRecord)(__ccgo_up(bp + 512))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		/* Inlined version of sqlite3VdbeIdxKeyCompare() */
		nCellKey = 0
		pCur2 = *(*uintptr)(unsafe.Pointer(pC29 + 48))
		nCellKey = libc.Int64FromUint32(_sqlite3BtreePayloadSize(tls, pCur2))
		/* nCellKey will always be between 0 and 0xffffffff because of the way
		 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
		if nCellKey <= 0 || nCellKey > int64(0x7fffffff) {
			rc = _sqlite3CorruptError(tls, int32(103483))
			goto abort_due_to_error
		}
		_sqlite3VdbeMemInit(tls, bp+552, db, uint16(0))
		rc = _sqlite3VdbeMemFromBtreeZeroOffset(tls, pCur2, libc.Uint32FromInt64(nCellKey), bp+552)
		if rc != 0 {
			goto abort_due_to_error
		}
		res11 = _sqlite3VdbeRecordCompareWithSkip(tls, (**(**TMem)(__ccgo_up(bp + 552))).Fn, (**(**TMem)(__ccgo_up(bp + 552))).Fz, bp+512, 0)
		_sqlite3VdbeMemReleaseMalloc(tls, bp+552)
		/* End of inlined sqlite3VdbeIdxKeyCompare() */
		if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode)&int32(1) == libc.Int32FromInt32(OP_IdxLT)&libc.Int32FromInt32(1) {
			res11 = -res11
		} else {
			res11 = res11 + 1
		}
		if res11 > 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: Destroy P1 P2 P3 * *
		 **
		 ** Delete an entire database table or index whose root page in the database
		 ** file is given by P1.
		 **
		 ** The table being destroyed is in the main database file if P3==0.  If
		 ** P3==1 then the table to be destroyed is in the auxiliary database file
		 ** that is used to store tables create using CREATE TEMPORARY TABLE.
		 **
		 ** If AUTOVACUUM is enabled then it is possible that another root page
		 ** might be moved into the newly deleted root page in order to keep all
		 ** root pages contiguous at the beginning of the database.  The former
		 ** value of the root page that moved - its value before the move occurred -
		 ** is stored in register P2. If no page movement was required (because the
		 ** table being dropped was already the last one in the database) then a
		 ** zero is stored in register P2.  If AUTOVACUUM is disabled then a zero
		 ** is stored in register P2.
		 **
		 ** This opcode throws an error if there are any active reader VMs when
		 ** it is invoked. This is done to avoid the difficulty associated with
		 ** updating existing cursors when a root page is moved in an AUTOVACUUM
		 ** database. This error is thrown even if the database is not an AUTOVACUUM
		 ** db in order to avoid introducing an incompatibility between autovacuum
		 ** and non-autovacuum modes.
		 **
		 ** See also: Clear
		 */
	_129:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
		if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > (*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy+int32(1) {
			rc = int32(SQLITE_LOCKED)
			(*TVdbe)(unsafe.Pointer(p)).FerrorAction = uint8(OE_Abort)
			goto abort_due_to_error
		} else {
			iDb2 = (*TOp)(unsafe.Pointer(pOp)).Fp3
			**(**int32)(__ccgo_up(bp + 608)) = 0 /* Not needed.  Only to silence a warning. */
			rc = _sqlite3BtreeDropTable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb2)*32))).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp1, bp+608)
			(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Int)
			*(*Ti64)(unsafe.Pointer(pOut)) = int64(**(**int32)(__ccgo_up(bp + 608)))
			if rc != 0 {
				goto abort_due_to_error
			}
			if **(**int32)(__ccgo_up(bp + 608)) != 0 {
				_sqlite3RootPageMoved(tls, db, iDb2, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 608))), libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp1))
				/* All OP_Destroy operations occur on the same btree */
				resetSchemaOnFault = libc.Uint8FromInt32(iDb2 + int32(1))
			}
		}
		goto _189
		/* Opcode: Clear P1 P2 P3
		 **
		 ** Delete all contents of the database table or index whose root page
		 ** in the database file is given by P1.  But, unlike Destroy, do not
		 ** remove the table or index from the database file.
		 **
		 ** The table being cleared is in the main database file if P2==0.  If
		 ** P2==1 then the table to be cleared is in the auxiliary database file
		 ** that is used to store tables create using CREATE TEMPORARY TABLE.
		 **
		 ** If the P3 value is non-zero, then the row change count is incremented
		 ** by the number of rows in the table being cleared. If P3 is greater
		 ** than zero, then the value stored in register P3 is also incremented
		 ** by the number of rows in the table being cleared.
		 **
		 ** See also: Destroy
		 */
	_130:
		;
		**(**Ti64)(__ccgo_up(bp + 616)) = 0
		rc = _sqlite3BtreeClearTable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*32))).FpBt, libc.Int32FromUint32(libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp1)), bp+616)
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			**(**Ti64)(__ccgo_up(p + 56)) += **(**Ti64)(__ccgo_up(bp + 616))
			if (*TOp)(unsafe.Pointer(pOp)).Fp3 > 0 {
				*(*Ti64)(unsafe.Pointer(aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56)) += **(**Ti64)(__ccgo_up(bp + 616))
			}
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: ResetSorter P1 * * * *
		 **
		 ** Delete all contents from the ephemeral table or sorter
		 ** that is open on cursor P1.
		 **
		 ** This opcode only works for cursors used for sorting and
		 ** opened with OP_OpenEphemeral or OP_SorterOpen.
		 */
	_131:
		;
		pC30 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pC30)).FeCurType) == int32(CURTYPE_SORTER) {
			_sqlite3VdbeSorterReset(tls, db, *(*uintptr)(unsafe.Pointer(pC30 + 48)))
		} else {
			rc = _sqlite3BtreeClearTableOfCursor(tls, *(*uintptr)(unsafe.Pointer(pC30 + 48)))
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode: CreateBtree P1 P2 P3 * *
		 ** Synopsis: r[P2]=root iDb=P1 flags=P3
		 **
		 ** Allocate a new b-tree in the main database file if P1==0 or in the
		 ** TEMP database file if P1==1 or in an attached database if
		 ** P1>1.  The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
		 ** it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
		 ** The root page number of the new b-tree is stored in register P2.
		 */
	_132:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		**(**TPgno)(__ccgo_up(bp + 624)) = uint32(0)
		pDb3 = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32
		rc = _sqlite3BtreeCreateTable(tls, (*TDb)(unsafe.Pointer(pDb3)).FpBt, bp+624, (*TOp)(unsafe.Pointer(pOp)).Fp3)
		if rc != 0 {
			goto abort_due_to_error
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = libc.Int64FromUint32(**(**TPgno)(__ccgo_up(bp + 624)))
		goto _189
		/* Opcode: SqlExec P1 P2 * P4 *
		 **
		 ** Run the SQL statement or statements specified in the P4 string.
		 **
		 ** The P1 parameter is a bitmask of options:
		 **
		 **    0x0001     Disable Auth and Trace callbacks while the statements
		 **               in P4 are running.
		 **
		 **    0x0002     Set db->nAnalysisLimit to P2 while the statements in
		 **               P4 are running.
		 **
		 */
	_133:
		;
		(*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec = (*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec + 1
		**(**uintptr)(__ccgo_up(bp + 632)) = uintptr(0)
		xAuth = (*Tsqlite3)(unsafe.Pointer(db)).FxAuth
		mTrace = (*Tsqlite3)(unsafe.Pointer(db)).FmTrace
		savedAnalysisLimit = (*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit
		if (*TOp)(unsafe.Pointer(pOp)).Fp1&int32(0x0001) != 0 {
			(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
			(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = uint8(0)
		}
		if (*TOp)(unsafe.Pointer(pOp)).Fp1&int32(0x0002) != 0 {
			(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = (*TOp)(unsafe.Pointer(pOp)).Fp2
		}
		rc = Xsqlite3_exec(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)), uintptr(0), uintptr(0), bp+632)
		(*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec = (*Tsqlite3)(unsafe.Pointer(db)).FnSqlExec - 1
		(*Tsqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
		(*Tsqlite3)(unsafe.Pointer(db)).FmTrace = mTrace
		(*Tsqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = savedAnalysisLimit
		if **(**uintptr)(__ccgo_up(bp + 632)) != 0 || rc != 0 {
			_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, **(**uintptr)(__ccgo_up(bp + 632))))
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 632)))
			if rc == int32(SQLITE_NOMEM) {
				goto no_mem
			}
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: ParseSchema P1 * * P4 *
		 **
		 ** Read and parse all entries from the schema table of database P1
		 ** that match the WHERE clause P4.  If P4 is a NULL pointer, then the
		 ** entire schema for P1 is reparsed.
		 **
		 ** This opcode invokes the parser to create a new virtual machine,
		 ** then runs the new virtual machine.  It is thus a re-entrant opcode.
		 */
	_134:
		;
		/* Any prepared statement that invokes this opcode will hold mutexes
		 ** on every btree.  This is a prerequisite for invoking
		 ** sqlite3InitCallback().
		 */
		iDb3 = (*TOp)(unsafe.Pointer(pOp)).Fp1
		if *(*uintptr)(unsafe.Pointer(pOp + 16)) == uintptr(0) {
			_sqlite3SchemaClear(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*32))).FpSchema)
			**(**Tu32)(__ccgo_up(db + 44)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(DBFLAG_SchemaKnownOk))
			rc = _sqlite3InitOne(tls, db, iDb3, p+168, uint32((*TOp)(unsafe.Pointer(pOp)).Fp5))
			**(**Tu32)(__ccgo_up(db + 44)) |= uint32(DBFLAG_SchemaChange)
			libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 14, 0xc000)
		} else {
			zSchema = __ccgo_ts + 6288
			(**(**TInitData)(__ccgo_up(bp + 640))).Fdb = db
			(**(**TInitData)(__ccgo_up(bp + 640))).FiDb = iDb3
			(**(**TInitData)(__ccgo_up(bp + 640))).FpzErrMsg = p + 168
			(**(**TInitData)(__ccgo_up(bp + 640))).FmInitFlags = uint32(0)
			(**(**TInitData)(__ccgo_up(bp + 640))).FmxPage = _sqlite3BtreeLastPage(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*32))).FpBt)
			zSql = _sqlite3MPrintf(tls, db, __ccgo_ts+6302, libc.VaList(bp+984, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb3)*32))).FzDbSName, zSchema, *(*uintptr)(unsafe.Pointer(pOp + 16))))
			if zSql == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(1)
				(**(**TInitData)(__ccgo_up(bp + 640))).Frc = SQLITE_OK
				(**(**TInitData)(__ccgo_up(bp + 640))).FnInitRow = uint32(0)
				rc = Xsqlite3_exec(tls, db, zSql, __ccgo_fp(_sqlite3InitCallback), bp+640, uintptr(0))
				if rc == SQLITE_OK {
					rc = (**(**TInitData)(__ccgo_up(bp + 640))).Frc
				}
				if rc == SQLITE_OK && (**(**TInitData)(__ccgo_up(bp + 640))).FnInitRow == uint32(0) {
					/* The OP_ParseSchema opcode with a non-NULL P4 argument should parse
					 ** at least one SQL statement. Any less than that indicates that
					 ** the sqlite_schema table is corrupt. */
					rc = _sqlite3CorruptError(tls, int32(103776))
				}
				_sqlite3DbFreeNN(tls, db, zSql)
				(*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy = uint8(0)
			}
		}
		if rc != 0 {
			_sqlite3ResetAllSchemasOfConnection(tls, db)
			if rc == int32(SQLITE_NOMEM) {
				goto no_mem
			}
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: LoadAnalysis P1 * * * *
		 **
		 ** Read the sqlite_stat1 table for database P1 and load the content
		 ** of that table into the internal index hash table.  This will cause
		 ** the analysis to be used when preparing all subsequent queries.
		 */
	_135:
		;
		rc = _sqlite3AnalysisLoad(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: DropTable P1 * * P4 *
		 **
		 ** Remove the internal (in-memory) data structures that describe
		 ** the table named P4 in database P1.  This is called after a table
		 ** is dropped from disk (using the Destroy opcode) in order to keep
		 ** the internal representation of the
		 ** schema consistent with what is on disk.
		 */
	_136:
		;
		_sqlite3UnlinkAndDeleteTable(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		goto _189
		/* Opcode: DropIndex P1 * * P4 *
		 **
		 ** Remove the internal (in-memory) data structures that describe
		 ** the index named P4 in database P1.  This is called after an index
		 ** is dropped from disk (using the Destroy opcode)
		 ** in order to keep the internal representation of the
		 ** schema consistent with what is on disk.
		 */
	_137:
		;
		_sqlite3UnlinkAndDeleteIndex(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		goto _189
		/* Opcode: DropTrigger P1 * * P4 *
		 **
		 ** Remove the internal (in-memory) data structures that describe
		 ** the trigger named P4 in database P1.  This is called after a trigger
		 ** is dropped from disk (using the Destroy opcode) in order to keep
		 ** the internal representation of the
		 ** schema consistent with what is on disk.
		 */
	_138:
		;
		_sqlite3UnlinkAndDeleteTrigger(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		goto _189
		/* Opcode: IntegrityCk P1 P2 P3 P4 P5
		 **
		 ** Do an analysis of the currently open database.  Store in
		 ** register (P1+1) the text of an error message describing any problems.
		 ** If no problems are found, store a NULL in register (P1+1).
		 **
		 ** The register (P1) contains one less than the maximum number of allowed
		 ** errors.  At most reg(P1) errors will be reported.
		 ** In other words, the analysis stops as soon as reg(P1) errors are
		 ** seen.  Reg(P1) is updated with the number of errors remaining.
		 **
		 ** The root page numbers of all tables in the database are integers
		 ** stored in P4_INTARRAY argument.
		 **
		 ** If P5 is not zero, the check is done on the auxiliary database
		 ** file, not the main database file.
		 **
		 ** This opcode is used to implement the integrity_check pragma.
		 */
	_139:
		; /* Register keeping track of errors remaining */
		nRoot = (*TOp)(unsafe.Pointer(pOp)).Fp2
		aRoot = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pnErr = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1+int32(1))*56
		rc = _sqlite3BtreeIntegrityCheck(tls, db, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp5)*32))).FpBt, aRoot+1*4, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56, nRoot, int32(*(*Ti64)(unsafe.Pointer(pnErr)))+int32(1), bp+680, bp+688)
		_sqlite3VdbeMemSetNull(tls, pIn1)
		if **(**int32)(__ccgo_up(bp + 680)) == 0 {
		} else {
			if rc != 0 {
				Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 688)))
				goto abort_due_to_error
			} else {
				*(*Ti64)(unsafe.Pointer(pnErr)) -= int64(**(**int32)(__ccgo_up(bp + 680)) - int32(1))
				_sqlite3VdbeMemSetStr(tls, pIn1, **(**uintptr)(__ccgo_up(bp + 688)), int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
			}
		}
		_sqlite3VdbeChangeEncoding(tls, pIn1, libc.Int32FromUint8(encoding))
		goto check_for_interrupt
		/* Opcode: IFindKey P1 P2 P3 P4 *
		 **
		 ** This instruction always follows an OP_Found with the same P1, P2 and P3
		 ** values as this instruction and a non-zero P4 value. The P4 value to
		 ** this opcode is of type P4_INDEX and contains a pointer to the Index
		 ** object of for the index being searched.
		 **
		 ** This opcode uses sqlite3VdbeFindIndexKey() to search around the current
		 ** cursor location for an index key that exactly matches all fields that
		 ** are not indexed expressions or references to VIRTUAL generated columns,
		 ** and either exactly match or are real numbers that are within 2 ULPs of
		 ** each other if the don't match.
		 **
		 ** To put it another way, this opcode looks for nearby index entries that
		 ** are very close to the search key, but which might have small differences
		 ** in floating-point values that come via an expression.
		 **
		 ** If no nearby alternative entry is found in cursor P1, then jump to P2.
		 ** But if a close match is found, fall through.
		 **
		 ** This opcode is used by PRAGMA integrity_check to help distinguish
		 ** between truely corrupt indexes and expression indexes that are holding
		 ** floating-point values that are off by one or two ULPs.
		 */
	_140:
		;
		pC31 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		libc.Xmemset(tls, bp+704, 0, uint64(40))
		(**(**TUnpackedRecord)(__ccgo_up(bp + 704))).FaMem = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		(**(**TUnpackedRecord)(__ccgo_up(bp + 704))).FnField = (*TIndex)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FnColumn
		(**(**TUnpackedRecord)(__ccgo_up(bp + 704))).FpKeyInfo = (*TVdbeCursor)(unsafe.Pointer(pC31)).FpKeyInfo
		rc = _sqlite3VdbeFindIndexKey(tls, *(*uintptr)(unsafe.Pointer(pC31 + 48)), *(*uintptr)(unsafe.Pointer(pOp + 16)), bp+704, bp+696, int32(1))
		if rc != 0 || **(**int32)(__ccgo_up(bp + 696)) != 0 {
			rc = SQLITE_OK
			goto jump_to_p2
		}
		(*TVdbeCursor)(unsafe.Pointer(pC31)).FnullRow = uint8(0)
		goto _189
		/* Opcode: RowSetAdd P1 P2 * * *
		 ** Synopsis: rowset(P1)=r[P2]
		 **
		 ** Insert the integer value held by register P2 into a RowSet object
		 ** held in register P1.
		 **
		 ** An assertion fails if P2 is not an integer.
		 */
	_141:
		; /* in1, in2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
			if _sqlite3VdbeMemSetRowSet(tls, pIn1) != 0 {
				goto no_mem
			}
		}
		_sqlite3RowSetInsert(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, *(*Ti64)(unsafe.Pointer(pIn2)))
		goto _189
		/* Opcode: RowSetRead P1 P2 P3 * *
		 ** Synopsis: r[P3]=rowset(P1)
		 **
		 ** Extract the smallest value from the RowSet object in P1
		 ** and put that value into register P3.
		 ** Or, if RowSet object P1 is initially empty, leave P3
		 ** unchanged and jump to instruction P2.
		 */
	_142:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 || _sqlite3RowSetNext(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, bp+744) == 0 {
			/* The boolean index is empty */
			_sqlite3VdbeMemSetNull(tls, pIn1)
			goto jump_to_p2_and_check_for_interrupt
		} else {
			/* A value was pulled from the index */
			_sqlite3VdbeMemSetInt64(tls, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56, **(**Ti64)(__ccgo_up(bp + 744)))
		}
		goto check_for_interrupt
		/* Opcode: RowSetTest P1 P2 P3 P4
		 ** Synopsis: if r[P3] in rowset(P1) goto P2
		 **
		 ** Register P3 is assumed to hold a 64-bit integer value. If register P1
		 ** contains a RowSet object and that RowSet object contains
		 ** the value held in P3, jump to register P2. Otherwise, insert the
		 ** integer in P3 into the RowSet and continue on to the
		 ** next opcode.
		 **
		 ** The RowSet object is optimized for the case where sets of integers
		 ** are inserted in distinct phases, which each set contains no duplicates.
		 ** Each set is identified by a unique P4 value. The first set
		 ** must have P4==0, the final set must have P4==-1, and for all other sets
		 ** must have P4>0.
		 **
		 ** This allows optimizations: (a) when P4==0 there is no need to test
		 ** the RowSet object for P3, as it is guaranteed not to contain it,
		 ** (b) when P4==-1 there is no need to insert the value, as it will
		 ** never be tested for, and (c) when a value that is part of set X is
		 ** inserted, there is no need to search to see if the same value was
		 ** previously inserted as part of set X (only if it was previously
		 ** inserted as part of some other set).
		 */
	_143:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		iSet = (*TOp)(unsafe.Pointer(pOp)).Fp4.Fi
		/* If there is anything other than a rowset object in memory cell P1,
		 ** delete it now and initialize P1 with an empty rowset
		 */
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Blob) == 0 {
			if _sqlite3VdbeMemSetRowSet(tls, pIn1) != 0 {
				goto no_mem
			}
		}
		if iSet != 0 {
			exists = _sqlite3RowSetTest(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, iSet, *(*Ti64)(unsafe.Pointer(pIn3)))
			if exists != 0 {
				goto jump_to_p2
			}
		}
		if iSet >= 0 {
			_sqlite3RowSetInsert(tls, (*TMem)(unsafe.Pointer(pIn1)).Fz, *(*Ti64)(unsafe.Pointer(pIn3)))
		}
		goto _189
		/* Opcode: Program P1 P2 P3 P4 P5
		 **
		 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
		 **
		 ** P1 contains the address of the memory cell that contains the first memory
		 ** cell in an array of values used as arguments to the sub-program. P2
		 ** contains the address to jump to if the sub-program throws an IGNORE
		 ** exception using the RAISE() function. P2 might be zero, if there is
		 ** no possibility that an IGNORE exception will be raised.
		 ** Register P3 contains the address
		 ** of a memory cell in this (the parent) VM that is used to allocate the
		 ** memory required by the sub-vdbe at runtime.
		 **
		 ** P4 is a pointer to the VM containing the trigger program.
		 **
		 ** If P5 is non-zero, then recursive program invocation is enabled.
		 */
	_144:
		; /* Token identifying trigger */
		pProgram = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pRt = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		/* If the p5 flag is clear, then recursive invocation of triggers is
		 ** disabled for backwards compatibility (p5 is set if this sub-program
		 ** is really a trigger, not a foreign key action, and the flag set
		 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
		 **
		 ** It is recursive invocation of triggers, at the SQL level, that is
		 ** disabled. In some cases a single trigger may generate more than one
		 ** SubProgram (if the trigger may be executed with more than one different
		 ** ON CONFLICT algorithm). SubProgram structures associated with a
		 ** single trigger all have the same value for the SubProgram.token
		 ** variable.  */
		if (*TOp)(unsafe.Pointer(pOp)).Fp5 != 0 {
			t1 = (*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken
			pFrame2 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
			for {
				if !(pFrame2 != 0 && (*TVdbeFrame)(unsafe.Pointer(pFrame2)).Ftoken != t1) {
					break
				}
				goto _278
			_278:
				;
				pFrame2 = (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpParent
			}
			if pFrame2 != 0 {
				goto _189
			}
		}
		if (*TVdbe)(unsafe.Pointer(p)).FnFrame >= **(**int32)(__ccgo_up(db + 136 + 10*4)) {
			rc = int32(SQLITE_ERROR)
			_sqlite3VdbeError(tls, p, __ccgo_ts+6345, 0)
			goto abort_due_to_error
		}
		/* Register pRt is used to store the memory required to save the state
		 ** of the current program, and the memory required at runtime to execute
		 ** the trigger program. If this trigger has been fired before, then pRt
		 ** is already allocated. Otherwise, it must be initialized.  */
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pRt)).Fflags)&int32(MEM_Blob) == 0 {
			/* SubProgram.nMem is set to the number of memory cells used by the
			 ** program stored in SubProgram.aOp. As well as these, one memory
			 ** cell is required for each cursor used by the program. Set local
			 ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
			 */
			nMem = (*TSubProgram)(unsafe.Pointer(pProgram)).FnMem + (*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr
			if (*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr == 0 {
				nMem = nMem + 1
			}
			nByte2 = libc.Int64FromUint64(uint64((libc.Uint64FromInt64(112)+libc.Uint64FromInt32(7))&libc.Uint64FromInt32(^libc.Int32FromInt32(7))+libc.Uint64FromInt32(nMem)*uint64(56)+libc.Uint64FromInt32((*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr)*uint64(8)) + libc.Uint64FromInt64((int64(7)+int64((*TSubProgram)(unsafe.Pointer(pProgram)).FnOp))/int64(8)))
			pFrame2 = _sqlite3DbMallocZero(tls, db, libc.Uint64FromInt64(nByte2))
			if !(pFrame2 != 0) {
				goto no_mem
			}
			_sqlite3VdbeMemRelease(tls, pRt)
			(*TMem)(unsafe.Pointer(pRt)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Blob) | libc.Int32FromInt32(MEM_Dyn))
			(*TMem)(unsafe.Pointer(pRt)).Fz = pFrame2
			(*TMem)(unsafe.Pointer(pRt)).Fn = int32(nByte2)
			(*TMem)(unsafe.Pointer(pRt)).FxDel = __ccgo_fp(_sqlite3VdbeFrameMemDel)
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).Fv = p
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem = nMem
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr = (*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).Fpc = int32((int64(pOp) - int64(aOp)) / 24)
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaMem = (*TVdbe)(unsafe.Pointer(p)).FaMem
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnMem = (*TVdbe)(unsafe.Pointer(p)).FnMem
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FapCsr = (*TVdbe)(unsafe.Pointer(p)).FapCsr
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnCursor = (*TVdbe)(unsafe.Pointer(p)).FnCursor
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOp = (*TVdbe)(unsafe.Pointer(p)).FaOp
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnOp = (*TVdbe)(unsafe.Pointer(p)).FnOp
			(*TVdbeFrame)(unsafe.Pointer(pFrame2)).Ftoken = (*TSubProgram)(unsafe.Pointer(pProgram)).Ftoken
			pEnd = pFrame2 + uintptr((libc.Uint64FromInt64(112)+libc.Uint64FromInt32(7))&libc.Uint64FromInt32(^libc.Int32FromInt32(7))) + uintptr((*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem)*56
			pMem1 = pFrame2 + uintptr((libc.Uint64FromInt64(112)+libc.Uint64FromInt32(7))&libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
			for {
				if !(pMem1 != pEnd) {
					break
				}
				(*TMem)(unsafe.Pointer(pMem1)).Fflags = uint16(MEM_Undefined)
				(*TMem)(unsafe.Pointer(pMem1)).Fdb = db
				goto _279
			_279:
				;
				pMem1 += 56
			}
		} else {
			pFrame2 = (*TMem)(unsafe.Pointer(pRt)).Fz
		}
		(*TVdbe)(unsafe.Pointer(p)).FnFrame = (*TVdbe)(unsafe.Pointer(p)).FnFrame + 1
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpParent = (*TVdbe)(unsafe.Pointer(p)).FpFrame
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FlastRowid = (*Tsqlite3)(unsafe.Pointer(db)).FlastRowid
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnDbChange = (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FnChange
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FpAuxData = (*TVdbe)(unsafe.Pointer(p)).FpAuxData
		(*TVdbe)(unsafe.Pointer(p)).FpAuxData = uintptr(0)
		(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
		(*TVdbe)(unsafe.Pointer(p)).FpFrame = pFrame2
		v191 = pFrame2 + uintptr((libc.Uint64FromInt64(112)+libc.Uint64FromInt32(7))&libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
		aMem = v191
		(*TVdbe)(unsafe.Pointer(p)).FaMem = v191
		(*TVdbe)(unsafe.Pointer(p)).FnMem = (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem
		(*TVdbe)(unsafe.Pointer(p)).FnCursor = libc.Int32FromUint16(libc.Uint16FromInt32((*TVdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr))
		(*TVdbe)(unsafe.Pointer(p)).FapCsr = aMem + uintptr((*TVdbe)(unsafe.Pointer(p)).FnMem)*56
		(*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce = (*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TSubProgram)(unsafe.Pointer(pProgram)).FnCsr)*8
		libc.Xmemset(tls, (*TVdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce, 0, libc.Uint64FromInt32(((*TSubProgram)(unsafe.Pointer(pProgram)).FnOp+int32(7))/int32(8)))
		v191 = (*TSubProgram)(unsafe.Pointer(pProgram)).FaOp
		aOp = v191
		(*TVdbe)(unsafe.Pointer(p)).FaOp = v191
		(*TVdbe)(unsafe.Pointer(p)).FnOp = (*TSubProgram)(unsafe.Pointer(pProgram)).FnOp
		pOp = aOp + uintptr(-libc.Int32FromInt32(1))*24
		goto check_for_interrupt
		/* Opcode: Param P1 P2 * * *
		 **
		 ** This opcode is only ever present in sub-programs called via the
		 ** OP_Program instruction. Copy a value currently stored in a memory
		 ** cell of the calling (parent) frame to cell P2 in the current frames
		 ** address space. This is used by trigger programs to access the new.*
		 ** and old.* values.
		 **
		 ** The address of the cell in the parent frame is determined by adding
		 ** the value of the P1 argument to the value of the P1 argument to the
		 ** calling OP_Program instruction.
		 */
	_145:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		pFrame3 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
		pIn = (*TVdbeFrame)(unsafe.Pointer(pFrame3)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1+(**(**TOp)(__ccgo_up((*TVdbeFrame)(unsafe.Pointer(pFrame3)).FaOp + uintptr((*TVdbeFrame)(unsafe.Pointer(pFrame3)).Fpc)*24))).Fp1)*56
		_sqlite3VdbeMemShallowCopy(tls, pOut, pIn, int32(MEM_Ephem))
		goto _189
		/* Opcode: FkCounter P1 P2 * * *
		 ** Synopsis: fkctr[P1]+=P2
		 **
		 ** Increment a "constraint counter" by P2 (P2 may be negative or positive).
		 ** If P1 is non-zero, the database constraint counter is incremented
		 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
		 ** statement counter is incremented (immediate foreign key constraints).
		 */
	_146:
		;
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
			**(**Ti64)(__ccgo_up(db + 784)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
				**(**Ti64)(__ccgo_up(db + 792)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
			} else {
				**(**Ti64)(__ccgo_up(p + 80)) += int64((*TOp)(unsafe.Pointer(pOp)).Fp2)
			}
		}
		goto _189
		/* Opcode: FkIfZero P1 P2 * * *
		 ** Synopsis: if fkctr[P1]==0 goto P2
		 **
		 ** This opcode tests if a foreign key constraint-counter is currently zero.
		 ** If so, jump to instruction P2. Otherwise, fall through to the next
		 ** instruction.
		 **
		 ** If P1 is non-zero, then the jump is taken if the database constraint-counter
		 ** is zero (the one that counts deferred constraint violations). If P1 is
		 ** zero, the jump is taken if the statement constraint-counter is zero
		 ** (immediate foreign key constraint violations).
		 */
	_147:
		; /* jump */
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
			if (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons == 0 {
				goto jump_to_p2
			}
		} else {
			if (*TVdbe)(unsafe.Pointer(p)).FnFkConstraint == 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons == 0 {
				goto jump_to_p2
			}
		}
		goto _189
		/* Opcode: MemMax P1 P2 * * *
		 ** Synopsis: r[P1]=max(r[P1],r[P2])
		 **
		 ** P1 is a register in the root frame of this VM (the root frame is
		 ** different from the current frame if this instruction is being executed
		 ** within a sub-program). Set the value of register P1 to the maximum of
		 ** its current value and the value in register P2.
		 **
		 ** This instruction throws an error if the memory cell is not initially
		 ** an integer.
		 */
	_148:
		;
		if (*TVdbe)(unsafe.Pointer(p)).FpFrame != 0 {
			pFrame4 = (*TVdbe)(unsafe.Pointer(p)).FpFrame
			for {
				if !((*TVdbeFrame)(unsafe.Pointer(pFrame4)).FpParent != 0) {
					break
				}
				goto _282
			_282:
				;
				pFrame4 = (*TVdbeFrame)(unsafe.Pointer(pFrame4)).FpParent
			}
			pIn1 = (*TVdbeFrame)(unsafe.Pointer(pFrame4)).FaMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		} else {
			pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		}
		_sqlite3VdbeMemIntegerify(tls, pIn1)
		pIn2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		_sqlite3VdbeMemIntegerify(tls, pIn2)
		if *(*Ti64)(unsafe.Pointer(pIn1)) < *(*Ti64)(unsafe.Pointer(pIn2)) {
			*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn2))
		}
		goto _189
		/* Opcode: IfPos P1 P2 P3 * *
		 ** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
		 **
		 ** Register P1 must contain an integer.
		 ** If the value of register P1 is 1 or greater, subtract P3 from the
		 ** value in P1 and jump to P2.
		 **
		 ** If the initial value of register P1 is less than 1, then the
		 ** value is unchanged and control passes through to the next instruction.
		 */
	_149:
		; /* jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if *(*Ti64)(unsafe.Pointer(pIn1)) > 0 {
			*(*Ti64)(unsafe.Pointer(pIn1)) -= int64((*TOp)(unsafe.Pointer(pOp)).Fp3)
			goto jump_to_p2
		}
		goto _189
		/* Opcode: OffsetLimit P1 P2 P3 * *
		 ** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
		 **
		 ** This opcode performs a commonly used computation associated with
		 ** LIMIT and OFFSET processing.  r[P1] holds the limit counter.  r[P3]
		 ** holds the offset counter.  The opcode computes the combined value
		 ** of the LIMIT and OFFSET and stores that value in r[P2].  The r[P2]
		 ** value computed is the total number of rows that will need to be
		 ** visited in order to complete the query.
		 **
		 ** If r[P3] is zero or negative, that means there is no OFFSET
		 ** and r[P2] is set to be the value of the LIMIT, r[P1].
		 **
		 ** if r[P1] is zero or negative, that means there is no LIMIT
		 ** and r[P2] is set to -1.
		 **
		 ** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
		 */
	_150:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pIn3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		pOut = _out2Prerelease(tls, p, pOp)
		**(**Ti64)(__ccgo_up(bp + 752)) = *(*Ti64)(unsafe.Pointer(pIn1))
		if v217 = **(**Ti64)(__ccgo_up(bp + 752)) <= 0; !v217 {
			if *(*Ti64)(unsafe.Pointer(pIn3)) > 0 {
				v206 = *(*Ti64)(unsafe.Pointer(pIn3))
			} else {
				v206 = 0
			}
		}
		if v217 || _sqlite3AddInt64(tls, bp+752, v206) != 0 {
			/* If the LIMIT is less than or equal to zero, loop forever.  This
			 ** is documented.  But also, if the LIMIT+OFFSET exceeds 2^63 then
			 ** also loop forever.  This is undocumented.  In fact, one could argue
			 ** that the loop should terminate.  But assuming 1 billion iterations
			 ** per second (far exceeding the capabilities of any current hardware)
			 ** it would take nearly 300 years to actually reach the limit.  So
			 ** looping forever is a reasonable approximation. */
			*(*Ti64)(unsafe.Pointer(pOut)) = int64(-int32(1))
		} else {
			*(*Ti64)(unsafe.Pointer(pOut)) = **(**Ti64)(__ccgo_up(bp + 752))
		}
		goto _189
		/* Opcode: IfNotZero P1 P2 * * *
		 ** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
		 **
		 ** Register P1 must contain an integer.  If the content of register P1 is
		 ** initially greater than zero, then decrement the value in register P1.
		 ** If it is non-zero (negative or positive) and then also jump to P2.
		 ** If register P1 is initially zero, leave it unchanged and fall through.
		 */
	_151:
		; /* jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if *(*Ti64)(unsafe.Pointer(pIn1)) != 0 {
			if *(*Ti64)(unsafe.Pointer(pIn1)) > 0 {
				*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn1)) - 1
			}
			goto jump_to_p2
		}
		goto _189
		/* Opcode: DecrJumpZero P1 P2 * * *
		 ** Synopsis: if (--r[P1])==0 goto P2
		 **
		 ** Register P1 must hold an integer.  Decrement the value in P1
		 ** and jump to P2 if the new value is exactly zero.
		 */
	_152:
		; /* jump, in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if *(*Ti64)(unsafe.Pointer(pIn1)) > int64(-libc.Int32FromInt32(1))-(libc.Int64FromUint32(0xffffffff)|libc.Int64FromInt32(0x7fffffff)<<libc.Int32FromInt32(32)) {
			*(*Ti64)(unsafe.Pointer(pIn1)) = *(*Ti64)(unsafe.Pointer(pIn1)) - 1
		}
		if *(*Ti64)(unsafe.Pointer(pIn1)) == 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: AggStep * P2 P3 P4 P5
		 ** Synopsis: accum=r[P3] step(r[P2@P5])
		 **
		 ** Execute the xStep function for an aggregate.
		 ** The function has P5 arguments.  P4 is a pointer to the
		 ** FuncDef structure that specifies the function.  Register P3 is the
		 ** accumulator.
		 **
		 ** The P5 arguments are taken from register P2 and its
		 ** successors.
		 */
		/* Opcode: AggInverse * P2 P3 P4 P5
		 ** Synopsis: accum=r[P3] inverse(r[P2@P5])
		 **
		 ** Execute the xInverse function for an aggregate.
		 ** The function has P5 arguments.  P4 is a pointer to the
		 ** FuncDef structure that specifies the function.  Register P3 is the
		 ** accumulator.
		 **
		 ** The P5 arguments are taken from register P2 and its
		 ** successors.
		 */
		/* Opcode: AggStep1 P1 P2 P3 P4 P5
		 ** Synopsis: accum=r[P3] step(r[P2@P5])
		 **
		 ** Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
		 ** aggregate.  The function has P5 arguments.  P4 is a pointer to the
		 ** FuncDef structure that specifies the function.  Register P3 is the
		 ** accumulator.
		 **
		 ** The P5 arguments are taken from register P2 and its
		 ** successors.
		 **
		 ** This opcode is initially coded as OP_AggStep0.  On first evaluation,
		 ** the FuncDef stored in P4 is converted into an sqlite3_context and
		 ** the opcode is changed.  In this way, the initialization of the
		 ** sqlite3_context only happens once, instead of on each call to the
		 ** step function.
		 */
	_154:
		;
	_153:
		;
		n4 = libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)
		/* Allocate space for (a) the context object and (n-1) extra pointers
		 ** to append to the sqlite3_context.argv[1] array, and (b) a memory
		 ** cell in which to store the accumulation. Be careful that the memory
		 ** cell is 8-byte aligned, even on platforms where a pointer is 32-bits.
		 **
		 ** Note: We could avoid this by using a regular memory cell from aMem[] for
		 ** the accumulator, instead of allocating one here. */
		nAlloc = uint64(uint64(libc.UintptrFromInt32(0)+48) + libc.Uint64FromInt32(n4)*libc.Uint64FromInt64(8))
		pCtx = _sqlite3DbMallocRawNN(tls, db, nAlloc+uint64(56))
		if pCtx == uintptr(0) {
			goto no_mem
		}
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut = pCtx + uintptr(nAlloc)
		_sqlite3VdbeMemInit(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut, db, uint16(MEM_Null))
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpMem = uintptr(0)
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpFunc = *(*uintptr)(unsafe.Pointer(pOp + 16))
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp = int32((int64(pOp) - int64(aOp)) / 24)
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe = p
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FskipFlag = uint8(0)
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = 0
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fenc = encoding
		(*Tsqlite3_context)(unsafe.Pointer(pCtx)).Fargc = libc.Uint16FromInt32(n4)
		(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(16))
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = pCtx
		/* OP_AggInverse must have P1==1 and OP_AggStep must have P1==0 */
		(*TOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_AggStep1)
		/* Fall through into OP_AggStep */
	_155:
		;
		pCtx1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		pMem2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		/* If this function is inside of a trigger, the register array in aMem[]
		 ** might change from one evaluation to the next.  The next block of code
		 ** checks to see if the register array has changed, and if so it
		 ** reinitializes the relevant parts of the sqlite3_context object */
		if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpMem != pMem2 {
			(*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpMem = pMem2
			i4 = libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc) - int32(1)
			for {
				if !(i4 >= 0) {
					break
				}
				*(*uintptr)(unsafe.Pointer(pCtx1 + 48 + uintptr(i4)*8)) = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2+i4)*56
				goto _285
			_285:
				;
				i4 = i4 - 1
			}
		}
		(*TMem)(unsafe.Pointer(pMem2)).Fn = (*TMem)(unsafe.Pointer(pMem2)).Fn + 1
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
			(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxInverse})))(tls, pCtx1, libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+48)
		} else {
			(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxSFunc})))(tls, pCtx1, libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+48)
		} /* IMP: R-24505-23230 */
		if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError != 0 {
			if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError > 0 {
				_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, Xsqlite3_value_text(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)))
				rc = (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError
			}
			if (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FskipFlag != 0 {
				i4 = (**(**TOp)(__ccgo_up(pOp + uintptr(-libc.Int32FromInt32(1))*24))).Fp1
				if i4 != 0 {
					_sqlite3VdbeMemSetInt64(tls, aMem+uintptr(i4)*56, int64(1))
				}
				(*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FskipFlag = uint8(0)
			}
			_sqlite3VdbeMemRelease(tls, (*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)
			(*TMem)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)).Fflags = uint16(MEM_Null)
			(*Tsqlite3_context)(unsafe.Pointer(pCtx1)).FisError = 0
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode: AggFinal P1 P2 * P4 *
		 ** Synopsis: accum=r[P1] N=P2
		 **
		 ** P1 is the memory location that is the accumulator for an aggregate
		 ** or window function.  Execute the finalizer function
		 ** for an aggregate and store the result in P1.
		 **
		 ** P2 is the number of arguments that the step function takes and
		 ** P4 is a pointer to the FuncDef for this function.  The P2
		 ** argument is not used by this opcode.  It is only there to disambiguate
		 ** functions that can take varying numbers of arguments.  The
		 ** P4 argument is only needed for the case where
		 ** the step function was not previously called.
		 */
		/* Opcode: AggValue * P2 P3 P4 *
		 ** Synopsis: r[P3]=value N=P2
		 **
		 ** Invoke the xValue() function and store the result in register P3.
		 **
		 ** P2 is the number of arguments that the step function takes and
		 ** P4 is a pointer to the FuncDef for this function.  The P2
		 ** argument is not used by this opcode.  It is only there to disambiguate
		 ** functions that can take varying numbers of arguments.  The
		 ** P4 argument is only needed for the case where
		 ** the step function was not previously called.
		 */
	_157:
		;
	_156:
		;
		pMem3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			rc = _sqlite3VdbeMemAggValue(tls, pMem3, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56, *(*uintptr)(unsafe.Pointer(pOp + 16)))
			pMem3 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		} else {
			rc = _sqlite3VdbeMemFinalize(tls, pMem3, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		}
		if rc != 0 {
			_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, Xsqlite3_value_text(tls, pMem3)))
			goto abort_due_to_error
		}
		_sqlite3VdbeChangeEncoding(tls, pMem3, libc.Int32FromUint8(encoding))
		goto _189
		/* Opcode: Checkpoint P1 P2 P3 * *
		 **
		 ** Checkpoint database P1. This is a no-op if P1 is not currently in
		 ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
		 ** RESTART, or TRUNCATE.  Write 1 or 0 into mem[P3] if the checkpoint returns
		 ** SQLITE_BUSY or not, respectively.  Write the number of pages in the
		 ** WAL after the checkpoint into mem[P3+1] and the number of pages
		 ** in the WAL that have been checkpointed after the checkpoint
		 ** completes into mem[P3+2].  However on an error, mem[P3+1] and
		 ** mem[P3+2] are initialized to -1.
		 */
	_158:
		; /* Write results here */
		(**(**[3]int32)(__ccgo_up(bp + 760)))[0] = 0
		v190 = -libc.Int32FromInt32(1)
		(**(**[3]int32)(__ccgo_up(bp + 760)))[int32(2)] = v190
		(**(**[3]int32)(__ccgo_up(bp + 760)))[int32(1)] = v190
		rc = _sqlite3Checkpoint(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, (*TOp)(unsafe.Pointer(pOp)).Fp2, bp+760+1*4, bp+760+2*4)
		if rc != 0 {
			if rc != int32(SQLITE_BUSY) {
				goto abort_due_to_error
			}
			rc = SQLITE_OK
			(**(**[3]int32)(__ccgo_up(bp + 760)))[0] = int32(1)
		}
		i5 = 0
		pMem4 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		for {
			if !(i5 < int32(3)) {
				break
			}
			_sqlite3VdbeMemSetInt64(tls, pMem4, int64((**(**[3]int32)(__ccgo_up(bp + 760)))[i5]))
			goto _287
		_287:
			;
			i5 = i5 + 1
			pMem4 += 56
		}
		goto _189
		/* Opcode: JournalMode P1 P2 P3 * *
		 **
		 ** Change the journal mode of database P1 to P3. P3 must be one of the
		 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
		 ** modes (delete, truncate, persist, off and memory), this is a simple
		 ** operation. No IO is required.
		 **
		 ** If changing into or out of WAL mode the procedure is more complicated.
		 **
		 ** Write a string containing the final journal-mode to register P2.
		 */
	_159:
		; /* Name of database file for pPager */
		pOut = _out2Prerelease(tls, p, pOp)
		eNew = (*TOp)(unsafe.Pointer(pOp)).Fp3
		pBt1 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32))).FpBt
		pPager = _sqlite3BtreePager(tls, pBt1)
		eOld = _sqlite3PagerGetJournalMode(tls, pPager)
		if eNew == -int32(1) {
			eNew = eOld
		}
		if !(_sqlite3PagerOkToChangeJournalMode(tls, pPager) != 0) {
			eNew = eOld
		}
		zFilename = _sqlite3PagerFilename(tls, pPager, int32(1))
		/* Do not allow a transition to journal_mode=WAL for a database
		 ** in temporary storage or if the VFS does not support shared memory
		 */
		if eNew == int32(PAGER_JOURNALMODE_WAL) && (_sqlite3Strlen30(tls, zFilename) == 0 || !(_sqlite3PagerWalSupported(tls, pPager) != 0)) {
			eNew = eOld
		}
		if eNew != eOld && (eOld == int32(PAGER_JOURNALMODE_WAL) || eNew == int32(PAGER_JOURNALMODE_WAL)) {
			if !((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0) || (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead > int32(1) {
				rc = int32(SQLITE_ERROR)
				if eNew == int32(PAGER_JOURNALMODE_WAL) {
					v191 = __ccgo_ts + 6382
				} else {
					v191 = __ccgo_ts + 6387
				}
				_sqlite3VdbeError(tls, p, __ccgo_ts+6394, libc.VaList(bp+984, v191))
				goto abort_due_to_error
			} else {
				if eOld == int32(PAGER_JOURNALMODE_WAL) {
					/* If leaving WAL mode, close the log file. If successful, the call
					 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
					 ** file. An EXCLUSIVE lock may still be held on the database file
					 ** after a successful return.
					 */
					rc = _sqlite3PagerCloseWal(tls, pPager, db)
					if rc == SQLITE_OK {
						_sqlite3PagerSetJournalMode(tls, pPager, eNew)
					}
				} else {
					if eOld == int32(PAGER_JOURNALMODE_MEMORY) {
						/* Cannot transition directly from MEMORY to WAL.  Use mode OFF
						 ** as an intermediate */
						_sqlite3PagerSetJournalMode(tls, pPager, int32(PAGER_JOURNALMODE_OFF))
					}
				}
				/* Open a transaction on the database file. Regardless of the journal
				 ** mode, this transaction always uses a rollback journal.
				 */
				if rc == SQLITE_OK {
					if eNew == int32(PAGER_JOURNALMODE_WAL) {
						v190 = int32(2)
					} else {
						v190 = int32(1)
					}
					rc = _sqlite3BtreeSetVersion(tls, pBt1, v190)
				}
			}
		}
		if rc != 0 {
			eNew = eOld
		}
		eNew = _sqlite3PagerSetJournalMode(tls, pPager, eNew)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Str) | libc.Int32FromInt32(MEM_Static) | libc.Int32FromInt32(MEM_Term))
		(*TMem)(unsafe.Pointer(pOut)).Fz = _sqlite3JournalModename(tls, eNew)
		(*TMem)(unsafe.Pointer(pOut)).Fn = _sqlite3Strlen30(tls, (*TMem)(unsafe.Pointer(pOut)).Fz)
		(*TMem)(unsafe.Pointer(pOut)).Fenc = uint8(SQLITE_UTF8)
		_sqlite3VdbeChangeEncoding(tls, pOut, libc.Int32FromUint8(encoding))
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: Vacuum P1 P2 * * *
		 **
		 ** Vacuum the entire database P1.  P1 is 0 for "main", and 2 or more
		 ** for an attached database.  The "temp" database may not be vacuumed.
		 **
		 ** If P2 is not zero, then it is a register holding a string which is
		 ** the file into which the result of vacuum should be written.  When
		 ** P2 is zero, the vacuum overwrites the original database.
		 */
	_160:
		;
		if (*TOp)(unsafe.Pointer(pOp)).Fp2 != 0 {
			v191 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		} else {
			v191 = uintptr(0)
		}
		rc = _sqlite3RunVacuum(tls, p+168, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, v191)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: IncrVacuum P1 P2 * * *
		 **
		 ** Perform a single step of the incremental vacuum procedure on
		 ** the P1 database. If the vacuum has finished, jump to instruction
		 ** P2. Otherwise, fall through to the next instruction.
		 */
	_161:
		;
		pBt2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32))).FpBt
		rc = _sqlite3BtreeIncrVacuum(tls, pBt2)
		if rc != 0 {
			if rc != int32(SQLITE_DONE) {
				goto abort_due_to_error
			}
			rc = SQLITE_OK
			goto jump_to_p2
		}
		goto _189
		/* Opcode: Expire P1 P2 * * *
		 **
		 ** Cause precompiled statements to expire.  When an expired statement
		 ** is executed using sqlite3_step() it will either automatically
		 ** reprepare itself (if it was originally created using sqlite3_prepare_v2())
		 ** or it will fail with SQLITE_SCHEMA.
		 **
		 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
		 ** then only the currently executing statement is expired.
		 **
		 ** If P2 is 0, then SQL statements are expired immediately.  If P2 is 1,
		 ** then running SQL statements are allowed to continue to run to completion.
		 ** The P2==1 case occurs when a CREATE INDEX or similar schema change happens
		 ** that might help the statement run faster but which does not affect the
		 ** correctness of operation.
		 */
	_162:
		;
		if !((*TOp)(unsafe.Pointer(pOp)).Fp1 != 0) {
			_sqlite3ExpirePreparedStatements(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp2)
		} else {
			libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp2+libc.Int32FromInt32(1)), 14, 0xc000)
		}
		goto _189
		/* Opcode: CursorLock P1 * * * *
		 **
		 ** Lock the btree to which cursor P1 is pointing so that the btree cannot be
		 ** written by an other cursor.
		 */
	_163:
		;
		pC32 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		_sqlite3BtreeCursorPin(tls, *(*uintptr)(unsafe.Pointer(pC32 + 48)))
		goto _189
		/* Opcode: CursorUnlock P1 * * * *
		 **
		 ** Unlock the btree to which cursor P1 is pointing so that it can be
		 ** written by other cursors.
		 */
	_164:
		;
		pC33 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		_sqlite3BtreeCursorUnpin(tls, *(*uintptr)(unsafe.Pointer(pC33 + 48)))
		goto _189
		/* Opcode: TableLock P1 P2 P3 P4 *
		 ** Synopsis: iDb=P1 root=P2 write=P3
		 **
		 ** Obtain a lock on a particular table. This instruction is only used when
		 ** the shared-cache feature is enabled.
		 **
		 ** P1 is the index of the database in sqlite3.aDb[] of the database
		 ** on which the lock is acquired.  A readlock is obtained if P3==0 or
		 ** a write lock if P3==1.
		 **
		 ** P2 contains the root-page of the table to lock.
		 **
		 ** P4 contains a pointer to the name of the table being locked. This is only
		 ** used to generate an error message if the lock cannot be obtained.
		 */
	_165:
		;
		isWriteLock = libc.Uint8FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
		if isWriteLock != 0 || uint64(0) == (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00004))<<libc.Int32FromInt32(32)) {
			p13 = (*TOp)(unsafe.Pointer(pOp)).Fp1
			rc = _sqlite3BtreeLockTable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(p13)*32))).FpBt, (*TOp)(unsafe.Pointer(pOp)).Fp2, isWriteLock)
			if rc != 0 {
				if rc&int32(0xFF) == int32(SQLITE_LOCKED) {
					z1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
					_sqlite3VdbeError(tls, p, __ccgo_ts+6446, libc.VaList(bp+984, z1))
				}
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode: VBegin * * * P4 *
		 **
		 ** P4 may be a pointer to an sqlite3_vtab structure. If so, call the
		 ** xBegin method for that table.
		 **
		 ** Also, whether or not P4 is set, check that this is not being called from
		 ** within a callback to a virtual table xSync() method. If it is, the error
		 ** code will be set to SQLITE_LOCKED.
		 */
	_166:
		;
		pVTab = *(*uintptr)(unsafe.Pointer(pOp + 16))
		rc = _sqlite3VtabBegin(tls, db, pVTab)
		if pVTab != 0 {
			_sqlite3VtabImportErrmsg(tls, p, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab)
		}
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: VCreate P1 P2 * * *
		 **
		 ** P2 is a register that holds the name of a virtual table in database
		 ** P1. Call the xCreate method for that table.
		 */
	_167:
		; /* Name of the virtual table */
		libc.Xmemset(tls, bp+776, 0, uint64(56))
		(**(**TMem)(__ccgo_up(bp + 776))).Fdb = db
		/* Because P2 is always a static string, it is impossible for the
		 ** sqlite3VdbeMemCopy() to fail */
		rc = _sqlite3VdbeMemCopy(tls, bp+776, aMem+uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56)
		zTab = Xsqlite3_value_text(tls, bp+776)
		if zTab != 0 {
			rc = _sqlite3VtabCallCreate(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, zTab, p+168)
		}
		_sqlite3VdbeMemRelease(tls, bp+776)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: VDestroy P1 * * P4 *
		 **
		 ** P4 is the name of a virtual table in database P1.  Call the xDestroy method
		 ** of that table.
		 */
	_168:
		;
		(*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy = (*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy + 1
		rc = _sqlite3VtabCallDestroy(tls, db, (*TOp)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		(*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy = (*Tsqlite3)(unsafe.Pointer(db)).FnVDestroy - 1
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: VOpen P1 * * P4 *
		 **
		 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
		 ** P1 is a cursor number.  This opcode opens a cursor to the virtual
		 ** table and stores that cursor in P1.
		 */
	_169:
		;
		pCur3 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if pCur3 != uintptr(0) && libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pCur3)).FeCurType) == int32(CURTYPE_VTAB) && (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur3 + 48)))).FpVtab == (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab {
			/* This opcode is a no-op if the cursor is already open */
			goto _189
		}
		**(**uintptr)(__ccgo_up(bp + 832)) = uintptr(0)
		pVtab1 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
		if pVtab1 == uintptr(0) || (*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FpModule == uintptr(0) {
			rc = int32(SQLITE_LOCKED)
			goto abort_due_to_error
		}
		pModule1 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FpModule
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule1)).FxOpen})))(tls, pVtab1, bp+832)
		_sqlite3VtabImportErrmsg(tls, p, pVtab1)
		if rc != 0 {
			goto abort_due_to_error
		}
		/* Initialize sqlite3_vtab_cursor base class */
		(*Tsqlite3_vtab_cursor)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 832)))).FpVtab = pVtab1
		/* Initialize vdbe cursor object */
		pCur3 = _allocateCursor(tls, p, (*TOp)(unsafe.Pointer(pOp)).Fp1, 0, uint8(CURTYPE_VTAB))
		if pCur3 != 0 {
			*(*uintptr)(unsafe.Pointer(pCur3 + 48)) = **(**uintptr)(__ccgo_up(bp + 832))
			(*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FnRef = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab1)).FnRef + 1
		} else {
			(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule1)).FxClose})))(tls, **(**uintptr)(__ccgo_up(bp + 832)))
			goto no_mem
		}
		goto _189
		/* Opcode: VCheck P1 P2 P3 P4 *
		 **
		 ** P4 is a pointer to a Table object that is a virtual table in schema P1
		 ** that supports the xIntegrity() method.  This opcode runs the xIntegrity()
		 ** method for that virtual table, using P3 as the integer argument.  If
		 ** an error is reported back, the table name is prepended to the error
		 ** message and that message is stored in P2.  If no errors are seen,
		 ** register P2 is set to NULL.
		 */
	_170:
		;
		**(**uintptr)(__ccgo_up(bp + 840)) = uintptr(0)
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		_sqlite3VdbeMemSetNull(tls, pOut) /* Innocent until proven guilty */
		pTab3 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		if (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 64))).Fp == uintptr(0) {
			goto _189
		}
		pVtab2 = (*TVTable)(unsafe.Pointer((*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 64))).Fp)).FpVtab
		pModule2 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab2)).FpModule
		_sqlite3VtabLock(tls, (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 64))).Fp)
		rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule2)).FxIntegrity})))(tls, pVtab2, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32))).FzDbSName, (*TTable)(unsafe.Pointer(pTab3)).FzName, (*TOp)(unsafe.Pointer(pOp)).Fp3, bp+840)
		_sqlite3VtabUnlock(tls, (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(pTab3 + 64))).Fp)
		if rc != 0 {
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 840)))
			goto abort_due_to_error
		}
		if **(**uintptr)(__ccgo_up(bp + 840)) != 0 {
			_sqlite3VdbeMemSetStr(tls, pOut, **(**uintptr)(__ccgo_up(bp + 840)), int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
		}
		goto _189
		/* Opcode: VInitIn P1 P2 P3 * *
		 ** Synopsis: r[P2]=ValueList(P1,P3)
		 **
		 ** Set register P2 to be a pointer to a ValueList object for cursor P1
		 ** with cache register P3 and output register P3+1.  This ValueList object
		 ** can be used as the first argument to sqlite3_vtab_in_first() and
		 ** sqlite3_vtab_in_next() to extract all of the values stored in the P1
		 ** cursor.  Register P3 is used to hold the values returned by
		 ** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
		 */
	_171:
		; /* New ValueList object to put in reg[P2] */
		pC34 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pRhs = Xsqlite3_malloc64(tls, uint64(16))
		if pRhs == uintptr(0) {
			goto no_mem
		}
		(*TValueList)(unsafe.Pointer(pRhs)).FpCsr = *(*uintptr)(unsafe.Pointer(pC34 + 48))
		(*TValueList)(unsafe.Pointer(pRhs)).FpOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		pOut = _out2Prerelease(tls, p, pOp)
		(*TMem)(unsafe.Pointer(pOut)).Fflags = uint16(MEM_Null)
		_sqlite3VdbeMemSetPointer(tls, pOut, pRhs, __ccgo_ts+6475, __ccgo_fp(_sqlite3VdbeValueListFree))
		goto _189
		/* Opcode: VFilter P1 P2 P3 P4 *
		 ** Synopsis: iplan=r[P3] zplan='P4'
		 **
		 ** P1 is a cursor opened using VOpen.  P2 is an address to jump to if
		 ** the filtered result set is empty.
		 **
		 ** P4 is either NULL or a string that was generated by the xBestIndex
		 ** method of the module.  The interpretation of the P4 string is left
		 ** to the module implementation.
		 **
		 ** This opcode invokes the xFilter method on the virtual table specified
		 ** by P1.  The integer query plan parameter to xFilter is stored in register
		 ** P3. Register P3+1 stores the argc parameter to be passed to the
		 ** xFilter method. Registers P3+2..P3+1+argc are the argc
		 ** additional parameters which are passed to
		 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
		 **
		 ** A jump is made to P2 if the result set after filtering would be empty.
		 */
	_172:
		;
		pQuery = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		pArgc = pQuery + 1*56
		pCur4 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pVCur1 = *(*uintptr)(unsafe.Pointer(pCur4 + 48))
		pVtab3 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVCur1)).FpVtab
		pModule3 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab3)).FpModule
		/* Grab the index number and argc parameters */
		nArg = int32(*(*Ti64)(unsafe.Pointer(pArgc)))
		iQuery = int32(*(*Ti64)(unsafe.Pointer(pQuery)))
		/* Invoke the xFilter method */
		apArg = (*TVdbe)(unsafe.Pointer(p)).FapArg
		i6 = 0
		for {
			if !(i6 < nArg) {
				break
			}
			**(**uintptr)(__ccgo_up(apArg + uintptr(i6)*8)) = pArgc + uintptr(i6+int32(1))*56
			goto _291
		_291:
			;
			i6 = i6 + 1
		}
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule3)).FxFilter})))(tls, pVCur1, iQuery, *(*uintptr)(unsafe.Pointer(pOp + 16)), nArg, apArg)
		_sqlite3VtabImportErrmsg(tls, p, pVtab3)
		if rc != 0 {
			goto abort_due_to_error
		}
		res13 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule3)).FxEof})))(tls, pVCur1)
		(*TVdbeCursor)(unsafe.Pointer(pCur4)).FnullRow = uint8(0)
		if res13 != 0 {
			goto jump_to_p2
		}
		goto _189
		/* Opcode: VColumn P1 P2 P3 * P5
		 ** Synopsis: r[P3]=vcolumn(P2)
		 **
		 ** Store in register P3 the value of the P2-th column of
		 ** the current row of the virtual-table of cursor P1.
		 **
		 ** If the VColumn opcode is being used to fetch the value of
		 ** an unchanging column during an UPDATE operation, then the P5
		 ** value is OPFLAG_NOCHNG.  This will cause the sqlite3_vtab_nochange()
		 ** function to return true inside the xColumn method of the virtual
		 ** table implementation.  The P5 column might also contain other
		 ** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
		 ** unused by OP_VColumn.
		 */
	_173:
		;
		pCur5 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		pDest2 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if (*TVdbeCursor)(unsafe.Pointer(pCur5)).FnullRow != 0 {
			_sqlite3VdbeMemSetNull(tls, pDest2)
			goto _189
		}
		pVtab4 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur5 + 48)))).FpVtab
		pModule4 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab4)).FpModule
		libc.Xmemset(tls, bp+848, 0, uint64(48))
		(**(**Tsqlite3_context)(__ccgo_up(bp + 848))).FpOut = pDest2
		(**(**Tsqlite3_context)(__ccgo_up(bp + 848))).Fenc = encoding
		(**(**TFuncDef)(__ccgo_up(bp + 896))).FpUserData = uintptr(0)
		(**(**TFuncDef)(__ccgo_up(bp + 896))).FfuncFlags = uint32(SQLITE_RESULT_SUBTYPE)
		(**(**Tsqlite3_context)(__ccgo_up(bp + 848))).FpFunc = bp + 896
		if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)&int32(OPFLAG_NOCHNG) != 0 {
			_sqlite3VdbeMemSetNull(tls, pDest2)
			(*TMem)(unsafe.Pointer(pDest2)).Fflags = libc.Uint16FromInt32(libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Zero))
			*(*int32)(unsafe.Pointer(&(*TMem)(unsafe.Pointer(pDest2)).Fu)) = 0
		} else {
			(*TMem)(unsafe.Pointer(pDest2)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pDest2)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule4)).FxColumn})))(tls, *(*uintptr)(unsafe.Pointer(pCur5 + 48)), bp+848, (*TOp)(unsafe.Pointer(pOp)).Fp2)
		_sqlite3VtabImportErrmsg(tls, p, pVtab4)
		if (**(**Tsqlite3_context)(__ccgo_up(bp + 848))).FisError > 0 {
			_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, Xsqlite3_value_text(tls, pDest2)))
			rc = (**(**Tsqlite3_context)(__ccgo_up(bp + 848))).FisError
		}
		_sqlite3VdbeChangeEncoding(tls, pDest2, libc.Int32FromUint8(encoding))
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: VNext P1 P2 * * *
		 **
		 ** Advance virtual table P1 to the next row in its result set and
		 ** jump to instruction P2.  Or, if the virtual table has reached
		 ** the end of its result set, then fall through to the next instruction.
		 */
	_174:
		;
		pCur6 = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*8))
		if (*TVdbeCursor)(unsafe.Pointer(pCur6)).FnullRow != 0 {
			goto _189
		}
		pVtab5 = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur6 + 48)))).FpVtab
		pModule5 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab5)).FpModule
		/* Invoke the xNext() method of the module. There is no way for the
		 ** underlying implementation to return an error if one occurs during
		 ** xNext(). Instead, if an error occurs, true is returned (indicating that
		 ** data is available) and the error code returned when xColumn or
		 ** some other method is next invoked on the save virtual table cursor.
		 */
		rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule5)).FxNext})))(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 48)))
		_sqlite3VtabImportErrmsg(tls, p, pVtab5)
		if rc != 0 {
			goto abort_due_to_error
		}
		res14 = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule5)).FxEof})))(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 48)))
		if !(res14 != 0) {
			/* If there is data, jump to P2 */
			goto jump_to_p2_and_check_for_interrupt
		}
		goto check_for_interrupt
		/* Opcode: VRename P1 * * P4 *
		 **
		 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
		 ** This opcode invokes the corresponding xRename method. The value
		 ** in register P1 is passed as the zName argument to the xRename method.
		 */
	_175:
		;
		isLegacy = libc.Int32FromUint64((*Tsqlite3)(unsafe.Pointer(db)).Fflags & libc.Uint64FromInt32(SQLITE_LegacyAlter))
		**(**Tu64)(__ccgo_up(db + 48)) |= uint64(SQLITE_LegacyAlter)
		pVtab6 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
		pName = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		rc = _sqlite3VdbeChangeEncoding(tls, pName, int32(SQLITE_UTF8))
		if rc != 0 {
			goto abort_due_to_error
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVtab6)).FpModule)).FxRename})))(tls, pVtab6, (*TMem)(unsafe.Pointer(pName)).Fz)
		if isLegacy == 0 {
			**(**Tu64)(__ccgo_up(db + 48)) &= ^libc.Uint64FromInt32(SQLITE_LegacyAlter)
		}
		_sqlite3VtabImportErrmsg(tls, p, pVtab6)
		libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 14, 0xc000)
		if rc != 0 {
			goto abort_due_to_error
		}
		goto _189
		/* Opcode: VUpdate P1 P2 P3 P4 P5
		 ** Synopsis: data=r[P3@P2]
		 **
		 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
		 ** This opcode invokes the corresponding xUpdate method. P2 values
		 ** are contiguous memory cells starting at P3 to pass to the xUpdate
		 ** invocation. The value in register (P3+P2-1) corresponds to the
		 ** p2th element of the argv array passed to xUpdate.
		 **
		 ** The xUpdate method will do a DELETE or an INSERT or both.
		 ** The argv[0] element (which corresponds to memory cell P3)
		 ** is the rowid of a row to delete.  If argv[0] is NULL then no
		 ** deletion occurs.  The argv[1] element is the rowid of the new
		 ** row.  This can be NULL to have the virtual table select the new
		 ** rowid for itself.  The subsequent elements in the array are
		 ** the values of columns in the new row.
		 **
		 ** If P2==1 then no insert is performed.  argv[0] is the rowid of
		 ** a row to delete.
		 **
		 ** P1 is a boolean flag. If it is set to true and the xUpdate call
		 ** is successful, then the value returned by sqlite3_last_insert_rowid()
		 ** is set to the value of the rowid for the row just inserted.
		 **
		 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
		 ** apply in the case of a constraint failure on an insert or update.
		 */
	_176:
		;
		**(**Tsqlite_int64)(__ccgo_up(bp + 968)) = 0
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto no_mem
		}
		pVtab7 = (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
		if pVtab7 == uintptr(0) || (*Tsqlite3_vtab)(unsafe.Pointer(pVtab7)).FpModule == uintptr(0) {
			rc = int32(SQLITE_LOCKED)
			goto abort_due_to_error
		}
		pModule6 = (*Tsqlite3_vtab)(unsafe.Pointer(pVtab7)).FpModule
		nArg1 = (*TOp)(unsafe.Pointer(pOp)).Fp2
		if (*Tsqlite3_module)(unsafe.Pointer(pModule6)).FxUpdate != 0 {
			vtabOnConflict = (*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict
			apArg1 = (*TVdbe)(unsafe.Pointer(p)).FapArg
			pX1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
			i7 = 0
			for {
				if !(i7 < nArg1) {
					break
				}
				**(**uintptr)(__ccgo_up(apArg1 + uintptr(i7)*8)) = pX1
				pX1 += 56
				goto _292
			_292:
				;
				i7 = i7 + 1
			}
			(*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict = uint8((*TOp)(unsafe.Pointer(pOp)).Fp5)
			rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule6)).FxUpdate})))(tls, pVtab7, nArg1, apArg1, bp+968)
			(*Tsqlite3)(unsafe.Pointer(db)).FvtabOnConflict = vtabOnConflict
			_sqlite3VtabImportErrmsg(tls, p, pVtab7)
			if rc == SQLITE_OK && (*TOp)(unsafe.Pointer(pOp)).Fp1 != 0 {
				(*Tsqlite3)(unsafe.Pointer(db)).FlastRowid = **(**Tsqlite_int64)(__ccgo_up(bp + 968))
			}
			if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) && (*TVTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FbConstraint != 0 {
				if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) == int32(OE_Ignore) {
					rc = SQLITE_OK
				} else {
					if libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5) == int32(OE_Replace) {
						v190 = int32(OE_Abort)
					} else {
						v190 = libc.Int32FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5)
					}
					(*TVdbe)(unsafe.Pointer(p)).FerrorAction = libc.Uint8FromInt32(v190)
				}
			} else {
				(*TVdbe)(unsafe.Pointer(p)).FnChange = (*TVdbe)(unsafe.Pointer(p)).FnChange + 1
			}
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode: Pagecount P1 P2 * * *
		 **
		 ** Write the current number of pages in database P1 to memory cell P2.
		 */
	_177:
		; /* out2 */
		pOut = _out2Prerelease(tls, p, pOp)
		*(*Ti64)(unsafe.Pointer(pOut)) = libc.Int64FromUint32(_sqlite3BtreeLastPage(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32))).FpBt))
		goto _189
		/* Opcode: MaxPgcnt P1 P2 P3 * *
		 **
		 ** Try to set the maximum page count for database P1 to the value in P3.
		 ** Do not let the maximum page count fall below the current page count and
		 ** do not change the maximum page count value if P3==0.
		 **
		 ** Store the maximum page count after the change in register P2.
		 */
	_178:
		;
		pOut = _out2Prerelease(tls, p, pOp)
		pBt3 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*32))).FpBt
		newMax = uint32(0)
		if (*TOp)(unsafe.Pointer(pOp)).Fp3 != 0 {
			newMax = _sqlite3BtreeLastPage(tls, pBt3)
			if newMax < libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3) {
				newMax = libc.Uint32FromInt32((*TOp)(unsafe.Pointer(pOp)).Fp3)
			}
		}
		*(*Ti64)(unsafe.Pointer(pOut)) = libc.Int64FromUint32(_sqlite3BtreeMaxPageCount(tls, pBt3, newMax))
		goto _189
		/* Opcode: Function P1 P2 P3 P4 *
		 ** Synopsis: r[P3]=func(r[P2@NP])
		 **
		 ** Invoke a user function (P4 is a pointer to an sqlite3_context object that
		 ** contains a pointer to the function to be run) with arguments taken
		 ** from register P2 and successors.  The number of arguments is in
		 ** the sqlite3_context object that P4 points to.
		 ** The result of the function is stored
		 ** in register P3.  Register P3 must not be one of the function inputs.
		 **
		 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
		 ** function was determined to be constant at compile time. If the first
		 ** argument was constant then bit 0 of P1 is set. This is used to determine
		 ** whether meta data associated with a user function argument using the
		 ** sqlite3_set_auxdata() API may be safely retained until the next
		 ** invocation of this opcode.
		 **
		 ** See also: AggStep, AggFinal, PureFunc
		 */
		/* Opcode: PureFunc P1 P2 P3 P4 *
		 ** Synopsis: r[P3]=func(r[P2@NP])
		 **
		 ** Invoke a user function (P4 is a pointer to an sqlite3_context object that
		 ** contains a pointer to the function to be run) with arguments taken
		 ** from register P2 and successors.  The number of arguments is in
		 ** the sqlite3_context object that P4 points to.
		 ** The result of the function is stored
		 ** in register P3.  Register P3 must not be one of the function inputs.
		 **
		 ** P1 is a 32-bit bitmask indicating whether or not each argument to the
		 ** function was determined to be constant at compile time. If the first
		 ** argument was constant then bit 0 of P1 is set. This is used to determine
		 ** whether meta data associated with a user function argument using the
		 ** sqlite3_set_auxdata() API may be safely retained until the next
		 ** invocation of this opcode.
		 **
		 ** This opcode works exactly like OP_Function.  The only difference is in
		 ** its name.  This opcode is used in places where the function must be
		 ** purely non-deterministic.  Some built-in date/time functions can be
		 ** either deterministic of non-deterministic, depending on their arguments.
		 ** When those function are used in a non-deterministic way, they will check
		 ** to see if they were called using OP_PureFunc instead of OP_Function, and
		 ** if they were, they throw an error.
		 **
		 ** See also: AggStep, AggFinal, Function
		 */
	_180:
		; /* group */
	_179:
		;
		pCtx2 = *(*uintptr)(unsafe.Pointer(pOp + 16))
		/* If this function is inside of a trigger, the register array in aMem[]
		 ** might change from one evaluation to the next.  The next block of code
		 ** checks to see if the register array has changed, and if so it
		 ** reinitializes the relevant parts of the sqlite3_context object */
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp3)*56
		if (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpOut != pOut {
			(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpVdbe = p
			(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpOut = pOut
			(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fenc = encoding
			i8 = libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fargc) - int32(1)
			for {
				if !(i8 >= 0) {
					break
				}
				*(*uintptr)(unsafe.Pointer(pCtx2 + 48 + uintptr(i8)*8)) = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2+i8)*56
				goto _294
			_294:
				;
				i8 = i8 - 1
			}
		}
		(*TMem)(unsafe.Pointer(pOut)).Fflags = libc.Uint16FromInt32(libc.Int32FromUint16((*TMem)(unsafe.Pointer(pOut)).Fflags) & ^(libc.Int32FromInt32(MEM_TypeMask)|libc.Int32FromInt32(MEM_Zero)) | int32(MEM_Null))
		(*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FpFunc)).FxSFunc})))(tls, pCtx2, libc.Int32FromUint16((*Tsqlite3_context)(unsafe.Pointer(pCtx2)).Fargc), pCtx2+48) /* IMP: R-24505-23230 */
		/* If the function returned an error, throw an exception */
		if (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError != 0 {
			if (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError > 0 {
				_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, Xsqlite3_value_text(tls, pOut)))
				rc = (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError
			}
			_sqlite3VdbeDeleteAuxData(tls, db, p+296, (*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FiOp, (*TOp)(unsafe.Pointer(pOp)).Fp1)
			(*Tsqlite3_context)(unsafe.Pointer(pCtx2)).FisError = 0
			if rc != 0 {
				goto abort_due_to_error
			}
		}
		goto _189
		/* Opcode: ClrSubtype P1 * * * *
		 ** Synopsis:  r[P1].subtype = 0
		 **
		 ** Clear the subtype from register P1.
		 */
	_181:
		; /* in1 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		v191 = pIn1 + 20
		*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Subtype))
		goto _189
		/* Opcode: GetSubtype P1 P2 * * *
		 ** Synopsis:  r[P2] = r[P1].subtype
		 **
		 ** Extract the subtype value from register P1 and write that subtype
		 ** into register P2.  If P1 has no subtype, then P1 gets a NULL.
		 */
	_182:
		; /* in1 out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Subtype) != 0 {
			_sqlite3VdbeMemSetInt64(tls, pOut, libc.Int64FromUint8((*TMem)(unsafe.Pointer(pIn1)).FeSubtype))
		} else {
			_sqlite3VdbeMemSetNull(tls, pOut)
		}
		goto _189
		/* Opcode: SetSubtype P1 P2 * * *
		 ** Synopsis:  r[P2].subtype = r[P1]
		 **
		 ** Set the subtype value of register P2 to the integer from register P1.
		 ** If P1 is NULL, clear the subtype from p2.
		 */
	_183:
		; /* in1 out2 */
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		pOut = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp2)*56
		if libc.Int32FromUint16((*TMem)(unsafe.Pointer(pIn1)).Fflags)&int32(MEM_Null) != 0 {
			v191 = pOut + 20
			*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) & ^libc.Int32FromInt32(MEM_Subtype))
		} else {
			v191 = pOut + 20
			*(*Tu16)(unsafe.Pointer(v191)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v191))) | libc.Int32FromInt32(MEM_Subtype))
			(*TMem)(unsafe.Pointer(pOut)).FeSubtype = libc.Uint8FromInt64(*(*Ti64)(unsafe.Pointer(pIn1)) & libc.Int64FromInt32(0xff))
		}
		goto _189
		/* Opcode: FilterAdd P1 * P3 P4 *
		 ** Synopsis: filter(P1) += key(P3@P4)
		 **
		 ** Compute a hash on the P4 registers starting with r[P3] and
		 ** add that hash to the bloom filter contained in r[P1].
		 */
	_184:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		h = _filterHash(tls, aMem, pOp)
		h = h % libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pIn1)).Fn*libc.Int32FromInt32(8))
		v191 = (*TMem)(unsafe.Pointer(pIn1)).Fz + uintptr(h/uint64(8))
		*(*uint8)(unsafe.Pointer(v191)) = uint8(int32(*(*uint8)(unsafe.Pointer(v191))) | libc.Int32FromInt32(1)<<(h&libc.Uint64FromInt32(7)))
		goto _189
		/* Opcode: Filter P1 P2 P3 P4 *
		 ** Synopsis: if key(P3@P4) not in filter(P1) goto P2
		 **
		 ** Compute a hash on the key contained in the P4 registers starting
		 ** with r[P3].  Check to see if that hash is found in the
		 ** bloom filter hosted by register P1.  If it is not present then
		 ** maybe jump to P2.  Otherwise fall through.
		 **
		 ** False negatives are harmless.  It is always safe to fall through,
		 ** even if the value is in the bloom filter.  A false negative causes
		 ** more CPU cycles to be used, but it should still yield the correct
		 ** answer.  However, an incorrect answer may well arise from a
		 ** false positive - if the jump is taken when it should fall through.
		 */
	_185:
		;
		pIn1 = aMem + uintptr((*TOp)(unsafe.Pointer(pOp)).Fp1)*56
		h1 = _filterHash(tls, aMem, pOp)
		h1 = h1 % libc.Uint64FromInt32((*TMem)(unsafe.Pointer(pIn1)).Fn*libc.Int32FromInt32(8))
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up((*TMem)(unsafe.Pointer(pIn1)).Fz + uintptr(h1/uint64(8)))))&(int32(1)<<(h1&uint64(7))) == 0 {
			**(**Tu32)(__ccgo_up(p + 212 + 8*4)) = **(**Tu32)(__ccgo_up(p + 212 + 8*4)) + 1
			goto jump_to_p2
		} else {
			**(**Tu32)(__ccgo_up(p + 212 + 7*4)) = **(**Tu32)(__ccgo_up(p + 212 + 7*4)) + 1
		}
		goto _189
		/* Opcode: Trace P1 P2 * P4 *
		 **
		 ** Write P4 on the statement trace output if statement tracing is
		 ** enabled.
		 **
		 ** Operand P1 must be 0x7fffffff and P2 must positive.
		 */
		/* Opcode: Init P1 P2 P3 P4 *
		 ** Synopsis: Start at P2
		 **
		 ** Programs contain a single instance of this opcode as the very first
		 ** opcode.
		 **
		 ** If tracing is enabled (by the sqlite3_trace()) interface, then
		 ** the UTF-8 string contained in P4 is emitted on the trace callback.
		 ** Or if P4 is blank, use the string returned by sqlite3_sql().
		 **
		 ** If P2 is not zero, jump to instruction P2.
		 **
		 ** Increment the value of P1 so that OP_Once opcodes will jump the
		 ** first time they are evaluated for this run.
		 **
		 ** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
		 ** error is encountered.
		 */
	_187:
		;
	_186:
		;
		/* If the P4 argument is not NULL, then it must be an SQL comment string.
		 ** The "--" string is broken up to prevent false-positives with srcck1.c.
		 **
		 ** This assert() provides evidence for:
		 ** EVIDENCE-OF: R-50676-09860 The callback can compute the same text that
		 ** would have been returned by the legacy sqlite3_trace() interface by
		 ** using the X argument when X begins with "--" and invoking
		 ** sqlite3_expanded_sql(P) otherwise.
		 */
		/* OP_Init is always instruction 0 */
		if v217 = libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&(libc.Int32FromInt32(SQLITE_TRACE_STMT)|libc.Int32FromInt32(SQLITE_TRACE_LEGACY)) != 0 && libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FminWriteFileFormat) != int32(254); v217 {
			if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
				v194 = *(*uintptr)(unsafe.Pointer(pOp + 16))
			} else {
				v194 = (*TVdbe)(unsafe.Pointer(p)).FzSql
			}
			v191 = v194
			zTrace = v191
		}
		if v217 && v191 != uintptr(0) {
			if libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FmTrace)&int32(SQLITE_TRACE_LEGACY) != 0 {
				z2 = _sqlite3VdbeExpandSql(tls, p, zTrace)
				(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).Ftrace.FxLegacy})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, z2)
				Xsqlite3_free(tls, z2)
			} else {
				if (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeExec > int32(1) {
					z3 = _sqlite3MPrintf(tls, db, __ccgo_ts+6485, libc.VaList(bp+984, zTrace))
					(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_STMT), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, z3)
					_sqlite3DbFree(tls, db, z3)
				} else {
					(*(*func(*libc.TLS, Tu32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(&(*Tsqlite3)(unsafe.Pointer(db)).Ftrace))})))(tls, uint32(SQLITE_TRACE_STMT), (*Tsqlite3)(unsafe.Pointer(db)).FpTraceArg, p, zTrace)
				}
			}
		}
		if (*TOp)(unsafe.Pointer(pOp)).Fp1 >= _sqlite3Config.FiOnceResetThreshold {
			if libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Trace) {
				goto _189
			}
			i9 = int32(1)
			for {
				if !(i9 < (*TVdbe)(unsafe.Pointer(p)).FnOp) {
					break
				}
				if libc.Int32FromUint8((**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i9)*24))).Fopcode) == int32(OP_Once) {
					(**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(i9)*24))).Fp1 = 0
				}
				goto _302
			_302:
				;
				i9 = i9 + 1
			}
			(*TOp)(unsafe.Pointer(pOp)).Fp1 = 0
		}
		(*TOp)(unsafe.Pointer(pOp)).Fp1 = (*TOp)(unsafe.Pointer(pOp)).Fp1 + 1
		**(**Tu32)(__ccgo_up(p + 212 + 6*4)) = **(**Tu32)(__ccgo_up(p + 212 + 6*4)) + 1
		goto jump_to_p2
		/* Opcode: Noop * * * * *
		 **
		 ** Do nothing.  Continue downward to the next opcode.
		 */
		/* Opcode: Explain P1 P2 P3 P4 *
		 **
		 ** This is the same as OP_Noop during normal query execution.  The
		 ** purpose of this opcode is to hold information about the query
		 ** plan for the purpose of EXPLAIN QUERY PLAN output.
		 **
		 ** The P4 value is human-readable text that describes the query plan
		 ** element.  Something like "SCAN t1" or "SEARCH t2 USING INDEX t2x1".
		 **
		 ** The P1 value is the ID of the current element and P2 is the parent
		 ** element for the case of nested query plan elements.  If P2 is zero
		 ** then this element is a top-level element.
		 **
		 ** For loop elements, P3 is the estimated code of each invocation of this
		 ** element.
		 **
		 ** As with all opcodes, the meanings of the parameters for OP_Explain
		 ** are subject to change from one release to the next.  Applications
		 ** should not attempt to interpret or use any of the information
		 ** contained in the OP_Explain opcode.  The information provided by this
		 ** opcode is intended for testing and debugging use only.
		 */
	_188:
		; /* This is really OP_Noop, OP_Explain */
		goto _189
		/*****************************************************************************
		 ** The cases of the switch statement above this line should all be indented
		 ** by 6 spaces.  But the left-most 6 spaces have been removed to improve the
		 ** readability.  From this point on down, the normal indentation rules are
		 ** restored.
		 *****************************************************************************/
	_189:
		;
		/* The following code adds nothing to the actual functionality
		 ** of the program.  It is only here for testing and debugging.
		 ** On the other hand, it does burn CPU cycles every time through
		 ** the evaluator loop.  So we can leave it out when NDEBUG is defined.
		 */
		goto _1
	_1:
		;
		pOp += 24
	} /* The end of the for(;;) loop the loops through opcodes */
	/* If we reach this point, it means that execution is finished with
	 ** an error of some kind.
	 */
	goto abort_due_to_error
abort_due_to_error:
	;
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = int32(SQLITE_NOMEM)
	} else {
		if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(33)<<libc.Int32FromInt32(8) {
			rc = _sqlite3CorruptError(tls, int32(105898))
		}
	}
	if (*TVdbe)(unsafe.Pointer(p)).FzErrMsg == uintptr(0) && rc != libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
		_sqlite3VdbeError(tls, p, __ccgo_ts+3944, libc.VaList(bp+984, _sqlite3ErrStr(tls, rc)))
	}
	(*TVdbe)(unsafe.Pointer(p)).Frc = rc
	_sqlite3SystemError(tls, db, rc)
	_sqlite3VdbeLogAbort(tls, p, rc, pOp, aOp)
	if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) == int32(VDBE_RUN_STATE) {
		_sqlite3VdbeHalt(tls, p)
	}
	if rc == libc.Int32FromInt32(SQLITE_IOERR)|libc.Int32FromInt32(12)<<libc.Int32FromInt32(8) {
		_sqlite3OomFault(tls, db)
	}
	if rc == int32(SQLITE_CORRUPT) && libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 {
		**(**Tu64)(__ccgo_up(db + 48)) |= libc.Uint64FromInt32(libc.Int32FromInt32(0x00002)) << libc.Int32FromInt32(32)
	}
	rc = int32(SQLITE_ERROR)
	if libc.Int32FromUint8(resetSchemaOnFault) > 0 {
		_sqlite3ResetOneSchema(tls, db, libc.Int32FromUint8(resetSchemaOnFault)-int32(1))
	}
	/* This is the only way out of this procedure.  We have to
	 ** release the mutexes on btrees that were acquired at the
	 ** top. */
	goto vdbe_return
vdbe_return:
	;
	for nVmStep >= nProgressLimit && (*Tsqlite3)(unsafe.Pointer(db)).FxProgress != uintptr(0) {
		nProgressLimit = nProgressLimit + uint64((*Tsqlite3)(unsafe.Pointer(db)).FnProgressOps)
		if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxProgress})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
			nProgressLimit = libc.Uint64FromUint32(0xffffffff) | libc.Uint64FromUint32(0xffffffff)<<libc.Int32FromInt32(32)
			rc = int32(SQLITE_INTERRUPT)
			goto abort_due_to_error
		}
	}
	**(**Tu32)(__ccgo_up(p + 212 + 4*4)) += libc.Uint32FromInt32(libc.Int32FromUint64(nVmStep))
	if (*TVdbe)(unsafe.Pointer(p)).FlockMask != uint32(0) {
		_sqlite3VdbeLeave(tls, p)
	}
	return rc
	/* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
	 ** is encountered.
	 */
	goto too_big
too_big:
	;
	_sqlite3VdbeError(tls, p, __ccgo_ts+5594, 0)
	rc = int32(SQLITE_TOOBIG)
	goto abort_due_to_error
	/* Jump to here if a malloc() fails.
	 */
	goto no_mem
no_mem:
	;
	_sqlite3OomFault(tls, db)
	_sqlite3VdbeError(tls, p, __ccgo_ts+1674, 0)
	rc = int32(SQLITE_NOMEM)
	goto abort_due_to_error
	/* Jump to here if the sqlite3_interrupt() API sets the interrupt
	 ** flag.
	 */
	goto abort_due_to_interrupt
abort_due_to_interrupt:
	;
	rc = int32(SQLITE_INTERRUPT)
	goto abort_due_to_error
	return r
}

func _sqlite3VdbeFreeCursorNN(tls *libc.TLS, p uintptr, pCx uintptr) {
	var pModule, pVCur uintptr
	_, _ = pModule, pVCur
	if int32(TBool(*(*uint8)(unsafe.Pointer(pCx + 8))&0x8>>3)) != 0 {
		_freeCursorWithCache(tls, p, pCx)
		return
	}
	switch libc.Int32FromUint8((*TVdbeCursor)(unsafe.Pointer(pCx)).FeCurType) {
	case int32(CURTYPE_SORTER):
		_sqlite3VdbeSorterClose(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, pCx)
	case CURTYPE_BTREE:
		_sqlite3BtreeCloseCursor(tls, *(*uintptr)(unsafe.Pointer(pCx + 48)))
	case int32(CURTYPE_VTAB):
		pVCur = *(*uintptr)(unsafe.Pointer(pCx + 48))
		pModule = (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVCur)).FpVtab)).FpModule
		(*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVCur)).FpVtab)).FnRef = (*Tsqlite3_vtab)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVCur)).FpVtab)).FnRef - 1
		(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxClose})))(tls, pVCur)
		break
	}
}

// C documentation
//
//	/*
//	** This routine is called the when a VDBE tries to halt.  If the VDBE
//	** has made changes and is in autocommit mode, then commit those
//	** changes.  If a rollback is needed, then do the rollback.
//	**
//	** This routine is the only way to move the sqlite3eOpenState of a VM from
//	** SQLITE_STATE_RUN to SQLITE_STATE_HALT.  It is harmless to
//	** call this on a VM that is in the SQLITE_STATE_HALT state.
//	**
//	** Return an error code.  If the commit could not complete because of
//	** lock contention, return SQLITE_BUSY.  If SQLITE_BUSY is returned, it
//	** means the close did not happen and needs to be repeated.
//	*/
func _sqlite3VdbeHalt(tls *libc.TLS, p uintptr) (r int32) {
	var db uintptr
	var eStatementOp, isSpecialError, mrc, rc, v1 int32
	_, _, _, _, _, _ = db, eStatementOp, isSpecialError, mrc, rc, v1 /* Used to store transient return codes */
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	/* This function contains the logic that determines if a statement or
	 ** transaction will be committed or rolled back as a result of the
	 ** execution of this virtual machine.
	 **
	 ** If any of the following errors occur:
	 **
	 **     SQLITE_NOMEM
	 **     SQLITE_IOERR
	 **     SQLITE_FULL
	 **     SQLITE_INTERRUPT
	 **
	 ** Then the internal cache might have been left in an inconsistent
	 ** state.  We need to rollback the statement transaction, if there is
	 ** one, or the complete transaction if there is no statement transaction.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
	}
	_closeAllCursors(tls, p)
	/* No commit or rollback needed if the program never started or if the
	 ** SQL statement does not read or write a database file.  */
	if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x100>>8)) != 0 { /* Primary error code from p->rc */
		eStatementOp = 0 /* Set to true if a 'special' error */
		/* Lock all btrees used by the statement */
		_sqlite3VdbeEnter(tls, p)
		/* Check for one of the special errors */
		if (*TVdbe)(unsafe.Pointer(p)).Frc != 0 {
			mrc = (*TVdbe)(unsafe.Pointer(p)).Frc & int32(0xff)
			isSpecialError = libc.BoolInt32(mrc == int32(SQLITE_NOMEM) || mrc == int32(SQLITE_IOERR) || mrc == int32(SQLITE_INTERRUPT) || mrc == int32(SQLITE_FULL))
		} else {
			v1 = libc.Int32FromInt32(0)
			isSpecialError = v1
			mrc = v1
		}
		if isSpecialError != 0 {
			/* If the query was read-only and the error code is SQLITE_INTERRUPT,
			 ** no rollback is necessary. Otherwise, at least a savepoint
			 ** transaction must be rolled back to restore the database to a
			 ** consistent state.
			 **
			 ** Even if the statement is read-only, it is important to perform
			 ** a statement or transaction rollback operation. If the error
			 ** occurred while writing to the journal, sub-journal or database
			 ** file as part of an effort to free up cache space (see function
			 ** pagerStress() in pager.c), the rollback is required to restore
			 ** the pager to a consistent state.
			 */
			if !(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x200>>9)) != 0) || mrc != int32(SQLITE_INTERRUPT) {
				if (mrc == int32(SQLITE_NOMEM) || mrc == int32(SQLITE_FULL)) && int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x400>>10)) != 0 {
					eStatementOp = int32(SAVEPOINT_ROLLBACK)
				} else {
					/* We are forced to roll back the active transaction. Before doing
					 ** so, abort any other statements this handle currently has active.
					 */
					_sqlite3RollbackAll(tls, db, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8))
					_sqlite3CloseSavepoints(tls, db)
					(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
					(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
				}
			}
		}
		/* Check for immediate foreign key violations. */
		if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Fail) && !(isSpecialError != 0) {
			_sqlite3VdbeCheckFkImmediate(tls, p)
		}
		/* If the auto-commit flag is set and this is the only active writer
		 ** VM, then we do either a commit or rollback of the current transaction.
		 **
		 ** Note: This block also runs if one of the special errors handled
		 ** above has occurred.
		 */
		if !((*Tsqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0)) && (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite == libc.BoolInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x200>>9)) == 0) {
			if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Fail) && !(isSpecialError != 0) {
				rc = _sqlite3VdbeCheckFkDeferred(tls, p)
				if rc != SQLITE_OK {
					if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x200>>9)) != 0 {
						_sqlite3VdbeLeave(tls, p)
						return int32(SQLITE_ERROR)
					}
					rc = libc.Int32FromInt32(SQLITE_CONSTRAINT) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
				} else {
					if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00002))<<libc.Int32FromInt32(32)) != 0 {
						rc = int32(SQLITE_CORRUPT)
						**(**Tu64)(__ccgo_up(db + 48)) &= ^(libc.Uint64FromInt32(libc.Int32FromInt32(0x00002)) << libc.Int32FromInt32(32))
					} else {
						/* The auto-commit flag is true, the vdbe program was successful
						 ** or hit an 'OR FAIL' constraint and there are no deferred foreign
						 ** key constraints to hold up the transaction. This means a commit
						 ** is required. */
						rc = _vdbeCommit(tls, db, p)
					}
				}
				if rc == int32(SQLITE_BUSY) && int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x200>>9)) != 0 {
					_sqlite3VdbeLeave(tls, p)
					return int32(SQLITE_BUSY)
				} else {
					if rc != SQLITE_OK {
						_sqlite3SystemError(tls, db, rc)
						(*TVdbe)(unsafe.Pointer(p)).Frc = rc
						_sqlite3RollbackAll(tls, db, SQLITE_OK)
						(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
					} else {
						(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = 0
						(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = 0
						**(**Tu64)(__ccgo_up(db + 48)) &= ^libc.Uint64FromInt32(SQLITE_DeferFKs)
						_sqlite3CommitInternalChanges(tls, db)
					}
				}
			} else {
				if (*TVdbe)(unsafe.Pointer(p)).Frc == int32(SQLITE_SCHEMA) && (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive > int32(1) {
					(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
				} else {
					_sqlite3RollbackAll(tls, db, SQLITE_OK)
					(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
				}
			}
			(*Tsqlite3)(unsafe.Pointer(db)).FnStatement = 0
		} else {
			if eStatementOp == 0 {
				if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Fail) {
					eStatementOp = int32(SAVEPOINT_RELEASE)
				} else {
					if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FerrorAction) == int32(OE_Abort) {
						eStatementOp = int32(SAVEPOINT_ROLLBACK)
					} else {
						_sqlite3RollbackAll(tls, db, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8))
						_sqlite3CloseSavepoints(tls, db)
						(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
						(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
					}
				}
			}
		}
		/* If eStatementOp is non-zero, then a statement transaction needs to
		 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
		 ** do so. If this operation returns an error, and the current statement
		 ** error code is SQLITE_OK or SQLITE_CONSTRAINT, then promote the
		 ** current statement error code.
		 */
		if eStatementOp != 0 {
			rc = _sqlite3VdbeCloseStatement(tls, p, eStatementOp)
			if rc != 0 {
				if (*TVdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || (*TVdbe)(unsafe.Pointer(p)).Frc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
					(*TVdbe)(unsafe.Pointer(p)).Frc = rc
					_sqlite3DbFree(tls, db, (*TVdbe)(unsafe.Pointer(p)).FzErrMsg)
					(*TVdbe)(unsafe.Pointer(p)).FzErrMsg = uintptr(0)
				}
				_sqlite3RollbackAll(tls, db, libc.Int32FromInt32(SQLITE_ABORT)|libc.Int32FromInt32(2)<<libc.Int32FromInt32(8))
				_sqlite3CloseSavepoints(tls, db)
				(*Tsqlite3)(unsafe.Pointer(db)).FautoCommit = uint8(1)
				(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
			}
		}
		/* If this was an INSERT, UPDATE or DELETE and no statement transaction
		 ** has been rolled back, update the database connection change-counter.
		 */
		if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x800>>11)) != 0 {
			if eStatementOp != int32(SAVEPOINT_ROLLBACK) {
				_sqlite3VdbeSetChanges(tls, db, (*TVdbe)(unsafe.Pointer(p)).FnChange)
			} else {
				_sqlite3VdbeSetChanges(tls, db, 0)
			}
			(*TVdbe)(unsafe.Pointer(p)).FnChange = 0
		}
		/* Release the locks */
		_sqlite3VdbeLeave(tls, p)
	}
	/* We have successfully halted and closed the VM.  Record this fact. */
	(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeActive - 1
	if !(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x200>>9)) != 0) {
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeWrite - 1
	}
	if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x100>>8)) != 0 {
		(*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead = (*Tsqlite3)(unsafe.Pointer(db)).FnVdbeRead - 1
	}
	(*TVdbe)(unsafe.Pointer(p)).FeVdbeState = uint8(VDBE_HALT_STATE)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
	}
	/* If the auto-commit flag is set to true, then any locks that were held
	 ** by connection db have now been released. Call sqlite3ConnectionUnlocked()
	 ** to invoke any required unlock-notify callbacks.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
		_sqlite3ConnectionUnlocked(tls, db)
	}
	if (*TVdbe)(unsafe.Pointer(p)).Frc == int32(SQLITE_BUSY) {
		v1 = int32(SQLITE_BUSY)
	} else {
		v1 = SQLITE_OK
	}
	return v1
}

// C documentation
//
//	/*
//	** Give a listing of the program in the virtual machine.
//	**
//	** The interface is the same as sqlite3VdbeExec().  But instead of
//	** running the code, it invokes the callback once for each instruction.
//	** This feature is used to implement "EXPLAIN".
//	**
//	** When p->explain==1, each instruction is listed.  When
//	** p->explain==2, only OP_Explain instructions are listed and these
//	** are shown in a different format.  p->explain==2 is used to implement
//	** EXPLAIN QUERY PLAN.
//	** 2018-04-24:  In p->explain==2 mode, the OP_Init opcodes of triggers
//	** are also shown, so that the boundaries between the main program and
//	** each trigger are clear.
//	**
//	** When p->explain==1, first the main program is listed, then each of
//	** the trigger subprograms are listed one by one.
//	*/
func _sqlite3VdbeList(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bListSubprogs, rc int32
	var db, pMem, pOp, pSub, zP4 uintptr
	var _ /* aOp at bp+8 */ uintptr
	var _ /* i at bp+0 */ int32
	_, _, _, _, _, _, _ = bListSubprogs, db, pMem, pOp, pSub, rc, zP4
	pSub = uintptr(0)                                                                                                                                                                        /* Memory cell hold array of subprogs */
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb                                                                                                                                                     /* Loop counter */
	rc = SQLITE_OK                                                                                                                                                                           /* Return code */
	pMem = (*TVdbe)(unsafe.Pointer(p)).FaMem + 1*56                                                                                                                                          /* First Mem of result set */
	bListSubprogs = libc.BoolInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)) == int32(1) || (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TriggerEQP) != uint64(0)) /* Current opcode */
	/* Even though this opcode does not use dynamic strings for
	 ** the result, result columns may become dynamic if the user calls
	 ** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
	 */
	_releaseMemArray(tls, pMem, int32(8))
	if (*TVdbe)(unsafe.Pointer(p)).Frc == int32(SQLITE_NOMEM) {
		/* This happens if a malloc() inside a call to sqlite3_column_text() or
		 ** sqlite3_column_text16() failed.  */
		_sqlite3OomFault(tls, db)
		return int32(SQLITE_ERROR)
	}
	if bListSubprogs != 0 {
		/* The first 8 memory cells are used for the result set.  So we will
		 ** commandeer the 9th cell to use as storage for an array of pointers
		 ** to trigger subprograms.  The VDBE is guaranteed to have at least 9
		 ** cells.  */
		pSub = (*TVdbe)(unsafe.Pointer(p)).FaMem + 9*56
	} else {
		pSub = uintptr(0)
	}
	/* Figure out which opcode is next to display */
	rc = _sqlite3VdbeNextOpcode(tls, p, pSub, libc.BoolInt32(int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)) == int32(2)), p+48, bp, bp+8)
	if rc == SQLITE_OK {
		pOp = **(**uintptr)(__ccgo_up(bp + 8)) + uintptr(**(**int32)(__ccgo_up(bp)))*24
		if libc.AtomicLoadNInt32(db+432, libc.Int32FromInt32(__ATOMIC_RELAXED)) != 0 {
			(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_INTERRUPT)
			rc = int32(SQLITE_ERROR)
			_sqlite3VdbeError(tls, p, _sqlite3ErrStr(tls, (*TVdbe)(unsafe.Pointer(p)).Frc), 0)
		} else {
			zP4 = _sqlite3VdbeDisplayP4(tls, db, pOp)
			if int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)) == int32(2) {
				_sqlite3VdbeMemSetInt64(tls, pMem, int64((*TOp)(unsafe.Pointer(pOp)).Fp1))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(1)*56, int64((*TOp)(unsafe.Pointer(pOp)).Fp2))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(2)*56, int64((*TOp)(unsafe.Pointer(pOp)).Fp3))
				_sqlite3VdbeMemSetStr(tls, pMem+uintptr(3)*56, zP4, int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
			} else {
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(0)*56, int64(**(**int32)(__ccgo_up(bp))))
				_sqlite3VdbeMemSetStr(tls, pMem+uintptr(1)*56, _sqlite3OpcodeName(tls, libc.Int32FromUint8((*TOp)(unsafe.Pointer(pOp)).Fopcode)), int64(-int32(1)), uint8(SQLITE_UTF8), libc.UintptrFromInt32(0))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(2)*56, int64((*TOp)(unsafe.Pointer(pOp)).Fp1))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(3)*56, int64((*TOp)(unsafe.Pointer(pOp)).Fp2))
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(4)*56, int64((*TOp)(unsafe.Pointer(pOp)).Fp3))
				/* pMem+5 for p4 is done last */
				_sqlite3VdbeMemSetInt64(tls, pMem+uintptr(6)*56, libc.Int64FromUint16((*TOp)(unsafe.Pointer(pOp)).Fp5))
				_sqlite3VdbeMemSetNull(tls, pMem+uintptr(7)*56)
				_sqlite3VdbeMemSetStr(tls, pMem+uintptr(5)*56, zP4, int64(-int32(1)), uint8(SQLITE_UTF8), __ccgo_fp(Xsqlite3_free))
			}
			(*TVdbe)(unsafe.Pointer(p)).FpResultRow = pMem
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				(*TVdbe)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
				rc = int32(SQLITE_ERROR)
			} else {
				(*TVdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
				rc = int32(SQLITE_ROW)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Prepare a virtual machine for execution for the first time after
//	** creating the virtual machine.  This involves things such
//	** as allocating registers and initializing the program counter.
//	** After the VDBE has be prepped, it can be executed by one or more
//	** calls to sqlite3VdbeExec().
//	**
//	** This function may be called exactly once on each virtual machine.
//	** After this routine is called the VM has been "packaged" and is ready
//	** to run.  After this routine is called, further calls to
//	** sqlite3VdbeAddOp() functions are prohibited.  This routine disconnects
//	** the Vdbe from the Parse object that helped generate it so that the
//	** the Vdbe becomes an independent entity and the Parse object can be
//	** destroyed.
//	**
//	** Use the sqlite3VdbeRewind() procedure to restore a virtual machine back
//	** to its initial state after it has been run.
//	*/
func _sqlite3VdbeMakeReady(tls *libc.TLS, p uintptr, pParse uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, v1 uintptr
	var n, nCursor, nMem, nVar int32
	var _ /* nArg at bp+0 */ int32
	var _ /* x at bp+8 */ TReusableSpace
	_, _, _, _, _, _ = db, n, nCursor, nMem, nVar, v1 /* Reusable bulk memory */
	(*TVdbe)(unsafe.Pointer(p)).FpVList = (*TParse)(unsafe.Pointer(pParse)).FpVList
	(*TParse)(unsafe.Pointer(pParse)).FpVList = uintptr(0)
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	nVar = int32((*TParse)(unsafe.Pointer(pParse)).FnVar)
	nMem = (*TParse)(unsafe.Pointer(pParse)).FnMem
	nCursor = (*TParse)(unsafe.Pointer(pParse)).FnTab
	**(**int32)(__ccgo_up(bp)) = (*TParse)(unsafe.Pointer(pParse)).FnMaxArg
	/* Each cursor uses a memory cell.  The first cursor (cursor 0) can
	 ** use aMem[0] which is not otherwise used by the VDBE program.  Allocate
	 ** space at the end of aMem[] for cursors 1 and greater.
	 ** See also: allocateCursor().
	 */
	nMem = nMem + nCursor
	if nCursor == 0 && nMem > 0 {
		nMem = nMem + 1
	} /* Space for aMem[0] even if not used */
	/* Figure out how much reusable memory is available at the end of the
	 ** opcode array.  This extra memory will be reallocated for other elements
	 ** of the prepared statement.
	 */
	n = libc.Int32FromUint64(libc.Uint64FromInt64(24) * libc.Uint64FromInt32((*TVdbe)(unsafe.Pointer(p)).FnOp))                            /* Bytes of opcode memory used */
	(**(**TReusableSpace)(__ccgo_up(bp + 8))).FpSpace = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(n)                                      /* Unused opcode memory */
	(**(**TReusableSpace)(__ccgo_up(bp + 8))).FnFree = int64(((*TParse)(unsafe.Pointer(pParse)).FszOpAlloc - n) & ^libc.Int32FromInt32(7)) /* Bytes of unused memory */
	_resolveP2Values(tls, p, bp)
	libc.SetBitFieldPtr16Uint32(p+200, uint32(libc.BoolUint8((*TParse)(unsafe.Pointer(pParse)).FisMultiWrite != 0 && int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 40))&0x4000>>14)) != 0)), 10, 0x400)
	if (*TParse)(unsafe.Pointer(pParse)).Fexplain != 0 {
		if nMem < int32(10) {
			nMem = int32(10)
		}
		libc.SetBitFieldPtr16Uint32(p+200, uint32((*TParse)(unsafe.Pointer(pParse)).Fexplain), 12, 0x3000)
		(*TVdbe)(unsafe.Pointer(p)).FnResColumn = libc.Uint16FromInt32(int32(12) - int32(4)*int32(Tbft(*(*uint16)(unsafe.Pointer(p + 200))&0x3000>>12)))
	}
	libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(0), 14, 0xc000)
	/* Memory for registers, parameters, cursor, etc, is allocated in one or two
	 ** passes.  On the first pass, we try to reuse unused memory at the
	 ** end of the opcode array.  If we are unable to satisfy all memory
	 ** requirements by reusing the opcode array tail, then the second
	 ** pass will fill in the remainder using a fresh memory allocation.
	 **
	 ** This two-pass approach that reuses as much memory as possible from
	 ** the leftover memory at the end of the opcode array.  This can significantly
	 ** reduce the amount of memory held by a prepared statement.
	 */
	(**(**TReusableSpace)(__ccgo_up(bp + 8))).FnNeeded = 0
	(*TVdbe)(unsafe.Pointer(p)).FaMem = _allocSpace(tls, bp+8, uintptr(0), libc.Int64FromUint64(libc.Uint64FromInt32(nMem)*uint64(56)))
	(*TVdbe)(unsafe.Pointer(p)).FaVar = _allocSpace(tls, bp+8, uintptr(0), libc.Int64FromUint64(libc.Uint64FromInt32(nVar)*uint64(56)))
	(*TVdbe)(unsafe.Pointer(p)).FapArg = _allocSpace(tls, bp+8, uintptr(0), libc.Int64FromUint64(libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(8)))
	(*TVdbe)(unsafe.Pointer(p)).FapCsr = _allocSpace(tls, bp+8, uintptr(0), libc.Int64FromUint64(libc.Uint64FromInt32(nCursor)*uint64(8)))
	if (**(**TReusableSpace)(__ccgo_up(bp + 8))).FnNeeded != 0 {
		v1 = _sqlite3DbMallocRawNN(tls, db, libc.Uint64FromInt64((**(**TReusableSpace)(__ccgo_up(bp + 8))).FnNeeded))
		(*TVdbe)(unsafe.Pointer(p)).FpFree = v1
		(**(**TReusableSpace)(__ccgo_up(bp + 8))).FpSpace = v1
		(**(**TReusableSpace)(__ccgo_up(bp + 8))).FnFree = (**(**TReusableSpace)(__ccgo_up(bp + 8))).FnNeeded
		if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
			(*TVdbe)(unsafe.Pointer(p)).FaMem = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FaMem, libc.Int64FromUint64(libc.Uint64FromInt32(nMem)*uint64(56)))
			(*TVdbe)(unsafe.Pointer(p)).FaVar = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FaVar, libc.Int64FromUint64(libc.Uint64FromInt32(nVar)*uint64(56)))
			(*TVdbe)(unsafe.Pointer(p)).FapArg = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FapArg, libc.Int64FromUint64(libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp)))*uint64(8)))
			(*TVdbe)(unsafe.Pointer(p)).FapCsr = _allocSpace(tls, bp+8, (*TVdbe)(unsafe.Pointer(p)).FapCsr, libc.Int64FromUint64(libc.Uint64FromInt32(nCursor)*uint64(8)))
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*TVdbe)(unsafe.Pointer(p)).FnVar = 0
		(*TVdbe)(unsafe.Pointer(p)).FnCursor = 0
		(*TVdbe)(unsafe.Pointer(p)).FnMem = 0
	} else {
		(*TVdbe)(unsafe.Pointer(p)).FnCursor = nCursor
		(*TVdbe)(unsafe.Pointer(p)).FnVar = int16(nVar)
		_initMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaVar, nVar, db, uint16(MEM_Null))
		(*TVdbe)(unsafe.Pointer(p)).FnMem = nMem
		_initMemArray(tls, (*TVdbe)(unsafe.Pointer(p)).FaMem, nMem, db, uint16(MEM_Undefined))
		libc.Xmemset(tls, (*TVdbe)(unsafe.Pointer(p)).FapCsr, 0, libc.Uint64FromInt32(nCursor)*uint64(8))
	}
	_sqlite3VdbeRewind(tls, p)
}

// C documentation
//
//	/*
//	** Walk the parse trees associated with all subqueries in the
//	** FROM clause of SELECT statement p.  Do not invoke the select
//	** callback on p, but do invoke it on each FROM clause subquery
//	** and on any subqueries further down in the tree.  Return
//	** WRC_Abort or WRC_Continue;
//	*/
func _sqlite3WalkSelectFrom(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var i int32
	var pItem, pSrc uintptr
	_, _, _ = i, pItem, pSrc
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
	if pSrc != 0 {
		i = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
		pItem = pSrc + 8
		for {
			if !(i > 0) {
				break
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 && _sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect) != 0 {
				return int32(WRC_Abort)
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000000>>28) != 0 && _sqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pItem + 48))) != 0 {
				return int32(WRC_Abort)
			}
			goto _1
		_1:
			;
			i = i - 1
			pItem += 80
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This function sets the P4 value of an existing OP_Explain opcode to
//	** text describing the loop in pLevel. If the OP_Explain opcode already has
//	** a P4 value, it is freed before it is overwritten.
//	*/
func _sqlite3WhereAddExplainText(tls *libc.TLS, pParse uintptr, addr int32, pTabList uintptr, pLevel uintptr, wctrlFlags Tu16) {
	bp := tls.Alloc(176)
	defer tls.Free(176)
	var cRangeOp uint8
	var db, pIdx, pItem, pLoop, pOp, zFmt, zRowid, v1, v2 uintptr
	var flags Tu32
	var isSearch int32
	var _ /* str at bp+0 */ TStrAccum
	var _ /* zBuf at bp+32 */ [100]uint8
	_, _, _, _, _, _, _, _, _, _, _, _ = cRangeOp, db, flags, isSearch, pIdx, pItem, pLoop, pOp, zFmt, zRowid, v1, v2
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(v1)).Fexplain) == int32(2) || libc.Bool(0 != 0) {
		pOp = _sqlite3VdbeGetOp(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, addr)
		pItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Initial space for EQP output string */
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return
		}
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		flags = (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags
		isSearch = libc.BoolInt32(flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_BTM_LIMIT)|libc.Int32FromInt32(WHERE_TOP_LIMIT)) != uint32(0) || flags&uint32(WHERE_VIRTUALTABLE) == uint32(0) && libc.Int32FromUint16((*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pLoop + 24))).FnEq) > 0 || libc.Int32FromUint16(wctrlFlags)&(libc.Int32FromInt32(WHERE_ORDERBY_MIN)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)) != 0)
		_sqlite3StrAccumInit(tls, bp, db, bp+32, int32(100), int32(SQLITE_MAX_LENGTH))
		(**(**TStrAccum)(__ccgo_up(bp))).FprintfFlags = uint8(SQLITE_PRINTF_INTERNAL)
		if isSearch != 0 {
			v1 = __ccgo_ts + 23657
		} else {
			v1 = __ccgo_ts + 23664
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x2000>>13) != 0 {
			v2 = __ccgo_ts + 23669
		} else {
			v2 = __ccgo_ts + 1704
		}
		Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23677, libc.VaList(bp+144, v1, pItem, v2))
		if flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_VIRTUALTABLE)) == uint32(0) {
			zFmt = uintptr(0)
			pIdx = (*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FpIndex
			if !((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
				if isSearch != 0 {
					zFmt = __ccgo_ts + 11596
				}
			} else {
				if flags&uint32(WHERE_PARTIALIDX) != 0 {
					zFmt = __ccgo_ts + 23685
				} else {
					if flags&uint32(WHERE_AUTO_INDEX) != 0 {
						zFmt = __ccgo_ts + 23718
					} else {
						if flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY)|libc.Int32FromInt32(WHERE_EXPRIDX)) != 0 {
							zFmt = __ccgo_ts + 23743
						} else {
							zFmt = __ccgo_ts + 23761
						}
					}
				}
			}
			if zFmt != 0 {
				Xsqlite3_str_append(tls, bp, __ccgo_ts+23770, int32(7))
				Xsqlite3_str_appendf(tls, bp, zFmt, libc.VaList(bp+144, (*TIndex)(unsafe.Pointer(pIdx)).FzName))
				_explainIndexRange(tls, bp, pLoop)
			}
		} else {
			if flags&uint32(WHERE_IPK) != uint32(0) && flags&uint32(WHERE_CONSTRAINT) != uint32(0) {
				zRowid = __ccgo_ts + 17967
				Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23778, libc.VaList(bp+144, zRowid))
				if flags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_EQ)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != 0 {
					cRangeOp = uint8('=')
				} else {
					if flags&uint32(WHERE_BOTH_LIMIT) == uint32(WHERE_BOTH_LIMIT) {
						Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23809, libc.VaList(bp+144, zRowid))
						cRangeOp = uint8('<')
					} else {
						if flags&uint32(WHERE_BTM_LIMIT) != 0 {
							cRangeOp = uint8('>')
						} else {
							cRangeOp = uint8('<')
						}
					}
				}
				Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23819, libc.VaList(bp+144, libc.Int32FromUint8(cRangeOp)))
			} else {
				if flags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
					Xsqlite3_str_appendall(tls, bp, __ccgo_ts+23824)
					if int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x20>>5)) != 0 {
						v1 = __ccgo_ts + 23846
					} else {
						v1 = __ccgo_ts + 23854
					}
					Xsqlite3_str_appendf(tls, bp, v1, libc.VaList(bp+144, (*(*struct {
						FidxNum    int32
						F__ccgo4   uint8
						FisOrdered Ti8
						FomitMask  Tu16
						FidxStr    uintptr
						FmHandleIn Tu32
					})(unsafe.Pointer(pLoop + 24))).FidxNum, (*(*struct {
						FidxNum    int32
						F__ccgo4   uint8
						FisOrdered Ti8
						FomitMask  Tu16
						FidxStr    uintptr
						FmHandleIn Tu32
					})(unsafe.Pointer(pLoop + 24))).FidxStr))
				}
			}
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
			Xsqlite3_str_appendf(tls, bp, __ccgo_ts+23860, 0)
		}
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)))
		(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(7))
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = _sqlite3StrAccumFinish(tls, bp)
	}
}

// C documentation
//
//	/*
//	** Generate the beginning of the loop used for WHERE clause processing.
//	** The return value is a pointer to an opaque structure that contains
//	** information needed to terminate the loop.  Later, the calling routine
//	** should invoke sqlite3WhereEnd() with the return value of this function
//	** in order to complete the WHERE clause processing.
//	**
//	** If an error occurs, this routine returns NULL.
//	**
//	** The basic idea is to do a nested loop, one loop for each table in
//	** the FROM clause of a select.  (INSERT and UPDATE statements are the
//	** same as a SELECT with only a single table in the FROM clause.)  For
//	** example, if the SQL is this:
//	**
//	**       SELECT * FROM t1, t2, t3 WHERE ...;
//	**
//	** Then the code generated is conceptually like the following:
//	**
//	**      foreach row1 in t1 do       \    Code generated
//	**        foreach row2 in t2 do      |-- by sqlite3WhereBegin()
//	**          foreach row3 in t3 do   /
//	**            ...
//	**          end                     \    Code generated
//	**        end                        |-- by sqlite3WhereEnd()
//	**      end                         /
//	**
//	** Note that the loops might not be nested in the order in which they
//	** appear in the FROM clause if a different order is better able to make
//	** use of indices.  Note also that when the IN operator appears in
//	** the WHERE clause, it might result in additional nested loops for
//	** scanning through all values on the right-hand side of the IN.
//	**
//	** There are Btree cursors associated with each table.  t1 uses cursor
//	** number pTabList->a[0].iCursor.  t2 uses the cursor pTabList->a[1].iCursor.
//	** And so forth.  This routine generates code to open those VDBE cursors
//	** and sqlite3WhereEnd() generates the code to close them.
//	**
//	** The code that sqlite3WhereBegin() generates leaves the cursors named
//	** in pTabList pointing at their appropriate entries.  The [...] code
//	** can use OP_Column and OP_Rowid opcodes on these cursors to extract
//	** data from the various tables of the loop.
//	**
//	** If the WHERE clause is empty, the foreach loops must each scan their
//	** entire tables.  Thus a three-way join is an O(N^3) operation.  But if
//	** the tables have indices and there are terms in the WHERE clause that
//	** refer to those indices, a complete table scan can be avoided and the
//	** code will run much faster.  Most of the work of this routine is checking
//	** to see if there are indices that can be used to speed up the loop.
//	**
//	** Terms of the WHERE clause are also used to limit which rows actually
//	** make it to the "..." in the middle of the loop.  After each "foreach",
//	** terms of the WHERE clause that use only terms in that loop and outer
//	** loops are evaluated and if false a jump is made around all subsequent
//	** inner loops (or around the "..." if the test occurs within the inner-
//	** most loop)
//	**
//	** OUTER JOINS
//	**
//	** An outer join of tables t1 and t2 is conceptually coded as follows:
//	**
//	**    foreach row1 in t1 do
//	**      flag = 0
//	**      foreach row2 in t2 do
//	**        start:
//	**          ...
//	**          flag = 1
//	**      end
//	**      if flag==0 then
//	**        move the row2 cursor to a null row
//	**        goto start
//	**      fi
//	**    end
//	**
//	** ORDER BY CLAUSE PROCESSING
//	**
//	** pOrderBy is a pointer to the ORDER BY clause (or the GROUP BY clause
//	** if the WHERE_GROUPBY flag is set in wctrlFlags) of a SELECT statement
//	** if there is one.  If there is no ORDER BY clause or if this routine
//	** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
//	**
//	** The iIdxCur parameter is the cursor number of an index.  If
//	** WHERE_OR_SUBCLAUSE is set, iIdxCur is the cursor number of an index
//	** to use for OR clause processing.  The WHERE clause should use this
//	** specific cursor.  If WHERE_ONEPASS_DESIRED is set, then iIdxCur is
//	** the first cursor in an array of cursors for all indices.  iIdxCur should
//	** be used to compute the appropriate cursor depending on which index is
//	** used.
//	*/
func _sqlite3WhereBegin(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pResultSet uintptr, pSelect uintptr, wctrlFlags Tu16, iAuxArg int32) (r uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var addrExplain, bOnerow, iCur, iDb, iIndexCur, iOnce, ii, n, nByteWInfo, nTabList, op, op1, rc, wsFlags, wsFlags1, v1 int32
	var b, notReady TBitmask
	var bFordelete Tu8
	var db, p, pInfo, pIx, pJ, pLevel, pLoop, pMaskSet, pPk, pRJ, pSrc, pSubq, pT, pTab, pTabItem, pVTab, pWInfo, pX, v, v7, v8 uintptr
	var v19 bool
	var _ /* sWLB at bp+0 */ TWhereLoopBuilder
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrExplain, b, bFordelete, bOnerow, db, iCur, iDb, iIndexCur, iOnce, ii, n, nByteWInfo, nTabList, notReady, op, op1, p, pInfo, pIx, pJ, pLevel, pLoop, pMaskSet, pPk, pRJ, pSrc, pSubq, pT, pTab, pTabItem, pVTab, pWInfo, pX, rc, v, wsFlags, wsFlags1, v1, v19, v7, v8 /* Will become the return value of this function */
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe                                                                                                                                                                                                                                                                                                                                                          /* Return code */
	bFordelete = uint8(0)                                                                                                                                                                                                                                                                                                                                                                                 /* OPFLAG_FORDELETE or zero, as appropriate */
	/* Only one of WHERE_OR_SUBCLAUSE or WHERE_USE_LIMIT */
	/* Variable initialization */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	libc.Xmemset(tls, bp, 0, uint64(56))
	/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
	if pOrderBy != 0 && (*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
		pOrderBy = uintptr(0)
		wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
		wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) | libc.Int32FromInt32(WHERE_KEEP_ALL_JOINS)) /* Disable omit-noop-join opt */
	}
	/* The number of tables in the FROM clause is limited by the number of
	 ** bits in a Bitmask
	 */
	if (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc > libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24104, libc.VaList(bp+64, libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))))
		return uintptr(0)
	}
	/* This function normally generates a nested loop for all tables in
	 ** pTabList.  But if the WHERE_OR_SUBCLAUSE flag is set, then we should
	 ** only generate code for the first table in pTabList and assume that
	 ** any cursors associated with subsequent tables are uninitialized.
	 */
	if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
		v1 = int32(1)
	} else {
		v1 = (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc
	}
	nTabList = v1
	/* Allocate and initialize the WhereInfo structure that will become the
	 ** return value. A single allocation is used to store the WhereInfo
	 ** struct, the contents of WhereInfo.a[], the WhereClause structure
	 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
	 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
	 ** some architectures. Hence the ROUND8() below.
	 */
	nByteWInfo = libc.Int32FromUint64((uint64(libc.UintptrFromInt32(0)+856) + libc.Uint64FromInt32(nTabList)*libc.Uint64FromInt64(112) + libc.Uint64FromInt32(7)) & libc.Uint64FromInt32(^libc.Int32FromInt32(7)))
	pWInfo = _sqlite3DbMallocRawNN(tls, db, uint64(libc.Uint64FromInt32(nByteWInfo)+uint64(104)))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3DbFree(tls, db, pWInfo)
		pWInfo = uintptr(0)
		goto whereBeginError
	}
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse = pParse
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList = pTabList
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy = pOrderBy
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet = pResultSet
	v1 = -libc.Int32FromInt32(1)
	**(**int32)(__ccgo_up(pWInfo + 40 + 1*4)) = v1
	**(**int32)(__ccgo_up(pWInfo + 40)) = v1
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel = libc.Uint8FromInt32(nTabList)
	v1 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue = v1
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak = v1
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags = wctrlFlags
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiLimit = int16(iAuxArg)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop = int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect = pSelect
	libc.Xmemset(tls, pWInfo+65, 0, uint64(libc.UintptrFromInt32(0)+104)-uint64(libc.UintptrFromInt32(0)+65))
	libc.Xmemset(tls, pWInfo+856, 0, uint64(104)+libc.Uint64FromInt32(nTabList)*uint64(112))
	/* ONEPASS defaults to OFF */
	pMaskSet = pWInfo + 592
	(*TWhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn = 0
	**(**int32)(__ccgo_up(pMaskSet + 8)) = -int32(99) /* Initialize ix[0] to a value that can never be
	 ** a valid cursor number, to avoid an initial
	 ** test for pMaskSet->n==0 in sqlite3WhereGetMask() */
	(**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWInfo = pWInfo
	(**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWC = pWInfo + 104
	(**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpNew = pWInfo + uintptr(nByteWInfo)
	_whereLoopInit(tls, (**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpNew)
	/* Split the WHERE clause into separate subexpressions where each
	 ** subexpression is separated by an AND operator.
	 */
	_sqlite3WhereClauseInit(tls, pWInfo+104, pWInfo)
	_sqlite3WhereSplit(tls, pWInfo+104, pWhere, uint8(TK_AND))
	/* Special case: No FROM clause
	 */
	if nTabList == 0 {
		if pOrderBy != 0 {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = int8((*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr)
		}
		if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DistinctOpt)) == uint32(0) {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNIQUE)
		}
		if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect != 0 && (*TSelect)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FselFlags&uint32(SF_MultiValue) == uint32(0) {
			_sqlite3VdbeExplain(tls, pParse, uint8(0), __ccgo_ts+24132, 0)
		}
	} else {
		/* Assign a bit from the bitmask to every term in the FROM clause.
		 **
		 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
		 **
		 ** The rule of the previous sentence ensures that if X is the bitmask for
		 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
		 ** Knowing the bitmask for all tables to the left of a left join is
		 ** important.  Ticket #3015.
		 **
		 ** Note that bitmasks are created for all pTabList->nSrc tables in
		 ** pTabList, not just the first nTabList tables.  nTabList is normally
		 ** equal to pTabList->nSrc but might be shortened to 1 if the
		 ** WHERE_OR_SUBCLAUSE flag is set.
		 */
		ii = 0
		for {
			_createMask(tls, pMaskSet, (*(*TSrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(ii)*80))).FiCursor)
			_sqlite3WhereTabFuncArgs(tls, pParse, pTabList+8+uintptr(ii)*80, pWInfo+104)
			goto _5
		_5:
			;
			ii = ii + 1
			v1 = ii
			if !(v1 < (*TSrcList)(unsafe.Pointer(pTabList)).FnSrc) {
				break
			}
		}
	}
	/* Analyze all of the subexpressions. */
	_sqlite3WhereExprAnalyze(tls, pTabList, pWInfo+104)
	if pSelect != 0 && (*TSelect)(unsafe.Pointer(pSelect)).FpLimit != 0 {
		_sqlite3WhereAddLimit(tls, pWInfo+104, pSelect)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto whereBeginError
	}
	/* The False-WHERE-Term-Bypass optimization:
	 **
	 ** If there are WHERE terms that are false, then no rows will be output,
	 ** so skip over all of the code generated here.
	 **
	 ** Conditions:
	 **
	 **   (1)  The WHERE term must not refer to any tables in the join.
	 **   (2)  The term must not come from an ON clause on the
	 **        right-hand side of a LEFT or FULL JOIN.
	 **   (3)  The term must not come from an ON clause, or there must be
	 **        no RIGHT or FULL OUTER joins in pTabList.
	 **   (4)  If the expression contains non-deterministic functions
	 **        that are not within a sub-select. This is not required
	 **        for correctness but rather to preserves SQLite's legacy
	 **        behaviour in the following two cases:
	 **
	 **          WHERE random()>0;           -- eval random() once per row
	 **          WHERE (SELECT random())>0;  -- eval random() just once overall
	 **
	 ** Note that the Where term need not be a constant in order for this
	 ** optimization to apply, though it does need to be constant relative to
	 ** the current subquery (condition 1).  The term might include variables
	 ** from outer queries so that the value of the term changes from one
	 ** invocation of the current subquery to the next.
	 */
	ii = 0
	for {
		if !(ii < (*TWhereClause)(unsafe.Pointer((**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWC)).FnBase) {
			break
		}
		pT = (*TWhereClause)(unsafe.Pointer((**(**TWhereLoopBuilder)(__ccgo_up(bp))).FpWC)).Fa + uintptr(ii)*56 /* The expression of pT */
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pT)).FwtFlags)&int32(TERM_VIRTUAL) != 0 {
			goto _6
		}
		pX = (*TWhereTerm)(unsafe.Pointer(pT)).FpExpr
		if (*TWhereTerm)(unsafe.Pointer(pT)).FprereqAll == uint64(0) && (nTabList == 0 || _exprIsDeterministic(tls, pX) != 0) && !((*TExpr)(unsafe.Pointer(pX)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_InnerON)) != uint32(0) && libc.Int32FromUint8((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).Ffg.Fjointype)&int32(JT_LTORJ) != 0) {
			_sqlite3ExprIfFalse(tls, pParse, pX, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak, int32(SQLITE_JUMPIFNULL))
			v7 = pT + 18
			*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) | libc.Int32FromInt32(TERM_CODED))
		}
		goto _6
	_6:
		;
		ii = ii + 1
	}
	if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
		if (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_DistinctOpt)) != uint32(0) {
			/* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
			 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
			wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
			v7 = pWInfo + 60
			*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) & ^libc.Int32FromInt32(WHERE_WANT_DISTINCT))
		} else {
			if _isDistinctRedundant(tls, pParse, pTabList, pWInfo+104, pResultSet) != 0 {
				/* The DISTINCT marking is pointless.  Ignore it. */
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNIQUE)
			} else {
				if pOrderBy == uintptr(0) {
					/* Try to ORDER BY the result set to make distinct processing easier */
					v7 = pWInfo + 60
					*(*Tu16)(unsafe.Pointer(v7)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v7))) | libc.Int32FromInt32(WHERE_DISTINCTBY))
					(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy = pResultSet
				}
			}
		}
	}
	/* Construct the WhereLoop objects */
	if nTabList != int32(1) || _whereShortCut(tls, bp) == 0 {
		rc = _whereLoopAddAll(tls, bp)
		if rc != 0 {
			goto whereBeginError
		}
		/* If one or more WhereTerm.truthProb values were used in estimating
		 ** loop parameters, but then those truthProb values were subsequently
		 ** changed based on STAT4 information while computing subsequent loops,
		 ** then we need to rerun the whole loop building process so that all
		 ** loops will be built using the revised truthProb values. */
		if libc.Int32FromUint8((**(**TWhereLoopBuilder)(__ccgo_up(bp))).FbldFlags2)&int32(SQLITE_BLDF2_2NDPASS) != 0 {
			for (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops != 0 {
				p = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops = (*TWhereLoop)(unsafe.Pointer(p)).FpNextLoop
				_whereLoopDelete(tls, db, p)
			}
			rc = _whereLoopAddAll(tls, bp)
			if rc != 0 {
				goto whereBeginError
			}
		}
		_wherePathSolver(tls, pWInfo, 0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			goto whereBeginError
		}
		if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
			_whereInterstageHeuristic(tls, pWInfo)
			if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut) < 0 {
				v1 = int32(1)
			} else {
				v1 = int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut) + int32(1)
			}
			_wherePathSolver(tls, pWInfo, int16(v1))
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				goto whereBeginError
			}
		}
		/* TUNING:  Assume that a DISTINCT clause on a subquery reduces
		 ** the output size by a factor of 8 (LogEst -30).  Search for
		 ** tag-20250414a to see other cases.
		 */
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
			v7 = pWInfo + 70
			*(*TLogEst)(unsafe.Pointer(v7)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v7))) - libc.Int32FromInt32(30))
		}
	}
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == uintptr(0) && (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ReverseOrder) != uint64(0) {
		_whereReverseScanOrder(tls, pWInfo)
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto whereBeginError
	}
	/* Attempt to omit tables from a join that do not affect the result.
	 ** See the comment on whereOmitNoopJoin() for further information.
	 **
	 ** This query optimization is factored out into a separate "no-inline"
	 ** procedure to keep the sqlite3WhereBegin() procedure from becoming
	 ** too large.  If sqlite3WhereBegin() becomes too large, that prevents
	 ** some C-compiler optimizers from in-lining the
	 ** sqlite3WhereCodeOneLoopStart() procedure, and it is important to
	 ** in-line sqlite3WhereCodeOneLoopStart() for performance reasons.
	 */
	notReady = ^libc.Uint64FromInt32(0)
	if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= int32(2) && pResultSet != uintptr(0) && 0 == libc.Int32FromUint16(wctrlFlags)&(libc.Int32FromInt32(WHERE_AGG_DISTINCT)|libc.Int32FromInt32(WHERE_KEEP_ALL_JOINS)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OmitNoopJoin)) == uint32(0) {
		notReady = _whereOmitNoopJoin(tls, pWInfo, notReady)
		nTabList = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)
	}
	/* Check to see if there are any SEARCH loops that might benefit from
	 ** using a Bloom filter.
	 */
	if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_BloomFilter)) == uint32(0) {
		_whereCheckIfBloomFilterIsUseful(tls, pWInfo)
	}
	v7 = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse + 28
	*(*TLogEst)(unsafe.Pointer(v7)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v7))) + int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut))
	/* If the caller is an UPDATE or DELETE statement that is requesting
	 ** to use a one-pass algorithm, determine if this is appropriate.
	 **
	 ** A one-pass approach can be used if the caller has requested one
	 ** and either (a) the scan visits at most one row or (b) each
	 ** of the following are true:
	 **
	 **   * the caller has indicated that a one-pass approach can be used
	 **     with multiple rows (by setting WHERE_ONEPASS_MULTIROW), and
	 **   * the table is not a virtual table, and
	 **   * either the scan does not use the OR optimization or the caller
	 **     is a DELETE operation (WHERE_DUPLICATES_OK is only specified
	 **     for DELETE).
	 **
	 ** The last qualification is because an UPDATE statement uses
	 ** WhereInfo.aiCurOnePass[1] to determine whether or not it really can
	 ** use a one-pass approach, and this is not set accurately for scans
	 ** that use the OR optimization.
	 */
	if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ONEPASS_DESIRED) != 0 {
		wsFlags = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FpWLoop)).FwsFlags)
		bOnerow = libc.BoolInt32(wsFlags&int32(WHERE_ONEROW) != 0)
		if bOnerow != 0 || 0 != libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ONEPASS_MULTIROW) && !(libc.Int32FromUint8((*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpSTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VTAB)) && (0 == wsFlags&int32(WHERE_MULTI_OR) || libc.Int32FromUint16(wctrlFlags)&int32(WHERE_DUPLICATES_OK) != 0) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OnePass)) == uint32(0) {
			if bOnerow != 0 {
				v1 = int32(ONEPASS_SINGLE)
			} else {
				v1 = int32(ONEPASS_MULTI)
			}
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass = libc.Uint8FromInt32(v1)
			if (*TTable)(unsafe.Pointer((*(*TSrcItem)(unsafe.Pointer(pTabList + 8))).FpSTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) && wsFlags&int32(WHERE_IDX_ONLY) != 0 {
				if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ONEPASS_MULTIROW) != 0 {
					bFordelete = uint8(OPFLAG_FORDELETE)
				}
				(*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FpWLoop)).FwsFlags = libc.Uint32FromInt32(wsFlags & ^libc.Int32FromInt32(WHERE_IDX_ONLY))
			}
		}
	}
	/* Open all tables in the pTabList and any indices selected for
	 ** searching those tables.
	 */
	ii = 0
	pLevel = pWInfo + 856
	for {
		if !(ii < nTabList) {
			break
		}
		pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = _sqlite3VdbeMakeLabel(tls, pParse)
		if ii == 0 || libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(pTabItem))).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
		} else {
			if (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(ii-int32(1))*112))).FpRJ != 0 {
				(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(ii-int32(1))*112))).FaddrBrk
			} else {
				(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(ii-int32(1))*112))).FaddrHalt
			}
		}
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) != uint32(0) || libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VIEW) {
			/* Do nothing */
		} else {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
				pVTab = _sqlite3GetVTable(tls, db, pTab)
				iCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
				_sqlite3VdbeAddOp4(tls, v, int32(OP_VOpen), iCur, 0, 0, pVTab, -int32(12))
			} else {
				if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
					/* noop */
				} else {
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) == uint32(0) && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) == 0 || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
						op = int32(OP_OpenRead)
						if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF {
							op = int32(OP_OpenWrite)
							**(**int32)(__ccgo_up(pWInfo + 40)) = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
						}
						_sqlite3OpenTable(tls, pParse, (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor, iDb, pTab, op)
						if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF && int32((*TTable)(unsafe.Pointer(pTab)).FnCol) < libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(libc.Int32FromInt32(TF_HasGenerated)|libc.Int32FromInt32(TF_WithoutRowid)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_AUTO_INDEX)|libc.Int32FromInt32(WHERE_BLOOMFILTER)) == uint32(0) {
							/* If we know that only a prefix of the record will be used,
							 ** it is advantageous to reduce the "column count" field in
							 ** the P4 operand of the OP_OpenRead/Write opcode. */
							b = (*TSrcItem)(unsafe.Pointer(pTabItem)).FcolUsed
							n = 0
							for {
								if !(b != 0) {
									break
								}
								goto _15
							_15:
								;
								b = b >> int32(1)
								n = n + 1
							}
							_sqlite3VdbeChangeP4(tls, v, -int32(1), uintptr(int64(n)), -int32(3))
						}
						_sqlite3VdbeChangeP5(tls, v, uint16(bFordelete))
						if ii >= int32(2) && libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(pTabItem))).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_LEFT)) == 0 && (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt == (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FaddrHalt {
							_sqlite3VdbeAddOp2(tls, v, int32(OP_IfEmpty), (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
						}
					} else {
						_sqlite3TableLock(tls, pParse, iDb, (*TTable)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pTab)).FzName)
					}
				}
			}
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != 0 {
			pIx = (*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FpIndex
			op1 = int32(OP_OpenRead)
			/* iAuxArg is always set to a positive value if ONEPASS is possible */
			if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
				/* This is one term of an OR-optimization using the PRIMARY KEY of a
				 ** WITHOUT ROWID table.  No need for a separate index */
				iIndexCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
				op1 = 0
			} else {
				if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF {
					pJ = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab)).FpIndex
					iIndexCur = iAuxArg
					for pJ != 0 && pJ != pIx {
						iIndexCur = iIndexCur + 1
						pJ = (*TIndex)(unsafe.Pointer(pJ)).FpNext
					}
					op1 = int32(OP_OpenWrite)
					**(**int32)(__ccgo_up(pWInfo + 40 + 1*4)) = iIndexCur
				} else {
					if iAuxArg != 0 && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
						iIndexCur = iAuxArg
						op1 = int32(OP_ReopenIdx)
					} else {
						v7 = pParse + 56
						v1 = *(*int32)(unsafe.Pointer(v7))
						*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
						iIndexCur = v1
						if int32(uint32(*(*uint16)(unsafe.Pointer(pIx + 100))&0x10>>4)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_IndexedExpr)) == uint32(0) {
							_whereAddIndexedExpr(tls, pParse, pIx, iIndexCur, pTabItem)
						}
						if (*TIndex)(unsafe.Pointer(pIx)).FpPartIdxWhere != 0 && libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
							_wherePartIdxExpr(tls, pParse, pIx, (*TIndex)(unsafe.Pointer(pIx)).FpPartIdxWhere, uintptr(0), iIndexCur, pTabItem)
						}
					}
				}
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = iIndexCur
			if op1 != 0 {
				_sqlite3VdbeAddOp3(tls, v, op1, iIndexCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIx)).Ftnum), iDb)
				_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
				if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_CONSTRAINT) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_RANGE)|libc.Int32FromInt32(WHERE_SKIPSCAN)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BIGNULL_SORT) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) == uint32(0) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_ORDERBY_MIN) == 0 && libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) != int32(WHERE_DISTINCT_ORDERED) {
					_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SEEKEQ))
				}
			}
		}
		if iDb >= 0 {
			_sqlite3CodeVerifySchema(tls, pParse, iDb)
		}
		if v19 = libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0; v19 {
			v7 = _sqlite3WhereMalloc(tls, pWInfo, uint64(20))
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ = v7
		}
		if v19 && v7 != uintptr(0) {
			pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
			v8 = pParse + 56
			v1 = *(*int32)(unsafe.Pointer(v8))
			*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch = v1
			v7 = pParse + 60
			*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
			v1 = *(*int32)(unsafe.Pointer(v7))
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Blob), int32(65536), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom)
			v7 = pParse + 60
			*(*int32)(unsafe.Pointer(v7)) = *(*int32)(unsafe.Pointer(v7)) + 1
			v1 = *(*int32)(unsafe.Pointer(v7))
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn)
			if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, int32(1))
				pInfo = _sqlite3KeyInfoAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(1), 0)
				if pInfo != 0 {
					*(*uintptr)(unsafe.Pointer(pInfo + 32)) = uintptr(0)
					**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags)) = uint8(0)
					_sqlite3VdbeAppendP4(tls, v, pInfo, -int32(9))
				}
			} else {
				pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
				_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
			}
			**(**Tu32)(__ccgo_up(pLoop + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(WHERE_IDX_ONLY))
			/* The nature of RIGHT JOIN processing is such that it messes up
			 ** the output order.  So omit any ORDER BY/GROUP BY elimination
			 ** optimizations.  We need to do an actual sort for RIGHT JOIN. */
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = 0
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNORDERED)
		}
		goto _14
	_14:
		;
		ii = ii + 1
		pLevel += 112
	}
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiTop = _sqlite3VdbeCurrentAddr(tls, v)
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		goto whereBeginError
	}
	/* Generate the code to do the search.  Each iteration of the for
	 ** loop below generates code for a single nested loop of the VM
	 ** program.
	 */
	ii = 0
	for {
		if !(ii < nTabList) {
			break
		}
		if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
			goto whereBeginError
		}
		pLevel = pWInfo + 856 + uintptr(ii)*112
		wsFlags1 = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags)
		pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x4000000>>26) != 0 {
			iOnce = 0
			pSubq = *(*uintptr)(unsafe.Pointer(pSrc + 72))
			if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x8000000>>27) == 0 {
				iOnce = _sqlite3VdbeAddOp0(tls, v, int32(OP_Once))
			} else {
				iOnce = 0
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
			if iOnce != 0 {
				_sqlite3VdbeJumpHere(tls, v, iOnce)
			}
		}
		if wsFlags1&(libc.Int32FromInt32(WHERE_AUTO_INDEX)|libc.Int32FromInt32(WHERE_BLOOMFILTER)) != 0 {
			if wsFlags1&int32(WHERE_AUTO_INDEX) != 0 {
				_constructAutomaticIndex(tls, pParse, pWInfo+104, notReady, pLevel)
			} else {
				_sqlite3ConstructBloomFilter(tls, pWInfo, ii, pLevel, notReady)
			}
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				goto whereBeginError
			}
		}
		addrExplain = _sqlite3WhereExplainOneScan(tls, pParse, pTabList, pLevel, wctrlFlags)
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody = _sqlite3VdbeCurrentAddr(tls, v)
		notReady = _sqlite3WhereCodeOneLoopStart(tls, pParse, v, pWInfo, ii, pLevel, notReady)
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont
		if wsFlags1&int32(WHERE_MULTI_OR) == 0 && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_OR_SUBCLAUSE) == 0 {
			_ = addrExplain
		}
		goto _26
	_26:
		;
		ii = ii + 1
	}
	/* Done. */
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FiEndWhere = _sqlite3VdbeCurrentAddr(tls, v)
	return pWInfo
	/* Jump here if malloc fails */
	goto whereBeginError
whereBeginError:
	;
	if pWInfo != 0 {
		(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = int16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop)
		_whereInfoFree(tls, db, pWInfo)
	}
	return uintptr(0)
}

/*
** Part of sqlite3WhereEnd() will rewrite opcodes to reference the
** index rather than the main table.  In SQLITE_DEBUG mode, we want
** to trace those changes if PRAGMA vdbe_addoptrace=on.  This routine
** does that.
 */

// C documentation
//
//	/*
//	** Generate code for the start of the iLevel-th loop in the WHERE clause
//	** implementation described by pWInfo.
//	*/
func _sqlite3WhereCodeOneLoopStart(tls *libc.TLS, pParse uintptr, v uintptr, pWInfo uintptr, iLevel int32, pLevel uintptr, notReady TBitmask) (r2 TBitmask) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var aMoveOp [4]Tu8
	var addrBrk, addrCont, addrExplain, addrNotFound, addrNxt, addrSeekScan, bRev, endEq, iCache, iCol, iCol1, iCovCur, iCur, iFld, iIdxCur, iIn, iLoop, iLoopBody, iNext, iPk, iPk1, iReg, iReleaseReg, iRetInit, iRowidReg, iSet, iTab, iTarget, iTerm, ii, j, jmp1, jmp11, k, memEndValue, nConstraint, nConstraint1, nExtraReg, nNotReady, nPk, nPk1, omitTable, op, op1, r, r1, r11, regBase, regBignull, regReturn, regRowid, regRowset, regYield, skipLikeAddr, start, startEq, start_constraints, testOp, untestedTerms, v1, v2 int32
	var bSeekPastNull, bStopAtNull, t1, t2 Tu8
	var db, origSrc, pAlt, pAndExpr, pCompare, pCov, pDelete, pE, pE1, pEnd, pExpr, pIdx, pLeft, pLoop, pOp, pOrExpr, pOrTab, pOrTerm, pOrWc, pPk, pPk1, pPk2, pPk3, pRJ, pRJ1, pRangeEnd, pRangeStart, pRight, pRight1, pRight2, pRight3, pStart, pSubLoop, pSubWInfo, pSubq, pTab, pTab1, pTabItem, pTerm, pWC, pX, pX1, t, zEndAff, v4, v8 uintptr
	var m TBitmask
	var nBtm, nEq, nTop Tu16
	var v6 uint32
	var v15 bool
	var _ /* rTemp at bp+0 */ int32
	var _ /* sEAlt at bp+16 */ TExpr
	var _ /* zStartAff at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aMoveOp, addrBrk, addrCont, addrExplain, addrNotFound, addrNxt, addrSeekScan, bRev, bSeekPastNull, bStopAtNull, db, endEq, iCache, iCol, iCol1, iCovCur, iCur, iFld, iIdxCur, iIn, iLoop, iLoopBody, iNext, iPk, iPk1, iReg, iReleaseReg, iRetInit, iRowidReg, iSet, iTab, iTarget, iTerm, ii, j, jmp1, jmp11, k, m, memEndValue, nBtm, nConstraint, nConstraint1, nEq, nExtraReg, nNotReady, nPk, nPk1, nTop, omitTable, op, op1, origSrc, pAlt, pAndExpr, pCompare, pCov, pDelete, pE, pE1, pEnd, pExpr, pIdx, pLeft, pLoop, pOp, pOrExpr, pOrTab, pOrTerm, pOrWc, pPk, pPk1, pPk2, pPk3, pRJ, pRJ1, pRangeEnd, pRangeStart, pRight, pRight1, pRight2, pRight3, pStart, pSubLoop, pSubWInfo, pSubq, pTab, pTab1, pTabItem, pTerm, pWC, pX, pX1, r, r1, r11, regBase, regBignull, regReturn, regRowid, regRowset, regYield, skipLikeAddr, start, startEq, start_constraints, t, t1, t2, testOp, untestedTerms, zEndAff, v1, v15, v2, v4, v6, v8 /* Jump here to continue with next cycle */
	iRowidReg = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       /* Rowid is stored in this register, if not zero */
	iReleaseReg = 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     /* Temp register to free before returning */
	pIdx = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   /* Iteration of constraint generator loop */
	pWC = pWInfo + 104
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
	iCur = (*TSrcItem)(unsafe.Pointer(pTabItem)).FiCursor
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady = notReady & ^_sqlite3WhereGetMask(tls, pWInfo+592, iCur)
	bRev = libc.Int32FromUint64((*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask >> iLevel & uint64(1))
	/* Create labels for the "break" and "continue" instructions
	 ** for the current loop.  Jump to addrBrk to break out of a loop.
	 ** Jump to cont to go immediately to the next iteration of the
	 ** loop.
	 **
	 ** When there is an IN operator, we also have a "addrNxt" label that
	 ** means to continue with the next IN value combination.  When
	 ** there are no IN operators in the constraints, the "addrNxt" label
	 ** is the same as "addrBrk".
	 */
	v1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt = v1
	addrBrk = v1
	v1 = _sqlite3VdbeMakeLabel(tls, pParse)
	(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = v1
	addrCont = v1
	/* If this is the right table of a LEFT OUTER JOIN, allocate and
	 ** initialize a memory cell that records if this table matches any
	 ** row of the left table of the join.
	 */
	if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom) > 0 && libc.Int32FromUint8((**(**TSrcItem)(__ccgo_up(pTabItem))).Ffg.Fjointype)&int32(JT_LEFT) != 0 {
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v1 = *(*int32)(unsafe.Pointer(v4))
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin = v1
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
	}
	/* Special case of a FROM clause subquery implemented as a co-routine */
	if int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x2000000>>25) != 0 {
		pSubq = *(*uintptr)(unsafe.Pointer(pTabItem + 72))
		regYield = (*TSubquery)(unsafe.Pointer(pSubq)).FregReturn
		_sqlite3VdbeAddOp3(tls, v, int32(OP_InitCoroutine), regYield, 0, (*TSubquery)(unsafe.Pointer(pSubq)).FaddrFillSub)
		(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Yield), regYield, addrBrk)
		(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Goto)
	} else {
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != uint32(0) {
			nConstraint = libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm)
			iReg = _sqlite3GetTempRange(tls, pParse, nConstraint+int32(2))
			addrNotFound = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
			j = 0
			for {
				if !(j < nConstraint) {
					break
				}
				iTarget = iReg + j + int32(2)
				pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
				if pTerm == uintptr(0) {
					goto _5
				}
				if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0 {
					if j <= int32(31) {
						v6 = libc.Uint32FromInt32(1) << j
					} else {
						v6 = uint32(0)
					}
					if v6&(*(*struct {
						FidxNum    int32
						F__ccgo4   uint8
						FisOrdered Ti8
						FomitMask  Tu16
						FidxStr    uintptr
						FmHandleIn Tu32
					})(unsafe.Pointer(pLoop + 24))).FmHandleIn != 0 {
						v4 = pParse + 56
						v1 = *(*int32)(unsafe.Pointer(v4))
						*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
						iTab = v1
						v8 = pParse + 60
						*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
						v2 = *(*int32)(unsafe.Pointer(v8))
						iCache = v2
						_sqlite3CodeRhsOfIN(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, iTab, 0)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_VInitIn), iTab, iTarget, iCache)
					} else {
						_codeEqualityTerm(tls, pParse, pTerm, pLevel, j, bRev, iTarget)
						addrNotFound = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
					}
				} else {
					pRight = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
					_codeExprOrVector(tls, pParse, pRight, iTarget, int32(1))
					if libc.Int32FromUint8((*TWhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) == int32(SQLITE_INDEX_CONSTRAINT_OFFSET) && int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x40>>6)) != 0 {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TSelect)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FiOffset)
					}
				}
				goto _5
			_5:
				;
				j = j + 1
			}
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), (*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(pLoop + 24))).FidxNum, iReg)
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), nConstraint, iReg+int32(1))
			/* The instruction immediately prior to OP_VFilter must be an OP_Integer
			 ** that sets the "argc" value for xVFilter.  This is necessary for
			 ** resolveP2() to work correctly.  See tag-20250207a. */
			if int32(Tu32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x80>>7)) != 0 {
				v1 = -int32(7)
			} else {
				v1 = -int32(1)
			}
			_sqlite3VdbeAddOp4(tls, v, int32(OP_VFilter), iCur, addrNotFound, iReg, (*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(pLoop + 24))).FidxStr, v1)
			libc.SetBitFieldPtr8Uint32(pLoop+24+4, libc.Uint32FromInt32(0), 7, 0x80)
			/* An OOM inside of AddOp4(OP_VFilter) instruction above might have freed
			 ** the u.vtab.idxStr.  NULL it out to prevent a use-after-free */
			if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				(*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pLoop + 24))).FidxStr = uintptr(0)
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
			if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass != 0 {
				v1 = int32(OP_Noop)
			} else {
				v1 = int32(OP_VNext)
			}
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = libc.Uint8FromInt32(v1)
			(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
			j = 0
			for {
				if !(j < nConstraint) {
					break
				}
				pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
				if j < int32(16) && libc.Int32FromUint16((*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pLoop + 24))).FomitMask)>>j&int32(1) != 0 {
					_disableTerm(tls, pLevel, pTerm)
					goto _13
				}
				if v15 = libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_IN) != 0; v15 {
					if j <= int32(31) {
						v6 = libc.Uint32FromInt32(1) << j
					} else {
						v6 = uint32(0)
					}
				}
				if v15 && v6&(*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pLoop + 24))).FmHandleIn == uint32(0) && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) { /* IN loop corresponding to the j-th constraint */
					/* Reload the constraint value into reg[iReg+j+2].  The same value
					 ** was loaded into the same register prior to the OP_VFilter, but
					 ** the xFilter implementation might have changed the datatype or
					 ** encoding of the value in the register, so it *must* be reloaded.
					 */
					iIn = 0
					for {
						if !(iIn < (*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 80))).FnIn) {
							break
						}
						pOp = _sqlite3VdbeGetOp(tls, v, (**(**TInLoop)(__ccgo_up((*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 80))).FaInLoop + uintptr(iIn)*20))).FaddrInTop)
						if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3 == iReg+j+int32(2) || libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Rowid) && (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 == iReg+j+int32(2) {
							_sqlite3VdbeAddOp3(tls, v, libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode), (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1, (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2, (*TVdbeOp)(unsafe.Pointer(pOp)).Fp3)
							break
						}
						goto _16
					_16:
						;
						iIn = iIn + 1
					}
					/* Generate code that will continue to the next row if
					 ** the IN constraint is not satisfied
					 */
					pCompare = _sqlite3PExpr(tls, pParse, int32(TK_EQ), uintptr(0), uintptr(0))
					if !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
						iFld = (*(*struct {
							FleftColumn int32
							FiField     int32
						})(unsafe.Pointer(pTerm + 32))).FiField
						pLeft = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft
						if iFld > 0 {
							(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 32)) + 8 + uintptr(iFld-int32(1))*32))).FpExpr
						} else {
							(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = pLeft
						}
						v4 = _sqlite3Expr(tls, db, int32(TK_REGISTER), uintptr(0))
						pRight1 = v4
						(*TExpr)(unsafe.Pointer(pCompare)).FpRight = v4
						if pRight1 != 0 {
							(*TExpr)(unsafe.Pointer(pRight1)).FiTable = iReg + j + int32(2)
							_sqlite3ExprIfFalse(tls, pParse, pCompare, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont, int32(SQLITE_JUMPIFNULL))
						}
						(*TExpr)(unsafe.Pointer(pCompare)).FpLeft = uintptr(0)
					}
					_sqlite3ExprDelete(tls, db, pCompare)
				}
				goto _13
			_13:
				;
				j = j + 1
			}
			/* These registers need to be preserved in case there is an IN operator
			 ** loop.  So we could deallocate the registers here (and potentially
			 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0.  But it seems
			 ** simpler and safer to simply not reuse the registers.
			 **
			 **    sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
			 */
		} else {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_IN)|libc.Int32FromInt32(WHERE_COLUMN_EQ)) != uint32(0) {
				/* Case 2:  We can directly reference a single row using an
				 **          equality comparison against the ROWID field.  Or
				 **          we reference multiple rows using a "rowid IN (...)"
				 **          construct.
				 */
				pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
				v4 = pParse + 60
				*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
				v1 = *(*int32)(unsafe.Pointer(v4))
				iReleaseReg = v1
				iRowidReg = _codeEqualityTerm(tls, pParse, pTerm, pLevel, 0, bRev, iReleaseReg)
				if iRowidReg != iReleaseReg {
					_sqlite3ReleaseTempReg(tls, pParse, iReleaseReg)
				}
				addrNxt = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
				if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0 {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_MustBeInt), iRowidReg, addrNxt)
					_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt, iRowidReg, int32(1))
					_filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), iCur, addrNxt, iRowidReg)
				(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Noop)
			} else {
				if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_COLUMN_RANGE) != uint32(0) {
					/* Case 3:  We have an inequality comparison against the ROWID field.
					 */
					testOp = int32(OP_Noop)
					memEndValue = 0
					j = 0
					v4 = libc.UintptrFromInt32(0)
					pEnd = v4
					pStart = v4
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
						v1 = j
						j = j + 1
						pStart = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
					}
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
						v1 = j
						j = j + 1
						pEnd = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
					}
					if bRev != 0 {
						pTerm = pStart
						pStart = pEnd
						pEnd = pTerm
					}
					if pStart != 0 { /* Cursor seek operation */
						/* The following constant maps TK_xx codes into corresponding
						 ** seek opcodes.  It depends on a particular ordering of TK_xx
						 */
						aMoveOp = [4]Tu8{
							0: uint8(OP_SeekGT),
							1: uint8(OP_SeekLE),
							2: uint8(OP_SeekLT),
							3: uint8(OP_SeekGE),
						}
						/* Make sure the ordering.. */
						/*  ... of the TK_xx values... */
						/*  ... is correct. */
						pX = (*TWhereTerm)(unsafe.Pointer(pStart)).FpExpr
						/* transitive constraints */
						if _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX)).FpRight) != 0 {
							v1 = _sqlite3GetTempReg(tls, pParse)
							**(**int32)(__ccgo_up(bp)) = v1
							r11 = v1
							_codeExprOrVector(tls, pParse, (*TExpr)(unsafe.Pointer(pX)).FpRight, r11, int32(1))
							op = libc.Int32FromUint8(aMoveOp[(libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX)).Fop)-int32(TK_GT)-int32(1))&int32(0x3)|int32(0x1)])
						} else {
							r11 = _sqlite3ExprCodeTemp(tls, pParse, (*TExpr)(unsafe.Pointer(pX)).FpRight, bp)
							_disableTerm(tls, pLevel, pStart)
							op = libc.Int32FromUint8(aMoveOp[libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX)).Fop)-int32(TK_GT)])
						}
						_sqlite3VdbeAddOp3(tls, v, op, iCur, addrBrk, r11)
						_sqlite3ReleaseTempReg(tls, pParse, **(**int32)(__ccgo_up(bp)))
					} else {
						if bRev != 0 {
							v1 = int32(OP_Last)
						} else {
							v1 = int32(OP_Rewind)
						}
						_sqlite3VdbeAddOp2(tls, v, v1, iCur, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt)
					}
					if pEnd != 0 {
						pX1 = (*TWhereTerm)(unsafe.Pointer(pEnd)).FpExpr
						/* Transitive constraints */
						v4 = pParse + 60
						*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
						v1 = *(*int32)(unsafe.Pointer(v4))
						memEndValue = v1
						_codeExprOrVector(tls, pParse, (*TExpr)(unsafe.Pointer(pX1)).FpRight, memEndValue, int32(1))
						if 0 == _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX1)).FpRight) && (libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX1)).Fop) == int32(TK_LT) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pX1)).Fop) == int32(TK_GT)) {
							if bRev != 0 {
								v1 = int32(OP_Le)
							} else {
								v1 = int32(OP_Ge)
							}
							testOp = v1
						} else {
							if bRev != 0 {
								v1 = int32(OP_Lt)
							} else {
								v1 = int32(OP_Gt)
							}
							testOp = v1
						}
						if 0 == _sqlite3ExprIsVector(tls, (*TExpr)(unsafe.Pointer(pX1)).FpRight) {
							_disableTerm(tls, pLevel, pEnd)
						}
					}
					start = _sqlite3VdbeCurrentAddr(tls, v)
					if bRev != 0 {
						v1 = int32(OP_Prev)
					} else {
						v1 = int32(OP_Next)
					}
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = libc.Uint8FromInt32(v1)
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
					(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = start
					if testOp != int32(OP_Noop) {
						v4 = pParse + 60
						*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
						v1 = *(*int32)(unsafe.Pointer(v4))
						iRowidReg = v1
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iCur, iRowidReg)
						_sqlite3VdbeAddOp3(tls, v, testOp, memEndValue, addrBrk, iRowidReg)
						_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(libc.Int32FromInt32(SQLITE_AFF_NUMERIC)|libc.Int32FromInt32(SQLITE_JUMPIFNULL)))
					}
				} else {
					if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != 0 {
						nEq = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnEq /* Number of == or IN terms */
						nBtm = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnBtm /* Length of BTM vector */
						nTop = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnTop /* Base register holding constraint values */
						pRangeStart = uintptr(0) /* Inequality constraint at range start */
						pRangeEnd = uintptr(0)   /* The VDBE cursor for the index */
						nExtraReg = 0            /* Affinity for start of range constraint */
						zEndAff = uintptr(0)     /* Affinity for end of range constraint */
						bSeekPastNull = uint8(0) /* True to seek past initial nulls */
						bStopAtNull = uint8(0)   /* True if we use the index only */
						regBignull = 0           /* big-null flag register */
						addrSeekScan = 0         /* Opcode of the OP_SeekScan, if any */
						pIdx = (*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FpIndex
						iIdxCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
						/* Find any inequality constraint terms for the start and end
						 ** of the range.
						 */
						j = libc.Int32FromUint16(nEq)
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
							v1 = j
							j = j + 1
							pRangeStart = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
							if nExtraReg > libc.Int32FromUint16((*(*struct {
								FnEq          Tu16
								FnBtm         Tu16
								FnTop         Tu16
								FnDistinctCol Tu16
								FpIndex       uintptr
								FpOrderBy     uintptr
							})(unsafe.Pointer(pLoop + 24))).FnBtm) {
								v1 = nExtraReg
							} else {
								v1 = libc.Int32FromUint16((*(*struct {
									FnEq          Tu16
									FnBtm         Tu16
									FnTop         Tu16
									FnDistinctCol Tu16
									FpIndex       uintptr
									FpOrderBy     uintptr
								})(unsafe.Pointer(pLoop + 24))).FnBtm)
							}
							nExtraReg = v1
							/* Like optimization range constraints always occur in pairs */
						}
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_TOP_LIMIT) != 0 {
							v1 = j
							j = j + 1
							pRangeEnd = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(v1)*8))
							if nExtraReg > libc.Int32FromUint16((*(*struct {
								FnEq          Tu16
								FnBtm         Tu16
								FnTop         Tu16
								FnDistinctCol Tu16
								FpIndex       uintptr
								FpOrderBy     uintptr
							})(unsafe.Pointer(pLoop + 24))).FnTop) {
								v1 = nExtraReg
							} else {
								v1 = libc.Int32FromUint16((*(*struct {
									FnEq          Tu16
									FnBtm         Tu16
									FnTop         Tu16
									FnDistinctCol Tu16
									FpIndex       uintptr
									FpOrderBy     uintptr
								})(unsafe.Pointer(pLoop + 24))).FnTop)
							}
							nExtraReg = v1
							if pRangeStart == uintptr(0) {
								j = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(nEq)*2)))
								if j >= 0 && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(j)*16 + 8))&0xf0>>4)) == 0 || j == -int32(2) {
									bSeekPastNull = uint8(1)
								}
							}
						}
						/* If the WHERE_BIGNULL_SORT flag is set, then index column nEq uses
						 ** a non-default "big-null" sort (either ASC NULLS LAST or DESC NULLS
						 ** FIRST). In both cases separate ordered scans are made of those
						 ** index entries for which the column is null and for those for which
						 ** it is not. For an ASC sort, the non-NULL entries are scanned first.
						 ** For DESC, NULL entries are scanned first.
						 */
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_TOP_LIMIT)|libc.Int32FromInt32(WHERE_BTM_LIMIT)) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_BIGNULL_SORT) != uint32(0) {
							nExtraReg = int32(1)
							bSeekPastNull = uint8(1)
							v4 = pParse + 60
							*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
							v2 = *(*int32)(unsafe.Pointer(v4))
							v1 = v2
							regBignull = v1
							(*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull = v1
							if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regBignull)
							}
							(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull = _sqlite3VdbeMakeLabel(tls, pParse)
						}
						/* If we are doing a reverse order scan on an ascending index, or
						 ** a forward order scan on a descending index, interchange the
						 ** start and end terms (pRangeStart and pRangeEnd).
						 */
						if libc.Int32FromUint16(nEq) < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) && bRev == libc.BoolInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(nEq)))) == SQLITE_SO_ASC) {
							t = pRangeEnd
							pRangeEnd = pRangeStart
							pRangeStart = t
							t1 = bSeekPastNull
							bSeekPastNull = bStopAtNull
							bStopAtNull = t1
							t2 = uint8(nBtm)
							nBtm = nTop
							nTop = uint16(t2)
						}
						if iLevel > 0 && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) != uint32(0) {
							/* In case OP_SeekScan is used, ensure that the index cursor does not
							 ** point to a valid row for the first iteration of this loop. */
							_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iIdxCur)
						}
						/* Generate code to evaluate all constraint terms using == or IN
						 ** and store the values of those terms in an array of registers
						 ** starting at regBase.
						 */
						regBase = _codeAllEqualityTerms(tls, pParse, pLevel, bRev, nExtraReg, bp+8)
						if **(**uintptr)(__ccgo_up(bp + 8)) != 0 && nTop != 0 {
							zEndAff = _sqlite3DbStrDup(tls, db, **(**uintptr)(__ccgo_up(bp + 8))+uintptr(nEq))
						}
						if regBignull != 0 {
							v1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull
						} else {
							v1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
						}
						addrNxt = v1
						startEq = libc.BoolInt32(!(pRangeStart != 0) || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FeOperator)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0)
						endEq = libc.BoolInt32(!(pRangeEnd != 0) || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FeOperator)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0)
						start_constraints = libc.BoolInt32(pRangeStart != 0 || libc.Int32FromUint16(nEq) > 0)
						/* Seek the index cursor to the start of the range. */
						nConstraint1 = libc.Int32FromUint16(nEq)
						if pRangeStart != 0 {
							pRight2 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FpExpr)).FpRight
							_codeExprOrVector(tls, pParse, pRight2, regBase+libc.Int32FromUint16(nEq), libc.Int32FromUint16(nBtm))
							if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeStart)).FwtFlags)&int32(TERM_VNULL) == 0 && _sqlite3ExprCanBeNull(tls, pRight2) != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+libc.Int32FromUint16(nEq), addrNxt)
							}
							if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
								_updateRangeAffinityStr(tls, pRight2, libc.Int32FromUint16(nBtm), **(**uintptr)(__ccgo_up(bp + 8))+uintptr(nEq))
							}
							nConstraint1 = nConstraint1 + libc.Int32FromUint16(nBtm)
							if _sqlite3ExprIsVector(tls, pRight2) == 0 {
								_disableTerm(tls, pLevel, pRangeStart)
							} else {
								startEq = int32(1)
							}
							bSeekPastNull = uint8(0)
						} else {
							if bSeekPastNull != 0 {
								startEq = 0
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+libc.Int32FromUint16(nEq))
								start_constraints = int32(1)
								nConstraint1 = nConstraint1 + 1
							} else {
								if regBignull != 0 {
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+libc.Int32FromUint16(nEq))
									start_constraints = int32(1)
									nConstraint1 = nConstraint1 + 1
								}
							}
						}
						_codeApplyAffinity(tls, pParse, regBase, nConstraint1-libc.Int32FromUint8(bSeekPastNull), **(**uintptr)(__ccgo_up(bp + 8)))
						if libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) > 0 && nConstraint1 == libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
							/* The skip-scan logic inside the call to codeAllEqualityConstraints()
							 ** above has already left the cursor sitting on the correct row,
							 ** so no further seeking is needed */
						} else {
							if regBignull != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), regBignull)
							}
							if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0 {
								_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt, regBase, libc.Int32FromUint16(nEq))
								_filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
							}
							op1 = libc.Int32FromUint8(_aStartOp[start_constraints<<int32(2)+startEq<<int32(1)+bRev])
							if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_SEEKSCAN) != uint32(0) && op1 == int32(OP_SeekGE) {
								/* TUNING:  The OP_SeekScan opcode seeks to reduce the number
								 ** of expensive seek operations by replacing a single seek with
								 ** 1 or more step operations.  The question is, how many steps
								 ** should we try before giving up and going with a seek.  The cost
								 ** of a seek is proportional to the logarithm of the of the number
								 ** of entries in the tree, so basing the number of steps to try
								 ** on the estimated number of rows in the btree seems like a good
								 ** guess. */
								addrSeekScan = _sqlite3VdbeAddOp1(tls, v, int32(OP_SeekScan), (int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst)))+int32(9))/int32(10))
								if pRangeStart != 0 || pRangeEnd != 0 {
									_sqlite3VdbeChangeP5(tls, v, uint16(1))
									_sqlite3VdbeChangeP2(tls, v, addrSeekScan, _sqlite3VdbeCurrentAddr(tls, v)+int32(1))
									addrSeekScan = 0
								}
							}
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1)
							if regBignull != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
								op1 = libc.Int32FromUint8(_aStartOp[libc.BoolInt32(nConstraint1 > int32(1))*int32(4)+int32(2)+bRev])
								_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1-startEq)
							}
						}
						/* Load the value for the inequality constraint at the end of the
						 ** range (if any).
						 */
						nConstraint1 = libc.Int32FromUint16(nEq)
						if pRangeEnd != 0 {
							pRight3 = (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FpExpr)).FpRight
							_codeExprOrVector(tls, pParse, pRight3, regBase+libc.Int32FromUint16(nEq), libc.Int32FromUint16(nTop))
							if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pRangeEnd)).FwtFlags)&int32(TERM_VNULL) == 0 && _sqlite3ExprCanBeNull(tls, pRight3) != 0 {
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IsNull), regBase+libc.Int32FromUint16(nEq), addrNxt)
							}
							if zEndAff != 0 {
								_updateRangeAffinityStr(tls, pRight3, libc.Int32FromUint16(nTop), zEndAff)
								_codeApplyAffinity(tls, pParse, regBase+libc.Int32FromUint16(nEq), libc.Int32FromUint16(nTop), zEndAff)
							} else {
							}
							nConstraint1 = nConstraint1 + libc.Int32FromUint16(nTop)
							if _sqlite3ExprIsVector(tls, pRight3) == 0 {
								_disableTerm(tls, pLevel, pRangeEnd)
							} else {
								endEq = int32(1)
							}
						} else {
							if bStopAtNull != 0 {
								if regBignull == 0 {
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regBase+libc.Int32FromUint16(nEq))
									endEq = 0
								}
								nConstraint1 = nConstraint1 + 1
							}
						}
						if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
							_sqlite3DbNNFreeNN(tls, db, **(**uintptr)(__ccgo_up(bp + 8)))
						}
						if zEndAff != 0 {
							_sqlite3DbNNFreeNN(tls, db, zEndAff)
						}
						/* Top of the loop body */
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
						/* Check if the index cursor is past the end of the range. */
						if nConstraint1 != 0 {
							if regBignull != 0 {
								/* Except, skip the end-of-range check while doing the NULL-scan */
								_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNot), regBignull, _sqlite3VdbeCurrentAddr(tls, v)+int32(3))
							}
							op1 = libc.Int32FromUint8(_aEndOp[bRev*int32(2)+endEq])
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1)
							if addrSeekScan != 0 {
								_sqlite3VdbeJumpHere(tls, v, addrSeekScan)
							}
						}
						if regBignull != 0 {
							/* During a NULL-scan, check to see if we have reached the end of
							 ** the NULLs */
							_sqlite3VdbeAddOp2(tls, v, int32(OP_If), regBignull, _sqlite3VdbeCurrentAddr(tls, v)+int32(2))
							op1 = libc.Int32FromUint8(_aEndOp[bRev*int32(2)+libc.Int32FromUint8(bSeekPastNull)])
							_sqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1+libc.Int32FromUint8(bSeekPastNull))
						}
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_EARLYOUT) != uint32(0) {
							_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekHit), iIdxCur, libc.Int32FromUint16(nEq), libc.Int32FromUint16(nEq))
						}
						/* Seek the table cursor, if required */
						omitTable = libc.BoolInt32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) != uint32(0) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_OR_SUBCLAUSE)|libc.Int32FromInt32(WHERE_RIGHT_JOIN)) == 0)
						if omitTable != 0 {
							/* pIdx is a covering index.  No need to access the main table. */
						} else {
							if (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
								_codeDeferredSeek(tls, pWInfo, pIdx, iCur, iIdxCur)
							} else {
								if iCur != iIdxCur {
									pPk = _sqlite3PrimaryKeyIndex(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpTable)
									iRowidReg = _sqlite3GetTempRange(tls, pParse, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
									j = 0
									for {
										if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)) {
											break
										}
										k = _sqlite3TableColumnToIndex(tls, pIdx, int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
										_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iIdxCur, k, iRowidReg+j)
										goto _40
									_40:
										;
										j = j + 1
									}
									_sqlite3VdbeAddOp4Int(tls, v, int32(OP_NotFound), iCur, addrCont, iRowidReg, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol))
								}
							}
						}
						if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin == 0 {
							/* If a partial index is driving the loop, try to eliminate WHERE clause
							 ** terms from the query that must be true due to the WHERE clause of
							 ** the partial index.  This optimization does not work on an outer join,
							 ** as shown by:
							 **
							 ** 2019-11-02 ticket 623eff57e76d45f6      (LEFT JOIN)
							 ** 2025-05-29 forum post 7dee41d32506c4ae  (RIGHT JOIN)
							 */
							if (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 && (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ == uintptr(0) {
								_whereApplyPartialIndexConstraints(tls, (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere, iCur, pWC)
							}
						} else {
							/* The following assert() is not a requirement, merely an observation:
							 ** The OR-optimization doesn't work for the right hand table of
							 ** a LEFT JOIN: */
						}
						/* Record the instruction used to terminate the loop. */
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_ONEROW) != 0 || (*(*struct {
							FnIn     int32
							FaInLoop uintptr
						})(unsafe.Pointer(pLevel + 80))).FnIn != 0 && regBignull == 0 && _whereLoopIsOneRow(tls, pLoop) != 0 {
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Noop)
						} else {
							if bRev != 0 {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Prev)
							} else {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Next)
							}
						}
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iIdxCur
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_UNQ_WANTED) != uint32(0) {
							v1 = int32(1)
						} else {
							v1 = 0
						}
						(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp3 = libc.Uint8FromInt32(v1)
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_CONSTRAINT) == uint32(0) {
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp5 = uint8(SQLITE_STMTSTATUS_FULLSCAN_STEP)
						} else {
						}
						if omitTable != 0 {
							pIdx = uintptr(0)
						}
					} else {
						if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_MULTI_OR) != 0 { /* Shortened table list or OR-clause generation */
							pCov = uintptr(0)
							v4 = pParse + 56
							v1 = *(*int32)(unsafe.Pointer(v4))
							*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1 /* Potential covering index (or NULL) */
							iCovCur = v1
							v8 = pParse + 60
							*(*int32)(unsafe.Pointer(v8)) = *(*int32)(unsafe.Pointer(v8)) + 1
							v2 = *(*int32)(unsafe.Pointer(v8))             /* Cursor used for index scans (if any) */
							regReturn = v2                                 /* Register used with OP_Gosub */
							regRowset = 0                                  /* Register for RowSet object */
							regRowid = 0                                   /* Register holding rowid */
							iLoopBody = _sqlite3VdbeMakeLabel(tls, pParse) /* Address of regReturn init */
							untestedTerms = 0                              /* Loop counter */
							pAndExpr = uintptr(0)                          /* An ".. AND (...)" expression */
							pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
							pTerm = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
							pOrWc = *(*uintptr)(unsafe.Pointer(pTerm + 32))
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Return)
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = regReturn
							/* Set up a new SrcList in pOrTab containing the table being scanned
							 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
							 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
							 */
							if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) > int32(1) || int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x2000>>13) != 0 { /* Original list of tables */
								nNotReady = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - iLevel - int32(1)
								pOrTab = _sqlite3DbMallocRawNN(tls, db, uint64(uint64(libc.UintptrFromInt32(0)+8)+libc.Uint64FromInt32(nNotReady+libc.Int32FromInt32(1))*libc.Uint64FromInt64(80)))
								if pOrTab == uintptr(0) {
									return notReady
								}
								(*TSrcList)(unsafe.Pointer(pOrTab)).FnAlloc = uint32(libc.Uint8FromInt32(nNotReady + libc.Int32FromInt32(1)))
								(*TSrcList)(unsafe.Pointer(pOrTab)).FnSrc = libc.Int32FromUint32((*TSrcList)(unsafe.Pointer(pOrTab)).FnAlloc)
								libc.Xmemcpy(tls, pOrTab+8, pTabItem, uint64(80))
								origSrc = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
								k = int32(1)
								for {
									if !(k <= nNotReady) {
										break
									}
									libc.Xmemcpy(tls, pOrTab+8+uintptr(k)*80, origSrc+uintptr((**(**TWhereLevel)(__ccgo_up(pLevel + uintptr(k)*112))).FiFrom)*80, uint64(80))
									goto _46
								_46:
									;
									k = k + 1
								}
								/* Clear the fromExists flag on the OR-optimized table entry so that
								 ** the calls to sqlite3WhereEnd() do not code early-exits after the
								 ** first row is visited. The early exit applies to this table's
								 ** overall loop - including the multiple OR branches and any WHERE
								 ** conditions not passed to the sub-loops - not to the sub-loops.  */
								libc.SetBitFieldPtr32Uint32(pOrTab+8+24+4, libc.Uint32FromInt32(0), 13, 0x2000)
							} else {
								pOrTab = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
							}
							/* Initialize the rowset register to contain NULL. An SQL NULL is
							 ** equivalent to an empty rowset.  Or, create an ephemeral index
							 ** capable of holding primary keys in the case of a WITHOUT ROWID.
							 **
							 ** Also initialize regReturn to contain the address of the instruction
							 ** immediately following the OP_Return at the bottom of the loop. This
							 ** is required in a few obscure LEFT JOIN cases where control jumps
							 ** over the top of the loop into the body of it. In this case the
							 ** correct response for the end-of-loop code (the OP_Return) is to
							 ** fall through to the next instruction, just as an OP_Next does if
							 ** called on an uninitialized cursor.
							 */
							if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DUPLICATES_OK) == 0 {
								if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
									v4 = pParse + 60
									*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
									v1 = *(*int32)(unsafe.Pointer(v4))
									regRowset = v1
									_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regRowset)
								} else {
									pPk1 = _sqlite3PrimaryKeyIndex(tls, pTab)
									v4 = pParse + 56
									v1 = *(*int32)(unsafe.Pointer(v4))
									*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
									regRowset = v1
									_sqlite3VdbeAddOp2(tls, v, int32(OP_OpenEphemeral), regRowset, libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk1)).FnKeyCol))
									_sqlite3VdbeSetP4KeyInfo(tls, pParse, pPk1)
								}
								v4 = pParse + 60
								*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
								v1 = *(*int32)(unsafe.Pointer(v4))
								regRowid = v1
							}
							iRetInit = _sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, regReturn)
							/* If the original WHERE clause is z of the form:  (x1 OR x2 OR ...) AND y
							 ** Then for every term xN, evaluate as the subexpression: xN AND y
							 ** That way, terms in y that are factored into the disjunction will
							 ** be picked up by the recursive calls to sqlite3WhereBegin() below.
							 **
							 ** Actually, each subexpression is converted to "xN AND w" where w is
							 ** the "interesting" terms of z - terms that did not originate in the
							 ** ON or USING clause of a LEFT JOIN, and terms that are usable as
							 ** indices.
							 **
							 ** This optimization also only applies if the (x1 OR x2 OR ...) term
							 ** is not contained in the ON clause of a LEFT JOIN.
							 ** See ticket http://sqlite.org/src/info/f2369304e4
							 **
							 ** 2022-02-04:  Do not push down slices of a row-value comparison.
							 ** In other words, "w" or "y" may not be a slice of a vector.  Otherwise,
							 ** the initialization of the right-hand operand of the vector comparison
							 ** might not occur, or might occur only in an OR branch that is not
							 ** taken.  dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
							 **
							 ** 2022-03-03:  Do not push down expressions that involve subqueries.
							 ** The subquery might get coded as a subroutine.  Any table-references
							 ** in the subquery might be resolved to index-references for the index on
							 ** the OR branch in which the subroutine is coded.  But if the subroutine
							 ** is invoked from a different OR branch that uses a different index, such
							 ** index-references will not work.  tag-20220303a
							 ** https://sqlite.org/forum/forumpost/36937b197273d403
							 */
							if (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm > int32(1) {
								iTerm = 0
								for {
									if !(iTerm < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
										break
									}
									pExpr = (**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56))).FpExpr
									if (*TWhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*56 == pTerm {
										goto _53
									}
									if libc.Int32FromUint16((**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56))).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)|libc.Int32FromInt32(TERM_SLICE)) != 0 {
										goto _53
									}
									if libc.Int32FromUint16((**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56))).FeOperator)&int32(WO_ALL) == 0 {
										goto _53
									}
									if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Subquery)) != uint32(0) {
										goto _53
									} /* tag-20220303a */
									pExpr = _sqlite3ExprDup(tls, db, pExpr, 0)
									pAndExpr = _sqlite3ExprAnd(tls, pParse, pAndExpr, pExpr)
									goto _53
								_53:
									;
									iTerm = iTerm + 1
								}
								if pAndExpr != 0 {
									/* The extra 0x10000 bit on the opcode is masked off and does not
									 ** become part of the new Expr.op.  However, it does make the
									 ** op==TK_AND comparison inside of sqlite3PExpr() false, and this
									 ** prevents sqlite3PExpr() from applying the AND short-circuit
									 ** optimization, which we do not want here. */
									pAndExpr = _sqlite3PExpr(tls, pParse, libc.Int32FromInt32(TK_AND)|libc.Int32FromInt32(0x10000), uintptr(0), pAndExpr)
								}
							}
							/* Run a separate WHERE clause for each term of the OR clause.  After
							 ** eliminating duplicates from other WHERE clauses, the action for each
							 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
							 */
							_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23900, 0)
							ii = 0
							for {
								if !(ii < (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm) {
									break
								}
								pOrTerm = (*TWhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr(ii)*56
								if (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCur || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&int32(WO_AND) != 0 { /* Info for single OR-term scan */
									pOrExpr = (*TWhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr /* Local copy of OR clause term */
									jmp1 = 0                                                /* Address of jump operation */
									/* See TH3 vtab25.400 and ticket 614b25314c766238 */
									v4 = _sqlite3ExprDup(tls, db, pOrExpr, 0)
									pOrExpr = v4
									pDelete = v4
									if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
										_sqlite3ExprDelete(tls, db, pDelete)
										goto _54
									}
									if pAndExpr != 0 {
										(*TExpr)(unsafe.Pointer(pAndExpr)).FpLeft = pOrExpr
										pOrExpr = pAndExpr
									}
									/* Loop through table entries that match term pOrTerm. */
									_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23915, libc.VaList(bp+96, ii+int32(1)))
									pSubWInfo = _sqlite3WhereBegin(tls, pParse, pOrTab, pOrExpr, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_OR_SUBCLAUSE), iCovCur)
									if pSubWInfo != 0 {
										addrExplain = _sqlite3WhereExplainOneScan(tls, pParse, pOrTab, pSubWInfo+856, uint16(0))
										_ = addrExplain
										/* This is the sub-WHERE clause body.  First skip over
										 ** duplicate rows from prior sub-WHERE clauses, and record the
										 ** rowid (or PRIMARY KEY) for the current row so that the same
										 ** row will be skipped in subsequent sub-WHERE clauses.
										 */
										if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DUPLICATES_OK) == 0 {
											if ii == (*TWhereClause)(unsafe.Pointer(pOrWc)).FnTerm-int32(1) {
												v1 = -int32(1)
											} else {
												v1 = ii
											}
											iSet = v1
											if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
												_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, -int32(1), regRowid)
												jmp1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_RowSetTest), regRowset, 0, regRowid, iSet)
											} else {
												pPk2 = _sqlite3PrimaryKeyIndex(tls, pTab)
												nPk = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk2)).FnKeyCol)
												/* Read the PK into an array of temp registers. */
												r = _sqlite3GetTempRange(tls, pParse, nPk)
												iPk = 0
												for {
													if !(iPk < nPk) {
														break
													}
													iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk2)).FaiColumn + uintptr(iPk)*2)))
													_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
													goto _57
												_57:
													;
													iPk = iPk + 1
												}
												/* Check if the temp table already contains this key. If so,
												 ** the row has already been included in the result set and
												 ** can be ignored (by jumping past the Gosub below). Otherwise,
												 ** insert the key into the temp table and proceed with processing
												 ** the row.
												 **
												 ** Use some of the same optimizations as OP_RowSetTest: If iSet
												 ** is zero, assume that the key cannot already be present in
												 ** the temp table. And if iSet is -1, assume that there is no
												 ** need to insert the key into the temp table, as it will never
												 ** be tested for.  */
												if iSet != 0 {
													jmp1 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), regRowset, 0, r, nPk)
												}
												if iSet >= 0 {
													_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r, nPk, regRowid)
													_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), regRowset, regRowid, r, nPk)
													if iSet != 0 {
														_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
													}
												}
												/* Release the array of temp registers */
												_sqlite3ReleaseTempRange(tls, pParse, r, nPk)
											}
										}
										/* Invoke the main loop body as a subroutine */
										_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), regReturn, iLoopBody)
										/* Jump here (skipping the main loop body subroutine) if the
										 ** current sub-WHERE row is a duplicate from prior sub-WHEREs. */
										if jmp1 != 0 {
											_sqlite3VdbeJumpHere(tls, v, jmp1)
										}
										/* The pSubWInfo->untestedTerms flag means that this OR term
										 ** contained one or more AND term from a notReady table.  The
										 ** terms from the notReady table could not be tested and will
										 ** need to be tested later.
										 */
										if int32(uint32(*(*uint8)(unsafe.Pointer(pSubWInfo + 68))&0x40>>6)) != 0 {
											untestedTerms = int32(1)
										}
										/* If all of the OR-connected terms are optimized using the same
										 ** index, and the index is opened using the same cursor number
										 ** by each call to sqlite3WhereBegin() made by this loop, it may
										 ** be possible to use that index as a covering index.
										 **
										 ** If the call to sqlite3WhereBegin() above resulted in a scan that
										 ** uses an index, and this is either the first OR-connected term
										 ** processed or the index is the same as that used by all previous
										 ** terms, set pCov to the candidate covering index. Otherwise, set
										 ** pCov to NULL to indicate that no candidate covering index will
										 ** be available.
										 */
										pSubLoop = (*(*TWhereLevel)(unsafe.Pointer(pSubWInfo + 856))).FpWLoop
										if (*TWhereLoop)(unsafe.Pointer(pSubLoop)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0) && (ii == 0 || (*(*struct {
											FnEq          Tu16
											FnBtm         Tu16
											FnTop         Tu16
											FnDistinctCol Tu16
											FpIndex       uintptr
											FpOrderBy     uintptr
										})(unsafe.Pointer(pSubLoop + 24))).FpIndex == pCov) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || !(int32(uint32(*(*uint16)(unsafe.Pointer((*(*struct {
											FnEq          Tu16
											FnBtm         Tu16
											FnTop         Tu16
											FnDistinctCol Tu16
											FpIndex       uintptr
											FpOrderBy     uintptr
										})(unsafe.Pointer(pSubLoop + 24))).FpIndex + 100))&0xc000>>14)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))) {
											pCov = (*(*struct {
												FnEq          Tu16
												FnBtm         Tu16
												FnTop         Tu16
												FnDistinctCol Tu16
												FpIndex       uintptr
												FpOrderBy     uintptr
											})(unsafe.Pointer(pSubLoop + 24))).FpIndex
										} else {
											pCov = uintptr(0)
										}
										if _sqlite3WhereUsesDeferredSeek(tls, pSubWInfo) != 0 {
											libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 7, 0x80)
										}
										/* Finish the loop through table entries that match term pOrTerm. */
										_sqlite3WhereEnd(tls, pSubWInfo)
										_sqlite3VdbeExplainPop(tls, pParse)
									}
									_sqlite3ExprDelete(tls, db, pDelete)
								}
								goto _54
							_54:
								;
								ii = ii + 1
							}
							_sqlite3VdbeExplainPop(tls, pParse)
							*(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu)) = pCov
							if pCov != 0 {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = iCovCur
							}
							if pAndExpr != 0 {
								(*TExpr)(unsafe.Pointer(pAndExpr)).FpLeft = uintptr(0)
								_sqlite3ExprDelete(tls, db, pAndExpr)
							}
							_sqlite3VdbeChangeP1(tls, v, iRetInit, _sqlite3VdbeCurrentAddr(tls, v))
							_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
							_sqlite3VdbeResolveLabel(tls, v, iLoopBody)
							/* Set the P2 operand of the OP_Return opcode that will end the current
							 ** loop to point to this spot, which is the top of the next containing
							 ** loop.  The byte-code formatter will use that P2 value as a hint to
							 ** indent everything in between the this point and the final OP_Return.
							 ** See tag-20220407a in vdbe.c and shell.c */
							(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = _sqlite3VdbeCurrentAddr(tls, v)
							if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList != pOrTab {
								_sqlite3DbFreeNN(tls, db, pOrTab)
							}
							if !(untestedTerms != 0) {
								_disableTerm(tls, pLevel, pTerm)
							}
						} else {
							if int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x1000000>>24) != 0 {
								/* Tables marked isRecursive have only a single row that is stored in
								 ** a pseudo-cursor.  No need to Rewind or Next such cursors. */
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = uint8(OP_Noop)
							} else {
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fop = _aStep[bRev]
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2 = int32(1) + _sqlite3VdbeAddOp2(tls, v, libc.Int32FromUint8(_aStart[bRev]), iCur, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrHalt)
								(*TWhereLevel)(unsafe.Pointer(pLevel)).Fp5 = uint8(SQLITE_STMTSTATUS_FULLSCAN_STEP)
							}
						}
					}
				}
			}
		}
	}
	/* Insert code to test every subexpression that can be completely
	 ** computed using the current set of tables.
	 **
	 ** This loop may run between one and three times, depending on the
	 ** constraints to be generated. The value of stack variable iLoop
	 ** determines the constraints coded by each iteration, as follows:
	 **
	 ** iLoop==1: Code only expressions that are entirely covered by pIdx.
	 ** iLoop==2: Code remaining expressions that do not contain correlated
	 **           sub-queries.
	 ** iLoop==3: Code all remaining expressions.
	 **
	 ** An effort is made to skip unnecessary iterations of the loop.
	 **
	 ** This optimization of causing simple query restrictions to occur before
	 ** more complex one is call the "push-down" optimization in MySQL.  Here
	 ** in SQLite, the name is "MySQL push-down", since there is also another
	 ** totally unrelated optimization called "WHERE-clause push-down".
	 ** Sometimes the qualifier is omitted, resulting in an ambiguity, so beware.
	 */
	if pIdx != 0 {
		v1 = int32(1)
	} else {
		v1 = int32(2)
	}
	iLoop = v1
	for cond := true; cond; cond = iLoop > 0 {
		iNext = 0 /* Next value for iLoop */
		pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
		j = (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm
		for {
			if !(j > 0) {
				break
			}
			skipLikeAddr = 0
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
				goto _59
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0) {
				libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 6, 0x40)
				goto _59
			}
			pE = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
				if !((*TExpr)(unsafe.Pointer(pE)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != libc.Uint32FromInt32(0)) {
					/* Defer processing WHERE clause constraints until after outer
					 ** join processing.  tag-20220513a */
					goto _59
				} else {
					if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LEFT) == int32(JT_LEFT) && !((*TExpr)(unsafe.Pointer(pE)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)) != libc.Uint32FromInt32(0)) {
						goto _59
					} else {
						m = _sqlite3WhereGetMask(tls, pWInfo+592, *(*int32)(unsafe.Pointer(pE + 52)))
						if m&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != 0 {
							/* An ON clause that is not ripe */
							goto _59
						}
					}
				}
			}
			if iLoop == int32(1) && !(_sqlite3ExprCoveredByIndex(tls, pE, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, pIdx) != 0) {
				iNext = int32(2)
				goto _59
			}
			if iLoop < int32(3) && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VARSELECT) != 0 {
				if iNext == 0 {
					iNext = int32(3)
				}
				goto _59
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_LIKECOND) != 0 {
				/* If the TERM_LIKECOND flag is set, that means that the range search
				 ** is sufficient to guarantee that the LIKE operator is true, so we
				 ** can skip the call to the like(A,B) function.  But this only works
				 ** for strings.  So do not skip the call to the function on the pass
				 ** that compares BLOBs. */
				goto _59
			}
			_sqlite3ExprIfFalse(tls, pParse, pE, addrCont, int32(SQLITE_JUMPIFNULL))
			if skipLikeAddr != 0 {
				_sqlite3VdbeJumpHere(tls, v, skipLikeAddr)
			}
			v4 = pTerm + 18
			*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
			goto _59
		_59:
			;
			j = j - 1
			pTerm += 56
		}
		iLoop = iNext
	}
	/* Insert code to test for implied constraints based on transitivity
	 ** of the "==" operator.
	 **
	 ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
	 ** and we are coding the t1 loop and the t2 loop has not yet coded,
	 ** then we cannot use the "t1.a=t2.b" constraint, but we can code
	 ** the implied "t1.a=123" constraint.
	 */
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	j = (*TWhereClause)(unsafe.Pointer(pWC)).FnBase
	for {
		if !(j > 0) {
			break
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) == 0 {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(WO_EQUIV) == 0 {
			goto _61
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != iCur {
			goto _61
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
			goto _61
		}
		pE1 = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		pAlt = _sqlite3WhereFindTerm(tls, pWC, iCur, (*(*struct {
			FleftColumn int32
			FiField     int32
		})(unsafe.Pointer(pTerm + 32))).FleftColumn, notReady, libc.Uint32FromInt32(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IN)|libc.Int32FromInt32(WO_IS)), uintptr(0))
		if pAlt == uintptr(0) {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pAlt)).FwtFlags)&int32(TERM_CODED) != 0 {
			goto _61
		}
		if (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)) != uint32(0) {
			goto _61
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pAlt)).FeOperator)&int32(WO_IN) != 0 && (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) && (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr + 32)))).FpEList)).FnExpr > int32(1) {
			goto _61
		}
		**(**TExpr)(__ccgo_up(bp + 16)) = **(**TExpr)(__ccgo_up((*TWhereTerm)(unsafe.Pointer(pAlt)).FpExpr))
		(**(**TExpr)(__ccgo_up(bp + 16))).FpLeft = (*TExpr)(unsafe.Pointer(pE1)).FpLeft
		_sqlite3ExprIfFalse(tls, pParse, bp+16, addrCont, int32(SQLITE_JUMPIFNULL))
		v4 = pAlt + 18
		*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
		goto _61
	_61:
		;
		j = j - 1
		pTerm += 56
	}
	/* For a RIGHT OUTER JOIN, record the fact that the current row has
	 ** been matched at least once.
	 */
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
		jmp11 = 0
		pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
		/* pTab is the right-hand table of the RIGHT JOIN.  Generate code that
		 ** will record that the current row of that table has been matched at
		 ** least once.  This is accomplished by storing the PK for the row in
		 ** both the iMatch index and the regBloom Bloom filter.
		 */
		pTab1 = (*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80))).FpSTab
		if (*TTable)(unsafe.Pointer(pTab1)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			r1 = _sqlite3GetTempRange(tls, pParse, int32(2))
			_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, -int32(1), r1+int32(1))
			nPk1 = int32(1)
		} else {
			pPk3 = _sqlite3PrimaryKeyIndex(tls, pTab1)
			nPk1 = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk3)).FnKeyCol)
			r1 = _sqlite3GetTempRange(tls, pParse, nPk1+int32(1))
			iPk1 = 0
			for {
				if !(iPk1 < nPk1) {
					break
				}
				iCol1 = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk3)).FaiColumn + uintptr(iPk1)*2)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, iCur, iCol1, r1+int32(1)+iPk1)
				goto _63
			_63:
				;
				iPk1 = iPk1 + 1
			}
		}
		jmp11 = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, 0, r1+int32(1), nPk1)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), r1+int32(1), nPk1, r1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, r1, r1+int32(1), nPk1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_FilterAdd), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom, 0, r1+int32(1), nPk1)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
		_sqlite3VdbeJumpHere(tls, v, jmp11)
		_sqlite3ReleaseTempRange(tls, pParse, r1, nPk1+int32(1))
	}
	/* For a LEFT OUTER JOIN, generate code that will record the fact that
	 ** at least one row of the right table has matched the left table.
	 */
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst = _sqlite3VdbeCurrentAddr(tls, v)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ == uintptr(0) {
			goto code_outer_join_constraints /* WHERE clause constraints */
		}
	}
	if !((*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0) {
		goto _64
	}
	/* Create a subroutine used to process all interior loops and code
	 ** of the RIGHT JOIN.  During normal operation, the subroutine will
	 ** be in-line with the rest of the code.  But at the end, a separate
	 ** loop will run that invokes this subroutine for unmatched rows
	 ** of pTab, with all tables to left begin set to NULL.
	 */
	pRJ1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	_sqlite3VdbeAddOp2(tls, v, int32(OP_BeginSubrtn), 0, (*TWhereRightJoin)(unsafe.Pointer(pRJ1)).FregReturn)
	(*TWhereRightJoin)(unsafe.Pointer(pRJ1)).FaddrSubrtn = _sqlite3VdbeCurrentAddr(tls, v)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn + 1
	/* WHERE clause constraints must be deferred until after outer join
	 ** row elimination has completed, since WHERE clause constraints apply
	 ** to the results of the OUTER JOIN.  The following loop generates the
	 ** appropriate WHERE clause constraint checks.  tag-20220513a.
	 */
	goto code_outer_join_constraints
code_outer_join_constraints:
	;
	pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
	j = libc.Int32FromInt32(0)
	for {
		if !(j < (*TWhereClause)(unsafe.Pointer(pWC)).FnBase) {
			break
		}
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_CODED)) != 0 {
			goto _65
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0) {
			goto _65
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LTORJ) != 0 {
			goto _65
		}
		_sqlite3ExprIfFalse(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, addrCont, int32(SQLITE_JUMPIFNULL))
		v4 = pTerm + 18
		*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(TERM_CODED))
		goto _65
	_65:
		;
		j = j + 1
		pTerm += 56
	}
_64:
	;
	return (*TWhereLevel)(unsafe.Pointer(pLevel)).FnotReady
}

// C documentation
//
//	/*
//	** Generate the end of the WHERE loop.  See comments on
//	** sqlite3WhereBegin() for additional information.
//	*/
func _sqlite3WhereEnd(tls *libc.TLS, pWInfo uintptr) {
	var addr, addrIfNull, addrSeek, bEarlyOut, i, iDb, iEnd, j, j1, k, last, m, n, n1, nRJ, op, r1, ws, x, v4 int32
	var db, p, pIdx, pIdx1, pIn, pIx, pLastOp, pLevel, pLoop, pOp, pParse, pPk, pRJ, pSrc, pTab, pTabItem, pTabList, v, v2 uintptr
	var v3, v5 bool
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr, addrIfNull, addrSeek, bEarlyOut, db, i, iDb, iEnd, j, j1, k, last, m, n, n1, nRJ, op, p, pIdx, pIdx1, pIn, pIx, pLastOp, pLevel, pLoop, pOp, pParse, pPk, pRJ, pSrc, pTab, pTabItem, pTabList, r1, v, ws, x, v2, v3, v4, v5
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pTabList = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iEnd = _sqlite3VdbeCurrentAddr(tls, v)
	nRJ = 0
	addrSeek = 0
	/* Generate loop termination code.
	 */
	i = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pLevel = pWInfo + 856 + uintptr(i)*112
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			/* Terminate the subroutine that forms the interior of the loop of
			 ** the RIGHT JOIN table */
			pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
			_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
			/* Replace addrCont with a new label that will never be used, just so
			 ** the subsequent call to resolve pLevel->addrCont will have something
			 ** to resolve. */
			(*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = _sqlite3VdbeMakeLabel(tls, pParse)
			(*TWhereRightJoin)(unsafe.Pointer(pRJ)).FendSubrtn = _sqlite3VdbeCurrentAddr(tls, v)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn, (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FaddrSubrtn, int32(1))
			nRJ = nRJ + 1
		}
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) != int32(OP_Noop) {
			if v3 = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == int32(WHERE_DISTINCT_ORDERED) && i == libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-int32(1) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_INDEXED) != uint32(0); v3 {
				v2 = (*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FpIndex
				pIdx = v2
			}
			if v5 = v3 && int32(uint32(*(*uint16)(unsafe.Pointer(v2 + 100))&0x100>>8)) != 0; v5 {
				v4 = libc.Int32FromUint16((*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FnDistinctCol)
				n = v4
			}
			if v5 && v4 > 0 && int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiRowLogEst + uintptr(n)*2))) >= int32(36) {
				r1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
				addrIfNull = 0 /* Init to avoid false-positive compiler warning */
				if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
					addrIfNull = _sqlite3VdbeAddOp2(tls, v, int32(OP_IfNullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, r1)
				}
				j = 0
				for {
					if !(j < n) {
						break
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, j, r1+j)
					goto _6
				_6:
					;
					j = j + 1
				}
				**(**int32)(__ccgo_up(pParse + 60)) += n + int32(1)
				if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) == int32(OP_Prev) {
					v4 = int32(OP_SeekLT)
				} else {
					v4 = int32(OP_SeekGT)
				}
				op = v4
				addrSeek = _sqlite3VdbeAddOp4Int(tls, v, op, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, 0, r1, n)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), int32(1), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2)
				if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
					_sqlite3VdbeJumpHere(tls, v, addrIfNull)
				}
			}
		}
		if int32(*(*uint32)(unsafe.Pointer(pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80 + 24 + 4))&0x2000>>13) != 0 {
			/* This is an EXISTS-to-JOIN optimization loop. If this loop sees a
			 ** successful row, it should break out of itself. */
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Goto), 0, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
		}
		_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
		if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) != int32(OP_Noop) {
			_sqlite3VdbeAddOp3(tls, v, libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2, libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fp3))
			_sqlite3VdbeChangeP5(tls, v, uint16((*TWhereLevel)(unsafe.Pointer(pLevel)).Fp5))
			if (*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull != 0 {
				_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_DecrJumpZero), (*TWhereLevel)(unsafe.Pointer(pLevel)).FregBignull, (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp2-int32(1))
			}
			if addrSeek != 0 {
				_sqlite3VdbeJumpHere(tls, v, addrSeek)
				addrSeek = 0
			}
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_ABLE) != uint32(0) && (*(*struct {
			FnIn     int32
			FaInLoop uintptr
		})(unsafe.Pointer(pLevel + 80))).FnIn > 0 {
			_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt)
			j1 = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 80))).FnIn
			pIn = (*(*struct {
				FnIn     int32
				FaInLoop uintptr
			})(unsafe.Pointer(pLevel + 80))).FaInLoop + uintptr(j1-int32(1))*20
			for {
				if !(j1 > 0) {
					break
				}
				_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop+int32(1))
				if libc.Int32FromUint8((*TInLoop)(unsafe.Pointer(pIn)).FeEndLoopOp) != int32(OP_Noop) {
					if (*TInLoop)(unsafe.Pointer(pIn)).FnPrefix != 0 {
						bEarlyOut = libc.BoolInt32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) == uint32(0) && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IN_EARLYOUT) != uint32(0))
						if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
							/* For LEFT JOIN queries, cursor pIn->iCur may not have been
							 ** opened yet. This occurs for WHERE clauses such as
							 ** "a = ? AND b IN (...)", where the index is on (a, b). If
							 ** the RHS of the (a=?) is NULL, then the "b IN (...)" may
							 ** never have been coded, but the body of the loop run to
							 ** return the null-row. So, if the cursor is not open yet,
							 ** jump over the OP_Next or OP_Prev instruction about to
							 ** be coded.  */
							_sqlite3VdbeAddOp2(tls, v, int32(OP_IfNotOpen), (*TInLoop)(unsafe.Pointer(pIn)).FiCur, _sqlite3VdbeCurrentAddr(tls, v)+int32(2)+bEarlyOut)
						}
						if bEarlyOut != 0 {
							_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IfNoHope), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, _sqlite3VdbeCurrentAddr(tls, v)+int32(2), (*TInLoop)(unsafe.Pointer(pIn)).FiBase, (*TInLoop)(unsafe.Pointer(pIn)).FnPrefix)
							/* Retarget the OP_IsNull against the left operand of IN so
							 ** it jumps past the OP_IfNoHope.  This is because the
							 ** OP_IsNull also bypasses the OP_Affinity opcode that is
							 ** required by OP_IfNoHope. */
							_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop+int32(1))
						}
					}
					_sqlite3VdbeAddOp2(tls, v, libc.Int32FromUint8((*TInLoop)(unsafe.Pointer(pIn)).FeEndLoopOp), (*TInLoop)(unsafe.Pointer(pIn)).FiCur, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop)
				}
				_sqlite3VdbeJumpHere(tls, v, (*TInLoop)(unsafe.Pointer(pIn)).FaddrInTop-int32(1))
				goto _8
			_8:
				;
				j1 = j1 - 1
				pIn -= 20
			}
		}
		_sqlite3VdbeResolveLabel(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Return), (*TWhereRightJoin)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ)).FregReturn, 0, int32(1))
		}
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip != 0 {
			_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip)
			_sqlite3VdbeJumpHere(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip)
			_sqlite3VdbeJumpHere(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip-int32(2))
		}
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
			ws = libc.Int32FromUint32((*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags)
			addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfPos), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
			if ws&int32(WHERE_IDX_ONLY) == 0 {
				pSrc = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000000>>25) != 0 {
					n1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 72)))).FregResult
					m = int32((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FnCol)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, n1, n1+m-int32(1))
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur)
			}
			if ws&int32(WHERE_INDEXED) != 0 || ws&int32(WHERE_MULTI_OR) != 0 && *(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu)) != 0 {
				if ws&int32(WHERE_MULTI_OR) != 0 {
					pIx = *(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu))
					iDb = _sqlite3SchemaToIndex(tls, db, (*TIndex)(unsafe.Pointer(pIx)).FpSchema)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_ReopenIdx), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pIx)).Ftnum), iDb)
					_sqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
				}
				_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
			}
			if libc.Int32FromUint8((*TWhereLevel)(unsafe.Pointer(pLevel)).Fop) == int32(OP_Return) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TWhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst)
			} else {
				_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst)
			}
			_sqlite3VdbeJumpHere(tls, v, addr)
		}
		goto _1
	_1:
		;
		i = i - 1
	}
	i = 0
	pLevel = pWInfo + 856
	for {
		if !(i < libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
			break
		}
		pIdx1 = uintptr(0)
		pTabItem = pTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
		pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		/* Do RIGHT JOIN processing.  Generate code that will output the
		 ** unmatched rows of the right operand of the RIGHT JOIN with
		 ** all of the columns of the left operand set to NULL.
		 */
		if (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			_sqlite3WhereRightJoinLoop(tls, pWInfo, i, pLevel)
			goto _9
		}
		/* For a co-routine, change all OP_Column references to the table of
		 ** the co-routine into OP_Copy of result contained in a register.
		 ** OP_Rowid becomes OP_Null.
		 */
		if int32(*(*uint32)(unsafe.Pointer(pTabItem + 24 + 4))&0x2000000>>25) != 0 {
			_translateColumnToCopy(tls, pParse, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody, (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTabItem + 72)))).FregResult, 0)
			goto _9
		}
		/* If this scan uses an index, make VDBE code substitutions to read data
		 ** from the index instead of from the table where possible.  In some cases
		 ** this optimization prevents the table from ever being read, which can
		 ** yield a significant performance boost.
		 **
		 ** Calls to the code generator in between sqlite3WhereBegin and
		 ** sqlite3WhereEnd will have created code that references the table
		 ** directly.  This loop scans all that code looking for opcodes
		 ** that reference the table and converts them into opcodes that
		 ** reference the index.
		 */
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_INDEXED)|libc.Int32FromInt32(WHERE_IDX_ONLY)) != 0 {
			pIdx1 = (*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FpIndex
		} else {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_MULTI_OR) != 0 {
				pIdx1 = *(*uintptr)(unsafe.Pointer(&(*TWhereLevel)(unsafe.Pointer(pLevel)).Fu))
			}
		}
		if pIdx1 != 0 && !((*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
			if libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF || !((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx1)).FpTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
				last = iEnd
			} else {
				last = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiEndWhere
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0x10>>4)) != 0 {
				p = (*TParse)(unsafe.Pointer(pParse)).FpIdxEpr
				for p != 0 {
					if (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur == (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur {
						(*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur = -int32(1)
						(*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur = -int32(1)
					}
					p = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
				}
			}
			k = (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody + int32(1)
			pOp = _sqlite3VdbeGetOp(tls, v, k)
			pLastOp = pOp + uintptr(last-k)*24
			for {
				if (*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 != (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur {
					/* no-op */
				} else {
					if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Column) || libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Offset) {
						x = (*TVdbeOp)(unsafe.Pointer(pOp)).Fp2
						if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Offset) {
							/* Do not need to translate the column number */
						} else {
							if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
								pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
								x = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(x)*2)))
							} else {
								x = int32(_sqlite3StorageColumnToTable(tls, pTab, int16(x)))
							}
						}
						x = _sqlite3TableColumnToIndex(tls, pIdx1, x)
						if x >= 0 {
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp2 = x
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
						} else {
							if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY)|libc.Int32FromInt32(WHERE_EXPRIDX)) != 0 {
								if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IDX_ONLY) != 0 {
									/* An error. pLoop is supposed to be a covering index loop,
									 ** and yet the VM code refers to a column of the table that
									 ** is not part of the index.  */
									_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24150, 0)
									(*TParse)(unsafe.Pointer(pParse)).Frc = int32(SQLITE_INTERNAL)
								} else {
									/* The WHERE_EXPRIDX flag is set by the planner when it is likely
									 ** that pLoop is a covering index loop, but it is not possible
									 ** to be 100% sure. In this case, any OP_Explain opcode
									 ** corresponding to this loop describes the index as a "COVERING
									 ** INDEX". But, pOp proves that pLoop is not actually a covering
									 ** index loop. So clear the WHERE_EXPRIDX flag and rewrite the
									 ** text that accompanies the OP_Explain opcode, if any.  */
									**(**Tu32)(__ccgo_up(pLoop + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(WHERE_EXPRIDX))
									_sqlite3WhereAddExplainText(tls, pParse, (*TWhereLevel)(unsafe.Pointer(pLevel)).FaddrBody-int32(1), pTabList, pLevel, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)
								}
							}
						}
					} else {
						if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_Rowid) {
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
							(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_IdxRowid)
						} else {
							if libc.Int32FromUint8((*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode) == int32(OP_IfNullRow) {
								(*TVdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
							}
						}
					}
				}
				goto _11
			_11:
				;
				pOp += 24
				v2 = pOp
				if !(v2 < pLastOp) {
					break
				}
			}
		}
		goto _9
	_9:
		;
		i = i + 1
		pLevel += 112
	}
	/* The "break" point is here, just past the end of the outer loop.
	 ** Set it.
	 */
	_sqlite3VdbeResolveLabel(tls, v, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
	/* Final cleanup
	 */
	(*TParse)(unsafe.Pointer(pParse)).FnQueryLoop = int16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop)
	_whereInfoFree(tls, db, pWInfo)
	v2 = pParse + 35
	*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) - nRJ)
	return
}

/************** End of where.c ***********************************************/
/************** Begin file window.c ******************************************/
/*
** 2018 May 08
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
 */
/* #include "sqliteInt.h" */

/*
** SELECT REWRITING
**
**   Any SELECT statement that contains one or more window functions in
**   either the select list or ORDER BY clause (the only two places window
**   functions may be used) is transformed by function sqlite3WindowRewrite()
**   in order to support window function processing. For example, with the
**   schema:
**
**     CREATE TABLE t1(a, b, c, d, e, f, g);
**
**   the statement:
**
**     SELECT a+1, max(b) OVER (PARTITION BY c ORDER BY d) FROM t1 ORDER BY e;
**
**   is transformed to:
**
**     SELECT a+1, max(b) OVER (PARTITION BY c ORDER BY d) FROM (
**         SELECT a, e, c, d, b FROM t1 ORDER BY c, d
**     ) ORDER BY e;
**
**   The flattening optimization is disabled when processing this transformed
**   SELECT statement. This allows the implementation of the window function
**   (in this case max()) to process rows sorted in order of (c, d), which
**   makes things easier for obvious reasons. More generally:
**
**     * FROM, WHERE, GROUP BY and HAVING clauses are all moved to
**       the sub-query.
**
**     * ORDER BY, LIMIT and OFFSET remain part of the parent query.
**
**     * Terminals from each of the expression trees that make up the
**       select-list and ORDER BY expressions in the parent query are
**       selected by the sub-query. For the purposes of the transformation,
**       terminals are column references and aggregate functions.
**
**   If there is more than one window function in the SELECT that uses
**   the same window declaration (the OVER bit), then a single scan may
**   be used to process more than one window function. For example:
**
**     SELECT max(b) OVER (PARTITION BY c ORDER BY d),
**            min(e) OVER (PARTITION BY c ORDER BY d)
**     FROM t1;
**
**   is transformed in the same way as the example above. However:
**
**     SELECT max(b) OVER (PARTITION BY c ORDER BY d),
**            min(e) OVER (PARTITION BY a ORDER BY b)
**     FROM t1;
**
**   Must be transformed to:
**
**     SELECT max(b) OVER (PARTITION BY c ORDER BY d) FROM (
**         SELECT e, min(e) OVER (PARTITION BY a ORDER BY b), c, d, b FROM
**           SELECT a, e, c, d, b FROM t1 ORDER BY a, b
**         ) ORDER BY c, d
**     ) ORDER BY e;
**
**   so that both min() and max() may process rows in the order defined by
**   their respective window declarations.
**
** INTERFACE WITH SELECT.C
**
**   When processing the rewritten SELECT statement, code in select.c calls
**   sqlite3WhereBegin() to begin iterating through the results of the
**   sub-query, which is always implemented as a co-routine. It then calls
**   sqlite3WindowCodeStep() to process rows and finish the scan by calling
**   sqlite3WhereEnd().
**
**   sqlite3WindowCodeStep() generates VM code so that, for each row returned
**   by the sub-query a sub-routine (OP_Gosub) coded by select.c is invoked.
**   When the sub-routine is invoked:
**
**     * The results of all window-functions for the row are stored
**       in the associated Window.regResult registers.
**
**     * The required terminal values are stored in the current row of
**       temp table Window.iEphCsr.
**
**   In some cases, depending on the window frame and the specific window
**   functions invoked, sqlite3WindowCodeStep() caches each entire partition
**   in a temp table before returning any rows. In other cases it does not.
**   This detail is encapsulated within this file, the code generated by
**   select.c is the same in either case.
**
** BUILT-IN WINDOW FUNCTIONS
**
**   This implementation features the following built-in window functions:
**
**     row_number()
**     rank()
**     dense_rank()
**     percent_rank()
**     cume_dist()
**     ntile(N)
**     lead(expr [, offset [, default]])
**     lag(expr [, offset [, default]])
**     first_value(expr)
**     last_value(expr)
**     nth_value(expr, N)
**
**   These are the same built-in window functions supported by Postgres.
**   Although the behaviour of aggregate window functions (functions that
**   can be used as either aggregates or window functions) allows them to
**   be implemented using an API, built-in window functions are much more
**   esoteric. Additionally, some window functions (e.g. nth_value())
**   may only be implemented by caching the entire partition in memory.
**   As such, some built-in window functions use the same API as aggregate
**   window functions and some are implemented directly using VDBE
**   instructions. Additionally, for those functions that use the API, the
**   window frame is sometimes modified before the SELECT statement is
**   rewritten. For example, regardless of the specified window frame, the
**   row_number() function always uses:
**
**     ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
**
**   See sqlite3WindowUpdate() for details.
**
**   As well as some of the built-in window functions, aggregate window
**   functions min() and max() are implemented using VDBE instructions if
**   the start of the window frame is declared as anything other than
**   UNBOUNDED PRECEDING.
 */

// C documentation
//
//	/*
//	** If the WHERE_GROUPBY flag is set in the mask passed to sqlite3WhereBegin(),
//	** the planner assumes that the specified pOrderBy list is actually a GROUP
//	** BY clause - and so any order that groups rows as required satisfies the
//	** request.
//	**
//	** Normally, in this case it is not possible for the caller to determine
//	** whether or not the rows are really being delivered in sorted order, or
//	** just in some other order that provides the required grouping. However,
//	** if the WHERE_SORTBYGROUP flag is also passed to sqlite3WhereBegin(), then
//	** this function may be called on the returned WhereInfo object. It returns
//	** true if the rows really will be sorted in the specified order, or false
//	** otherwise.
//	**
//	** For example, assuming:
//	**
//	**   CREATE INDEX i1 ON t1(x, Y);
//	**
//	** then
//	**
//	**   SELECT * FROM t1 GROUP BY x,y ORDER BY x,y;   -- IsSorted()==1
//	**   SELECT * FROM t1 GROUP BY y,x ORDER BY y,x;   -- IsSorted()==0
//	*/
func _sqlite3WhereIsSorted(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 68)) & 0x10 >> 4))
}

// C documentation
//
//	/*
//	** While generating code for the min/max optimization, after handling
//	** the aggregate-step call to min() or max(), check to see if any
//	** additional looping is required.  If the output order is such that
//	** we are certain that the correct answer has already been found, then
//	** code an OP_Goto to by pass subsequent processing.
//	**
//	** Any extra OP_Goto that is coded here is an optimization.  The
//	** correct answer should be obtained regardless.  This OP_Goto just
//	** makes the answer appear faster.
//	*/
func _sqlite3WhereMinMaxOptEarlyOut(tls *libc.TLS, v uintptr, pWInfo uintptr) {
	var i int32
	var pInner uintptr
	_, _ = i, pInner
	if !(int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 68))&0x20>>5)) != 0) {
		return
	}
	if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == 0 {
		return
	}
	i = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - int32(1)
	for {
		if !(i >= 0) {
			break
		}
		pInner = pWInfo + 856 + uintptr(i)*112
		if (*TWhereLoop)(unsafe.Pointer((*TWhereLevel)(unsafe.Pointer(pInner)).FpWLoop)).FwsFlags&uint32(WHERE_COLUMN_IN) != uint32(0) {
			_sqlite3VdbeGoto(tls, v, (*TWhereLevel)(unsafe.Pointer(pInner)).FaddrNxt)
			return
		}
		goto _1
	_1:
		;
		i = i - 1
	}
	_sqlite3VdbeGoto(tls, v, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
}

// C documentation
//
//	/*
//	** In the ORDER BY LIMIT optimization, if the inner-most loop is known
//	** to emit rows in increasing order, and if the last row emitted by the
//	** inner-most loop did not fit within the sorter, then we can skip all
//	** subsequent rows for the current iteration of the inner loop (because they
//	** will not fit in the sorter either) and continue with the second inner
//	** loop - the loop immediately outside the inner-most.
//	**
//	** When a row does not fit in the sorter (because the sorter already
//	** holds LIMIT+OFFSET rows that are smaller), then a jump is made to the
//	** label returned by this function.
//	**
//	** If the ORDER BY LIMIT optimization applies, the jump destination should
//	** be the continuation for the second-inner-most loop.  If the ORDER BY
//	** LIMIT optimization does not apply, then the jump destination should
//	** be the continuation for the inner-most loop.
//	**
//	** It is always safe for this routine to return the continuation of the
//	** inner-most loop, in the sense that a correct answer will result.
//	** Returning the continuation the second inner loop is an optimization
//	** that might make the code run a little faster, but should not change
//	** the final answer.
//	*/
func _sqlite3WhereOrderByLimitOptLabel(tls *libc.TLS, pWInfo uintptr) (r int32) {
	var pInner uintptr
	var v1 int32
	_, _ = pInner, v1
	if !(int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 68))&0x20>>5)) != 0) {
		/* The ORDER BY LIMIT optimization does not apply.  Jump to the
		 ** continuation of the inner-most loop. */
		return (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
	}
	pInner = pWInfo + 856 + uintptr(libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-int32(1))*112
	if (*TWhereLevel)(unsafe.Pointer(pInner)).FpRJ != 0 {
		v1 = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
	} else {
		v1 = (*TWhereLevel)(unsafe.Pointer(pInner)).FaddrNxt
	}
	return v1
}

// C documentation
//
//	/*
//	** Generate the code for the loop that finds all non-matched terms
//	** for a RIGHT JOIN.
//	*/
func _sqlite3WhereRightJoinLoop(tls *libc.TLS, pWInfo uintptr, iLevel int32, pLevel uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var addrCont, iCol, iCur, iIdxCur, iPk, jmp, k, nPk, r, v3 int32
	var mAll TBitmask
	var pFrom, pLoop, pParse, pPk, pRJ, pRight, pSubWInfo, pSubWhere, pSubq, pTab, pTabItem, pTerm, pWC, v, v4 uintptr
	var _ /* uSrc at bp+0 */ struct {
		FfromSpace   [0][88]Tu8
		FsSrc        TSrcList
		F__ccgo_pad2 [80]byte
	}
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addrCont, iCol, iCur, iIdxCur, iPk, jmp, k, mAll, nPk, pFrom, pLoop, pParse, pPk, pRJ, pRight, pSubWInfo, pSubWhere, pSubq, pTab, pTabItem, pTerm, pWC, r, v, v3, v4
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	pRJ = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	pSubWhere = uintptr(0)
	pWC = pWInfo + 104
	pLoop = (*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	pTabItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80
	mAll = uint64(0)
	_sqlite3VdbeExplain(tls, pParse, uint8(1), __ccgo_ts+23924, libc.VaList(bp+96, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab)).FzName))
	k = 0
	for {
		if !(k < iLevel) {
			break
		}
		pRight = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FiFrom)*80
		mAll = mAll | (*TWhereLoop)(unsafe.Pointer((*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FpWLoop)).FmaskSelf
		if int32(*(*uint32)(unsafe.Pointer(pRight + 24 + 4))&0x2000000>>25) != 0 {
			pSubq = *(*uintptr)(unsafe.Pointer(pRight + 72))
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Null), 0, (*TSubquery)(unsafe.Pointer(pSubq)).FregResult, (*TSubquery)(unsafe.Pointer(pSubq)).FregResult+(*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(pSubq)).FpSelect)).FpEList)).FnExpr-int32(1))
		}
		_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FiTabCur)
		iIdxCur = (*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*112))).FiIdxCur
		if iIdxCur != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), iIdxCur)
		}
		goto _1
	_1:
		;
		k = k + 1
	}
	if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&int32(JT_LTORJ) == 0 {
		mAll = mAll | (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		k = 0
		for {
			if !(k < (*TWhereClause)(unsafe.Pointer(pWC)).FnTerm) {
				break
			}
			pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(k)*56
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(libc.Int32FromInt32(TERM_VIRTUAL)|libc.Int32FromInt32(TERM_SLICE)) != 0 && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) != int32(WO_ROWVAL) {
				break
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll & ^mAll != 0 {
				goto _2
			}
			if (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_OuterON)|libc.Int32FromInt32(EP_InnerON)) != uint32(0) {
				goto _2
			}
			pSubWhere = _sqlite3ExprAnd(tls, pParse, pSubWhere, _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr, 0))
			goto _2
		_2:
			;
			k = k + 1
		}
	}
	if (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur != 0 {
		/* pSubWhere may contain expressions that read from an index on the
		 ** table on the RHS of the right join. All such expressions first test
		 ** if the index is pointing at a NULL row, and if so, read from the
		 ** table cursor instead. So ensure that the index cursor really is
		 ** pointing at a NULL row here, so that no values are read from it during
		 ** the scan of the RHS of the RIGHT join below.  */
		_sqlite3VdbeAddOp1(tls, v, int32(OP_NullRow), (*TWhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
	}
	pFrom = bp
	(*TSrcList)(unsafe.Pointer(pFrom)).FnSrc = int32(1)
	(*TSrcList)(unsafe.Pointer(pFrom)).FnAlloc = uint32(1)
	libc.Xmemcpy(tls, pFrom+8, pTabItem, uint64(80))
	(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).Ffg.Fjointype = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn + 1
	pSubWInfo = _sqlite3WhereBegin(tls, pParse, pFrom, pSubWhere, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_RIGHT_JOIN), 0)
	if pSubWInfo != 0 {
		iCur = (*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
		v4 = pParse + 60
		*(*int32)(unsafe.Pointer(v4)) = *(*int32)(unsafe.Pointer(v4)) + 1
		v3 = *(*int32)(unsafe.Pointer(v4))
		r = v3
		addrCont = _sqlite3WhereContinueLabel(tls, pSubWInfo)
		pTab = (*TSrcItem)(unsafe.Pointer(pTabItem)).FpSTab
		if (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
			_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, -int32(1), r)
			nPk = int32(1)
		} else {
			pPk = _sqlite3PrimaryKeyIndex(tls, pTab)
			nPk = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pPk)).FnKeyCol)
			**(**int32)(__ccgo_up(pParse + 60)) += nPk - int32(1)
			iPk = 0
			for {
				if !(iPk < nPk) {
					break
				}
				iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iPk)*2)))
				_sqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
				goto _5
			_5:
				;
				iPk = iPk + 1
			}
		}
		jmp = _sqlite3VdbeAddOp4Int(tls, v, int32(OP_Filter), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom, 0, r, nPk)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, addrCont, r, nPk)
		_sqlite3VdbeJumpHere(tls, v, jmp)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn, (*TWhereRightJoin)(unsafe.Pointer(pRJ)).FaddrSubrtn)
		_sqlite3WhereEnd(tls, pSubWInfo)
	}
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSubWhere)
	_sqlite3VdbeExplainPop(tls, pParse)
	(*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn = (*TParse)(unsafe.Pointer(pParse)).FwithinRJSubrtn - 1
}

// C documentation
//
//	/*
//	** For table-valued-functions, transform the function arguments into
//	** new WHERE clause terms.
//	**
//	** Each function argument translates into an equality constraint against
//	** a HIDDEN column in the table.
//	*/
func _sqlite3WhereTabFuncArgs(tls *libc.TLS, pParse uintptr, pItem uintptr, pWC uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var j, k, v2 int32
	var joinType Tu32
	var pArgs, pColRef, pRhs, pTab, pTerm uintptr
	_, _, _, _, _, _, _, _, _ = j, joinType, k, pArgs, pColRef, pRhs, pTab, pTerm, v2
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000000>>28) == 0 {
		return
	}
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
	pArgs = *(*uintptr)(unsafe.Pointer(pItem + 48))
	if pArgs == uintptr(0) {
		return
	}
	v2 = libc.Int32FromInt32(0)
	k = v2
	j = v2
	for {
		if !(j < (*TExprList)(unsafe.Pointer(pArgs)).FnExpr) {
			break
		}
		for k < int32((*TTable)(unsafe.Pointer(pTab)).FnCol) && libc.Int32FromUint16((**(**TColumn)(__ccgo_up((*TTable)(unsafe.Pointer(pTab)).FaCol + uintptr(k)*16))).FcolFlags)&int32(COLFLAG_HIDDEN) == 0 {
			k = k + 1
		}
		if k >= int32((*TTable)(unsafe.Pointer(pTab)).FnCol) {
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+23952, libc.VaList(bp+8, (*TTable)(unsafe.Pointer(pTab)).FzName, j))
			return
		}
		pColRef = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_COLUMN), uintptr(0), 0)
		if pColRef == uintptr(0) {
			return
		}
		(*TExpr)(unsafe.Pointer(pColRef)).FiTable = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
		v2 = k
		k = k + 1
		(*TExpr)(unsafe.Pointer(pColRef)).FiColumn = int16(v2)
		*(*uintptr)(unsafe.Pointer(pColRef + 64)) = pTab
		**(**TBitmask)(__ccgo_up(pItem + 40)) |= _sqlite3ExprColUsed(tls, pColRef)
		pRhs = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), _sqlite3ExprDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*(*TExprList_item)(unsafe.Pointer(pArgs + 8 + uintptr(j)*32))).FpExpr, 0), uintptr(0))
		pTerm = _sqlite3PExpr(tls, pParse, int32(TK_EQ), pColRef, pRhs)
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_RIGHT)) != 0 {
			/* testtag-20230227a */
			/* testtag-20230227b */
			joinType = uint32(EP_OuterON)
		} else {
			/* testtag-20230227c */
			joinType = uint32(EP_InnerON)
		}
		_sqlite3SetJoinExpr(tls, pTerm, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor, joinType)
		_whereClauseInsert(tls, pWC, pTerm, uint16(TERM_DYNAMIC))
		goto _1
	_1:
		;
		j = j + 1
	}
}

/************** End of whereexpr.c *******************************************/
/************** Begin file where.c *******************************************/
/*
** 2001 September 15
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is responsible for
** generating the code that loops through a table looking for applicable
** rows.  Indices are selected and used to speed the search when doing
** so is applicable.  Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
 */
/* #include "sqliteInt.h" */
/* #include "whereInt.h" */

// C documentation
//
//	/*
//	** Return TRUE if the WHERE loop uses the OP_DeferredSeek opcode to move
//	** the data cursor to the row selected by the index cursor.
//	*/
func _sqlite3WhereUsesDeferredSeek(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 68)) & 0x80 >> 7))
}

// C documentation
//
//	/*
//	** If the SELECT statement passed as the second argument does not invoke
//	** any SQL window functions, this function is a no-op. Otherwise, it
//	** rewrites the SELECT statement so that window function xStep functions
//	** are invoked in the correct order as described under "SELECT REWRITING"
//	** at the top of this file.
//	*/
func _sqlite3WindowRewrite(tls *libc.TLS, pParse uintptr, p uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var db, pArgs, pFilter, pGroupBy, pHaving, pMWin, pSort, pSrc, pSub, pTab, pTab2, pWhere, pWin, v, v2 uintptr
	var nSave, rc, v1 int32
	var selFlags Tu32
	var _ /* pSublist at bp+0 */ uintptr
	var _ /* w at bp+8 */ TWalker
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = db, nSave, pArgs, pFilter, pGroupBy, pHaving, pMWin, pSort, pSrc, pSub, pTab, pTab2, pWhere, pWin, rc, selFlags, v, v1, v2
	rc = SQLITE_OK
	if (*TSelect)(unsafe.Pointer(p)).FpWin != 0 && (*TSelect)(unsafe.Pointer(p)).FpPrior == uintptr(0) && (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_WinRewrite) == uint32(0) && !(libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= libc.Int32FromInt32(PARSE_MODE_RENAME)) {
		v = _sqlite3GetVdbe(tls, pParse)
		db = (*TParse)(unsafe.Pointer(pParse)).Fdb
		pSub = uintptr(0) /* The subquery */
		pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
		pWhere = (*TSelect)(unsafe.Pointer(p)).FpWhere
		pGroupBy = (*TSelect)(unsafe.Pointer(p)).FpGroupBy
		pHaving = (*TSelect)(unsafe.Pointer(p)).FpHaving
		pSort = uintptr(0)
		**(**uintptr)(__ccgo_up(bp)) = uintptr(0) /* Expression list for sub-query */
		pMWin = (*TSelect)(unsafe.Pointer(p)).FpWin
		selFlags = (*TSelect)(unsafe.Pointer(p)).FselFlags
		pTab = _sqlite3DbMallocZero(tls, db, uint64(120))
		if pTab == uintptr(0) {
			return _sqlite3ErrorToParser(tls, db, int32(SQLITE_NOMEM))
		}
		_sqlite3AggInfoPersistWalkerInit(tls, bp+8, pParse)
		_sqlite3WalkSelect(tls, bp+8, p)
		if (*TSelect)(unsafe.Pointer(p)).FselFlags&uint32(SF_Aggregate) == uint32(0) {
			(**(**TWalker)(__ccgo_up(bp + 8))).FxExprCallback = __ccgo_fp(_disallowAggregatesInOrderByCb)
			(**(**TWalker)(__ccgo_up(bp + 8))).FxSelectCallback = uintptr(0)
			_sqlite3WalkExprList(tls, bp+8, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
		}
		(*TSelect)(unsafe.Pointer(p)).FpSrc = uintptr(0)
		(*TSelect)(unsafe.Pointer(p)).FpWhere = uintptr(0)
		(*TSelect)(unsafe.Pointer(p)).FpGroupBy = uintptr(0)
		(*TSelect)(unsafe.Pointer(p)).FpHaving = uintptr(0)
		**(**Tu32)(__ccgo_up(p + 4)) &= ^libc.Uint32FromInt32(SF_Aggregate)
		**(**Tu32)(__ccgo_up(p + 4)) |= uint32(SF_WinRewrite)
		/* Create the ORDER BY clause for the sub-select. This is the concatenation
		 ** of the window PARTITION and ORDER BY clauses. Then, if this makes it
		 ** redundant, remove the ORDER BY from the parent SELECT.  */
		pSort = _exprListAppendList(tls, pParse, uintptr(0), (*TWindow)(unsafe.Pointer(pMWin)).FpPartition, int32(1))
		pSort = _exprListAppendList(tls, pParse, pSort, (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy, int32(1))
		if pSort != 0 && (*TSelect)(unsafe.Pointer(p)).FpOrderBy != 0 && (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy)).FnExpr <= (*TExprList)(unsafe.Pointer(pSort)).FnExpr {
			nSave = (*TExprList)(unsafe.Pointer(pSort)).FnExpr
			(*TExprList)(unsafe.Pointer(pSort)).FnExpr = (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpOrderBy)).FnExpr
			if _sqlite3ExprListCompare(tls, pSort, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, -int32(1)) == 0 {
				_sqlite3ExprListDelete(tls, db, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
				(*TSelect)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
			}
			(*TExprList)(unsafe.Pointer(pSort)).FnExpr = nSave
		}
		/* Assign a cursor number for the ephemeral table used to buffer rows.
		 ** The OpenEphemeral instruction is coded later, after it is known how
		 ** many columns the table will have.  */
		v2 = pParse + 56
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		(*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr = v1
		**(**int32)(__ccgo_up(pParse + 56)) += int32(3)
		_selectWindowRewriteEList(tls, pParse, pMWin, pSrc, (*TSelect)(unsafe.Pointer(p)).FpEList, pTab, bp)
		_selectWindowRewriteEList(tls, pParse, pMWin, pSrc, (*TSelect)(unsafe.Pointer(p)).FpOrderBy, pTab, bp)
		if **(**uintptr)(__ccgo_up(bp)) != 0 {
			v1 = (*TExprList)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnExpr
		} else {
			v1 = 0
		}
		(*TWindow)(unsafe.Pointer(pMWin)).FnBufferCol = v1
		/* Append the PARTITION BY and ORDER BY expressions to the to the
		 ** sub-select expression list. They are required to figure out where
		 ** boundaries for partitions and sets of peer rows lie.  */
		**(**uintptr)(__ccgo_up(bp)) = _exprListAppendList(tls, pParse, **(**uintptr)(__ccgo_up(bp)), (*TWindow)(unsafe.Pointer(pMWin)).FpPartition, 0)
		**(**uintptr)(__ccgo_up(bp)) = _exprListAppendList(tls, pParse, **(**uintptr)(__ccgo_up(bp)), (*TWindow)(unsafe.Pointer(pMWin)).FpOrderBy, 0)
		/* Append the arguments passed to each window function to the
		 ** sub-select expression list. Also allocate two registers for each
		 ** window function - one for the accumulator, another for interim
		 ** results.  */
		pWin = pMWin
		for {
			if !(pWin != 0) {
				break
			}
			pArgs = *(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 32))
			if (*TFuncDef)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpWFunc)).FfuncFlags&uint32(SQLITE_SUBTYPE) != 0 {
				_selectWindowRewriteEList(tls, pParse, pMWin, pSrc, pArgs, pTab, bp)
				if **(**uintptr)(__ccgo_up(bp)) != 0 {
					v1 = (*TExprList)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnExpr
				} else {
					v1 = 0
				}
				(*TWindow)(unsafe.Pointer(pWin)).FiArgCol = v1
				(*TWindow)(unsafe.Pointer(pWin)).FbExprArgs = uint8(1)
			} else {
				if **(**uintptr)(__ccgo_up(bp)) != 0 {
					v1 = (*TExprList)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FnExpr
				} else {
					v1 = 0
				}
				(*TWindow)(unsafe.Pointer(pWin)).FiArgCol = v1
				**(**uintptr)(__ccgo_up(bp)) = _exprListAppendList(tls, pParse, **(**uintptr)(__ccgo_up(bp)), pArgs, 0)
			}
			if (*TWindow)(unsafe.Pointer(pWin)).FpFilter != 0 {
				pFilter = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(pWin)).FpFilter, 0)
				**(**uintptr)(__ccgo_up(bp)) = _sqlite3ExprListAppend(tls, pParse, **(**uintptr)(__ccgo_up(bp)), pFilter)
			}
			v2 = pParse + 60
			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
			v1 = *(*int32)(unsafe.Pointer(v2))
			(*TWindow)(unsafe.Pointer(pWin)).FregAccum = v1
			v2 = pParse + 60
			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
			v1 = *(*int32)(unsafe.Pointer(v2))
			(*TWindow)(unsafe.Pointer(pWin)).FregResult = v1
			_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregAccum)
			goto _4
		_4:
			;
			pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
		}
		/* If there is no ORDER BY or PARTITION BY clause, and the window
		 ** function accepts zero arguments, and there are no other columns
		 ** selected (e.g. "SELECT row_number() OVER () FROM t1"), it is possible
		 ** that pSublist is still NULL here. Add a constant expression here to
		 ** keep everything legal in this case.
		 */
		if **(**uintptr)(__ccgo_up(bp)) == uintptr(0) {
			**(**uintptr)(__ccgo_up(bp)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), _sqlite3ExprInt32(tls, db, 0))
		}
		pSub = _sqlite3SelectNew(tls, pParse, **(**uintptr)(__ccgo_up(bp)), pSrc, pWhere, pGroupBy, pHaving, pSort, uint32(0), uintptr(0))
		(*TSelect)(unsafe.Pointer(p)).FpSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
		/* Due to db->mallocFailed test inside
		 ** of sqlite3DbMallocRawNN() called from
		 ** sqlite3SrcListAppend() */
		if (*TSelect)(unsafe.Pointer(p)).FpSrc == uintptr(0) {
			_sqlite3SelectDelete(tls, db, pSub)
		} else {
			if _sqlite3SrcItemAttachSubquery(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpSrc+8, pSub, 0) != 0 {
				libc.SetBitFieldPtr32Uint32((*TSelect)(unsafe.Pointer(p)).FpSrc+8+24+4, libc.Uint32FromInt32(1), 27, 0x8000000)
				_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpSrc)
				**(**Tu32)(__ccgo_up(pSub + 4)) |= libc.Uint32FromInt32(libc.Int32FromInt32(SF_Expanded) | libc.Int32FromInt32(SF_OrderByReqd))
				pTab2 = _sqlite3ResultSetOfSelect(tls, pParse, pSub, uint8(SQLITE_AFF_NONE))
				**(**Tu32)(__ccgo_up(pSub + 4)) |= selFlags & uint32(SF_Aggregate)
				if pTab2 == uintptr(0) {
					/* Might actually be some other kind of error, but in that case
					 ** pParse->nErr will be set, so if SQLITE_NOMEM is set, we will get
					 ** the correct error message regardless. */
					rc = int32(SQLITE_NOMEM)
				} else {
					libc.Xmemcpy(tls, pTab, pTab2, uint64(120))
					**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_Ephemeral)
					(*(*TSrcItem)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpSrc + 8))).FpSTab = pTab
					pTab = pTab2
					libc.Xmemset(tls, bp+8, 0, uint64(48))
					(**(**TWalker)(__ccgo_up(bp + 8))).FxExprCallback = __ccgo_fp(_sqlite3WindowExtraAggFuncDepth)
					(**(**TWalker)(__ccgo_up(bp + 8))).FxSelectCallback = __ccgo_fp(_sqlite3WalkerDepthIncrease)
					(**(**TWalker)(__ccgo_up(bp + 8))).FxSelectCallback2 = __ccgo_fp(_sqlite3WalkerDepthDecrease)
					_sqlite3WalkSelect(tls, bp+8, pSub)
				}
			}
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			rc = int32(SQLITE_NOMEM)
		}
		/* Defer deleting the temporary table pTab because if an error occurred,
		 ** there could still be references to that table embedded in the
		 ** result-set or ORDER BY clause of the SELECT statement p.  */
		_sqlite3ParserAddCleanup(tls, pParse, __ccgo_fp(_sqlite3DbFree), pTab)
	}
	return rc
}

// C documentation
//
//	/*
//	** Assign new cursor numbers to each of the items in pSrc. For each
//	** new cursor number assigned, set an entry in the aCsrMap[] array
//	** to map the old cursor number to the new:
//	**
//	**     aCsrMap[iOld+1] = iNew;
//	**
//	** The array is guaranteed by the caller to be large enough for all
//	** existing cursor numbers in pSrc.  aCsrMap[0] is the array size.
//	**
//	** If pSrc contains any sub-selects, call this routine recursively
//	** on the FROM clause of each such sub-select, with iExcept set to -1.
//	*/
func _srclistRenumberCursors(tls *libc.TLS, pParse uintptr, aCsrMap uintptr, pSrc uintptr, iExcept int32) {
	var i, v2 int32
	var p, pItem, v3 uintptr
	_, _, _, _, _ = i, p, pItem, v2, v3
	i = 0
	pItem = pSrc + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		if i != iExcept {
			if !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x1000000>>24) != 0) || **(**int32)(__ccgo_up(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4)) == 0 {
				v3 = pParse + 56
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				**(**int32)(__ccgo_up(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4)) = v2
			}
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = **(**int32)(__ccgo_up(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4))
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
				p = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect
				for {
					if !(p != 0) {
						break
					}
					_srclistRenumberCursors(tls, pParse, aCsrMap, (*TSelect)(unsafe.Pointer(p)).FpSrc, -int32(1))
					goto _4
				_4:
					;
					p = (*TSelect)(unsafe.Pointer(p)).FpPrior
				}
			}
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 80
	}
}

// C documentation
//
//	/*
//	**    strftime( FORMAT, TIMESTRING, MOD, MOD, ...)
//	**
//	** Return a string described by FORMAT.  Conversions as follows:
//	**
//	**   %d  day of month  01-31
//	**   %e  day of month  1-31
//	**   %f  ** fractional seconds  SS.SSS
//	**   %F  ISO date.  YYYY-MM-DD
//	**   %G  ISO year corresponding to %V 0000-9999.
//	**   %g  2-digit ISO year corresponding to %V 00-99
//	**   %H  hour 00-24
//	**   %k  hour  0-24  (leading zero converted to space)
//	**   %I  hour 01-12
//	**   %j  day of year 001-366
//	**   %J  ** julian day number
//	**   %l  hour  1-12  (leading zero converted to space)
//	**   %m  month 01-12
//	**   %M  minute 00-59
//	**   %p  "AM" or "PM"
//	**   %P  "am" or "pm"
//	**   %R  time as HH:MM
//	**   %s  seconds since 1970-01-01
//	**   %S  seconds 00-59
//	**   %T  time as HH:MM:SS
//	**   %u  day of week 1-7  Monday==1, Sunday==7
//	**   %w  day of week 0-6  Sunday==0, Monday==1
//	**   %U  week of year 00-53  (First Sunday is start of week 01)
//	**   %V  week of year 01-53  (First week containing Thursday is week 01)
//	**   %W  week of year 00-53  (First Monday is start of week 01)
//	**   %Y  year 0000-9999
//	**   %%  %
//	*/
func _strftimeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(208)
	defer tls.Free(208)
	var c, cf uint8
	var db, zFmt, v3 uintptr
	var h int32
	var i, j, v2 Tsize_t
	var iS Ti64
	var s float64
	var _ /* sRes at bp+48 */ Tsqlite3_str
	var _ /* x at bp+0 */ TDateTime
	var _ /* y at bp+128 */ TDateTime
	var _ /* y at bp+80 */ TDateTime
	_, _, _, _, _, _, _, _, _, _, _ = c, cf, db, h, i, iS, j, s, zFmt, v2, v3
	if argc == 0 {
		return
	}
	zFmt = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	if zFmt == uintptr(0) || _isDate(tls, context, argc-int32(1), argv+uintptr(1)*8, bp) != 0 {
		return
	}
	db = Xsqlite3_context_db_handle(tls, context)
	_sqlite3StrAccumInit(tls, bp+48, uintptr(0), uintptr(0), 0, **(**int32)(__ccgo_up(db + 136)))
	_computeJD(tls, bp)
	_computeYMD_HMS(tls, bp)
	v2 = libc.Uint64FromInt32(0)
	j = v2
	i = v2
	for {
		if !(**(**uint8)(__ccgo_up(zFmt + uintptr(i))) != 0) {
			break
		}
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(zFmt + uintptr(i)))) != int32('%') {
			goto _1
		}
		if j < i {
			Xsqlite3_str_append(tls, bp+48, zFmt+uintptr(j), libc.Int32FromUint64(i-j))
		}
		i = i + 1
		j = i + uint64(1)
		cf = **(**uint8)(__ccgo_up(zFmt + uintptr(i)))
		switch libc.Int32FromUint8(cf) {
		case int32('d'): /* Fall thru */
			fallthrough
		case int32('e'):
			if libc.Int32FromUint8(cf) == int32('d') {
				v3 = __ccgo_ts + 1391
			} else {
				v3 = __ccgo_ts + 1396
			}
			Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).FD))
		case int32('f'): /* Fractional seconds.  (Non-standard) */
			s = (**(**TDateTime)(__ccgo_up(bp))).Fs
			if s > float64(59.999) {
				s = float64(59.999)
			}
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1400, libc.VaList(bp+184, s))
		case int32('F'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1407, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).FY, (**(**TDateTime)(__ccgo_up(bp))).FM, (**(**TDateTime)(__ccgo_up(bp))).FD))
		case int32('G'): /* Fall thru */
			fallthrough
		case int32('g'):
			**(**TDateTime)(__ccgo_up(bp + 80)) = **(**TDateTime)(__ccgo_up(bp))
			/* Move y so that it is the Thursday in the same week as x */
			(**(**TDateTime)(__ccgo_up(bp + 80))).FiJD += int64((int32(3) - _daysAfterMonday(tls, bp)) * int32(86400000))
			(**(**TDateTime)(__ccgo_up(bp + 80))).FvalidYMD = uint8(0)
			_computeYMD(tls, bp+80)
			if libc.Int32FromUint8(cf) == int32('g') {
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp + 80))).FY%int32(100)))
			} else {
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1422, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp + 80))).FY))
			}
		case int32('H'):
			fallthrough
		case int32('k'):
			if libc.Int32FromUint8(cf) == int32('H') {
				v3 = __ccgo_ts + 1391
			} else {
				v3 = __ccgo_ts + 1396
			}
			Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).Fh))
		case int32('I'): /* Fall thru */
			fallthrough
		case int32('l'):
			h = (**(**TDateTime)(__ccgo_up(bp))).Fh
			if h > int32(12) {
				h = h - int32(12)
			}
			if h == 0 {
				h = int32(12)
			}
			if libc.Int32FromUint8(cf) == int32('I') {
				v3 = __ccgo_ts + 1391
			} else {
				v3 = __ccgo_ts + 1396
			}
			Xsqlite3_str_appendf(tls, bp+48, v3, libc.VaList(bp+184, h))
		case int32('j'): /* Day of year.  Jan01==1, Jan02==2, and so forth */
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1427, libc.VaList(bp+184, _daysAfterJan01(tls, bp)+int32(1)))
		case int32('J'): /* Julian day number.  (Non-standard) */
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1432, libc.VaList(bp+184, float64((**(**TDateTime)(__ccgo_up(bp))).FiJD)/float64(8.64e+07)))
		case int32('m'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).FM))
		case int32('M'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).Fm))
		case int32('p'): /* Fall thru */
			fallthrough
		case int32('P'):
			if (**(**TDateTime)(__ccgo_up(bp))).Fh >= int32(12) {
				if libc.Int32FromUint8(cf) == int32('p') {
					v3 = __ccgo_ts + 1438
				} else {
					v3 = __ccgo_ts + 1441
				}
				Xsqlite3_str_append(tls, bp+48, v3, int32(2))
			} else {
				if libc.Int32FromUint8(cf) == int32('p') {
					v3 = __ccgo_ts + 1444
				} else {
					v3 = __ccgo_ts + 1447
				}
				Xsqlite3_str_append(tls, bp+48, v3, int32(2))
			}
		case int32('R'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1450, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).Fh, (**(**TDateTime)(__ccgo_up(bp))).Fm))
		case int32('s'):
			if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x20>>5)) != 0 {
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1460, libc.VaList(bp+184, float64((**(**TDateTime)(__ccgo_up(bp))).FiJD-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000000))/float64(1000)))
			} else {
				iS = (**(**TDateTime)(__ccgo_up(bp))).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000)
				Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1465, libc.VaList(bp+184, iS))
			}
		case int32('S'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, int32((**(**TDateTime)(__ccgo_up(bp))).Fs)))
		case int32('T'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1470, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).Fh, (**(**TDateTime)(__ccgo_up(bp))).Fm, int32((**(**TDateTime)(__ccgo_up(bp))).Fs)))
		case int32('u'): /* Day of week.  1 to 7.  Monday==1, Sunday==7 */
			fallthrough
		case int32('w'): /* Day of week.  0 to 6.  Sunday==0, Monday==1 */
			c = libc.Uint8FromInt32(libc.Int32FromUint8(libc.Uint8FromInt32(_daysAfterSunday(tls, bp))) + int32('0'))
			if libc.Int32FromUint8(c) == int32('0') && libc.Int32FromUint8(cf) == int32('u') {
				c = uint8('7')
			}
			Xsqlite3_str_appendchar(tls, bp+48, int32(1), c)
		case int32('U'): /* Week num. 00-53. First Sun of the year is week 01 */
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, (_daysAfterJan01(tls, bp)-_daysAfterSunday(tls, bp)+int32(7))/int32(7)))
		case int32('V'): /* Week num. 01-53. First week with a Thur is week 01 */
			**(**TDateTime)(__ccgo_up(bp + 128)) = **(**TDateTime)(__ccgo_up(bp))
			/* Adjust y so that is the Thursday in the same week as x */
			(**(**TDateTime)(__ccgo_up(bp + 128))).FiJD += int64((int32(3) - _daysAfterMonday(tls, bp)) * int32(86400000))
			(**(**TDateTime)(__ccgo_up(bp + 128))).FvalidYMD = uint8(0)
			_computeYMD(tls, bp+128)
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, _daysAfterJan01(tls, bp+128)/int32(7)+int32(1)))
		case int32('W'): /* Week num. 00-53. First Mon of the year is week 01 */
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1391, libc.VaList(bp+184, (_daysAfterJan01(tls, bp)-_daysAfterMonday(tls, bp)+int32(7))/int32(7)))
		case int32('Y'):
			Xsqlite3_str_appendf(tls, bp+48, __ccgo_ts+1422, libc.VaList(bp+184, (**(**TDateTime)(__ccgo_up(bp))).FY))
		case int32('%'):
			Xsqlite3_str_appendchar(tls, bp+48, int32(1), uint8('%'))
		default:
			Xsqlite3_str_reset(tls, bp+48)
			return
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if j < i {
		Xsqlite3_str_append(tls, bp+48, zFmt+uintptr(j), libc.Int32FromUint64(i-j))
	}
	_sqlite3ResultStrAccum(tls, context, bp+48)
}

func _substSelect(tls *libc.TLS, pSubst uintptr, p uintptr, doPrior int32) {
	var i int32
	var pItem, pSrc, v1 uintptr
	var v2 bool
	_, _, _, _, _ = i, pItem, pSrc, v1, v2
	if !(p != 0) {
		return
	}
	(*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth = (*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth + 1
	for {
		_substExprList(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpEList)
		_substExprList(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpGroupBy)
		_substExprList(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
		(*TSelect)(unsafe.Pointer(p)).FpHaving = _substExpr(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpHaving)
		(*TSelect)(unsafe.Pointer(p)).FpWhere = _substExpr(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpWhere)
		pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
		i = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
		pItem = pSrc + 8
		for {
			if !(i > 0) {
				break
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) != 0 {
				_substSelect(tls, pSubst, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect, int32(1))
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x10000000>>28) != 0 {
				_substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pItem + 48)))
			}
			goto _4
		_4:
			;
			i = i - 1
			pItem += 80
		}
		goto _3
	_3:
		;
		if v2 = doPrior != 0; v2 {
			v1 = (*TSelect)(unsafe.Pointer(p)).FpPrior
			p = v1
		}
		if !(v2 && v1 != uintptr(0)) {
			break
		}
	}
	(*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth = (*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth - 1
}

// C documentation
//
//	/*
//	**    time( TIMESTRING, MOD, MOD, ...)
//	**
//	** Return HH:MM:SS
//	*/
func _timeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var n, s int32
	var _ /* x at bp+0 */ TDateTime
	var _ /* zBuf at bp+48 */ [16]uint8
	_, _ = n, s
	if _isDate(tls, context, argc, argv, bp) == 0 {
		_computeHMS(tls, bp)
		(**(**[16]uint8)(__ccgo_up(bp + 48)))[0] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fh/int32(10)%int32(10))
		(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(1)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fh%int32(10))
		(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(2)] = uint8(':')
		(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(3)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fm/int32(10)%int32(10))
		(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(4)] = libc.Uint8FromInt32(int32('0') + (**(**TDateTime)(__ccgo_up(bp))).Fm%int32(10))
		(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(5)] = uint8(':')
		if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x20>>5)) != 0 {
			s = int32(float64(libc.Float64FromFloat64(1000)*(**(**TDateTime)(__ccgo_up(bp))).Fs) + libc.Float64FromFloat64(0.5))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(6)] = libc.Uint8FromInt32(int32('0') + s/int32(10000)%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(7)] = libc.Uint8FromInt32(int32('0') + s/int32(1000)%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(8)] = uint8('.')
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(9)] = libc.Uint8FromInt32(int32('0') + s/int32(100)%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(10)] = libc.Uint8FromInt32(int32('0') + s/int32(10)%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(11)] = libc.Uint8FromInt32(int32('0') + s%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(12)] = uint8(0)
			n = int32(12)
		} else {
			s = int32((**(**TDateTime)(__ccgo_up(bp))).Fs)
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(6)] = libc.Uint8FromInt32(int32('0') + s/int32(10)%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(7)] = libc.Uint8FromInt32(int32('0') + s%int32(10))
			(**(**[16]uint8)(__ccgo_up(bp + 48)))[int32(8)] = uint8(0)
			n = int32(8)
		}
		Xsqlite3_result_text(tls, context, bp+48, n, uintptr(-libc.Int32FromInt32(1)))
	}
}

// C documentation
//
//	/*
//	** Assuming the input DateTime is UTC, move it to its localtime equivalent.
//	*/
func _toLocaltime(tls *libc.TLS, p uintptr, pCtx uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var iYearDiff int32
	var _ /* sLocal at bp+8 */ Ttm
	var _ /* t at bp+0 */ Ttime_t
	var _ /* x at bp+64 */ TDateTime
	_ = iYearDiff
	/* Initialize the contents of sLocal to avoid a compiler warning. */
	libc.Xmemset(tls, bp+8, 0, uint64(56))
	_computeJD(tls, p)
	if (*TDateTime)(unsafe.Pointer(p)).FiJD < libc.Int64FromInt32(2108667600)*libc.Int64FromInt32(100000) || (*TDateTime)(unsafe.Pointer(p)).FiJD > libc.Int64FromInt32(2130141456)*libc.Int64FromInt32(100000) {
		/* EVIDENCE-OF: R-55269-29598 The localtime_r() C function normally only
		 ** works for years between 1970 and 2037. For dates outside this range,
		 ** SQLite attempts to map the year into an equivalent year within this
		 ** range, do the calculation, then map the year back.
		 */
		**(**TDateTime)(__ccgo_up(bp + 64)) = **(**TDateTime)(__ccgo_up(p))
		_computeYMD_HMS(tls, bp+64)
		iYearDiff = int32(2000) + (**(**TDateTime)(__ccgo_up(bp + 64))).FY%int32(4) - (**(**TDateTime)(__ccgo_up(bp + 64))).FY
		(**(**TDateTime)(__ccgo_up(bp + 64))).FY += iYearDiff
		(**(**TDateTime)(__ccgo_up(bp + 64))).FvalidJD = uint8(0)
		_computeJD(tls, bp+64)
		**(**Ttime_t)(__ccgo_up(bp)) = int64((**(**TDateTime)(__ccgo_up(bp + 64))).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
	} else {
		iYearDiff = 0
		**(**Ttime_t)(__ccgo_up(bp)) = int64((*TDateTime)(unsafe.Pointer(p)).FiJD/libc.Int64FromInt32(1000) - libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
	}
	if _osLocaltime(tls, bp, bp+8) != 0 {
		Xsqlite3_result_error(tls, pCtx, __ccgo_ts+1249, -int32(1))
		return int32(SQLITE_ERROR)
	}
	(*TDateTime)(unsafe.Pointer(p)).FY = (**(**Ttm)(__ccgo_up(bp + 8))).Ftm_year + int32(1900) - iYearDiff
	(*TDateTime)(unsafe.Pointer(p)).FM = (**(**Ttm)(__ccgo_up(bp + 8))).Ftm_mon + int32(1)
	(*TDateTime)(unsafe.Pointer(p)).FD = (**(**Ttm)(__ccgo_up(bp + 8))).Ftm_mday
	(*TDateTime)(unsafe.Pointer(p)).Fh = (**(**Ttm)(__ccgo_up(bp + 8))).Ftm_hour
	(*TDateTime)(unsafe.Pointer(p)).Fm = (**(**Ttm)(__ccgo_up(bp + 8))).Ftm_min
	(*TDateTime)(unsafe.Pointer(p)).Fs = float64((**(**Ttm)(__ccgo_up(bp + 8))).Ftm_sec) + float64(float64((*TDateTime)(unsafe.Pointer(p)).FiJD%libc.Int64FromInt32(1000))*float64(0.001))
	(*TDateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(1)
	(*TDateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
	(*TDateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 7, 0x80)
	(*TDateTime)(unsafe.Pointer(p)).Ftz = 0
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(0), 6, 0x40)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	**    unixepoch( TIMESTRING, MOD, MOD, ...)
//	**
//	** Return the number of seconds (including fractional seconds) since
//	** the unix epoch of 1970-01-01 00:00:00 GMT.
//	*/
func _unixepochFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* x at bp+0 */ TDateTime
	if _isDate(tls, context, argc, argv, bp) == 0 {
		_computeJD(tls, bp)
		if int32(uint32(*(*uint8)(unsafe.Pointer(bp + 44))&0x20>>5)) != 0 {
			Xsqlite3_result_double(tls, context, float64((**(**TDateTime)(__ccgo_up(bp))).FiJD-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000000))/float64(1000))
		} else {
			Xsqlite3_result_int64(tls, context, (**(**TDateTime)(__ccgo_up(bp))).FiJD/int64(1000)-libc.Int64FromInt32(21086676)*libc.Int64FromInt32(10000))
		}
	}
}

// C documentation
//
//	/*
//	** For OP_Column, factor out the case where content is loaded from
//	** overflow pages, so that the code to implement this case is separate
//	** the common case where all content fits on the page.  Factoring out
//	** the code reduces register pressure and helps the common case
//	** to run faster.
//	*/
func _vdbeColumnFromOverflow(tls *libc.TLS, pC uintptr, iCol int32, t Tu32, iOffset Ti64, cacheStatus Tu32, colCacheCtr Tu32, pDest uintptr) (r int32) {
	var db, pBuf, pCache, v1 uintptr
	var encoding, len1, rc int32
	_, _, _, _, _, _, _ = db, encoding, len1, pBuf, pCache, rc, v1
	db = (*TMem)(unsafe.Pointer(pDest)).Fdb
	encoding = libc.Int32FromUint8((*TMem)(unsafe.Pointer(pDest)).Fenc)
	len1 = libc.Int32FromUint32(_sqlite3VdbeSerialTypeLen(tls, t))
	if len1 > **(**int32)(__ccgo_up(db + 136)) {
		return int32(SQLITE_TOOBIG)
	}
	if len1 > int32(4000) && (*TVdbeCursor)(unsafe.Pointer(pC)).FpKeyInfo == uintptr(0) {
		if int32(TBool(*(*uint8)(unsafe.Pointer(pC + 8))&0x8>>3)) == 0 {
			(*TVdbeCursor)(unsafe.Pointer(pC)).FpCache = _sqlite3DbMallocZero(tls, db, uint64(32))
			if (*TVdbeCursor)(unsafe.Pointer(pC)).FpCache == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
			libc.SetBitFieldPtr8Uint32(pC+8, libc.Uint32FromInt32(1), 3, 0x8)
		}
		pCache = (*TVdbeCursor)(unsafe.Pointer(pC)).FpCache
		if (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue == uintptr(0) || (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FiCol != iCol || (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FcacheStatus != cacheStatus || (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FcolCacheCtr != colCacheCtr || (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FiOffset != _sqlite3BtreeOffset(tls, *(*uintptr)(unsafe.Pointer(pC + 48))) {
			if (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue != 0 {
				_sqlite3RCStrUnref(tls, (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue)
			}
			v1 = _sqlite3RCStrNew(tls, libc.Uint64FromInt32(len1+int32(3)))
			(*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue = v1
			pBuf = v1
			if pBuf == uintptr(0) {
				return int32(SQLITE_NOMEM)
			}
			rc = _sqlite3BtreePayload(tls, *(*uintptr)(unsafe.Pointer(pC + 48)), libc.Uint32FromInt64(iOffset), libc.Uint32FromInt32(len1), pBuf)
			if rc != 0 {
				return rc
			}
			**(**uint8)(__ccgo_up(pBuf + uintptr(len1))) = uint8(0)
			**(**uint8)(__ccgo_up(pBuf + uintptr(len1+int32(1)))) = uint8(0)
			**(**uint8)(__ccgo_up(pBuf + uintptr(len1+int32(2)))) = uint8(0)
			(*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FiCol = iCol
			(*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FcacheStatus = cacheStatus
			(*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FcolCacheCtr = colCacheCtr
			(*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FiOffset = _sqlite3BtreeOffset(tls, *(*uintptr)(unsafe.Pointer(pC + 48)))
		} else {
			pBuf = (*TVdbeTxtBlbCache)(unsafe.Pointer(pCache)).FpCValue
		}
		_sqlite3RCStrRef(tls, pBuf)
		if t&uint32(1) != 0 {
			rc = _sqlite3VdbeMemSetStr(tls, pDest, pBuf, int64(len1), libc.Uint8FromInt32(encoding), __ccgo_fp(_sqlite3RCStrUnref))
			v1 = pDest + 20
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(MEM_Term))
		} else {
			rc = _sqlite3VdbeMemSetStr(tls, pDest, pBuf, int64(len1), uint8(0), __ccgo_fp(_sqlite3RCStrUnref))
		}
	} else {
		rc = _sqlite3VdbeMemFromBtree(tls, *(*uintptr)(unsafe.Pointer(pC + 48)), libc.Uint32FromInt64(iOffset), libc.Uint32FromInt32(len1), pDest)
		if rc != 0 {
			return rc
		}
		_sqlite3VdbeSerialGet(tls, (*TMem)(unsafe.Pointer(pDest)).Fz, t, pDest)
		if t&uint32(1) != uint32(0) && encoding == int32(SQLITE_UTF8) {
			**(**uint8)(__ccgo_up((*TMem)(unsafe.Pointer(pDest)).Fz + uintptr(len1))) = uint8(0)
			v1 = pDest + 20
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(MEM_Term))
		}
	}
	v1 = pDest + 20
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(MEM_Ephem))
	return rc
}

// C documentation
//
//	/******************************* sqlite3_bind_  ***************************
//	**
//	** Routines used to attach values to wildcards in a compiled SQL statement.
//	*/
//	/*
//	** Unbind the value bound to variable i in virtual machine p. This is the
//	** the same as binding a NULL value to the column. If the "i" parameter is
//	** out of range, then SQLITE_RANGE is returned. Otherwise SQLITE_OK.
//	**
//	** A successful evaluation of this routine acquires the mutex on p.
//	** the mutex is released if any kind of error occurs.
//	**
//	** The error code stored in database p->db is overwritten with the return
//	** value in any case.
//	**
//	** (tag-20240917-01) If  vdbeUnbind(p,(u32)(i-1))  returns SQLITE_OK,
//	** that means all of the the following will be true:
//	**
//	**     p!=0
//	**     p->pVar!=0
//	**     i>0
//	**     i<=p->nVar
//	**
//	** An assert() is normally added after vdbeUnbind() to help static analyzers
//	** realize this.
//	*/
func _vdbeUnbind(tls *libc.TLS, p uintptr, i uint32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pVar uintptr
	var v1 uint32
	var v2 bool
	_, _, _ = pVar, v1, v2
	if _vdbeSafetyNotNull(tls, p) != 0 {
		return _sqlite3MisuseError(tls, int32(95346))
	}
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	if libc.Int32FromUint8((*TVdbe)(unsafe.Pointer(p)).FeVdbeState) != int32(VDBE_READY_STATE) {
		_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, _sqlite3MisuseError(tls, int32(95350)))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		Xsqlite3_log(tls, int32(SQLITE_MISUSE), __ccgo_ts+5677, libc.VaList(bp+8, (*TVdbe)(unsafe.Pointer(p)).FzSql))
		return _sqlite3MisuseError(tls, int32(95354))
	}
	if i >= libc.Uint32FromInt16((*TVdbe)(unsafe.Pointer(p)).FnVar) {
		_sqlite3Error(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, int32(SQLITE_RANGE))
		Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		return int32(SQLITE_RANGE)
	}
	pVar = (*TVdbe)(unsafe.Pointer(p)).FaVar + uintptr(i)*56
	_sqlite3VdbeMemRelease(tls, pVar)
	(*TMem)(unsafe.Pointer(pVar)).Fflags = uint16(MEM_Null)
	(*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FerrCode = SQLITE_OK
	/* If the bit corresponding to this variable in Vdbe.expmask is set, then
	 ** binding a new value to this variable invalidates the current query plan.
	 **
	 ** IMPLEMENTATION-OF: R-57496-20354 If the specific value bound to a host
	 ** parameter in the WHERE clause might influence the choice of query plan
	 ** for a statement, then the statement will be automatically recompiled,
	 ** as if there had been a schema change, on the first sqlite3_step() call
	 ** following any change to the bindings of that parameter.
	 */
	if v2 = (*TVdbe)(unsafe.Pointer(p)).Fexpmask != uint32(0); v2 {
		if i >= uint32(31) {
			v1 = uint32(0x80000000)
		} else {
			v1 = libc.Uint32FromInt32(1) << i
		}
	}
	if v2 && (*TVdbe)(unsafe.Pointer(p)).Fexpmask&v1 != uint32(0) {
		libc.SetBitFieldPtr16Uint32(p+200, libc.Uint32FromInt32(1), 14, 0xc000)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Check to see if the frame with header in aFrame[] and content
//	** in aData[] is valid.  If it is a valid frame, fill *piPage and
//	** *pnTruncate and return true.  Return if the frame is not valid.
//	*/
func _walDecodeFrame(tls *libc.TLS, pWal uintptr, piPage uintptr, pnTruncate uintptr, aData uintptr, aFrame uintptr) (r int32) {
	var aCksum uintptr
	var nativeCksum int32
	var pgno Tu32
	_, _, _ = aCksum, nativeCksum, pgno /* True for native byte-order checksums */
	aCksum = pWal + 72 + 24             /* Page number of the frame */
	/* A frame is only valid if the salt values in the frame-header
	 ** match the salt values in the wal-header.
	 */
	if libc.Xmemcmp(tls, pWal+72+32, aFrame+8, uint64(8)) != 0 {
		return 0
	}
	/* A frame is only valid if the page number is greater than zero.
	 */
	pgno = _sqlite3Get4byte(tls, aFrame)
	if pgno == uint32(0) {
		return 0
	}
	/* Need a valid page size
	 */
	if !((*TWal)(unsafe.Pointer(pWal)).FszPage != 0) {
		return 0
	}
	/* A frame is only valid if a checksum of the WAL header,
	 ** all prior frames, the first 16 bytes of this frame-header,
	 ** and the frame-data matches the checksum in the last 8
	 ** bytes of this frame-header.
	 */
	nativeCksum = libc.BoolInt32(libc.Int32FromUint8((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == int32(SQLITE_BIGENDIAN))
	_walChecksumBytes(tls, nativeCksum, aFrame, int32(8), aCksum, aCksum)
	_walChecksumBytes(tls, nativeCksum, aData, libc.Int32FromUint32((*TWal)(unsafe.Pointer(pWal)).FszPage), aCksum, aCksum)
	if **(**Tu32)(__ccgo_up(aCksum)) != _sqlite3Get4byte(tls, aFrame+16) || **(**Tu32)(__ccgo_up(aCksum + 1*4)) != _sqlite3Get4byte(tls, aFrame+20) {
		/* Checksum failed. */
		return 0
	}
	/* If we reach this point, the frame is valid.  Return the page number
	 ** and the new database size.
	 */
	**(**Tu32)(__ccgo_up(piPage)) = pgno
	**(**Tu32)(__ccgo_up(pnTruncate)) = _sqlite3Get4byte(tls, aFrame+4)
	return int32(1)
}

// C documentation
//
//	/*
//	** This function encodes a single frame header and writes it to a buffer
//	** supplied by the caller. A frame-header is made up of a series of
//	** 4-byte big-endian integers, as follows:
//	**
//	**     0: Page number.
//	**     4: For commit records, the size of the database image in pages
//	**        after the commit. For all other records, zero.
//	**     8: Salt-1 (copied from the wal-header)
//	**    12: Salt-2 (copied from the wal-header)
//	**    16: Checksum-1.
//	**    20: Checksum-2.
//	*/
func _walEncodeFrame(tls *libc.TLS, pWal uintptr, iPage Tu32, nTruncate Tu32, aData uintptr, aFrame uintptr) {
	var aCksum uintptr
	var nativeCksum int32
	_, _ = aCksum, nativeCksum /* True for native byte-order checksums */
	aCksum = pWal + 72 + 24
	_sqlite3Put4byte(tls, aFrame, iPage)
	_sqlite3Put4byte(tls, aFrame+4, nTruncate)
	if (*TWal)(unsafe.Pointer(pWal)).FiReCksum == uint32(0) {
		libc.Xmemcpy(tls, aFrame+8, pWal+72+32, uint64(8))
		nativeCksum = libc.BoolInt32(libc.Int32FromUint8((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == int32(SQLITE_BIGENDIAN))
		_walChecksumBytes(tls, nativeCksum, aFrame, int32(8), aCksum, aCksum)
		_walChecksumBytes(tls, nativeCksum, aData, libc.Int32FromUint32((*TWal)(unsafe.Pointer(pWal)).FszPage), aCksum, aCksum)
		_sqlite3Put4byte(tls, aFrame+16, **(**Tu32)(__ccgo_up(aCksum)))
		_sqlite3Put4byte(tls, aFrame+20, **(**Tu32)(__ccgo_up(aCksum + 1*4)))
	} else {
		libc.Xmemset(tls, aFrame+8, 0, uint64(16))
	}
}

// C documentation
//
//	/*
//	** Recover the wal-index by reading the write-ahead log file.
//	**
//	** This routine first tries to establish an exclusive lock on the
//	** wal-index to prevent other threads/processes from doing anything
//	** with the WAL or wal-index while recovery is running.  The
//	** WAL_RECOVER_LOCK is also held so that other threads will know
//	** that this thread is running recovery.  If unable to establish
//	** the necessary locks, this routine returns SQLITE_BUSY.
//	*/
func _walIndexRecover(tls *libc.TLS, pWal uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var aData, aFrame, aPrivate, pInfo uintptr
	var aFrameCksum [2]Tu32
	var i, iLock, isValid, rc, szFrame, szPage int32
	var iFirst, iFrame, iLast, iLastFrame, iPg, magic, nHdr, nHdr32, version Tu32
	var iOffset Ti64
	var v2, v3 uint64
	var _ /* aBuf at bp+8 */ [32]Tu8
	var _ /* aShare at bp+40 */ uintptr
	var _ /* nSize at bp+0 */ Ti64
	var _ /* nTruncate at bp+52 */ Tu32
	var _ /* pgno at bp+48 */ Tu32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aData, aFrame, aFrameCksum, aPrivate, i, iFirst, iFrame, iLast, iLastFrame, iLock, iOffset, iPg, isValid, magic, nHdr, nHdr32, pInfo, rc, szFrame, szPage, version, v2, v3 /* Size of log file */
	aFrameCksum = [2]Tu32{}                                                                                                                                                                                                                          /* Lock offset to lock for checkpoint */
	/* Obtain an exclusive lock on all byte in the locking range not already
	 ** locked by the caller. The caller is guaranteed to have locked the
	 ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte.
	 ** If successful, the same bytes that are locked here are unlocked before
	 ** this function returns.
	 */
	iLock = int32(WAL_ALL_BUT_WRITE) + libc.Int32FromUint8((*TWal)(unsafe.Pointer(pWal)).FckptLock)
	rc = _walLockExclusive(tls, pWal, iLock, libc.Int32FromInt32(3)+libc.Int32FromInt32(0)-iLock)
	if rc != 0 {
		return rc
	}
	libc.Xmemset(tls, pWal+72, 0, uint64(48))
	rc = _sqlite3OsFileSize(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp)
	if rc != SQLITE_OK {
		goto recovery_error
	}
	if **(**Ti64)(__ccgo_up(bp)) > int64(WAL_HDRSIZE) { /* Buffer to load WAL header into */
		aPrivate = uintptr(0) /* Heap copy of *-shm hash being populated */
		aFrame = uintptr(0)   /* Last frame in wal, based on nSize alone */
		/* Read in the WAL header. */
		rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, bp+8, int32(WAL_HDRSIZE), 0)
		if rc != SQLITE_OK {
			goto recovery_error
		}
		/* If the database page size is not a power of two, or is greater than
		 ** SQLITE_MAX_PAGE_SIZE, conclude that the WAL file contains no valid
		 ** data. Similarly, if the 'magic' value is invalid, ignore the whole
		 ** WAL file.
		 */
		magic = _sqlite3Get4byte(tls, bp+8)
		szPage = libc.Int32FromUint32(_sqlite3Get4byte(tls, bp+8+8))
		if magic&uint32(0xFFFFFFFE) != uint32(WAL_MAGIC) || szPage&(szPage-int32(1)) != 0 || szPage > int32(SQLITE_MAX_PAGE_SIZE) || szPage < int32(512) {
			goto finished
		}
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum = uint8(magic & libc.Uint32FromInt32(0x00000001))
		(*TWal)(unsafe.Pointer(pWal)).FszPage = libc.Uint32FromInt32(szPage)
		(*TWal)(unsafe.Pointer(pWal)).FnCkpt = _sqlite3Get4byte(tls, bp+8+12)
		libc.Xmemcpy(tls, pWal+72+32, bp+8+16, uint64(8))
		/* Verify that the WAL header checksum is correct */
		_walChecksumBytes(tls, libc.BoolInt32(libc.Int32FromUint8((*TWal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == int32(SQLITE_BIGENDIAN)), bp+8, libc.Int32FromInt32(WAL_HDRSIZE)-libc.Int32FromInt32(2)*libc.Int32FromInt32(4), uintptr(0), pWal+72+24)
		if **(**Tu32)(__ccgo_up(pWal + 72 + 24)) != _sqlite3Get4byte(tls, bp+8+24) || **(**Tu32)(__ccgo_up(pWal + 72 + 24 + 1*4)) != _sqlite3Get4byte(tls, bp+8+28) {
			goto finished
		}
		/* Verify that the version number on the WAL format is one that
		 ** are able to understand */
		version = _sqlite3Get4byte(tls, bp+8+4)
		if version != uint32(WAL_MAX_VERSION) {
			rc = _sqlite3CantopenError(tls, int32(68992))
			goto finished
		}
		/* Malloc a buffer to read frames into. */
		szFrame = szPage + int32(WAL_FRAME_HDRSIZE)
		aFrame = Xsqlite3_malloc64(tls, uint64(libc.Uint64FromInt32(szFrame)+(libc.Uint64FromInt64(2)*libc.Uint64FromInt32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint64FromInt32(HASHTABLE_NPAGE)*libc.Uint64FromInt64(4))))
		if !(aFrame != 0) {
			rc = int32(SQLITE_NOMEM)
			goto recovery_error
		}
		aData = aFrame + 24
		aPrivate = aData + uintptr(szPage)
		/* Read all frames from the log file. */
		iLastFrame = libc.Uint32FromInt64((**(**Ti64)(__ccgo_up(bp)) - int64(WAL_HDRSIZE)) / int64(szFrame))
		iPg = uint32(0)
		for {
			if !(iPg <= libc.Uint32FromInt32(_walFramePage(tls, iLastFrame))) {
				break
			}
			if uint64(iLastFrame) < libc.Uint64FromInt32(HASHTABLE_NPAGE)-(libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(40))/libc.Uint64FromInt64(4)+uint64(iPg*uint32(HASHTABLE_NPAGE)) {
				v2 = uint64(iLastFrame)
			} else {
				v2 = libc.Uint64FromInt32(HASHTABLE_NPAGE) - (libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(40))/libc.Uint64FromInt64(4) + uint64(iPg*uint32(HASHTABLE_NPAGE))
			} /* Index of last frame read */
			iLast = uint32(v2)
			if iPg == uint32(0) {
				v3 = uint64(0)
			} else {
				v3 = libc.Uint64FromInt32(HASHTABLE_NPAGE) - (libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2)+libc.Uint64FromInt64(40))/libc.Uint64FromInt64(4) + uint64((iPg-uint32(1))*uint32(HASHTABLE_NPAGE))
			}
			iFirst = uint32(uint64(1) + v3)
			rc = _walIndexPage(tls, pWal, libc.Int32FromUint32(iPg), bp+40)
			if **(**uintptr)(__ccgo_up(bp + 40)) == uintptr(0) {
				break
			}
			**(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*8)) = aPrivate
			iFrame = iFirst
			for {
				if !(iFrame <= iLast) {
					break
				}
				iOffset = libc.Int64FromInt32(WAL_HDRSIZE) + libc.Int64FromUint32(iFrame-libc.Uint32FromInt32(1))*int64(szPage+libc.Int32FromInt32(WAL_FRAME_HDRSIZE)) /* dbsize field from frame header */
				/* Read and decode the next log frame. */
				rc = _sqlite3OsRead(tls, (*TWal)(unsafe.Pointer(pWal)).FpWalFd, aFrame, szFrame, iOffset)
				if rc != SQLITE_OK {
					break
				}
				isValid = _walDecodeFrame(tls, pWal, bp+48, bp+52, aData, aFrame)
				if !(isValid != 0) {
					break
				}
				rc = _walIndexAppend(tls, pWal, iFrame, **(**Tu32)(__ccgo_up(bp + 48)))
				if rc != SQLITE_OK {
					break
				}
				/* If nTruncate is non-zero, this is a commit record. */
				if **(**Tu32)(__ccgo_up(bp + 52)) != 0 {
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = iFrame
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage = **(**Tu32)(__ccgo_up(bp + 52))
					(*TWal)(unsafe.Pointer(pWal)).Fhdr.FszPage = libc.Uint16FromInt32(szPage&libc.Int32FromInt32(0xff00) | szPage>>libc.Int32FromInt32(16))
					aFrameCksum[0] = **(**Tu32)(__ccgo_up(pWal + 72 + 24))
					aFrameCksum[int32(1)] = **(**Tu32)(__ccgo_up(pWal + 72 + 24 + 1*4))
				}
				goto _4
			_4:
				;
				iFrame = iFrame + 1
			}
			**(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*8)) = **(**uintptr)(__ccgo_up(bp + 40))
			if iPg == uint32(0) {
				v2 = libc.Uint64FromInt64(48)*libc.Uint64FromInt32(2) + libc.Uint64FromInt64(40)
			} else {
				v2 = uint64(0)
			}
			nHdr = uint32(v2)
			nHdr32 = uint32(uint64(nHdr) / uint64(4))
			/* Memcpy() should work fine here, on all reasonable implementations.
			 ** Technically, memcpy() might change the destination to some
			 ** intermediate value before setting to the final value, and that might
			 ** cause a concurrent reader to malfunction.  Memcpy() is allowed to
			 ** do that, according to the spec, but no memcpy() implementation that
			 ** we know of actually does that, which is why we say that memcpy()
			 ** is safe for this.  Memcpy() is certainly a lot faster.
			 */
			libc.Xmemcpy(tls, **(**uintptr)(__ccgo_up(bp + 40))+uintptr(nHdr32)*4, aPrivate+uintptr(nHdr32)*4, libc.Uint64FromInt64(2)*libc.Uint64FromInt32(libc.Int32FromInt32(HASHTABLE_NPAGE)*libc.Int32FromInt32(2))+libc.Uint64FromInt32(HASHTABLE_NPAGE)*libc.Uint64FromInt64(4)-uint64(nHdr))
			if iFrame <= iLast {
				break
			}
			goto _1
		_1:
			;
			iPg = iPg + 1
		}
		Xsqlite3_free(tls, aFrame)
	}
	goto finished
finished:
	;
	if rc == SQLITE_OK {
		**(**Tu32)(__ccgo_up(pWal + 72 + 24)) = aFrameCksum[0]
		**(**Tu32)(__ccgo_up(pWal + 72 + 24 + 1*4)) = aFrameCksum[int32(1)]
		_walIndexWriteHdr(tls, pWal)
		/* Reset the checkpoint-header. This is safe because this thread is
		 ** currently holding locks that exclude all other writers and
		 ** checkpointers. Then set the values of read-mark slots 1 through N.
		 */
		pInfo = _walCkptInfo(tls, pWal)
		(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill = uint32(0)
		(*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
		**(**Tu32)(__ccgo_up(pInfo + 4)) = uint32(0)
		i = int32(1)
		for {
			if !(i < libc.Int32FromInt32(SQLITE_SHM_NLOCK)-libc.Int32FromInt32(3)) {
				break
			}
			rc = _walLockExclusive(tls, pWal, int32(3)+i, int32(1))
			if rc == SQLITE_OK {
				if i == int32(1) && (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame != 0 {
					**(**Tu32)(__ccgo_up(pInfo + 4 + uintptr(i)*4)) = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
				} else {
					**(**Tu32)(__ccgo_up(pInfo + 4 + uintptr(i)*4)) = uint32(READMARK_NOT_USED)
				}
				_walUnlockExclusive(tls, pWal, int32(3)+i, int32(1))
			} else {
				if rc != int32(SQLITE_BUSY) {
					goto recovery_error
				}
			}
			goto _6
		_6:
			;
			i = i + 1
		}
		/* If more than one frame was recovered from the log file, report an
		 ** event via sqlite3_log(). This is to help with identifying performance
		 ** problems caused by applications routinely shutting down without
		 ** checkpointing the log file.
		 */
		if (*TWal)(unsafe.Pointer(pWal)).Fhdr.FnPage != 0 {
			Xsqlite3_log(tls, libc.Int32FromInt32(SQLITE_NOTICE)|libc.Int32FromInt32(1)<<libc.Int32FromInt32(8), __ccgo_ts+4280, libc.VaList(bp+64, (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame, (*TWal)(unsafe.Pointer(pWal)).FzWalName))
		}
	}
	goto recovery_error
recovery_error:
	;
	_walUnlockExclusive(tls, pWal, iLock, libc.Int32FromInt32(3)+libc.Int32FromInt32(0)-iLock)
	return rc
}

// C documentation
//
//	/*
//	** pIdx is an index that covers all of the low-number columns used by
//	** pWInfo->pSelect (columns from 0 through 62) or an index that has
//	** expressions terms.  Hence, we cannot determine whether or not it is
//	** a covering index by using the colUsed bitmasks.  We have to do a search
//	** to see if the index is covering.  This routine does that search.
//	**
//	** The return value is one of these:
//	**
//	**      0                The index is definitely not a covering index
//	**
//	**      WHERE_IDX_ONLY   The index is definitely a covering index
//	**
//	**      WHERE_EXPRIDX    The index is likely a covering index, but it is
//	**                       difficult to determine precisely because of the
//	**                       expressions that are indexed.  Score it as a
//	**                       covering index, but still keep the main table open
//	**                       just in case we need it.
//	**
//	** This routine is an optimization.  It is always safe to return zero.
//	** But returning one of the other two values when zero should have been
//	** returned can lead to incorrect bytecode and assertion faults.
//	*/
func _whereIsCoveringIndex(tls *libc.TLS, pWInfo uintptr, pIdx uintptr, iTabCur int32) (r Tu32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i, rc int32
	var _ /* ck at bp+0 */ TCoveringIndexCheck
	var _ /* w at bp+16 */ TWalker
	_, _ = i, rc
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect == uintptr(0) {
		/* We don't have access to the full query, so we cannot check to see
		 ** if pIdx is covering.  Assume it is not. */
		return uint32(0)
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x10>>4)) == 0 {
		i = 0
		for {
			if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)) {
				break
			}
			if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) >= libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		if i >= libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn) {
			/* pIdx does not index any columns greater than 62, but we know from
			 ** colMask that columns greater than 62 are used, so this is not a
			 ** covering index */
			return uint32(0)
		}
	}
	(**(**TCoveringIndexCheck)(__ccgo_up(bp))).FpIdx = pIdx
	(**(**TCoveringIndexCheck)(__ccgo_up(bp))).FiTabCur = iTabCur
	(**(**TCoveringIndexCheck)(__ccgo_up(bp))).FbExpr = uint8(0)
	(**(**TCoveringIndexCheck)(__ccgo_up(bp))).FbUnidx = uint8(0)
	libc.Xmemset(tls, bp+16, 0, uint64(48))
	(**(**TWalker)(__ccgo_up(bp + 16))).FxExprCallback = __ccgo_fp(_whereIsCoveringIndexWalkCallback)
	(**(**TWalker)(__ccgo_up(bp + 16))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	*(*uintptr)(unsafe.Pointer(bp + 16 + 40)) = bp
	_sqlite3WalkSelect(tls, bp+16, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)
	if (**(**TCoveringIndexCheck)(__ccgo_up(bp))).FbUnidx != 0 {
		rc = 0
	} else {
		if (**(**TCoveringIndexCheck)(__ccgo_up(bp))).FbExpr != 0 {
			rc = int32(WHERE_EXPRIDX)
		} else {
			rc = int32(WHERE_IDX_ONLY)
		}
	}
	return libc.Uint32FromInt32(rc)
}

// C documentation
//
//	/*
//	** Information passed in is pWalk->u.pCovIdxCk.  Call it pCk.
//	**
//	** If the Expr node references the table with cursor pCk->iTabCur, then
//	** make sure that column is covered by the index pCk->pIdx.  We know that
//	** all columns less than 63 (really BMS-1) are covered, so we don't need
//	** to check them.  But we do need to check any column at 63 or greater.
//	**
//	** If the index does not cover the column, then set pWalk->eCode to
//	** non-zero and return WRC_Abort to stop the search.
//	**
//	** If this node does not disprove that the index can be a covering index,
//	** then just return WRC_Continue, to continue the search.
//	**
//	** If pCk->pIdx contains indexed expressions and one of those expressions
//	** matches pExpr, then prune the search.
//	*/
func _whereIsCoveringIndexWalkCallback(tls *libc.TLS, pWalk uintptr, pExpr uintptr) (r int32) {
	var aiColumn, pCk, pIdx uintptr
	var i int32
	var nColumn Tu16
	_, _, _, _, _ = aiColumn, i, nColumn, pCk, pIdx /* Info about this search */
	pCk = *(*uintptr)(unsafe.Pointer(pWalk + 40))
	pIdx = (*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FpIdx
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_COLUMN) || libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pExpr)).Fop) == int32(TK_AGG_COLUMN) {
		/* if( pExpr->iColumn<(BMS-1) && pIdx->bHasExpr==0 ) return WRC_Continue;*/
		if (*TExpr)(unsafe.Pointer(pExpr)).FiTable != (*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FiTabCur {
			return WRC_Continue
		}
		pIdx = (*TCoveringIndexCheck)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalk + 40)))).FpIdx
		aiColumn = (*TIndex)(unsafe.Pointer(pIdx)).FaiColumn
		nColumn = (*TIndex)(unsafe.Pointer(pIdx)).FnColumn
		i = 0
		for {
			if !(i < libc.Int32FromUint16(nColumn)) {
				break
			}
			if int32(**(**Ti16)(__ccgo_up(aiColumn + uintptr(i)*2))) == int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) {
				return WRC_Continue
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		(*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FbUnidx = uint8(1)
		return int32(WRC_Abort)
	} else {
		if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x10>>4)) != 0 && _exprIsCoveredByIndex(tls, pExpr, pIdx, (*TCoveringIndexCheck)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalk + 40)))).FiTabCur) != 0 {
			(*TCoveringIndexCheck)(unsafe.Pointer(pCk)).FbExpr = uint8(1)
			return int32(WRC_Prune)
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Estimate the location of a particular key among all keys in an
//	** index.  Store the results in aStat as follows:
//	**
//	**    aStat[0]      Est. number of rows less than pRec
//	**    aStat[1]      Est. number of rows equal to pRec
//	**
//	** Return the index of the sample that is the smallest sample that
//	** is greater than or equal to pRec. Note that this index is not an index
//	** into the aSample[] array - it is an index into a virtual set of samples
//	** based on the contents of aSample[] and the number of fields in record
//	** pRec.
//	*/
func _whereKeyStats(tls *libc.TLS, pParse uintptr, pIdx uintptr, pRec uintptr, roundUp int32, aStat uintptr) (r int32) {
	var aSample uintptr
	var i, iCol, iMin, iSamp, iSample, iTest, n, nField, res, v1 int32
	var iGap, iLower, iUpper TtRowcnt
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = aSample, i, iCol, iGap, iLower, iMin, iSamp, iSample, iTest, iUpper, n, nField, res, v1
	aSample = (*TIndex)(unsafe.Pointer(pIdx)).FaSample /* Smallest sample larger than or equal to pRec */
	iMin = 0                                           /* Number of fields in pRec */
	iLower = uint64(0)                                 /* anLt[] + anEq[] of largest sample pRec is > */
	_ = pParse
	/* Do a binary search to find the first sample greater than or equal
	 ** to pRec. If pRec contains a single field, the set of samples to search
	 ** is simply the aSample[] array. If the samples in aSample[] contain more
	 ** than one fields, all fields following the first are ignored.
	 **
	 ** If pRec contains N fields, where N is more than one, then as well as the
	 ** samples in aSample[] (truncated to N fields), the search also has to
	 ** consider prefixes of those samples. For example, if the set of samples
	 ** in aSample is:
	 **
	 **     aSample[0] = (a, 5)
	 **     aSample[1] = (a, 10)
	 **     aSample[2] = (b, 5)
	 **     aSample[3] = (c, 100)
	 **     aSample[4] = (c, 105)
	 **
	 ** Then the search space should ideally be the samples above and the
	 ** unique prefixes [a], [b] and [c]. But since that is hard to organize,
	 ** the code actually searches this set:
	 **
	 **     0: (a)
	 **     1: (a, 5)
	 **     2: (a, 10)
	 **     3: (a, 10)
	 **     4: (b)
	 **     5: (b, 5)
	 **     6: (c)
	 **     7: (c, 100)
	 **     8: (c, 105)
	 **     9: (c, 105)
	 **
	 ** For each sample in the aSample[] array, N samples are present in the
	 ** effective sample array. In the above, samples 0 and 1 are based on
	 ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
	 **
	 ** Often, sample i of each block of N effective samples has (i+1) fields.
	 ** Except, each sample may be extended to ensure that it is greater than or
	 ** equal to the previous sample in the array. For example, in the above,
	 ** sample 2 is the first sample of a block of N samples, so at first it
	 ** appears that it should be 1 field in size. However, that would make it
	 ** smaller than sample 1, so the binary search would not work. As a result,
	 ** it is extended to two fields. The duplicates that this creates do not
	 ** cause any problems.
	 */
	if !((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
		nField = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)
	} else {
		nField = libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnColumn)
	}
	if libc.Int32FromUint16((*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField) < nField {
		v1 = libc.Int32FromUint16((*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField)
	} else {
		v1 = nField
	}
	nField = v1
	iCol = 0
	iSample = (*TIndex)(unsafe.Pointer(pIdx)).FnSample * nField
	for cond := true; cond; cond = res != 0 && iMin < iSample { /* Number of fields in test sample */
		iTest = (iMin + iSample) / int32(2)
		iSamp = iTest / nField
		if iSamp > 0 {
			/* The proposed effective sample is a prefix of sample aSample[iSamp].
			 ** Specifically, the shortest prefix of at least (1 + iTest%nField)
			 ** fields that is greater than the previous effective sample.  */
			n = iTest%nField + int32(1)
			for {
				if !(n < nField) {
					break
				}
				if **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp-int32(1))*40))).FanLt + uintptr(n-int32(1))*8)) != **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp)*40))).FanLt + uintptr(n-int32(1))*8)) {
					break
				}
				goto _2
			_2:
				;
				n = n + 1
			}
		} else {
			n = iTest + int32(1)
		}
		(*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField = libc.Uint16FromInt32(n)
		res = _sqlite3VdbeRecordCompare(tls, (**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp)*40))).Fn, (**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp)*40))).Fp, pRec)
		if res < 0 {
			iLower = **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp)*40))).FanLt + uintptr(n-int32(1))*8)) + **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp)*40))).FanEq + uintptr(n-int32(1))*8))
			iMin = iTest + int32(1)
		} else {
			if res == 0 && n < nField {
				iLower = **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(iSamp)*40))).FanLt + uintptr(n-int32(1))*8))
				iMin = iTest + int32(1)
				res = -int32(1)
			} else {
				iSample = iTest
				iCol = n - int32(1)
			}
		}
	}
	i = iSample / nField
	if res == 0 {
		/* Record pRec is equal to sample i */
		**(**TtRowcnt)(__ccgo_up(aStat)) = **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(i)*40))).FanLt + uintptr(iCol)*8))
		**(**TtRowcnt)(__ccgo_up(aStat + 1*8)) = **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(i)*40))).FanEq + uintptr(iCol)*8))
	} else {
		if i >= (*TIndex)(unsafe.Pointer(pIdx)).FnSample {
			iUpper = (*TIndex)(unsafe.Pointer(pIdx)).FnRowEst0
		} else {
			iUpper = **(**TtRowcnt)(__ccgo_up((**(**TIndexSample)(__ccgo_up(aSample + uintptr(i)*40))).FanLt + uintptr(iCol)*8))
		}
		if iLower >= iUpper {
			iGap = uint64(0)
		} else {
			iGap = iUpper - iLower
		}
		if roundUp != 0 {
			iGap = iGap * uint64(2) / uint64(3)
		} else {
			iGap = iGap / uint64(3)
		}
		**(**TtRowcnt)(__ccgo_up(aStat)) = iLower + iGap
		**(**TtRowcnt)(__ccgo_up(aStat + 1*8)) = **(**TtRowcnt)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(nField-int32(1))*8))
	}
	/* Restore the pRec->nField value before returning.  */
	(*TUnpackedRecord)(unsafe.Pointer(pRec)).FnField = libc.Uint16FromInt32(nField)
	return i
}

// C documentation
//
//	/*
//	** Add all WhereLoop objects for all tables
//	*/
func _whereLoopAddAll(tls *libc.TLS, pBuilder uintptr) (r int32) {
	var bFirstPastRJ, hasRightCrossJoin, i, iTab, rc int32
	var db, p, pEnd, pItem, pNew, pTabList, pTerm, pWC, pWInfo uintptr
	var mPrereq, mPrior, mUnusable TBitmask
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bFirstPastRJ, db, hasRightCrossJoin, i, iTab, mPrereq, mPrior, mUnusable, p, pEnd, pItem, pNew, pTabList, pTerm, pWC, pWInfo, rc
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	mPrereq = uint64(0)
	mPrior = uint64(0)
	pTabList = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	pEnd = pTabList + 8 + uintptr((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)*80
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	rc = SQLITE_OK
	bFirstPastRJ = 0
	hasRightCrossJoin = 0
	/* Loop over the tables in the join, from left to right */
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	/* Verify that pNew has already been initialized */
	(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit = uint32(SQLITE_QUERY_PLANNER_LIMIT)
	iTab = 0
	pItem = pTabList + 8
	for {
		if !(pItem < pEnd) {
			break
		}
		mUnusable = uint64(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FiTab = libc.Uint8FromInt32(iTab)
		**(**uint32)(__ccgo_up(pBuilder + 48)) += uint32(SQLITE_QUERY_PLANNER_LIMIT_INCR)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf = _sqlite3WhereGetMask(tls, pWInfo+592, (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor)
		if bFirstPastRJ != 0 || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)|libc.Int32FromInt32(JT_LTORJ)) != 0 {
			/* Add prerequisites to prevent reordering of FROM clause terms
			 ** across CROSS joins and outer joins.  The bFirstPastRJ boolean
			 ** prevents the right operand of a RIGHT JOIN from being swapped with
			 ** other elements even further to the right.
			 **
			 ** The hasRightCrossJoin flag prevent FROM-clause terms from moving
			 ** from the right side of a LEFT JOIN or CROSS JOIN over to the
			 ** left side of that same join.  This is a required restriction in
			 ** the case of LEFT JOIN - an incorrect answer may results if it is
			 ** not enforced.  This restriction is not required for CROSS JOIN.
			 ** It is provided merely as a means of controlling join order, under
			 ** the theory that no real-world queries that care about performance
			 ** actually use the CROSS JOIN syntax.
			 */
			if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_CROSS)) != 0 {
				hasRightCrossJoin = int32(1)
			}
			mPrereq = mPrereq | mPrior
			bFirstPastRJ = libc.BoolInt32(libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&int32(JT_RIGHT) != 0)
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x2000>>13) != 0 {
				/* joins that result from the EXISTS-to-JOIN optimization should not
				 ** be moved to the left of any of their dependencies */
				pWC = pWInfo + 104
				i = (*TWhereClause)(unsafe.Pointer(pWC)).FnBase
				pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
				for {
					if !(i > 0) {
						break
					}
					if (*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf&(*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll != uint64(0) {
						mPrereq = mPrereq | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&((*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf-uint64(1))
					}
					goto _2
				_2:
					;
					i = i - 1
					pTerm += 56
				}
			} else {
				if !(hasRightCrossJoin != 0) {
					mPrereq = uint64(0)
				}
			}
		}
		if libc.Int32FromUint8((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FeTabType) == int32(TABTYP_VTAB) {
			p = pItem + 1*80
			for {
				if !(p < pEnd) {
					break
				}
				if mUnusable != 0 || libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(p)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_OUTER)|libc.Int32FromInt32(JT_CROSS)) != 0 {
					mUnusable = mUnusable | _sqlite3WhereGetMask(tls, pWInfo+592, (*TSrcItem)(unsafe.Pointer(p)).FiCursor)
				}
				goto _3
			_3:
				;
				p += 80
			}
			rc = _whereLoopAddVirtual(tls, pBuilder, mPrereq, mUnusable)
		} else {
			rc = _whereLoopAddBtree(tls, pBuilder, mPrereq)
		}
		if rc == SQLITE_OK && (*TWhereClause)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC)).FhasOr != 0 {
			rc = _whereLoopAddOr(tls, pBuilder, mPrereq, mUnusable)
		}
		mPrior = mPrior | (*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf
		if rc != 0 || (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			if rc == int32(SQLITE_DONE) {
				/* We hit the query planner search limit set by iPlanLimit */
				Xsqlite3_log(tls, int32(SQLITE_WARNING), __ccgo_ts+24051, 0)
				rc = SQLITE_OK
			} else {
				break
			}
		}
		goto _1
	_1:
		;
		iTab = iTab + 1
		pItem += 80
	}
	_whereLoopClear(tls, db, pNew)
	return rc
}

// C documentation
//
//	/*
//	** Add all WhereLoop objects for a single table of the join where the table
//	** is identified by pBuilder->pNew->iTab.  That table is guaranteed to be
//	** a b-tree table, not a virtual table.
//	**
//	** The costs (WhereLoop.rRun) of the b-tree loops added by this function
//	** are calculated as follows:
//	**
//	** For a full scan, assuming the table (or index) contains nRow rows:
//	**
//	**     cost = nRow * 3.0                    // full-table scan
//	**     cost = nRow * K                      // scan of covering index
//	**     cost = nRow * (K+3.0)                // scan of non-covering index
//	**
//	** where K is a value between 1.1 and 3.0 set based on the relative
//	** estimated average size of the index and table records.
//	**
//	** For an index scan, where nVisit is the number of index rows visited
//	** by the scan, and nSeek is the number of seek operations required on
//	** the index b-tree:
//	**
//	**     cost = nSeek * (log(nRow) + K * nVisit)          // covering index
//	**     cost = nSeek * (log(nRow) + (K+3.0) * nVisit)    // non-covering index
//	**
//	** Normally, nSeek is 1. nSeek values greater than 1 come about if the
//	** WHERE clause includes "x IN (....)" terms used in place of "x=?". Or when
//	** implicit "x IN (SELECT x FROM tbl)" terms are added for skip-scans.
//	**
//	** The estimated values (nRow, nVisit, nSeek) often contain a large amount
//	** of uncertainty.  For this reason, scoring is designed to pick plans that
//	** "do the least harm" if the estimates are inaccurate.  For example, a
//	** log(nRow) factor is omitted from a non-covering index scan in order to
//	** bias the scoring in favor of using an index, since the worst-case
//	** performance of using an index is far better than the worst-case performance
//	** of a full table scan.
//	*/
func _whereLoopAddBtree(tls *libc.TLS, pBuilder uintptr, mPrereq TBitmask) (r int32) {
	bp := tls.Alloc(176)
	defer tls.Free(176)
	var b, iCur, iSortIdx, ii, rc, v5 int32
	var isCov Tu32
	var nLookup, rLogSize, rSize TLogEst
	var pFirst, pNew, pProbe, pSrc, pTab, pTabList, pTerm, pTerm1, pWC, pWC2, pWCEnd, pWInfo, v2 uintptr
	var _ /* aiColumnPk at bp+164 */ Ti16
	var _ /* aiRowEstPk at bp+160 */ [2]TLogEst
	var _ /* m at bp+168 */ TBitmask
	var _ /* sPk at bp+0 */ TIndex
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = b, iCur, iSortIdx, ii, isCov, nLookup, pFirst, pNew, pProbe, pSrc, pTab, pTabList, pTerm, pTerm1, pWC, pWC2, pWCEnd, pWInfo, rLogSize, rSize, rc, v2, v5 /* The aiRowLogEst[] value for the sPk index */
	**(**Ti16)(__ccgo_up(bp + 164)) = int16(-int32(1))                                                                                                                                                                             /* Template WhereLoop object */
	rc = SQLITE_OK                                                                                                                                                                                                                 /* Return code */
	iSortIdx = int32(1)                                                                                                                                                                                                            /* Table being queried */
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	pTabList = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	pSrc = pTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pNew)).FiTab)*80
	pTab = (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x40000000>>30) != 0 {
		/* An INDEXED BY clause specifies a particular index to use */
		pProbe = *(*uintptr)(unsafe.Pointer(pSrc + 56))
	} else {
		if !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) {
			pProbe = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		} else { /* First of real indices on the table */
			libc.Xmemset(tls, bp, 0, uint64(160))
			(**(**TIndex)(__ccgo_up(bp))).FnKeyCol = uint16(1)
			(**(**TIndex)(__ccgo_up(bp))).FnColumn = uint16(1)
			(**(**TIndex)(__ccgo_up(bp))).FaiColumn = bp + 164
			(**(**TIndex)(__ccgo_up(bp))).FaiRowLogEst = bp + 160
			(**(**TIndex)(__ccgo_up(bp))).FonError = uint8(OE_Replace)
			(**(**TIndex)(__ccgo_up(bp))).FpTable = pTab
			(**(**TIndex)(__ccgo_up(bp))).FszIdxRow = int16(3) /* TUNING: Interior rows of IPK table are very small */
			libc.SetBitFieldPtr16Uint32(bp+100, libc.Uint32FromInt32(SQLITE_IDXTYPE_IPK), 14, 0xc000)
			(**(**[2]TLogEst)(__ccgo_up(bp + 160)))[0] = (*TTable)(unsafe.Pointer(pTab)).FnRowLogEst
			(**(**[2]TLogEst)(__ccgo_up(bp + 160)))[int32(1)] = 0
			pFirst = (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FpIndex
			if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x80000000>>31) == 0 {
				/* The real indices of the table are only considered if the
				 ** NOT INDEXED qualifier is omitted from the FROM clause */
				(**(**TIndex)(__ccgo_up(bp))).FpNext = pFirst
			}
			pProbe = bp
		}
	}
	rSize = (*TTable)(unsafe.Pointer(pTab)).FnRowLogEst
	/* Automatic indexes */
	if !((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != 0) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_RIGHT_JOIN)|libc.Int32FromInt32(WHERE_OR_SUBCLAUSE)) == 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb)).Fflags&uint64(SQLITE_AutoIndex) != uint64(0) && !(int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x40000000>>30) != 0) && !(int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x80000000>>31) != 0) && !(int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x8000000>>27) != 0) && !(int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x1000000>>24) != 0) && libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_RIGHT) == 0 {
		pWCEnd = (*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*TWhereClause)(unsafe.Pointer(pWC)).FnTerm)*56
		rLogSize = _estLog(tls, rSize)
		pTerm = (*TWhereClause)(unsafe.Pointer(pWC)).Fa
		for {
			if !(rc == SQLITE_OK && pTerm < pWCEnd) {
				break
			}
			if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf != 0 {
				goto _1
			}
			if _termCanDriveIndex(tls, pTerm, pSrc, uint64(0)) != 0 {
				(*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pNew + 24))).FnEq = uint16(1)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = uint16(0)
				(*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pNew + 24))).FpIndex = uintptr(0)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = uint16(1)
				**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm)) = pTerm
				/* TUNING: One-time cost for computing the automatic index is
				 ** estimated to be X*N*log2(N) where N is the number of rows in
				 ** the table being indexed and where X is 7 (LogEst=28) for normal
				 ** tables or 0.5 (LogEst=-10) for views and subqueries.  The value
				 ** of X is smaller for views and subqueries so that the query planner
				 ** will be more aggressive about generating automatic indexes for
				 ** those objects, since there is no opportunity to add schema
				 ** indexes on subqueries and views. */
				(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(int32(rLogSize) + int32(rSize))
				if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == libc.Int32FromInt32(TABTYP_VIEW)) && (*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_Ephemeral) == uint32(0) {
					v2 = pNew + 18
					*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) + libc.Int32FromInt32(28))
				} else {
					v2 = pNew + 18
					*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) - libc.Int32FromInt32(25)) /* Greatly reduced setup cost for auto indexes
					 ** on ephemeral materializations of views */
				}
				if int32((*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup) < 0 {
					(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
				}
				/* TUNING: Each index lookup yields 20 rows in the table.  This
				 ** is more than the usual guess of 10 rows, since we have no way
				 ** of knowing how selective the index will ultimately be.  It would
				 ** not be unreasonable to make this value much larger. */
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = int16(43)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = _sqlite3LogEstAdd(tls, rLogSize, (*TWhereLoop)(unsafe.Pointer(pNew)).FnOut)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(WHERE_AUTO_INDEX)
				(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
				rc = _whereLoopInsert(tls, pBuilder, pNew)
			}
			goto _1
		_1:
			;
			pTerm += 56
		}
	}
	/* Loop over all indices. If there was an INDEXED BY clause, then only
	 ** consider index pProbe.  */
	for {
		if !(rc == SQLITE_OK && pProbe != 0) {
			break
		}
		if (*TIndex)(unsafe.Pointer(pProbe)).FpPartIdxWhere != uintptr(0) && !(_whereUsablePartialIndex(tls, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor, (*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype, pWC, (*TIndex)(unsafe.Pointer(pProbe)).FpPartIdxWhere) != 0) {
			/* See ticket [98d973b8f5] */
			goto _4 /* Partial index inappropriate for this query */
		}
		if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x80>>7)) != 0 {
			goto _4
		}
		rSize = **(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst))
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq = uint16(0)
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnBtm = uint16(0)
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnTop = uint16(0)
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnDistinctCol = uint16(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = uint16(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = uint16(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = uint8(0)
		(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FpIndex = pProbe
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FpOrderBy = uintptr(0)
		b = _indexMightHelpWithOrderBy(tls, pBuilder, pProbe, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor)
		/* The ONEPASS_DESIRED flags never occurs together with ORDER BY */
		if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_IPK) {
			/* Integer primary key index */
			(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(WHERE_IPK)
			/* Full table scan */
			if b != 0 {
				v5 = iSortIdx
			} else {
				v5 = 0
			}
			(*TWhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = libc.Uint8FromInt32(v5)
			/* TUNING: Cost of full table scan is 3.0*N.  The 3.0 factor is an
			 ** extra cost designed to discourage the use of full table scans,
			 ** since index lookups have better worst-case performance if our
			 ** stat guesses are wrong.  Reduce the 3.0 penalty slightly
			 ** (to 2.75) if we have valid STAT4 information for the table.
			 ** At 2.75, a full table scan is preferred over using an index on
			 ** a column with just two distinct values where each value has about
			 ** an equal number of appearances.  Without STAT4 data, we still want
			 ** to use an index in that case, since the constraint might be for
			 ** the scarcer of the two values, and in that case an index lookup is
			 ** better.
			 */
			(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = int16(int32(rSize) + int32(16) - int32(2)*libc.BoolInt32((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_HasStat4) != uint32(0)))
			_whereLoopOutputAdjust(tls, pWC, pNew, rSize)
			if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x20000000>>29) != 0 {
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000000>>25) != 0 {
					**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_COROUTINE)
				}
				/* Do not set btree.pOrderBy for a recursive CTE. In this case
				 ** the ORDER BY clause does not determine the overall order that
				 ** rows are emitted from the CTE in.  */
				if (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 72)))).FpSelect)).FselFlags&uint32(SF_Recursive) == uint32(0) {
					(*(*struct {
						FnEq          Tu16
						FnBtm         Tu16
						FnTop         Tu16
						FnDistinctCol Tu16
						FpIndex       uintptr
						FpOrderBy     uintptr
					})(unsafe.Pointer(pNew + 24))).FpOrderBy = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 72)))).FpSelect)).FpOrderBy
				}
			} else {
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000>>13) != 0 {
					(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = 0
				}
			}
			rc = _whereLoopInsert(tls, pBuilder, pNew)
			(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
			if rc != 0 {
				break
			}
		} else {
			if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x400>>10)) != 0 {
				**(**TBitmask)(__ccgo_up(bp + 168)) = uint64(0)
				(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY) | libc.Int32FromInt32(WHERE_INDEXED))
			} else {
				**(**TBitmask)(__ccgo_up(bp + 168)) = (*TSrcItem)(unsafe.Pointer(pSrc)).FcolUsed & (*TIndex)(unsafe.Pointer(pProbe)).FcolNotIdxed
				if (*TIndex)(unsafe.Pointer(pProbe)).FpPartIdxWhere != 0 {
					_wherePartIdxExpr(tls, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse, pProbe, (*TIndex)(unsafe.Pointer(pProbe)).FpPartIdxWhere, bp+168, 0, uintptr(0))
				}
				(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(WHERE_INDEXED)
				if **(**TBitmask)(__ccgo_up(bp + 168)) == libc.Uint64FromInt32(1)<<(libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1)) || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x10>>4)) != 0 && !(int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x20>>5)) != 0) && **(**TBitmask)(__ccgo_up(bp + 168)) != uint64(0) {
					isCov = _whereIsCoveringIndex(tls, pWInfo, pProbe, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor)
					if isCov == uint32(0) {
					} else {
						**(**TBitmask)(__ccgo_up(bp + 168)) = uint64(0)
						**(**Tu32)(__ccgo_up(pNew + 48)) |= isCov
						if isCov&uint32(WHERE_IDX_ONLY) != 0 {
						} else {
						}
					}
				} else {
					if **(**TBitmask)(__ccgo_up(bp + 168)) == uint64(0) && ((*TTable)(unsafe.Pointer(pTab)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) || (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpSelect != uintptr(0) || _sqlite3FaultSim(tls, int32(700)) != 0) {
						(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY) | libc.Int32FromInt32(WHERE_INDEXED))
					}
				}
			}
			/* Full scan via index */
			if b != 0 || !((*TTable)(unsafe.Pointer(pTab)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) || (*TIndex)(unsafe.Pointer(pProbe)).FpPartIdxWhere != uintptr(0) || int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x40000000>>30) != 0 || **(**TBitmask)(__ccgo_up(bp + 168)) == uint64(0) && int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x2000>>13)) == 0 && int32((*TIndex)(unsafe.Pointer(pProbe)).FszIdxRow) < int32((*TTable)(unsafe.Pointer(pTab)).FszTabRow) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_ONEPASS_DESIRED) == 0 && _sqlite3Config.FbUseCis != 0 && (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_CoverIdxScan)) == uint32(0) {
				if b != 0 {
					v5 = iSortIdx
				} else {
					v5 = 0
				}
				(*TWhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = libc.Uint8FromInt32(v5)
				/* The cost of visiting the index rows is N*K, where K is
				 ** between 1.1 and 3.0, depending on the relative sizes of the
				 ** index and table rows. */
				(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = int16(int32(rSize) + int32(1) + int32(15)*int32((*TIndex)(unsafe.Pointer(pProbe)).FszIdxRow)/int32((*TTable)(unsafe.Pointer(pTab)).FszTabRow))
				if **(**TBitmask)(__ccgo_up(bp + 168)) != uint64(0) {
					/* If this is a non-covering index scan, add in the cost of
					 ** doing table lookups.  The cost will be 3x the number of
					 ** lookups.  Take into account WHERE clause terms that can be
					 ** satisfied using just the index, and that do not require a
					 ** table lookup. */
					nLookup = int16(int32(rSize) + int32(16))
					iCur = (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor
					pWC2 = pWInfo + 104
					ii = 0
					for {
						if !(ii < (*TWhereClause)(unsafe.Pointer(pWC2)).FnTerm) {
							break
						}
						pTerm1 = (*TWhereClause)(unsafe.Pointer(pWC2)).Fa + uintptr(ii)*56
						if !(_sqlite3ExprCoveredByIndex(tls, (*TWhereTerm)(unsafe.Pointer(pTerm1)).FpExpr, iCur, pProbe) != 0) {
							break
						}
						/* pTerm can be evaluated using just the index.  So reduce
						 ** the expected number of table lookups accordingly */
						if int32((*TWhereTerm)(unsafe.Pointer(pTerm1)).FtruthProb) <= 0 {
							nLookup = int16(int32(nLookup) + int32((*TWhereTerm)(unsafe.Pointer(pTerm1)).FtruthProb))
						} else {
							nLookup = nLookup - 1
							if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0 {
								nLookup = int16(int32(nLookup) - libc.Int32FromInt32(19))
							}
						}
						goto _7
					_7:
						;
						ii = ii + 1
					}
					(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = _sqlite3LogEstAdd(tls, (*TWhereLoop)(unsafe.Pointer(pNew)).FrRun, nLookup)
				}
				_whereLoopOutputAdjust(tls, pWC, pNew, rSize)
				if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&int32(JT_RIGHT) != 0 && (*TIndex)(unsafe.Pointer(pProbe)).FaColExpr != 0 {
					/* Do not do an SCAN of a index-on-expression in a RIGHT JOIN
					 ** because the cursor used to access the index might not be
					 ** positioned to the correct row during the right-join no-match
					 ** loop. */
				} else {
					if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000>>13) != 0 {
						(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = 0
					}
					rc = _whereLoopInsert(tls, pBuilder, pNew)
				}
				(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
				if rc != 0 {
					break
				}
			}
		}
		(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FbldFlags1 = uint8(0)
		rc = _whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, 0)
		if libc.Int32FromUint8((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FbldFlags1) == int32(SQLITE_BLDF1_INDEXED) {
			/* If a non-unique index is used, or if a prefix of the key for
			 ** unique index is used (making the index functionally non-unique)
			 ** then the sqlite_stat1 data becomes important for scoring the
			 ** plan */
			**(**Tu32)(__ccgo_up(pTab + 48)) |= uint32(TF_MaybeReanalyze)
		}
		_sqlite3Stat4ProbeFree(tls, (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec)
		(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = 0
		(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec = uintptr(0)
		goto _4
	_4:
		;
		if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x40000000>>30) != 0 {
			v2 = uintptr(0)
		} else {
			v2 = (*TIndex)(unsafe.Pointer(pProbe)).FpNext
		}
		pProbe = v2
		iSortIdx = iSortIdx + 1
	}
	return rc
}

// C documentation
//
//	/*
//	** We have so far matched pBuilder->pNew->u.btree.nEq terms of the
//	** index pIndex. Try to match one more.
//	**
//	** When this function is called, pBuilder->pNew->nOut contains the
//	** number of rows expected to be visited by filtering using the nEq
//	** terms only. If it is modified, this value is restored before this
//	** function returns.
//	**
//	** If pProbe->idxType==SQLITE_IDXTYPE_IPK, that means pIndex is
//	** a fake index used for the INTEGER PRIMARY KEY.
//	*/
func _whereLoopAddBtreeIndex(tls *libc.TLS, pBuilder uintptr, pSrc uintptr, pProbe uintptr, nInMul TLogEst) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var M, logK, nIter, nOutUnadjusted, rCostIdx, rLogSize, rSize, saved_nOut, x TLogEst
	var bRedundant, i, iCol, nEq, nIn, nRecValid, nVecLen, opMask, rc, v21 int32
	var db, pBtm, pExpr, pExpr1, pNew, pParse, pTerm, pTop, pWInfo, v2 uintptr
	var eOp, saved_nBtm, saved_nEq, saved_nLTerm, saved_nSkip, saved_nTop, v4 Tu16
	var saved_prereq TBitmask
	var saved_wsFlags Tu32
	var v22 bool
	var _ /* nOut at bp+112 */ TtRowcnt
	var _ /* scan at bp+0 */ TWhereScan
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = M, bRedundant, db, eOp, i, iCol, logK, nEq, nIn, nIter, nOutUnadjusted, nRecValid, nVecLen, opMask, pBtm, pExpr, pExpr1, pNew, pParse, pTerm, pTop, pWInfo, rCostIdx, rLogSize, rSize, rc, saved_nBtm, saved_nEq, saved_nLTerm, saved_nOut, saved_nSkip, saved_nTop, saved_prereq, saved_wsFlags, x, v2, v21, v22, v4
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo /* WHERE analyze context */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse          /* Parsing context */
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb                      /* Original value of pNew->nOut */
	rc = SQLITE_OK                                                  /* Logarithm of table size */
	pTop = uintptr(0)
	pBtm = uintptr(0) /* Top and bottom range constraints */
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return (*TParse)(unsafe.Pointer(pParse)).Frc
	}
	if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&uint32(WHERE_BTM_LIMIT) != 0 {
		opMask = libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ))
	} else {
		opMask = libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IN) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_ISNULL) | libc.Int32FromInt32(WO_IS)
	}
	if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x2000>>13)) != 0 {
		opMask = opMask & ^(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) | libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LE)-libc.Int32FromInt32(TK_EQ)))
	}
	saved_nEq = (*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pNew + 24))).FnEq
	saved_nBtm = (*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pNew + 24))).FnBtm
	saved_nTop = (*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pNew + 24))).FnTop
	saved_nSkip = (*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip
	saved_nLTerm = (*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm
	saved_wsFlags = (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags
	saved_prereq = (*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq
	saved_nOut = (*TWhereLoop)(unsafe.Pointer(pNew)).FnOut
	pTerm = _whereScanInit(tls, bp, (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor, libc.Int32FromUint16(saved_nEq), libc.Uint32FromInt32(opMask), pProbe)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
	rSize = **(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst))
	rLogSize = _estLog(tls, rSize)
	for {
		if !(rc == SQLITE_OK && pTerm != uintptr(0)) {
			break
		}
		eOp = (*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator /* nOut before IN() and WHERE adjustments */
		nIn = 0
		nRecValid = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid
		if (libc.Int32FromUint16(eOp) == int32(WO_ISNULL) || libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_VNULL) != 0) && _indexColumnNotNull(tls, pProbe, libc.Int32FromUint16(saved_nEq)) != 0 {
			goto _1 /* ignore IS [NOT] NULL constraints on NOT NULL columns */
		}
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf != 0 {
			goto _1
		}
		/* Do not allow the upper bound of a LIKE optimization range constraint
		 ** to mix with a lower range bound from some other source */
		if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_LIKEOPT) != 0 && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) == libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_LT)-libc.Int32FromInt32(TK_EQ)) {
			goto _1
		}
		if libc.Int32FromUint8((*TSrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(libc.Int32FromInt32(JT_LEFT)|libc.Int32FromInt32(JT_LTORJ)|libc.Int32FromInt32(JT_RIGHT)) != 0 && !(_constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
			goto _1
		}
		if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pProbe)).FonError) != OE_None && libc.Int32FromUint16(saved_nEq) == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol)-int32(1) {
			v2 = pBuilder + 44
			*(*uint8)(unsafe.Pointer(v2)) = uint8(int32(*(*uint8)(unsafe.Pointer(v2))) | libc.Int32FromInt32(SQLITE_BLDF1_UNIQUE))
		} else {
			v2 = pBuilder + 44
			*(*uint8)(unsafe.Pointer(v2)) = uint8(int32(*(*uint8)(unsafe.Pointer(v2))) | libc.Int32FromInt32(SQLITE_BLDF1_INDEXED))
		}
		(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq = saved_nEq
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnBtm = saved_nBtm
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnTop = saved_nTop
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = saved_nLTerm
		if libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm) >= libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLSlot) && _whereLoopResize(tls, db, pNew, libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+int32(1)) != 0 {
			break /* OOM while trying to enlarge the pNew->aLTerm array */
		}
		v2 = pNew + 52
		v4 = *(*Tu16)(unsafe.Pointer(v2))
		*(*Tu16)(unsafe.Pointer(v2)) = *(*Tu16)(unsafe.Pointer(v2)) + 1
		**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(v4)*8)) = pTerm
		(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = (saved_prereq | (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight) & ^(*TWhereLoop)(unsafe.Pointer(pNew)).FmaskSelf
		if libc.Int32FromUint16(eOp)&int32(WO_IN) != 0 {
			pExpr = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
				bRedundant = 0
				nIn = int32(46)
				/* The expression may actually be of the form (x, y) IN (SELECT...).
				 ** In this case there is a separate term for each of (x) and (y).
				 ** However, the nIn multiplier should only be applied once, not once
				 ** for each such term. The following loop checks that pTerm is the
				 ** first such term in use, and sets nIn back to 0 if it is not. */
				i = 0
				for {
					if !(i < libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)-int32(1)) {
						break
					}
					if **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)) != 0 && (*TWhereTerm)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)))).FpExpr == pExpr {
						nIn = 0
						if (*(*struct {
							FleftColumn int32
							FiField     int32
						})(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)) + 32))).FiField == (*(*struct {
							FleftColumn int32
							FiField     int32
						})(unsafe.Pointer(pTerm + 32))).FiField {
							/* Detect when two or more columns of an index match the same
							 ** column of a vector IN operater, and avoid adding the column
							 ** to the WhereLoop more than once.  See tag-20250707-01
							 ** in test/rowvalue.test */
							bRedundant = int32(1)
						}
					}
					goto _6
				_6:
					;
					i = i + 1
				}
				if bRedundant != 0 {
					(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = (*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm - 1
					goto _1
				}
			} else {
				if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != 0 && (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr != 0 {
					/* "x IN (value, value, ...)" */
					nIn = int32(_sqlite3LogEst(tls, libc.Uint64FromInt32((*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr)))
				}
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x100>>8)) != 0 && int32(rLogSize) >= int32(10) {
				/* Let:
				 **   N = the total number of rows in the table
				 **   K = the number of entries on the RHS of the IN operator
				 **   M = the number of rows in the table that match terms to the
				 **       to the left in the same index.  If the IN operator is on
				 **       the left-most index column, M==N.
				 **
				 ** Given the definitions above, it is better to omit the IN operator
				 ** from the index lookup and instead do a scan of the M elements,
				 ** testing each scanned row against the IN operator separately, if:
				 **
				 **        M*log(K) < K*log(N)
				 **
				 ** Our estimates for M, K, and N might be inaccurate, so we build in
				 ** a safety margin of 2 (LogEst: 10) that favors using the IN operator
				 ** with the index, as using an index has better worst-case behavior.
				 ** If we do not have real sqlite_stat1 data, always prefer to use
				 ** the index.  Do not bother with this optimization on very small
				 ** tables (less than 2 rows) as it is pointless in that case.
				 */
				M = **(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(saved_nEq)*2))
				logK = _estLog(tls, int16(nIn))
				/* TUNING      v-----  10 to bias toward indexed IN */
				x = int16(int32(M) + int32(logK) + int32(10) - (nIn + int32(rLogSize)))
				if int32(x) >= 0 {
				} else {
					if int32(nInMul) < int32(2) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_SeekScan)) == uint32(0) {
						**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_IN_SEEKSCAN)
					} else {
						goto _1
					}
				}
			}
			**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_COLUMN_IN)
		} else {
			if libc.Int32FromUint16(eOp)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0 {
				iCol = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiColumn + uintptr(saved_nEq)*2)))
				**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_COLUMN_EQ)
				if iCol == -int32(1) || iCol >= 0 && int32(nInMul) == 0 && libc.Int32FromUint16(saved_nEq) == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol)-int32(1) {
					if iCol == -int32(1) || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x1000>>12)) != 0 || libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol) == int32(1) && (*TIndex)(unsafe.Pointer(pProbe)).FonError != 0 && libc.Int32FromUint16(eOp)&int32(WO_EQ) != 0 {
						**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_ONEROW)
					} else {
						**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_UNQ_WANTED)
					}
				}
				if libc.Int32FromUint8((**(**TWhereScan)(__ccgo_up(bp))).FiEquiv) > int32(1) {
					**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_TRANSCONS)
				}
			} else {
				if libc.Int32FromUint16(eOp)&int32(WO_ISNULL) != 0 {
					**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_COLUMN_NULL)
				} else {
					nVecLen = _whereRangeVectorLen(tls, pParse, (*TSrcItem)(unsafe.Pointer(pSrc)).FiCursor, pProbe, libc.Int32FromUint16(saved_nEq), pTerm)
					if libc.Int32FromUint16(eOp)&(libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GT)-libc.Int32FromInt32(TK_EQ))|libc.Int32FromInt32(WO_EQ)<<(libc.Int32FromInt32(TK_GE)-libc.Int32FromInt32(TK_EQ))) != 0 {
						**(**Tu32)(__ccgo_up(pNew + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_RANGE) | libc.Int32FromInt32(WHERE_BTM_LIMIT))
						(*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pNew + 24))).FnBtm = libc.Uint16FromInt32(nVecLen)
						pBtm = pTerm
						pTop = uintptr(0)
						if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_LIKEOPT) != 0 {
							/* Range constraints that come from the LIKE optimization are
							 ** always used in pairs. */
							pTop = pTerm + 1*56
							if _whereLoopResize(tls, db, pNew, libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+int32(1)) != 0 {
								break
							} /* OOM */
							v2 = pNew + 52
							v4 = *(*Tu16)(unsafe.Pointer(v2))
							*(*Tu16)(unsafe.Pointer(v2)) = *(*Tu16)(unsafe.Pointer(v2)) + 1
							**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(v4)*8)) = pTop
							**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_TOP_LIMIT)
							(*(*struct {
								FnEq          Tu16
								FnBtm         Tu16
								FnTop         Tu16
								FnDistinctCol Tu16
								FpIndex       uintptr
								FpOrderBy     uintptr
							})(unsafe.Pointer(pNew + 24))).FnTop = uint16(1)
						}
					} else {
						**(**Tu32)(__ccgo_up(pNew + 48)) |= libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_RANGE) | libc.Int32FromInt32(WHERE_TOP_LIMIT))
						(*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pNew + 24))).FnTop = libc.Uint16FromInt32(nVecLen)
						pTop = pTerm
						if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&uint32(WHERE_BTM_LIMIT) != uint32(0) {
							v2 = **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)-int32(2))*8))
						} else {
							v2 = uintptr(0)
						}
						pBtm = v2
					}
				}
			}
		}
		/* At this point pNew->nOut is set to the number of rows expected to
		 ** be visited by the index scan before considering term pTerm, or the
		 ** values of nIn and nInMul. In other words, assuming that all
		 ** "x IN(...)" terms are replaced with "x = ?". This block updates
		 ** the value of pNew->nOut to account for pTerm (but not nIn/nInMul).  */
		if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&uint32(WHERE_COLUMN_RANGE) != 0 {
			/* Adjust nOut using stat4 data. Or, if there is no stat4
			 ** data, using some other estimate.  */
			_whereRangeScanEst(tls, pParse, pBuilder, pBtm, pTop, pNew)
		} else {
			v2 = pNew + 24
			*(*Tu16)(unsafe.Pointer(v2)) = *(*Tu16)(unsafe.Pointer(v2)) + 1
			v4 = *(*Tu16)(unsafe.Pointer(v2))
			nEq = libc.Int32FromUint16(v4)
			if int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 && int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiColumn + uintptr(saved_nEq)*2))) >= 0 {
				v2 = pNew + 22
				*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) + int32((*TWhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
				v2 = pNew + 22
				*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) - nIn)
			} else {
				**(**TtRowcnt)(__ccgo_up(bp + 112)) = uint64(0)
				if int32(nInMul) == 0 && (*TIndex)(unsafe.Pointer(pProbe)).FnSample != 0 && libc.Int32FromUint16((*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pNew + 24))).FnEq) <= (*TIndex)(unsafe.Pointer(pProbe)).FnSampleCol && (libc.Int32FromUint16(eOp)&int32(WO_IN) == 0 || (*TExpr)(unsafe.Pointer((*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&uint32(EP_xIsSelect) == uint32(0)) && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_Stat4)) == uint32(0) {
					pExpr1 = (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr
					if libc.Int32FromUint16(eOp)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_ISNULL)|libc.Int32FromInt32(WO_IS)) != 0 {
						rc = _whereEqualScanEst(tls, pParse, pBuilder, (*TExpr)(unsafe.Pointer(pExpr1)).FpRight, bp+112)
					} else {
						rc = _whereInScanEst(tls, pParse, pBuilder, *(*uintptr)(unsafe.Pointer(pExpr1 + 32)), bp+112)
					}
					if rc == int32(SQLITE_NOTFOUND) {
						rc = SQLITE_OK
					}
					if rc != SQLITE_OK {
						break
					} /* Jump out of the pTerm loop */
					if **(**TtRowcnt)(__ccgo_up(bp + 112)) != 0 {
						(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = _sqlite3LogEst(tls, **(**TtRowcnt)(__ccgo_up(bp + 112)))
						if nEq == int32(1) && int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut)+int32(10) > int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst))) {
							v2 = pTerm + 18
							*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) | libc.Int32FromInt32(TERM_HIGHTRUTH))
							if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&int32(TERM_HEURTRUTH) != 0 {
								/* If the term has previously been used with an assumption of
								 ** higher selectivity, then set the flag to rerun the
								 ** loop computations. */
								v2 = pBuilder + 45
								*(*uint8)(unsafe.Pointer(v2)) = uint8(int32(*(*uint8)(unsafe.Pointer(v2))) | libc.Int32FromInt32(SQLITE_BLDF2_2NDPASS))
							}
						}
						if int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut) > int32(saved_nOut) {
							(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
						}
						v2 = pNew + 22
						*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) - nIn)
					}
				}
				if **(**TtRowcnt)(__ccgo_up(bp + 112)) == uint64(0) {
					v2 = pNew + 22
					*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) + (int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(nEq)*2))) - int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(nEq-int32(1))*2)))))
					if libc.Int32FromUint16(eOp)&int32(WO_ISNULL) != 0 {
						/* TUNING: If there is no likelihood() value, assume that a
						 ** "col IS NULL" expression matches twice as many rows
						 ** as (col=?). */
						v2 = pNew + 22
						*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) + libc.Int32FromInt32(10))
					}
				}
			}
		}
		/* Set rCostIdx to the estimated cost of visiting selected rows in the
		 ** index.  The estimate is the sum of two values:
		 **   1.  The cost of doing one search-by-key to find the first matching
		 **       entry
		 **   2.  Stepping forward in the index pNew->nOut times to find all
		 **       additional matching entries.
		 */
		if int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_IPK) {
			/* The pProbe->szIdxRow is low for an IPK table since the interior
			 ** pages are small.  Thus szIdxRow gives a good estimate of seek cost.
			 ** But the leaf pages are full-size, so pProbe->szIdxRow would badly
			 ** under-estimate the scanning cost. */
			rCostIdx = int16(int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut) + int32(16))
		} else {
			rCostIdx = int16(int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut) + int32(1) + int32(15)*int32((*TIndex)(unsafe.Pointer(pProbe)).FszIdxRow)/int32((*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FszTabRow))
		}
		rCostIdx = _sqlite3LogEstAdd(tls, rLogSize, rCostIdx)
		/* Estimate the cost of running the loop.  If all data is coming
		 ** from the index, then this is just the cost of doing the index
		 ** lookup and scan.  But if some data is coming out of the main table,
		 ** we also have to add in the cost of doing pNew->nOut searches to
		 ** locate the row in the main table that corresponds to the index entry.
		 */
		(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = rCostIdx
		if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IDX_ONLY)|libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_EXPRIDX)) == uint32(0) {
			(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = _sqlite3LogEstAdd(tls, (*TWhereLoop)(unsafe.Pointer(pNew)).FrRun, int16(int32((*TWhereLoop)(unsafe.Pointer(pNew)).FnOut)+int32(16)))
		}
		nOutUnadjusted = (*TWhereLoop)(unsafe.Pointer(pNew)).FnOut
		v2 = pNew + 20
		*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) + (int32(nInMul) + nIn))
		v2 = pNew + 22
		*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) + (int32(nInMul) + nIn))
		_whereLoopOutputAdjust(tls, (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC, pNew, rSize)
		if int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000>>13) != 0 {
			(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = 0
		}
		rc = _whereLoopInsert(tls, pBuilder, pNew)
		if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&uint32(WHERE_COLUMN_RANGE) != 0 {
			(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		} else {
			(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = nOutUnadjusted
		}
		if (*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags&uint32(WHERE_TOP_LIMIT) == uint32(0) && libc.Int32FromUint16((*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq) < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pProbe)).FnColumn) && (libc.Int32FromUint16((*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq) < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol) || int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0xc000>>14)) != int32(SQLITE_IDXTYPE_PRIMARYKEY)) {
			if libc.Int32FromUint16((*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pNew + 24))).FnEq) > int32(3) {
				_sqlite3ProgressCheck(tls, pParse)
			}
			_whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(int32(nInMul)+nIn))
		}
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = nRecValid
		goto _1
	_1:
		;
		pTerm = _whereScanNext(tls, bp)
	}
	(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = saved_prereq
	(*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pNew + 24))).FnEq = saved_nEq
	(*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pNew + 24))).FnBtm = saved_nBtm
	(*(*struct {
		FnEq          Tu16
		FnBtm         Tu16
		FnTop         Tu16
		FnDistinctCol Tu16
		FpIndex       uintptr
		FpOrderBy     uintptr
	})(unsafe.Pointer(pNew + 24))).FnTop = saved_nTop
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = saved_nSkip
	(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = saved_nLTerm
	/* Consider using a skip-scan if there are no WHERE clause constraints
	 ** available for the left-most terms of the index, and if the average
	 ** number of repeats in the left-most terms is at least 18.
	 **
	 ** The magic number 18 is selected on the basis that scanning 17 rows
	 ** is almost always quicker than an index seek (even though if the index
	 ** contains fewer than 2^17 rows we assume otherwise in other parts of
	 ** the code). And, even if it is not, it should not be too much slower.
	 ** On the other hand, the extra seeks could end up being significantly
	 ** more expensive.  */
	if v22 = libc.Int32FromUint16(saved_nEq) == libc.Int32FromUint16(saved_nSkip) && libc.Int32FromUint16(saved_nEq)+int32(1) < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pProbe)).FnKeyCol) && libc.Int32FromUint16(saved_nEq) == libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm) && int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x200>>9)) == 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x100>>8)) != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_SkipScan)) == uint32(0) && int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(libc.Int32FromUint16(saved_nEq)+int32(1))*2))) >= int32(42) && int32(*(*uint32)(unsafe.Pointer(pSrc + 24 + 4))&0x2000>>13) == 0; v22 {
		v21 = _whereLoopResize(tls, db, pNew, libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+int32(1))
		rc = v21
	}
	if v22 && v21 == SQLITE_OK {
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq = (*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq + 1
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = (*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip + 1
		v2 = pNew + 52
		v4 = *(*Tu16)(unsafe.Pointer(v2))
		*(*Tu16)(unsafe.Pointer(v2)) = *(*Tu16)(unsafe.Pointer(v2)) + 1
		**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(v4)*8)) = uintptr(0)
		**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_SKIPSCAN)
		nIter = int16(int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(saved_nEq)*2))) - int32(**(**TLogEst)(__ccgo_up((*TIndex)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(libc.Int32FromUint16(saved_nEq)+int32(1))*2))))
		v2 = pNew + 22
		*(*TLogEst)(unsafe.Pointer(v2)) = TLogEst(int32(*(*TLogEst)(unsafe.Pointer(v2))) - int32(nIter))
		/* TUNING:  Because uncertainties in the estimates for skip-scan queries,
		 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
		nIter = int16(int32(nIter) + libc.Int32FromInt32(5))
		_whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(int32(nIter)+int32(nInMul)))
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pNew + 24))).FnEq = saved_nEq
		(*TWhereLoop)(unsafe.Pointer(pNew)).FnSkip = saved_nSkip
		(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
	}
	return rc
}

// C documentation
//
//	/*
//	** Add all WhereLoop objects for a table of the join identified by
//	** pBuilder->pNew->iTab.  That table is guaranteed to be a virtual table.
//	**
//	** If there are no LEFT or CROSS JOIN joins in the query, both mPrereq and
//	** mUnusable are set to 0. Otherwise, mPrereq is a mask of all FROM clause
//	** entries that occur before the virtual table in the FROM clause and are
//	** separated from it by at least one LEFT or CROSS JOIN. Similarly, the
//	** mUnusable mask contains all FROM clause entries that occur after the
//	** virtual table and are separated from it by at least one LEFT or
//	** CROSS JOIN.
//	**
//	** For example, if the query were:
//	**
//	**   ... FROM t1, t2 LEFT JOIN t3, t4, vt CROSS JOIN t5, t6;
//	**
//	** then mPrereq corresponds to (t1, t2) and mUnusable to (t5, t6).
//	**
//	** All the tables in mPrereq must be scanned before the current virtual
//	** table. So any terms for which all prerequisites are satisfied by
//	** mPrereq may be specified as "usable" in all calls to xBestIndex.
//	** Conversely, all tables in mUnusable must be scanned after the current
//	** virtual table, so any terms for which the prerequisites overlap with
//	** mUnusable should always be configured as "not-usable" for xBestIndex.
//	*/
func _whereLoopAddVirtual(tls *libc.TLS, pBuilder uintptr, mPrereq TBitmask, mUnusable TBitmask) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iTerm, nConstraint, rc, seenZero, seenZeroNoIN int32
	var mBest, mBestNoIn, mNext, mPrev, mThis, v1 TBitmask
	var p, pNew, pParse, pSrc, pWC, pWInfo uintptr
	var v2 bool
	var _ /* bIn at bp+0 */ int32
	var _ /* bRetry at bp+8 */ int32
	var _ /* mNoOmit at bp+4 */ Tu16
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iTerm, mBest, mBestNoIn, mNext, mPrev, mThis, nConstraint, p, pNew, pParse, pSrc, pWC, pWInfo, rc, seenZero, seenZeroNoIN, v1, v2
	rc = SQLITE_OK
	**(**int32)(__ccgo_up(bp + 8)) = 0 /* True to retry with LIMIT/OFFSET disabled */
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	pSrc = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pNew)).FiTab)*80
	p = _allocateIndexInfo(tls, pWInfo, pWC, mUnusable, pSrc, bp+4)
	if p == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
	(*TWhereLoop)(unsafe.Pointer(pNew)).FwsFlags = uint32(WHERE_VIRTUALTABLE)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = uint16(0)
	libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32(0), 7, 0x80)
	nConstraint = (*Tsqlite3_index_info)(unsafe.Pointer(p)).FnConstraint
	if _whereLoopResize(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pNew, nConstraint) != 0 {
		_freeIndexInfo(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p)
		return int32(SQLITE_NOMEM)
	}
	/* First call xBestIndex() with all constraints usable. */
	rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, libc.Uint64FromInt32(-libc.Int32FromInt32(1)), uint16(0), p, **(**Tu16)(__ccgo_up(bp + 4)), bp, bp+8)
	if **(**int32)(__ccgo_up(bp + 8)) != 0 {
		rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, libc.Uint64FromInt32(-libc.Int32FromInt32(1)), uint16(0), p, **(**Tu16)(__ccgo_up(bp + 4)), bp, uintptr(0))
	}
	/* If the call to xBestIndex() with all terms enabled produced a plan
	 ** that does not require any source tables (IOW: a plan with mBest==0)
	 ** and does not use an IN(...) operator, then there is no point in making
	 ** any further calls to xBestIndex() since they will all return the same
	 ** result (if the xBestIndex() implementation is sane). */
	if v2 = rc == SQLITE_OK; v2 {
		v1 = (*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq & ^mPrereq
		mBest = v1
	}
	if v2 && (v1 != uint64(0) || **(**int32)(__ccgo_up(bp)) != 0) {
		seenZero = 0     /* True if a plan with no prereqs seen */
		seenZeroNoIN = 0 /* Plan with no prereqs and no IN(...) seen */
		mPrev = uint64(0)
		mBestNoIn = uint64(0)
		/* If the plan produced by the earlier call uses an IN(...) term, call
		 ** xBestIndex again, this time with IN(...) terms disabled. */
		if **(**int32)(__ccgo_up(bp)) != 0 {
			rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, libc.Uint64FromInt32(-libc.Int32FromInt32(1)), uint16(WO_IN), p, **(**Tu16)(__ccgo_up(bp + 4)), bp, uintptr(0))
			mBestNoIn = (*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq & ^mPrereq
			if mBestNoIn == uint64(0) {
				seenZero = int32(1)
				seenZeroNoIN = int32(1)
			}
		}
		/* Call xBestIndex once for each distinct value of (prereqRight & ~mPrereq)
		 ** in the set of terms that apply to the current virtual table.  */
		for rc == SQLITE_OK {
			mNext = libc.Uint64FromInt32(-libc.Int32FromInt32(1))
			i = 0
			for {
				if !(i < nConstraint) {
					break
				}
				iTerm = (**(**Tsqlite3_index_constraint)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(p)).FaConstraint + uintptr(i)*12))).FiTermOffset
				mThis = (*TWhereTerm)(unsafe.Pointer(_termFromWhereClause(tls, pWC, iTerm))).FprereqRight & ^mPrereq
				if mThis > mPrev && mThis < mNext {
					mNext = mThis
				}
				goto _3
			_3:
				;
				i = i + 1
			}
			mPrev = mNext
			if mNext == libc.Uint64FromInt32(-libc.Int32FromInt32(1)) {
				break
			}
			if mNext == mBest || mNext == mBestNoIn {
				continue
			}
			rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, mNext|mPrereq, uint16(0), p, **(**Tu16)(__ccgo_up(bp + 4)), bp, uintptr(0))
			if (*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq == mPrereq {
				seenZero = int32(1)
				if **(**int32)(__ccgo_up(bp)) == 0 {
					seenZeroNoIN = int32(1)
				}
			}
		}
		/* If the calls to xBestIndex() in the above loop did not find a plan
		 ** that requires no source tables at all (i.e. one guaranteed to be
		 ** usable), make a call here with all source tables disabled */
		if rc == SQLITE_OK && seenZero == 0 {
			rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, mPrereq, uint16(0), p, **(**Tu16)(__ccgo_up(bp + 4)), bp, uintptr(0))
			if **(**int32)(__ccgo_up(bp)) == 0 {
				seenZeroNoIN = int32(1)
			}
		}
		/* If the calls to xBestIndex() have so far failed to find a plan
		 ** that requires no source tables at all and does not use an IN(...)
		 ** operator, make a final call to obtain one here.  */
		if rc == SQLITE_OK && seenZeroNoIN == 0 {
			rc = _whereLoopAddVirtualOne(tls, pBuilder, mPrereq, mPrereq, uint16(WO_IN), p, **(**Tu16)(__ccgo_up(bp + 4)), bp, uintptr(0))
		}
	}
	_freeIndexInfo(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, p)
	return rc
}

// C documentation
//
//	/*
//	** Argument pIdxInfo is already populated with all constraints that may
//	** be used by the virtual table identified by pBuilder->pNew->iTab. This
//	** function marks a subset of those constraints usable, invokes the
//	** xBestIndex method and adds the returned plan to pBuilder.
//	**
//	** A constraint is marked usable if:
//	**
//	**   * Argument mUsable indicates that its prerequisites are available, and
//	**
//	**   * It is not one of the operators specified in the mExclude mask passed
//	**     as the fourth argument (which in practice is either WO_IN or 0).
//	**
//	** Argument mPrereq is a mask of tables that must be scanned before the
//	** virtual table in question. These are added to the plans prerequisites
//	** before it is added to pBuilder.
//	**
//	** Output parameter *pbIn is set to true if the plan added to pBuilder
//	** uses one or more WO_IN terms, or false otherwise.
//	*/
func _whereLoopAddVirtualOne(tls *libc.TLS, pBuilder uintptr, mPrereq TBitmask, mUsable TBitmask, mExclude Tu16, pIdxInfo uintptr, mNoOmit Tu16, pbIn uintptr, pbRetryLimit uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, iTerm, j, mxTerm, nConstraint, rc, v3 int32
	var pHidden, pIdxCons, pNew, pParse, pSrc, pTerm, pTerm1, pUsage, pWC, v4 uintptr
	var v5 bool
	var v7 uint32
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = i, iTerm, j, mxTerm, nConstraint, pHidden, pIdxCons, pNew, pParse, pSrc, pTerm, pTerm1, pUsage, pWC, rc, v3, v4, v5, v7
	pWC = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pHidden = pIdxInfo + 1*96
	pUsage = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage
	rc = SQLITE_OK
	pNew = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	pParse = (*TWhereInfo)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpParse
	pSrc = (*TWhereInfo)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pNew)).FiTab)*80
	nConstraint = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint
	**(**int32)(__ccgo_up(pbIn)) = 0
	(*TWhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq
	/* Set the usable flag on the subset of constraints identified by
	 ** arguments mUsable and mExclude. */
	pIdxCons = **(**uintptr)(__ccgo_up(pIdxInfo + 8))
	i = 0
	for {
		if !(i < nConstraint) {
			break
		}
		pTerm = _termFromWhereClause(tls, pWC, (*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset)
		(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(0)
		if (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUsable == (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight && libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&libc.Int32FromUint16(mExclude) == 0 && (pbRetryLimit != 0 || !(_isLimitTerm(tls, pTerm) != 0)) {
			(*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(1)
		}
		goto _1
	_1:
		;
		i = i + 1
		pIdxCons += 12
	}
	/* Initialize the output fields of the sqlite3_index_info structure */
	libc.Xmemset(tls, pUsage, 0, uint64(8)*libc.Uint64FromInt32(nConstraint))
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = uintptr(0)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 0
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 0
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(1e+99) / libc.Float64FromInt32(2)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(25)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = 0
	(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn = uint32(0)
	/* Invoke the virtual table xBestIndex() method */
	rc = _vtabBestIndex(tls, pParse, (*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab, pIdxInfo)
	if rc != 0 {
		if rc == int32(SQLITE_CONSTRAINT) {
			/* If the xBestIndex method returns SQLITE_CONSTRAINT, that means
			 ** that the particular combination of parameters provided is unusable.
			 ** Make no entries in the loop table.
			 */
			_freeIdxStr(tls, pIdxInfo)
			return SQLITE_OK
		}
		return rc
	}
	mxTerm = -int32(1)
	libc.Xmemset(tls, (*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm, 0, uint64(8)*libc.Uint64FromInt32(nConstraint))
	libc.Xmemset(tls, pNew+24, 0, uint64(24))
	pIdxCons = **(**uintptr)(__ccgo_up(pIdxInfo + 8))
	i = 0
	for {
		if !(i < nConstraint) {
			break
		}
		v3 = (**(**Tsqlite3_index_constraint_usage)(__ccgo_up(pUsage + uintptr(i)*8))).FargvIndex - libc.Int32FromInt32(1)
		iTerm = v3
		if v3 >= 0 {
			j = (*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset
			if v5 = iTerm >= nConstraint || j < 0; !v5 {
				v4 = _termFromWhereClause(tls, pWC, j)
				pTerm1 = v4
			}
			if v5 || v4 == uintptr(0) || **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*8)) != uintptr(0) || libc.Int32FromUint8((*Tsqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable) == 0 {
				_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24025, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FzName))
				_freeIdxStr(tls, pIdxInfo)
				return int32(SQLITE_ERROR)
			}
			**(**TBitmask)(__ccgo_up(pNew)) |= (*TWhereTerm)(unsafe.Pointer(pTerm1)).FprereqRight
			**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*8)) = pTerm1
			if iTerm > mxTerm {
				mxTerm = iTerm
			}
			if (**(**Tsqlite3_index_constraint_usage)(__ccgo_up(pUsage + uintptr(i)*8))).Fomit != 0 {
				if i < int32(16) && int32(1)<<i&libc.Int32FromUint16(mNoOmit) == 0 {
					v4 = pNew + 24 + 6
					*(*Tu16)(unsafe.Pointer(v4)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v4))) | libc.Int32FromInt32(1)<<iTerm)
				} else {
				}
				if libc.Int32FromUint8((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeMatchOp) == int32(SQLITE_INDEX_CONSTRAINT_OFFSET) {
					libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32(1), 6, 0x40)
				}
			}
			if i <= int32(31) {
				v7 = libc.Uint32FromInt32(1) << i
			} else {
				v7 = uint32(0)
			}
			if v7&(*THiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn != 0 {
				(*(*struct {
					FidxNum    int32
					F__ccgo4   uint8
					FisOrdered Ti8
					FomitMask  Tu16
					FidxStr    uintptr
					FmHandleIn Tu32
				})(unsafe.Pointer(pNew + 24))).FmHandleIn |= libc.Uint32FromInt32(1) << iTerm
			} else {
				if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm1)).FeOperator)&int32(WO_IN) != 0 {
					/* A virtual table that is constrained by an IN clause may not
					 ** consume the ORDER BY clause because (1) the order of IN terms
					 ** is not necessarily related to the order of output terms and
					 ** (2) Multiple outputs from a single IN value will not merge
					 ** together.  */
					(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 0
					**(**int32)(__ccgo_up(pIdxInfo + 80)) &= ^libc.Int32FromInt32(SQLITE_INDEX_SCAN_UNIQUE)
					**(**int32)(__ccgo_up(pbIn)) = int32(1)
				}
			}
			/* Unless pbRetryLimit is non-NULL, there should be no LIMIT/OFFSET
			 ** terms. And if there are any, they should follow all other terms. */
			if _isLimitTerm(tls, pTerm1) != 0 && (**(**int32)(__ccgo_up(pbIn)) != 0 || !(_allConstraintsUsed(tls, pUsage, i) != 0)) {
				/* If there is an IN(...) term handled as an == (separate call to
				 ** xFilter for each value on the RHS of the IN) and a LIMIT or
				 ** OFFSET term handled as well, the plan is unusable. Similarly,
				 ** if there is a LIMIT/OFFSET and there are other unused terms,
				 ** the plan cannot be used. In these cases set variable *pbRetryLimit
				 ** to true to tell the caller to retry with LIMIT and OFFSET
				 ** disabled. */
				_freeIdxStr(tls, pIdxInfo)
				**(**int32)(__ccgo_up(pbRetryLimit)) = int32(1)
				return SQLITE_OK
			}
		}
		goto _2
	_2:
		;
		i = i + 1
		pIdxCons += 12
	}
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnLTerm = libc.Uint16FromInt32(mxTerm + int32(1))
	i = 0
	for {
		if !(i <= mxTerm) {
			break
		}
		if **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)) == uintptr(0) {
			/* The non-zero argvIdx values must be contiguous.  Raise an
			 ** error if they are not */
			_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24025, libc.VaList(bp+8, (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pSrc)).FpSTab)).FzName))
			_freeIdxStr(tls, pIdxInfo)
			return int32(SQLITE_ERROR)
		}
		goto _8
	_8:
		;
		i = i + 1
	}
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FidxNum = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum
	libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr), 7, 0x80)
	(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = 0
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FidxStr = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr
	if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed != 0 {
		v3 = (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy
	} else {
		v3 = 0
	}
	(*(*struct {
		FidxNum    int32
		F__ccgo4   uint8
		FisOrdered Ti8
		FomitMask  Tu16
		FidxStr    uintptr
		FmHandleIn Tu32
	})(unsafe.Pointer(pNew + 24))).FisOrdered = int8(v3)
	libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.BoolUint32((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags&libc.Int32FromInt32(SQLITE_INDEX_SCAN_HEX) != libc.Int32FromInt32(0)), 5, 0x20)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrSetup = 0
	(*TWhereLoop)(unsafe.Pointer(pNew)).FrRun = _sqlite3LogEstFromDouble(tls, (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost)
	(*TWhereLoop)(unsafe.Pointer(pNew)).FnOut = _sqlite3LogEst(tls, libc.Uint64FromInt64((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows))
	/* Set the WHERE_ONEROW flag if the xBestIndex() method indicated
	 ** that the scan will visit at most one row. Clear it otherwise. */
	if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags&int32(SQLITE_INDEX_SCAN_UNIQUE) != 0 {
		**(**Tu32)(__ccgo_up(pNew + 48)) |= uint32(WHERE_ONEROW)
	} else {
		**(**Tu32)(__ccgo_up(pNew + 48)) &= libc.Uint32FromInt32(^libc.Int32FromInt32(WHERE_ONEROW))
	}
	rc = _whereLoopInsert(tls, pBuilder, pNew)
	if int32(Tu32(*(*uint8)(unsafe.Pointer(pNew + 24 + 4))&0x80>>7)) != 0 {
		Xsqlite3_free(tls, (*(*struct {
			FidxNum    int32
			F__ccgo4   uint8
			FisOrdered Ti8
			FomitMask  Tu16
			FidxStr    uintptr
			FmHandleIn Tu32
		})(unsafe.Pointer(pNew + 24))).FidxStr)
		libc.SetBitFieldPtr8Uint32(pNew+24+4, libc.Uint32FromInt32(0), 7, 0x80)
	}
	return rc
}

// C documentation
//
//	/*
//	** Clear the WhereLoop.u union.  Leave WhereLoop.pLTerm intact.
//	*/
func _whereLoopClearUnion(tls *libc.TLS, db uintptr, p uintptr) {
	if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_VIRTUALTABLE)|libc.Int32FromInt32(WHERE_AUTO_INDEX)) != 0 {
		if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != uint32(0) && int32(Tu32(*(*uint8)(unsafe.Pointer(p + 24 + 4))&0x80>>7)) != 0 {
			Xsqlite3_free(tls, (*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(p + 24))).FidxStr)
			libc.SetBitFieldPtr8Uint32(p+24+4, libc.Uint32FromInt32(0), 7, 0x80)
			(*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(p + 24))).FidxStr = uintptr(0)
		} else {
			if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_AUTO_INDEX) != uint32(0) && (*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(p + 24))).FpIndex != uintptr(0) {
				_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer((*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(p + 24))).FpIndex)).FzColAff)
				_sqlite3DbFreeNN(tls, db, (*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(p + 24))).FpIndex)
				(*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(p + 24))).FpIndex = uintptr(0)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Insert or replace a WhereLoop entry using the template supplied.
//	**
//	** An existing WhereLoop entry might be overwritten if the new template
//	** is better and has fewer dependencies.  Or the template will be ignored
//	** and no insert will occur if an existing WhereLoop is faster and has
//	** fewer dependencies than the template.  Otherwise a new WhereLoop is
//	** added based on the template.
//	**
//	** If pBuilder->pOrSet is not NULL then we care about only the
//	** prerequisites and rRun and nOut costs of the N best loops.  That
//	** information is gathered in the pBuilder->pOrSet object.  This special
//	** processing mode is used only for OR clause processing.
//	**
//	** When accumulating multiple loops (when pBuilder->pOrSet is NULL) we
//	** still might overwrite similar loops with the new template if the
//	** new template is better.  Loops may be overwritten if the following
//	** conditions are met:
//	**
//	**    (1)  They have the same iTab.
//	**    (2)  They have the same iSortIdx.
//	**    (3)  The template has same or fewer dependencies than the current loop
//	**    (4)  The template has the same or lower cost than the current loop
//	*/
func _whereLoopInsert(tls *libc.TLS, pBuilder uintptr, pTemplate uintptr) (r int32) {
	var db, p, pIndex, pToDel, pWInfo, ppPrev, ppTail, v1 uintptr
	var rc int32
	_, _, _, _, _, _, _, _, _ = db, p, pIndex, pToDel, pWInfo, ppPrev, ppTail, rc, v1
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	/* Stop the search once we hit the query planner search limit */
	if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit == uint32(0) {
		if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != 0 {
			(*TWhereOrSet)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet)).Fn = uint16(0)
		}
		return int32(SQLITE_DONE)
	}
	(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit - 1
	_whereLoopAdjustCost(tls, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops, pTemplate)
	/* If pBuilder->pOrSet is defined, then only keep track of the costs
	 ** and prereqs.
	 */
	if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != uintptr(0) {
		if (*TWhereLoop)(unsafe.Pointer(pTemplate)).FnLTerm != 0 {
			_whereOrInsert(tls, (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet, (*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq, (*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun, (*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut)
		}
		return SQLITE_OK
	}
	/* Look for an existing WhereLoop to replace with pTemplate
	 */
	ppPrev = _whereLoopFindLesser(tls, pWInfo+80, pTemplate)
	if ppPrev == uintptr(0) {
		/* There already exists a WhereLoop on the list that is better
		 ** than pTemplate, so just ignore pTemplate */
		return SQLITE_OK
	} else {
		p = **(**uintptr)(__ccgo_up(ppPrev))
	}
	/* If we reach this point it means that either p[] should be overwritten
	 ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
	 ** WhereLoop and insert it.
	 */
	if p == uintptr(0) {
		/* Allocate a new WhereLoop to add to the end of the list */
		v1 = _sqlite3DbMallocRawNN(tls, db, uint64(104))
		p = v1
		**(**uintptr)(__ccgo_up(ppPrev)) = v1
		if p == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		_whereLoopInit(tls, p)
		(*TWhereLoop)(unsafe.Pointer(p)).FpNextLoop = uintptr(0)
	} else {
		/* We will be overwriting WhereLoop p[].  But before we do, first
		 ** go through the rest of the list and delete any other entries besides
		 ** p[] that are also supplanted by pTemplate */
		ppTail = p + 72
		for **(**uintptr)(__ccgo_up(ppTail)) != 0 {
			ppTail = _whereLoopFindLesser(tls, ppTail, pTemplate)
			if ppTail == uintptr(0) {
				break
			}
			pToDel = **(**uintptr)(__ccgo_up(ppTail))
			if pToDel == uintptr(0) {
				break
			}
			**(**uintptr)(__ccgo_up(ppTail)) = (*TWhereLoop)(unsafe.Pointer(pToDel)).FpNextLoop
			_whereLoopDelete(tls, db, pToDel)
		}
	}
	rc = _whereLoopXfer(tls, db, p, pTemplate)
	if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_VIRTUALTABLE) == uint32(0) {
		pIndex = (*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(p + 24))).FpIndex
		if pIndex != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_IPK) {
			(*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(p + 24))).FpIndex = uintptr(0)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Transfer content from the second pLoop into the first.
//	*/
func _whereLoopXfer(tls *libc.TLS, db uintptr, pTo uintptr, pFrom uintptr) (r int32) {
	_whereLoopClearUnion(tls, db, pTo)
	if libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pFrom)).FnLTerm) > libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pTo)).FnLSlot) && _whereLoopResize(tls, db, pTo, libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pFrom)).FnLTerm)) != 0 {
		libc.Xmemset(tls, pTo, 0, uint64(libc.UintptrFromInt32(0)+56))
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint64(libc.UintptrFromInt32(0)+56))
	libc.Xmemcpy(tls, (*TWhereLoop)(unsafe.Pointer(pTo)).FaLTerm, (*TWhereLoop)(unsafe.Pointer(pFrom)).FaLTerm, uint64((*TWhereLoop)(unsafe.Pointer(pTo)).FnLTerm)*uint64(8))
	if (*TWhereLoop)(unsafe.Pointer(pFrom)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != 0 {
		libc.SetBitFieldPtr8Uint32(pFrom+24+4, libc.Uint32FromInt32(0), 7, 0x80)
	} else {
		if (*TWhereLoop)(unsafe.Pointer(pFrom)).FwsFlags&uint32(WHERE_AUTO_INDEX) != uint32(0) {
			(*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pFrom + 24))).FpIndex = uintptr(0)
		}
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
//	** parameters) to see if it outputs rows in the requested ORDER BY
//	** (or GROUP BY) without requiring a separate sort operation.  Return N:
//	**
//	**   N>0:   N terms of the ORDER BY clause are satisfied
//	**   N==0:  No terms of the ORDER BY clause are satisfied
//	**   N<0:   Unknown yet how many terms of ORDER BY might be satisfied.
//	**
//	** Note that processing for WHERE_GROUPBY and WHERE_DISTINCTBY is not as
//	** strict.  With GROUP BY and DISTINCT the only requirement is that
//	** equivalent rows appear immediately adjacent to one another.  GROUP BY
//	** and DISTINCT do not require rows to appear in any particular order as long
//	** as equivalent rows are grouped together.  Thus for GROUP BY and DISTINCT
//	** the pOrderBy terms can be matched in any order.  With ORDER BY, the
//	** pOrderBy terms must be matched in strict left-to-right order.
//	*/
func _wherePathSatisfiesOrderBy(tls *libc.TLS, pWInfo uintptr, pOrderBy uintptr, pPath uintptr, wctrlFlags Tu16, nLoop Tu16, pLast uintptr, pRevMask uintptr) (r Ti8) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bOnce, distinctColumns, isMatch, isOrderDistinct, rev, revIdx, revSet, v5 Tu8
	var db, p, pColl, pColl1, pColl2, pIndex, pIxExpr, pLoop, pOBExpr, pParse, pTerm, pX, v4 uintptr
	var eOp, eqOpMask, nColumn, nKeyCol, nOrderBy Tu16
	var i, iColumn, iCur, iLoop, j int32
	var m, mTerm, obDone, orderDistinctMask, ready TBitmask
	var v11 uint64
	var _ /* obSat at bp+0 */ TBitmask
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bOnce, db, distinctColumns, eOp, eqOpMask, i, iColumn, iCur, iLoop, isMatch, isOrderDistinct, j, m, mTerm, nColumn, nKeyCol, nOrderBy, obDone, orderDistinctMask, p, pColl, pColl1, pColl2, pIndex, pIxExpr, pLoop, pOBExpr, pParse, pTerm, pX, ready, rev, revIdx, revSet, v11, v4, v5 /* A column number within table iCur */
	pLoop = uintptr(0)                                                                                                                                                                                                                                                                                                                                                                                      /* The index associated with pLoop */
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb                                                                                                                                                                                                                                                                                                                       /* Database connection */
	**(**TBitmask)(__ccgo_up(bp)) = uint64(0)                                                                                                                                                                                                                                                                                                                                                               /* Mask of inner loops */
	/*
	 ** We say the WhereLoop is "one-row" if it generates no more than one
	 ** row of output.  A WhereLoop is one-row if all of the following are true:
	 **  (a) All index columns match with WHERE_COLUMN_EQ.
	 **  (b) The index is unique
	 ** Any WhereLoop with an WHERE_COLUMN_EQ constraint on the rowid is one-row.
	 ** Every one-row WhereLoop will have the WHERE_ONEROW bit set in wsFlags.
	 **
	 ** We say the WhereLoop is "order-distinct" if the set of columns from
	 ** that WhereLoop that are in the ORDER BY clause are different for every
	 ** row of the WhereLoop.  Every one-row WhereLoop is automatically
	 ** order-distinct.   A WhereLoop that has no columns in the ORDER BY clause
	 ** is not order-distinct. To be order-distinct is not quite the same as being
	 ** UNIQUE since a UNIQUE column or index can have multiple rows that
	 ** are NULL and NULL values are equivalent for the purpose of order-distinct.
	 ** To be order-distinct, the columns must be UNIQUE and NOT NULL.
	 **
	 ** The rowid for a table is always UNIQUE and NOT NULL so whenever the
	 ** rowid appears in the ORDER BY clause, the corresponding WhereLoop is
	 ** automatically order-distinct.
	 */
	if nLoop != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OrderByIdxJoin)) != uint32(0) {
		return 0
	}
	nOrderBy = libc.Uint16FromInt32((*TExprList)(unsafe.Pointer(pOrderBy)).FnExpr)
	if libc.Int32FromUint16(nOrderBy) > libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8))-libc.Int32FromInt32(1) {
		return 0
	} /* Cannot optimize overly large ORDER BYs */
	isOrderDistinct = uint8(1)
	obDone = libc.Uint64FromInt32(1)<<nOrderBy - uint64(1)
	orderDistinctMask = uint64(0)
	ready = uint64(0)
	eqOpMask = libc.Uint16FromInt32(libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IS) | libc.Int32FromInt32(WO_ISNULL))
	if libc.Int32FromUint16(wctrlFlags)&(libc.Int32FromInt32(WHERE_ORDERBY_LIMIT)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)|libc.Int32FromInt32(WHERE_ORDERBY_MIN)) != 0 {
		eqOpMask = libc.Uint16FromInt32(int32(eqOpMask) | libc.Int32FromInt32(WO_IN))
	}
	iLoop = 0
	for {
		if !(isOrderDistinct != 0 && **(**TBitmask)(__ccgo_up(bp)) < obDone && iLoop <= libc.Int32FromUint16(nLoop)) {
			break
		}
		if iLoop > 0 {
			ready = ready | (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		}
		if iLoop < libc.Int32FromUint16(nLoop) {
			pLoop = **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pPath)).FaLoop + uintptr(iLoop)*8))
			if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_ORDERBY_LIMIT) != 0 {
				goto _1
			}
		} else {
			pLoop = pLast
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_VIRTUALTABLE) != 0 {
			if (*(*struct {
				FidxNum    int32
				F__ccgo4   uint8
				FisOrdered Ti8
				FomitMask  Tu16
				FidxStr    uintptr
				FmHandleIn Tu32
			})(unsafe.Pointer(pLoop + 24))).FisOrdered != 0 && (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == pOrderBy {
				**(**TBitmask)(__ccgo_up(bp)) = obDone
			} else {
				/* No further ORDER BY terms may be matched. So this call should
				 ** return >=0, not -1. Clear isOrderDistinct to ensure it does so. */
				isOrderDistinct = uint8(0)
			}
			break
		}
		iCur = (*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLoop)(unsafe.Pointer(pLoop)).FiTab)*80))).FiCursor
		/* Mark off any ORDER BY term X that is a column in the table of
		 ** the current loop for which there is term in the WHERE
		 ** clause of the form X IS NULL or X=? that reference only outer
		 ** loops.
		 */
		i = 0
		for {
			if !(i < libc.Int32FromUint16(nOrderBy)) {
				break
			}
			if libc.Uint64FromInt32(1)<<i&**(**TBitmask)(__ccgo_up(bp)) != 0 {
				goto _2
			}
			pOBExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr)
			if pOBExpr == uintptr(0) {
				goto _2
			}
			if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_COLUMN) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_AGG_COLUMN) {
				goto _2
			}
			if (*TExpr)(unsafe.Pointer(pOBExpr)).FiTable != iCur {
				goto _2
			}
			pTerm = _sqlite3WhereFindTerm(tls, pWInfo+104, iCur, int32((*TExpr)(unsafe.Pointer(pOBExpr)).FiColumn), ^ready, uint32(eqOpMask), uintptr(0))
			if pTerm == uintptr(0) {
				goto _2
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator) == int32(WO_IN) {
				/* IN terms are only valid for sorting in the ORDER BY LIMIT
				 ** optimization, and then only if they are actually used
				 ** by the query plan */
				j = 0
				for {
					if !(j < libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) && pTerm != **(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))) {
						break
					}
					goto _3
				_3:
					;
					j = j + 1
				}
				if j >= libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) {
					goto _2
				}
			}
			if libc.Int32FromUint16((*TWhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)) != 0 && int32((*TExpr)(unsafe.Pointer(pOBExpr)).FiColumn) >= 0 {
				pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
				pColl1 = _sqlite3ExprNNCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr)
				pColl2 = _sqlite3ExprCompareCollSeq(tls, pParse, (*TWhereTerm)(unsafe.Pointer(pTerm)).FpExpr)
				if pColl2 == uintptr(0) || _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pColl1)).FzName, (*TCollSeq)(unsafe.Pointer(pColl2)).FzName) != 0 {
					goto _2
				}
			}
			**(**TBitmask)(__ccgo_up(bp)) = **(**TBitmask)(__ccgo_up(bp)) | libc.Uint64FromInt32(1)<<i
			goto _2
		_2:
			;
			i = i + 1
		}
		if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_ONEROW) == uint32(0) {
			if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_IPK) != 0 {
				if (*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FpOrderBy != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FdbOptFlags&libc.Uint32FromInt32(libc.Int32FromInt32(SQLITE_OrderBySubq)) == uint32(0) && _wherePathMatchSubqueryOB(tls, pWInfo, pLoop, iLoop, iCur, pOrderBy, pRevMask, bp) != 0 {
					nColumn = uint16(0)
					isOrderDistinct = uint8(0)
				} else {
					nColumn = uint16(1)
				}
				pIndex = uintptr(0)
				nKeyCol = uint16(0)
			} else {
				v4 = (*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FpIndex
				pIndex = v4
				if v4 == uintptr(0) || int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x2000>>13)) != 0 {
					return 0
				} else {
					nKeyCol = (*TIndex)(unsafe.Pointer(pIndex)).FnKeyCol
					nColumn = (*TIndex)(unsafe.Pointer(pIndex)).FnColumn
					/* All relevant terms of the index must also be non-NULL in order
					 ** for isOrderDistinct to be true.  So the isOrderDistinct value
					 ** computed here might be a false positive.  Corrections will be
					 ** made at tag-20210426-1 below */
					isOrderDistinct = libc.BoolUint8(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIndex)).FonError) != OE_None && (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&uint32(WHERE_SKIPSCAN) == uint32(0))
				}
			}
			/* Loop through all columns of the index and deal with the ones
			 ** that are not constrained by == or IN.
			 */
			v5 = libc.Uint8FromInt32(0)
			revSet = v5
			rev = v5
			distinctColumns = uint8(0)
			j = 0
			for {
				if !(j < libc.Int32FromUint16(nColumn)) {
					break
				}
				bOnce = uint8(1) /* True to run the ORDER BY search loop */
				if j < libc.Int32FromUint16((*(*struct {
					FnEq          Tu16
					FnBtm         Tu16
					FnTop         Tu16
					FnDistinctCol Tu16
					FpIndex       uintptr
					FpOrderBy     uintptr
				})(unsafe.Pointer(pLoop + 24))).FnEq) && j >= libc.Int32FromUint16((*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
					eOp = (*TWhereTerm)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)))).FeOperator
					/* Skip over == and IS and ISNULL terms.  (Also skip IN terms when
					 ** doing WHERE_ORDERBY_LIMIT processing).  Except, IS and ISNULL
					 ** terms imply that the index is not UNIQUE NOT NULL in which case
					 ** the loop need to be marked as not order-distinct because it can
					 ** have repeated NULL rows.
					 **
					 ** If the current term is a column of an ((?,?) IN (SELECT...))
					 ** expression for which the SELECT returns more than one column,
					 ** check that it is the only column used by this loop. Otherwise,
					 ** if it is one of two or more, none of the columns can be
					 ** considered to match an ORDER BY term.
					 */
					if libc.Int32FromUint16(eOp)&libc.Int32FromUint16(eqOpMask) != 0 {
						if libc.Int32FromUint16(eOp)&(libc.Int32FromInt32(WO_ISNULL)|libc.Int32FromInt32(WO_IS)) != 0 {
							isOrderDistinct = uint8(0)
						}
						goto _6
					} else {
						if libc.Int32FromUint16(eOp)&int32(WO_IN) != 0 {
							/* ALWAYS() justification: eOp is an equality operator due to the
							 ** j<pLoop->u.btree.nEq constraint above.  Any equality other
							 ** than WO_IN is captured by the previous "if".  So this one
							 ** always has to be WO_IN. */
							pX = (*TWhereTerm)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)))).FpExpr
							i = j + int32(1)
							for {
								if !(i < libc.Int32FromUint16((*(*struct {
									FnEq          Tu16
									FnBtm         Tu16
									FnTop         Tu16
									FnDistinctCol Tu16
									FpIndex       uintptr
									FpOrderBy     uintptr
								})(unsafe.Pointer(pLoop + 24))).FnEq)) {
									break
								}
								if (*TWhereTerm)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)))).FpExpr == pX {
									bOnce = uint8(0)
									break
								}
								goto _7
							_7:
								;
								i = i + 1
							}
						}
					}
				}
				/* Get the column number in the table (iColumn) and sort order
				 ** (revIdx) for the j-th column of the index.
				 */
				if pIndex != 0 {
					iColumn = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(j)*2)))
					revIdx = libc.Uint8FromInt32(libc.Int32FromUint8(**(**Tu8)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(j)))) & int32(KEYINFO_ORDER_DESC))
					if iColumn == int32((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FiPKey) {
						iColumn = -int32(1)
					}
				} else {
					iColumn = -int32(1)
					revIdx = uint8(0)
				}
				/* An unconstrained column that might be NULL means that this
				 ** WhereLoop is not well-ordered.  tag-20210426-1
				 */
				if isOrderDistinct != 0 {
					if iColumn >= 0 && j >= libc.Int32FromUint16((*(*struct {
						FnEq          Tu16
						FnBtm         Tu16
						FnTop         Tu16
						FnDistinctCol Tu16
						FpIndex       uintptr
						FpOrderBy     uintptr
					})(unsafe.Pointer(pLoop + 24))).FnEq) && int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FaCol + uintptr(iColumn)*16 + 8))&0xf0>>4)) == 0 {
						isOrderDistinct = uint8(0)
					}
					if iColumn == -int32(2) {
						isOrderDistinct = uint8(0)
					}
				}
				/* Find the ORDER BY term that corresponds to the j-th column
				 ** of the index and mark that ORDER BY term having been satisfied.
				 */
				isMatch = uint8(0)
				i = 0
				for {
					if !(bOnce != 0 && i < libc.Int32FromUint16(nOrderBy)) {
						break
					}
					if libc.Uint64FromInt32(1)<<i&**(**TBitmask)(__ccgo_up(bp)) != 0 {
						goto _8
					}
					pOBExpr = _sqlite3ExprSkipCollateAndLikely(tls, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr)
					if pOBExpr == uintptr(0) {
						goto _8
					}
					if libc.Int32FromUint16(wctrlFlags)&(libc.Int32FromInt32(WHERE_GROUPBY)|libc.Int32FromInt32(WHERE_DISTINCTBY)) == 0 {
						bOnce = uint8(0)
					}
					if iColumn >= -int32(1) {
						if libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_COLUMN) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pOBExpr)).Fop) != int32(TK_AGG_COLUMN) {
							goto _8
						}
						if (*TExpr)(unsafe.Pointer(pOBExpr)).FiTable != iCur {
							goto _8
						}
						if int32((*TExpr)(unsafe.Pointer(pOBExpr)).FiColumn) != iColumn {
							goto _8
						}
					} else {
						pIxExpr = (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FaColExpr + 8 + uintptr(j)*32))).FpExpr
						if _sqlite3ExprCompareSkip(tls, pOBExpr, pIxExpr, iCur) != 0 {
							goto _8
						}
					}
					if iColumn != -int32(1) {
						pColl = _sqlite3ExprNNCollSeq(tls, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse, (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr)
						if _sqlite3StrICmp(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FzName, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIndex)).FazColl + uintptr(j)*8))) != 0 {
							goto _8
						}
					}
					if libc.Int32FromUint16(wctrlFlags)&int32(WHERE_DISTINCTBY) != 0 {
						(*(*struct {
							FnEq          Tu16
							FnBtm         Tu16
							FnTop         Tu16
							FnDistinctCol Tu16
							FpIndex       uintptr
							FpOrderBy     uintptr
						})(unsafe.Pointer(pLoop + 24))).FnDistinctCol = libc.Uint16FromInt32(j + int32(1))
					}
					isMatch = uint8(1)
					break
					goto _8
				_8:
					;
					i = i + 1
				}
				if isMatch != 0 && libc.Int32FromUint16(wctrlFlags)&int32(WHERE_GROUPBY) == 0 {
					/* Make sure the sort order is compatible in an ORDER BY clause.
					 ** Sort order is irrelevant for a GROUP BY clause. */
					if revSet != 0 {
						if libc.Int32FromUint8(rev)^libc.Int32FromUint8(revIdx) != libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_DESC) {
							isMatch = uint8(0)
						}
					} else {
						rev = libc.Uint8FromInt32(libc.Int32FromUint8(revIdx) ^ libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_DESC))
						if rev != 0 {
							**(**TBitmask)(__ccgo_up(pRevMask)) |= libc.Uint64FromInt32(1) << iLoop
						}
						revSet = uint8(1)
					}
				}
				if isMatch != 0 && libc.Int32FromUint8((*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).Ffg.FsortFlags)&int32(KEYINFO_ORDER_BIGNULL) != 0 {
					if j == libc.Int32FromUint16((*(*struct {
						FnEq          Tu16
						FnBtm         Tu16
						FnTop         Tu16
						FnDistinctCol Tu16
						FpIndex       uintptr
						FpOrderBy     uintptr
					})(unsafe.Pointer(pLoop + 24))).FnEq) {
						**(**Tu32)(__ccgo_up(pLoop + 48)) |= uint32(WHERE_BIGNULL_SORT)
					} else {
						isMatch = uint8(0)
					}
				}
				if isMatch != 0 {
					if iColumn == -int32(1) {
						distinctColumns = uint8(1)
					}
					**(**TBitmask)(__ccgo_up(bp)) = **(**TBitmask)(__ccgo_up(bp)) | libc.Uint64FromInt32(1)<<i
				} else {
					/* No match found */
					if j == 0 || j < libc.Int32FromUint16(nKeyCol) {
						isOrderDistinct = uint8(0)
					}
					break
				}
				goto _6
			_6:
				;
				j = j + 1
			} /* end Loop over all index columns */
			if distinctColumns != 0 {
				isOrderDistinct = uint8(1)
			}
		} /* end-if not one-row */
		/* Mark off any other ORDER BY terms that reference pLoop */
		if isOrderDistinct != 0 {
			orderDistinctMask = orderDistinctMask | (*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
			i = 0
			for {
				if !(i < libc.Int32FromUint16(nOrderBy)) {
					break
				}
				if libc.Uint64FromInt32(1)<<i&**(**TBitmask)(__ccgo_up(bp)) != 0 {
					goto _9
				}
				p = (*(*TExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32))).FpExpr
				mTerm = _sqlite3WhereExprUsage(tls, pWInfo+592, p)
				if mTerm == uint64(0) && !(_sqlite3ExprIsConstant(tls, uintptr(0), p) != 0) {
					goto _9
				}
				if mTerm & ^orderDistinctMask == uint64(0) {
					**(**TBitmask)(__ccgo_up(bp)) = **(**TBitmask)(__ccgo_up(bp)) | libc.Uint64FromInt32(1)<<i
				}
				goto _9
			_9:
				;
				i = i + 1
			}
		}
		goto _1
	_1:
		;
		iLoop = iLoop + 1
	} /* End the loop over all WhereLoops from outer-most down to inner-most */
	if **(**TBitmask)(__ccgo_up(bp)) == obDone {
		return libc.Int8FromUint16(nOrderBy)
	}
	if !(isOrderDistinct != 0) {
		i = libc.Int32FromUint16(nOrderBy) - int32(1)
		for {
			if !(i > 0) {
				break
			}
			if i < libc.Int32FromUint64(libc.Uint64FromInt64(8)*libc.Uint64FromInt32(8)) {
				v11 = libc.Uint64FromInt32(1)<<i - uint64(1)
			} else {
				v11 = uint64(0)
			}
			m = v11
			if **(**TBitmask)(__ccgo_up(bp))&m == m {
				return int8(i)
			}
			goto _10
		_10:
			;
			i = i - 1
		}
		return 0
	}
	return int8(-int32(1))
}

// C documentation
//
//	/*
//	** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
//	** attempts to find the lowest cost path that visits each WhereLoop
//	** once.  This path is then loaded into the pWInfo->a[].pWLoop fields.
//	**
//	** Assume that the total number of output rows that will need to be sorted
//	** will be nRowEst (in the 10*log2 representation).  Or, ignore sorting
//	** costs if nRowEst==0.
//	**
//	** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation
//	** error occurs.
//	*/
func _wherePathSolver(tls *libc.TLS, pWInfo uintptr, nRowEst TLogEst) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aFrom, aSortCost, aTo, pFrom, pLevel, pParse, pSpace, pTo, pWLoop, pX, v11 uintptr
	var iLoop, ii, jj, mxChoice, mxI, nFrom, nLoop, nOrder, nOrderBy, nSpace, nTo, rc, rc1, v2 int32
	var isOrdered Ti8
	var maskNew TBitmask
	var mxCost, mxUnsort, nOut, rCost, rUnsort TLogEst
	var wsFlags Tu32
	var _ /* m at bp+16 */ TBitmask
	var _ /* notUsed at bp+8 */ TBitmask
	var _ /* revMask at bp+0 */ TBitmask
	var _ /* revMask at bp+24 */ TBitmask
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aFrom, aSortCost, aTo, iLoop, ii, isOrdered, jj, maskNew, mxChoice, mxCost, mxI, mxUnsort, nFrom, nLoop, nOrder, nOrderBy, nOut, nSpace, nTo, pFrom, pLevel, pParse, pSpace, pTo, pWLoop, pX, rCost, rUnsort, rc, rc1, wsFlags, v11, v2 /* Loop counters */
	mxI = 0                                                                                                                                                                                                                                                                                                                                     /* Number of ORDER BY clause terms */
	mxCost = 0                                                                                                                                                                                                                                                                                                                                  /* Maximum cost of a set of paths */
	mxUnsort = 0                                                                                                                                                                                                                                                                                                                                /* Used to divy up the pSpace memory */
	aSortCost = uintptr(0)                                                                                                                                                                                                                                                                                                                      /* Bytes of space allocated at pSpace */
	pParse = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	nLoop = libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)
	/* TUNING: mxChoice is the maximum number of possible paths to preserve
	 ** at each step.  Based on the number of loops in the FROM clause:
	 **
	 **     nLoop      mxChoice
	 **     -----      --------
	 **       1            1            // the most common case
	 **       2            5
	 **       3+        12 or 18        // see computeMxChoice()
	 */
	if nLoop <= int32(1) {
		mxChoice = int32(1)
	} else {
		if nLoop == int32(2) {
			mxChoice = int32(5)
		} else {
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				mxChoice = int32(1)
			} else {
				mxChoice = _computeMxChoice(tls, pWInfo)
			}
		}
	}
	/* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this
	 ** case the purpose of this call is to estimate the number of rows returned
	 ** by the overall query. Once this estimate has been obtained, the caller
	 ** will invoke this function a second time, passing the estimate as the
	 ** nRowEst parameter.  */
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == uintptr(0) || int32(nRowEst) == 0 {
		nOrderBy = 0
	} else {
		nOrderBy = (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr
	}
	/* Allocate and initialize space for aTo, aFrom and aSortCost[] */
	nSpace = libc.Int32FromUint64((uint64(32) + uint64(8)*libc.Uint64FromInt32(nLoop)) * libc.Uint64FromInt32(mxChoice) * uint64(2))
	nSpace = libc.Int32FromUint64(uint64(nSpace) + libc.Uint64FromInt64(2)*libc.Uint64FromInt32(nOrderBy))
	pSpace = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, libc.Uint64FromInt32(nSpace))
	if pSpace == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	aTo = pSpace
	aFrom = aTo + uintptr(mxChoice)*32
	libc.Xmemset(tls, aFrom, 0, uint64(32))
	pX = aFrom + uintptr(mxChoice)*32
	ii = mxChoice * int32(2)
	pFrom = aTo
	for {
		if !(ii > 0) {
			break
		}
		(*TWherePath)(unsafe.Pointer(pFrom)).FaLoop = pX
		goto _1
	_1:
		;
		ii = ii - 1
		pFrom += 32
		pX = pX + uintptr(nLoop)*8
	}
	if nOrderBy != 0 {
		/* If there is an ORDER BY clause and it is not being ignored, set up
		 ** space for the aSortCost[] array. Each element of the aSortCost array
		 ** is either zero - meaning it has not yet been initialized - or the
		 ** cost of sorting nRowEst rows of data where the first X terms of
		 ** the ORDER BY clause are already in order, where X is the array
		 ** index.  */
		aSortCost = pX
		libc.Xmemset(tls, aSortCost, 0, uint64(2)*libc.Uint64FromInt32(nOrderBy))
	}
	/* Seed the search with a single WherePath containing zero WhereLoops.
	 **
	 ** TUNING: Do not let the number of iterations go above 28.  If the cost
	 ** of computing an automatic index is not paid back within the first 28
	 ** rows, then do not use the automatic index. */
	if int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop) < int32(48) {
		v2 = int32((*TParse)(unsafe.Pointer(pParse)).FnQueryLoop)
	} else {
		v2 = int32(48)
	}
	(**(**TWherePath)(__ccgo_up(aFrom))).FnRow = int16(v2)
	nFrom = int32(1)
	if nOrderBy != 0 {
		/* If nLoop is zero, then there are no FROM terms in the query. Since
		 ** in this case the query may return a maximum of one row, the results
		 ** are already in the requested order. Set isOrdered to nOrderBy to
		 ** indicate this. Or, if nLoop is greater than zero, set isOrdered to
		 ** -1, indicating that the result set may or may not be ordered,
		 ** depending on the loops added to the current plan.  */
		if nLoop > 0 {
			v2 = -int32(1)
		} else {
			v2 = nOrderBy
		}
		(**(**TWherePath)(__ccgo_up(aFrom))).FisOrdered = int8(v2)
	}
	/* Compute successively longer WherePaths using the previous generation
	 ** of WherePaths as the basis for the next.  Keep track of the mxChoice
	 ** best paths at each generation */
	iLoop = 0
	for {
		if !(iLoop < nLoop) {
			break
		}
		nTo = 0
		ii = 0
		pFrom = aFrom
		for {
			if !(ii < nFrom) {
				break
			}
			pWLoop = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
			for {
				if !(pWLoop != 0) {
					break
				} /* Mask of rev-order loops for (..) */
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).Fprereq & ^(*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					goto _6
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&(*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					goto _6
				}
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FwsFlags&uint32(WHERE_AUTO_INDEX) != uint32(0) && int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow) < int32(3) {
					/* Do not use an automatic index if the this loop is expected
					 ** to run less than 1.25 times.  It is tempting to also exclude
					 ** automatic index usage on an outer loop, but sometimes an automatic
					 ** index is useful in the outer loop of a correlated subquery. */
					goto _6
				}
				/* At this point, pWLoop is a candidate to be the next loop.
				 ** Compute its cost */
				rUnsort = int16(int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FrRun) + int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow))
				if (*TWhereLoop)(unsafe.Pointer(pWLoop)).FrSetup != 0 {
					rUnsort = _sqlite3LogEstAdd(tls, (*TWhereLoop)(unsafe.Pointer(pWLoop)).FrSetup, rUnsort)
				}
				rUnsort = _sqlite3LogEstAdd(tls, rUnsort, (*TWherePath)(unsafe.Pointer(pFrom)).FrUnsort)
				nOut = int16(int32((*TWherePath)(unsafe.Pointer(pFrom)).FnRow) + int32((*TWhereLoop)(unsafe.Pointer(pWLoop)).FnOut))
				maskNew = (*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop | (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
				isOrdered = (*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered
				if int32(isOrdered) < 0 {
					**(**TBitmask)(__ccgo_up(bp)) = uint64(0)
					isOrdered = _wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags, libc.Uint16FromInt32(iLoop), pWLoop, bp)
				} else {
					**(**TBitmask)(__ccgo_up(bp)) = (*TWherePath)(unsafe.Pointer(pFrom)).FrevLoop
				}
				if int32(isOrdered) >= 0 && int32(isOrdered) < nOrderBy {
					if int32(**(**TLogEst)(__ccgo_up(aSortCost + uintptr(isOrdered)*2))) == 0 {
						**(**TLogEst)(__ccgo_up(aSortCost + uintptr(isOrdered)*2)) = _whereSortingCost(tls, pWInfo, nRowEst, nOrderBy, int32(isOrdered))
					}
					/* TUNING:  Add a small extra penalty (3) to sorting as an
					 ** extra encouragement to the query planner to select a plan
					 ** where the rows emerge in the correct order without any sorting
					 ** required. */
					rCost = int16(int32(_sqlite3LogEstAdd(tls, rUnsort, **(**TLogEst)(__ccgo_up(aSortCost + uintptr(isOrdered)*2)))) + int32(3))
				} else {
					rCost = rUnsort
					rUnsort = int16(int32(rUnsort) - libc.Int32FromInt32(2)) /* TUNING:  Slight bias in favor of no-sort plans */
				}
				/* Check to see if pWLoop should be added to the set of
				 ** mxChoice best-so-far paths.
				 **
				 ** First look for an existing path among best-so-far paths
				 ** that:
				 **     (1) covers the same set of loops, and
				 **     (2) has a compatible isOrdered value.
				 **
				 ** "Compatible isOrdered value" means either
				 **     (A) both have isOrdered==-1, or
				 **     (B) both have isOrder>=0, or
				 **     (C) ordering does not matter because this is the last round
				 **         of the solver.
				 **
				 ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent
				 ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range
				 ** of legal values for isOrdered, -1..64.
				 */
				jj = 0
				pTo = aTo
				for {
					if !(jj < nTo) {
						break
					}
					if (*TWherePath)(unsafe.Pointer(pTo)).FmaskLoop == maskNew && ((int32((*TWherePath)(unsafe.Pointer(pTo)).FisOrdered)^int32(isOrdered))&int32(0x80) == 0 || iLoop == nLoop-int32(1)) {
						break
					}
					goto _7
				_7:
					;
					jj = jj + 1
					pTo += 32
				}
				if jj >= nTo {
					/* None of the existing best-so-far paths match the candidate. */
					if nTo >= mxChoice && (int32(rCost) > int32(mxCost) || int32(rCost) == int32(mxCost) && int32(rUnsort) >= int32(mxUnsort)) {
						/* The current candidate is no better than any of the mxChoice
						 ** paths currently in the best-so-far buffer.  So discard
						 ** this candidate as not viable. */
						goto _6
					}
					/* If we reach this points it means that the new candidate path
					 ** needs to be added to the set of best-so-far paths. */
					if nTo < mxChoice {
						/* Increase the size of the aTo set by one */
						v2 = nTo
						nTo = nTo + 1
						jj = v2
					} else {
						/* New path replaces the prior worst to keep count below mxChoice */
						jj = mxI
					}
					pTo = aTo + uintptr(jj)*32
				} else {
					/* Control reaches here if best-so-far path pTo=aTo[jj] covers the
					 ** same set of loops and has the same isOrdered setting as the
					 ** candidate path.  Check to see if the candidate should replace
					 ** pTo or if the candidate should be skipped.
					 **
					 ** The conditional is an expanded vector comparison equivalent to:
					 **   (pTo->rCost,pTo->nRow,pTo->rUnsort) <= (rCost,nOut,rUnsort)
					 */
					if int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) < int32(rCost) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) < int32(nOut) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) == int32(nOut) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsort) < int32(rUnsort) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FnRow) == int32(nOut) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsort) == int32(rUnsort) && _whereLoopIsNoBetter(tls, pWLoop, **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*8))) != 0 {
						/* Discard the candidate path from further consideration */
						goto _6
					}
					/* Control reaches here if the candidate path is better than the
					 ** pTo path.  Replace pTo with the candidate. */
				}
				/* pWLoop is a winner.  Add it to the set of best so far */
				(*TWherePath)(unsafe.Pointer(pTo)).FmaskLoop = (*TWherePath)(unsafe.Pointer(pFrom)).FmaskLoop | (*TWhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
				(*TWherePath)(unsafe.Pointer(pTo)).FrevLoop = **(**TBitmask)(__ccgo_up(bp))
				(*TWherePath)(unsafe.Pointer(pTo)).FnRow = nOut
				(*TWherePath)(unsafe.Pointer(pTo)).FrCost = rCost
				(*TWherePath)(unsafe.Pointer(pTo)).FrUnsort = rUnsort
				(*TWherePath)(unsafe.Pointer(pTo)).FisOrdered = isOrdered
				libc.Xmemcpy(tls, (*TWherePath)(unsafe.Pointer(pTo)).FaLoop, (*TWherePath)(unsafe.Pointer(pFrom)).FaLoop, uint64(8)*libc.Uint64FromInt32(iLoop))
				**(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*8)) = pWLoop
				if nTo >= mxChoice {
					mxI = 0
					mxCost = (**(**TWherePath)(__ccgo_up(aTo))).FrCost
					mxUnsort = (**(**TWherePath)(__ccgo_up(aTo))).FnRow
					jj = int32(1)
					pTo = aTo + 1*32
					for {
						if !(jj < mxChoice) {
							break
						}
						if int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) > int32(mxCost) || int32((*TWherePath)(unsafe.Pointer(pTo)).FrCost) == int32(mxCost) && int32((*TWherePath)(unsafe.Pointer(pTo)).FrUnsort) > int32(mxUnsort) {
							mxCost = (*TWherePath)(unsafe.Pointer(pTo)).FrCost
							mxUnsort = (*TWherePath)(unsafe.Pointer(pTo)).FrUnsort
							mxI = jj
						}
						goto _9
					_9:
						;
						jj = jj + 1
						pTo += 32
					}
				}
				goto _6
			_6:
				;
				pWLoop = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop
			}
			goto _5
		_5:
			;
			ii = ii + 1
			pFrom += 32
		}
		/* Swap the roles of aFrom and aTo for the next generation */
		pFrom = aTo
		aTo = aFrom
		aFrom = pFrom
		nFrom = nTo
		goto _4
	_4:
		;
		iLoop = iLoop + 1
	}
	if nFrom == 0 {
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24086, 0)
		_sqlite3DbFreeNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSpace)
		return int32(SQLITE_ERROR)
	}
	/* Only one path is available, which is the best path */
	pFrom = aFrom
	/* Load the lowest cost path into pWInfo */
	iLoop = 0
	for {
		if !(iLoop < nLoop) {
			break
		}
		pLevel = pWInfo + 856 + uintptr(iLoop)*112
		v11 = **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(iLoop)*8))
		pWLoop = v11
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FpWLoop = v11
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom = (*TWhereLoop)(unsafe.Pointer(pWLoop)).FiTab
		(*TWhereLevel)(unsafe.Pointer(pLevel)).FiTabCur = (*(*TSrcItem)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*TWhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*80))).FiCursor
		goto _10
	_10:
		;
		iLoop = iLoop + 1
	}
	if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) == 0 && libc.Int32FromUint8((*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == WHERE_DISTINCT_NOOP && nRowEst != 0 {
		rc = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet, pFrom, uint16(WHERE_DISTINCTBY), libc.Uint16FromInt32(nLoop-int32(1)), **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)), bp+8))
		if rc == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet)).FnExpr {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_ORDERED)
		}
	}
	libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(0), 5, 0x20)
	if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = (*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_DISTINCTBY) != 0 {
			if int32((*TWherePath)(unsafe.Pointer(pFrom)).FisOrdered) == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_ORDERED)
			}
			/* vvv--- See check-in [12ad822d9b827777] on 2023-03-16 ---vvv */
		} else {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = (*TWherePath)(unsafe.Pointer(pFrom)).FrevLoop
			if int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) <= 0 {
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = 0
				if nLoop > 0 {
					wsFlags = (*TWhereLoop)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)))).FwsFlags
					if wsFlags&uint32(WHERE_ONEROW) == uint32(0) && wsFlags&libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_COLUMN_IN)) != libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_IPK)|libc.Int32FromInt32(WHERE_COLUMN_IN)) {
						**(**TBitmask)(__ccgo_up(bp + 16)) = uint64(0)
						rc1 = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, uint16(WHERE_ORDERBY_LIMIT), libc.Uint16FromInt32(nLoop-int32(1)), **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)), bp+16))
						if rc1 == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
							libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 5, 0x20)
							(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = **(**TBitmask)(__ccgo_up(bp + 16))
						}
					}
				}
			} else {
				if nLoop != 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == int32(1) && libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(libc.Int32FromInt32(WHERE_ORDERBY_MIN)|libc.Int32FromInt32(WHERE_ORDERBY_MAX)) != 0 {
					libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 5, 0x20)
				}
			}
		}
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_SORTBYGROUP) != 0 && int32((*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr && nLoop > 0 {
			**(**TBitmask)(__ccgo_up(bp + 24)) = uint64(0)
			nOrder = int32(_wherePathSatisfiesOrderBy(tls, pWInfo, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, uint16(0), libc.Uint16FromInt32(nLoop-int32(1)), **(**uintptr)(__ccgo_up((*TWherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-int32(1))*8)), bp+24))
			if nOrder == (*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				libc.SetBitFieldPtr8Uint32(pWInfo+68, libc.Uint32FromInt32(1), 4, 0x10)
				(*TWhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = **(**TBitmask)(__ccgo_up(bp + 24))
			}
		}
	}
	(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut = (*TWherePath)(unsafe.Pointer(pFrom)).FnRow
	/* Free temporary memory and return success */
	_sqlite3DbFreeNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSpace)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Set the reverse-scan order mask to one for all tables in the query
//	** with the exception of MATERIALIZED common table expressions that have
//	** their own internal ORDER BY clauses.
//	**
//	** This implements the PRAGMA reverse_unordered_selects=ON setting.
//	** (Also SQLITE_DBCONFIG_REVERSE_SCANORDER).
//	*/
func _whereReverseScanOrder(tls *libc.TLS, pWInfo uintptr) {
	var ii int32
	var pItem uintptr
	_, _ = ii, pItem
	ii = 0
	for {
		if !(ii < (*TSrcList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList)).FnSrc) {
			break
		}
		pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr(ii)*80
		if !(int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x400000>>22) != 0) || libc.Int32FromUint8((*TCteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 56)))).FeM10d) != M10d_Yes || int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x20000000>>29) == 0 || (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 72)))).FpSelect)).FpOrderBy == uintptr(0) {
			**(**TBitmask)(__ccgo_up(pWInfo + 96)) |= libc.Uint64FromInt32(1) << ii
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
}

// C documentation
//
//	/*
//	** Most queries use only a single table (they are not joins) and have
//	** simple == constraints against indexed fields.  This routine attempts
//	** to plan those simple cases using much less ceremony than the
//	** general-purpose query planner, and thereby yield faster sqlite3_prepare()
//	** times for the common case.
//	**
//	** Return non-zero on success, if this query can be handled by this
//	** no-frills query planner.  Return zero if this query needs the
//	** general-purpose query planner.
//	*/
func _whereShortCut(tls *libc.TLS, pBuilder uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var iCur, j, opMask, v2 int32
	var pIdx, pItem, pLoop, pTab, pTerm, pWC, pWInfo uintptr
	var _ /* scan at bp+0 */ TWhereScan
	_, _, _, _, _, _, _, _, _, _, _ = iCur, j, opMask, pIdx, pItem, pLoop, pTab, pTerm, pWC, pWInfo, v2
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_OR_SUBCLAUSE) != 0 {
		return 0
	}
	pItem = (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
	pTab = (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pTab)).FeTabType) == int32(TABTYP_VTAB) {
		return 0
	}
	if int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x40000000>>30) != 0 || int32(*(*uint32)(unsafe.Pointer(pItem + 24 + 4))&0x80000000>>31) != 0 {
		return 0
	}
	iCur = (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor
	pWC = pWInfo + 104
	pLoop = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = uint32(0)
	(*TWhereLoop)(unsafe.Pointer(pLoop)).FnSkip = uint16(0)
	pTerm = _whereScanInit(tls, bp, pWC, iCur, -int32(1), libc.Uint32FromInt32(libc.Int32FromInt32(WO_EQ)|libc.Int32FromInt32(WO_IS)), uintptr(0))
	for pTerm != 0 && (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight != 0 {
		pTerm = _whereScanNext(tls, bp)
	}
	if pTerm != 0 {
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_EQ) | libc.Int32FromInt32(WHERE_IPK) | libc.Int32FromInt32(WHERE_ONEROW))
		**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm)) = pTerm
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = uint16(1)
		(*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(pLoop + 24))).FnEq = uint16(1)
		/* TUNING: Cost of a rowid lookup is 10 */
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FrRun = int16(33) /* 33==sqlite3LogEst(10) */
	} else {
		pIdx = (*TTable)(unsafe.Pointer(pTab)).FpIndex
		for {
			if !(pIdx != 0) {
				break
			}
			if !(libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pIdx)).FonError) != libc.Int32FromInt32(OE_None)) || (*TIndex)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) || libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) > libc.Int32FromUint64(libc.Uint64FromInt64(24)/libc.Uint64FromInt64(8)) {
				goto _1
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x1000>>12)) != 0 {
				v2 = libc.Int32FromInt32(WO_EQ) | libc.Int32FromInt32(WO_IS)
			} else {
				v2 = int32(WO_EQ)
			}
			opMask = v2
			j = 0
			for {
				if !(j < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol)) {
					break
				}
				pTerm = _whereScanInit(tls, bp, pWC, iCur, j, libc.Uint32FromInt32(opMask), pIdx)
				for pTerm != 0 && (*TWhereTerm)(unsafe.Pointer(pTerm)).FprereqRight != 0 {
					pTerm = _whereScanNext(tls, bp)
				}
				if pTerm == uintptr(0) {
					break
				}
				**(**uintptr)(__ccgo_up((*TWhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)) = pTerm
				goto _3
			_3:
				;
				j = j + 1
			}
			if j != libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pIdx)).FnKeyCol) {
				goto _1
			}
			(*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = libc.Uint32FromInt32(libc.Int32FromInt32(WHERE_COLUMN_EQ) | libc.Int32FromInt32(WHERE_ONEROW) | libc.Int32FromInt32(WHERE_INDEXED))
			if int32(uint32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x400>>10)) != 0 || (*TSrcItem)(unsafe.Pointer(pItem)).FcolUsed&(*TIndex)(unsafe.Pointer(pIdx)).FcolNotIdxed == uint64(0) {
				**(**Tu32)(__ccgo_up(pLoop + 48)) |= uint32(WHERE_IDX_ONLY)
			}
			(*TWhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = libc.Uint16FromInt32(j)
			(*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FnEq = libc.Uint16FromInt32(j)
			(*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(pLoop + 24))).FpIndex = pIdx
			/* TUNING: Cost of a unique index lookup is 15 */
			(*TWhereLoop)(unsafe.Pointer(pLoop)).FrRun = int16(39) /* 39==sqlite3LogEst(15) */
			break
			goto _1
		_1:
			;
			pIdx = (*TIndex)(unsafe.Pointer(pIdx)).FpNext
		}
	}
	if (*TWhereLoop)(unsafe.Pointer(pLoop)).FwsFlags != 0 {
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FnOut = libc.Int16FromInt32(1)
		(*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FpWLoop = pLoop
		(*TWhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf = uint64(1) /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
		(*(*TWhereLevel)(unsafe.Pointer(pWInfo + 856))).FiTabCur = iCur
		(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut = int16(1)
		if (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = int8((*TExprList)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr)
		}
		if libc.Int32FromUint16((*TWhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&int32(WHERE_WANT_DISTINCT) != 0 {
			(*TWhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = uint8(WHERE_DISTINCT_UNIQUE)
		}
		if libc.Int32FromUint8((**(**TWhereScan)(__ccgo_up(bp))).FiEquiv) > int32(1) {
			**(**Tu32)(__ccgo_up(pLoop + 48)) |= uint32(WHERE_TRANSCONS)
		}
		return int32(1)
	}
	return 0
}

func _writeCoord(tls *libc.TLS, p uintptr, pCoord uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* i at bp+0 */ Tu32
	**(**Tu32)(__ccgo_up(bp)) = *(*Tu32)(unsafe.Pointer(pCoord))
	libc.Xmemcpy(tls, p, bp, uint64(4))
	return int32(4)
}

func _writeInt64(tls *libc.TLS, p uintptr, _i Ti64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Ti64)(unsafe.Pointer(bp)) = _i
	libc.Xmemcpy(tls, p, bp, uint64(8))
	return int32(8)
}

// C documentation
//
//	/*
//	** Attempt the transfer optimization on INSERTs of the form
//	**
//	**     INSERT INTO tab1 SELECT * FROM tab2;
//	**
//	** The xfer optimization transfers raw records from tab2 over to tab1.
//	** Columns are not decoded and reassembled, which greatly improves
//	** performance.  Raw index records are transferred in the same way.
//	**
//	** The xfer optimization is only attempted if tab1 and tab2 are compatible.
//	** There are lots of rules for determining compatibility - see comments
//	** embedded in the code for details.
//	**
//	** This routine returns TRUE if the optimization is guaranteed to be used.
//	** Sometimes the xfer optimization will only work if the destination table
//	** is empty - a factor that can only be determined at run-time.  In that
//	** case, this routine generates code for the xfer optimization but also
//	** does a test to see if the destination table is empty and jumps over the
//	** xfer optimization code if the test fails.  In that case, this routine
//	** returns FALSE so that the caller will know to go ahead and generate
//	** an unoptimized transfer.  This routine also returns FALSE if there
//	** is no chance that the xfer optimization can be applied.
//	**
//	** This optimization is particularly useful at making VACUUM run faster.
//	*/
func _xferOptimization(tls *libc.TLS, pParse uintptr, pDest uintptr, pSelect uintptr, onError int32, iDbDest int32) (r int32) {
	var addr1, addr2, destHasUniqueIdx, emptyDestTest, emptySrcTest, i, iDbSrc, iDest, iSrc, regAutoinc, regData, regRowid, v4 int32
	var db, pDestCol, pDestExpr, pDestIdx, pEList, pItem, pSrc, pSrcCol, pSrcExpr, pSrcIdx, v, zColl, v5 uintptr
	var idxInsFlags, insFlags Tu8
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = addr1, addr2, db, destHasUniqueIdx, emptyDestTest, emptySrcTest, i, iDbSrc, iDest, iSrc, idxInsFlags, insFlags, pDestCol, pDestExpr, pDestIdx, pEList, pItem, pSrc, pSrcCol, pSrcExpr, pSrcIdx, regAutoinc, regData, regRowid, v, zColl, v4, v5
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb /* Loop addresses */
	emptyDestTest = 0                          /* Address of test for empty pDest */
	emptySrcTest = 0                           /* Memory register used by AUTOINC */
	destHasUniqueIdx = 0                       /* Registers holding data and rowid */
	if (*TParse)(unsafe.Pointer(pParse)).FpWith != 0 || (*TSelect)(unsafe.Pointer(pSelect)).FpWith != 0 {
		/* Do not attempt to process this query if there are an WITH clauses
		 ** attached to it. Proceeding may generate a false "no such table: xxx"
		 ** error if pSelect reads from a CTE named "xxx".  */
		return 0
	}
	if libc.Int32FromUint8((*TTable)(unsafe.Pointer(pDest)).FeTabType) == int32(TABTYP_VTAB) {
		return 0 /* tab1 must not be a virtual table */
	}
	if onError == int32(OE_Default) {
		if int32((*TTable)(unsafe.Pointer(pDest)).FiPKey) >= 0 {
			onError = libc.Int32FromUint8((*TTable)(unsafe.Pointer(pDest)).FkeyConf)
		}
		if onError == int32(OE_Default) {
			onError = int32(OE_Abort)
		}
	}
	/* allocated even if there is no FROM clause */
	if (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc)).FnSrc != int32(1) {
		return 0 /* FROM clause must have exactly one term */
	}
	if int32(*(*uint32)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8 + 24 + 4))&0x20000000>>29) != 0 {
		return 0 /* FROM clause cannot contain a subquery */
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FpWhere != 0 {
		return 0 /* SELECT may not have a WHERE clause */
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FpOrderBy != 0 {
		return 0 /* SELECT may not have an ORDER BY clause */
	}
	/* Do not need to test for a HAVING clause.  If HAVING is present but
	 ** there is no ORDER BY, we will get an error. */
	if (*TSelect)(unsafe.Pointer(pSelect)).FpGroupBy != 0 {
		return 0 /* SELECT may not have a GROUP BY clause */
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FpLimit != 0 {
		return 0 /* SELECT may not have a LIMIT clause */
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		return 0 /* SELECT may not be a compound query */
	}
	if (*TSelect)(unsafe.Pointer(pSelect)).FselFlags&uint32(SF_Distinct) != 0 {
		return 0 /* SELECT may not be DISTINCT */
	}
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	if (*TExprList)(unsafe.Pointer(pEList)).FnExpr != int32(1) {
		return 0 /* The result set must have exactly one column */
	}
	if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pEList + 8))).FpExpr)).Fop) != int32(TK_ASTERISK) {
		return 0 /* The result set must be the special operator "*" */
	}
	/* At this point we have established that the statement is of the
	 ** correct syntactic form to participate in this optimization.  Now
	 ** we have to check the semantics.
	 */
	pItem = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc + 8
	pSrc = _sqlite3LocateTableItem(tls, pParse, uint32(0), pItem)
	if pSrc == uintptr(0) {
		return 0 /* FROM clause does not contain a real table */
	}
	if (*TTable)(unsafe.Pointer(pSrc)).Ftnum == (*TTable)(unsafe.Pointer(pDest)).Ftnum && (*TTable)(unsafe.Pointer(pSrc)).FpSchema == (*TTable)(unsafe.Pointer(pDest)).FpSchema {
		/* Possible due to bad sqlite_schema.rootpage */
		return 0 /* tab1 and tab2 may not be the same table */
	}
	if libc.BoolInt32((*TTable)(unsafe.Pointer(pDest)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)) != libc.BoolInt32((*TTable)(unsafe.Pointer(pSrc)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0)) {
		return 0 /* source and destination must both be WITHOUT ROWID or not */
	}
	if !(libc.Int32FromUint8((*TTable)(unsafe.Pointer(pSrc)).FeTabType) == libc.Int32FromInt32(TABTYP_NORM)) {
		return 0 /* tab2 may not be a view or virtual table */
	}
	if int32((*TTable)(unsafe.Pointer(pDest)).FnCol) != int32((*TTable)(unsafe.Pointer(pSrc)).FnCol) {
		return 0 /* Number of columns must be the same in tab1 and tab2 */
	}
	if int32((*TTable)(unsafe.Pointer(pDest)).FiPKey) != int32((*TTable)(unsafe.Pointer(pSrc)).FiPKey) {
		return 0 /* Both tables must have the same INTEGER PRIMARY KEY */
	}
	if (*TTable)(unsafe.Pointer(pDest)).FtabFlags&uint32(TF_Strict) != uint32(0) && (*TTable)(unsafe.Pointer(pSrc)).FtabFlags&uint32(TF_Strict) == uint32(0) {
		return 0 /* Cannot feed from a non-strict into a strict table */
	}
	i = 0
	for {
		if !(i < int32((*TTable)(unsafe.Pointer(pDest)).FnCol)) {
			break
		}
		pDestCol = (*TTable)(unsafe.Pointer(pDest)).FaCol + uintptr(i)*16
		pSrcCol = (*TTable)(unsafe.Pointer(pSrc)).FaCol + uintptr(i)*16
		/* Even if tables t1 and t2 have identical schemas, if they contain
		 ** generated columns, then this statement is semantically incorrect:
		 **
		 **     INSERT INTO t2 SELECT * FROM t1;
		 **
		 ** The reason is that generated column values are returned by the
		 ** the SELECT statement on the right but the INSERT statement on the
		 ** left wants them to be omitted.
		 **
		 ** Nevertheless, this is a useful notational shorthand to tell SQLite
		 ** to do a bulk transfer all of the content from t1 over to t2.
		 **
		 ** We could, in theory, disable this (except for internal use by the
		 ** VACUUM command where it is actually needed).  But why do that?  It
		 ** seems harmless enough, and provides a useful service.
		 */
		if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pDestCol)).FcolFlags)&int32(COLFLAG_GENERATED) != libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pSrcCol)).FcolFlags)&int32(COLFLAG_GENERATED) {
			return 0 /* Both columns have the same generated-column type */
		}
		/* But the transfer is only allowed if both the source and destination
		 ** tables have the exact same expressions for generated columns.
		 ** This requirement could be relaxed for VIRTUAL columns, I suppose.
		 */
		if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pDestCol)).FcolFlags)&int32(COLFLAG_GENERATED) != 0 {
			if _sqlite3ExprCompare(tls, uintptr(0), _sqlite3ColumnExpr(tls, pSrc, pSrcCol), _sqlite3ColumnExpr(tls, pDest, pDestCol), -int32(1)) != 0 {
				return 0 /* Different generator expressions */
			}
		}
		if libc.Int32FromUint8((*TColumn)(unsafe.Pointer(pDestCol)).Faffinity) != libc.Int32FromUint8((*TColumn)(unsafe.Pointer(pSrcCol)).Faffinity) {
			return 0 /* Affinity must be the same on all columns */
		}
		if Xsqlite3_stricmp(tls, _sqlite3ColumnColl(tls, pDestCol), _sqlite3ColumnColl(tls, pSrcCol)) != 0 {
			return 0 /* Collating sequence must be the same on all columns */
		}
		if int32(uint32(*(*uint8)(unsafe.Pointer(pDestCol + 8))&0xf0>>4)) != 0 && !(int32(uint32(*(*uint8)(unsafe.Pointer(pSrcCol + 8))&0xf0>>4)) != 0) {
			return 0 /* tab2 must be NOT NULL if tab1 is */
		}
		/* Default values for second and subsequent columns need to match. */
		if libc.Int32FromUint16((*TColumn)(unsafe.Pointer(pDestCol)).FcolFlags)&int32(COLFLAG_GENERATED) == 0 && i > 0 {
			pDestExpr = _sqlite3ColumnExpr(tls, pDest, pDestCol)
			pSrcExpr = _sqlite3ColumnExpr(tls, pSrc, pSrcCol)
			if libc.BoolInt32(pDestExpr == uintptr(0)) != libc.BoolInt32(pSrcExpr == uintptr(0)) || pDestExpr != uintptr(0) && libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(pDestExpr + 8)), *(*uintptr)(unsafe.Pointer(pSrcExpr + 8))) != 0 {
				return 0 /* Default values must be the same for all columns */
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	pDestIdx = (*TTable)(unsafe.Pointer(pDest)).FpIndex
	for {
		if !(pDestIdx != 0) {
			break
		}
		if libc.Int32FromUint8((*TIndex)(unsafe.Pointer(pDestIdx)).FonError) != OE_None {
			destHasUniqueIdx = int32(1)
		}
		pSrcIdx = (*TTable)(unsafe.Pointer(pSrc)).FpIndex
		for {
			if !(pSrcIdx != 0) {
				break
			}
			if _xferCompatibleIndex(tls, pDestIdx, pSrcIdx) != 0 {
				break
			}
			goto _3
		_3:
			;
			pSrcIdx = (*TIndex)(unsafe.Pointer(pSrcIdx)).FpNext
		}
		if pSrcIdx == uintptr(0) {
			return 0 /* pDestIdx has no corresponding index in pSrc */
		}
		if (*TIndex)(unsafe.Pointer(pSrcIdx)).Ftnum == (*TIndex)(unsafe.Pointer(pDestIdx)).Ftnum && (*TTable)(unsafe.Pointer(pSrc)).FpSchema == (*TTable)(unsafe.Pointer(pDest)).FpSchema && _sqlite3FaultSim(tls, int32(411)) == SQLITE_OK {
			/* The sqlite3FaultSim() call allows this corruption test to be
			 ** bypassed during testing, in order to exercise other corruption tests
			 ** further downstream. */
			return 0 /* Corrupt schema - two indexes on the same btree */
		}
		goto _2
	_2:
		;
		pDestIdx = (*TIndex)(unsafe.Pointer(pDestIdx)).FpNext
	}
	if (*TTable)(unsafe.Pointer(pDest)).FpCheck != 0 && (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) && _sqlite3ExprListCompare(tls, (*TTable)(unsafe.Pointer(pSrc)).FpCheck, (*TTable)(unsafe.Pointer(pDest)).FpCheck, -int32(1)) != 0 {
		return 0 /* Tables have different CHECK constraints.  Ticket #2252 */
	}
	/* Disallow the transfer optimization if the destination table contains
	 ** any foreign key constraints.  This is more restrictive than necessary.
	 ** But the main beneficiary of the transfer optimization is the VACUUM
	 ** command, and the VACUUM command disables foreign key constraints.  So
	 ** the extra complication to make this rule less restrictive is probably
	 ** not worth the effort.  Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != uint64(0) && (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pDest + 64))).FpFKey != uintptr(0) {
		return 0
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).Fflags&(libc.Uint64FromInt32(libc.Int32FromInt32(0x00001))<<libc.Int32FromInt32(32)) != uint64(0) {
		return 0 /* xfer opt does not play well with PRAGMA count_changes */
	}
	/* If we get this far, it means that the xfer optimization is at
	 ** least a possibility, though it might only work if the destination
	 ** table (tab1) is initially empty.
	 */
	iDbSrc = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pSrc)).FpSchema)
	v = _sqlite3GetVdbe(tls, pParse)
	_sqlite3CodeVerifySchema(tls, pParse, iDbSrc)
	v5 = pParse + 56
	v4 = *(*int32)(unsafe.Pointer(v5))
	*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
	iSrc = v4
	v5 = pParse + 56
	v4 = *(*int32)(unsafe.Pointer(v5))
	*(*int32)(unsafe.Pointer(v5)) = *(*int32)(unsafe.Pointer(v5)) + 1
	iDest = v4
	regAutoinc = _autoIncBegin(tls, pParse, iDbDest, pDest)
	regData = _sqlite3GetTempReg(tls, pParse)
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, regData)
	regRowid = _sqlite3GetTempReg(tls, pParse)
	_sqlite3OpenTable(tls, pParse, iDest, iDbDest, pDest, int32(OP_OpenWrite))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) && (int32((*TTable)(unsafe.Pointer(pDest)).FiPKey) < 0 && (*TTable)(unsafe.Pointer(pDest)).FpIndex != uintptr(0) || destHasUniqueIdx != 0 || onError != int32(OE_Abort) && onError != int32(OE_Rollback)) {
		/* In some circumstances, we are able to run the xfer optimization
		 ** only if the destination table is initially empty. Unless the
		 ** DBFLAG_Vacuum flag is set, this block generates code to make
		 ** that determination. If DBFLAG_Vacuum is set, then the destination
		 ** table is always empty.
		 **
		 ** Conditions under which the destination must be empty:
		 **
		 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
		 **     (If the destination is not initially empty, the rowid fields
		 **     of index entries might need to change.)
		 **
		 ** (2) The destination has a unique index.  (The xfer optimization
		 **     is unable to test uniqueness.)
		 **
		 ** (3) onError is something other than OE_Abort and OE_Rollback.
		 */
		addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iDest, 0)
		emptyDestTest = _sqlite3VdbeAddOp0(tls, v, int32(OP_Goto))
		_sqlite3VdbeJumpHere(tls, v, addr1)
	}
	if (*TTable)(unsafe.Pointer(pSrc)).FtabFlags&uint32(TF_WithoutRowid) == uint32(0) {
		_sqlite3OpenTable(tls, pParse, iSrc, iDbSrc, pSrc, int32(OP_OpenRead))
		emptySrcTest = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iSrc, 0)
		if int32((*TTable)(unsafe.Pointer(pDest)).FiPKey) >= 0 {
			addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iSrc, regRowid)
			if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) {
				addr2 = _sqlite3VdbeAddOp3(tls, v, int32(OP_NotExists), iDest, 0, regRowid)
				_sqlite3RowidConstraint(tls, pParse, onError, pDest)
				_sqlite3VdbeJumpHere(tls, v, addr2)
			}
			_autoIncStep(tls, pParse, regAutoinc, regRowid)
		} else {
			if (*TTable)(unsafe.Pointer(pDest)).FpIndex == uintptr(0) && !((*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&libc.Uint32FromInt32(DBFLAG_VacuumInto) != 0) {
				addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_NewRowid), iDest, regRowid)
			} else {
				addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iSrc, regRowid)
			}
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) != 0 {
			_sqlite3VdbeAddOp1(tls, v, int32(OP_SeekEnd), iDest)
			insFlags = libc.Uint8FromInt32(libc.Int32FromInt32(OPFLAG_APPEND) | libc.Int32FromInt32(OPFLAG_USESEEKRESULT) | libc.Int32FromInt32(OPFLAG_PREFORMAT))
		} else {
			insFlags = libc.Uint8FromInt32(libc.Int32FromInt32(OPFLAG_NCHANGE) | libc.Int32FromInt32(OPFLAG_LASTROWID) | libc.Int32FromInt32(OPFLAG_APPEND) | libc.Int32FromInt32(OPFLAG_PREFORMAT))
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_RowData), iSrc, regData, int32(1))
			insFlags = libc.Uint8FromInt32(int32(insFlags) & ^libc.Int32FromInt32(OPFLAG_PREFORMAT))
		} else {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_RowCell), iDest, iSrc, regRowid)
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Insert), iDest, regData, regRowid)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) {
			_sqlite3VdbeChangeP4(tls, v, -int32(1), pDest, -int32(5))
		}
		_sqlite3VdbeChangeP5(tls, v, uint16(insFlags))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iSrc, addr1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), iSrc, 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), iDest, 0)
	} else {
		_sqlite3TableLock(tls, pParse, iDbDest, (*TTable)(unsafe.Pointer(pDest)).Ftnum, uint8(1), (*TTable)(unsafe.Pointer(pDest)).FzName)
		_sqlite3TableLock(tls, pParse, iDbSrc, (*TTable)(unsafe.Pointer(pSrc)).Ftnum, uint8(0), (*TTable)(unsafe.Pointer(pSrc)).FzName)
	}
	pDestIdx = (*TTable)(unsafe.Pointer(pDest)).FpIndex
	for {
		if !(pDestIdx != 0) {
			break
		}
		idxInsFlags = uint8(0)
		pSrcIdx = (*TTable)(unsafe.Pointer(pSrc)).FpIndex
		for {
			if !(pSrcIdx != 0) {
				break
			}
			if _xferCompatibleIndex(tls, pDestIdx, pSrcIdx) != 0 {
				break
			}
			goto _9
		_9:
			;
			pSrcIdx = (*TIndex)(unsafe.Pointer(pSrcIdx)).FpNext
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenRead), iSrc, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pSrcIdx)).Ftnum), iDbSrc)
		_sqlite3VdbeSetP4KeyInfo(tls, pParse, pSrcIdx)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_OpenWrite), iDest, libc.Int32FromUint32((*TIndex)(unsafe.Pointer(pDestIdx)).Ftnum), iDbDest)
		_sqlite3VdbeSetP4KeyInfo(tls, pParse, pDestIdx)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_BULKCSR))
		addr1 = _sqlite3VdbeAddOp2(tls, v, int32(OP_Rewind), iSrc, 0)
		if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) != 0 {
			/* This INSERT command is part of a VACUUM operation, which guarantees
			 ** that the destination table is empty. If all indexed columns use
			 ** collation sequence BINARY, then it can also be assumed that the
			 ** index will be populated by inserting keys in strictly sorted
			 ** order. In this case, instead of seeking within the b-tree as part
			 ** of every OP_IdxInsert opcode, an OP_SeekEnd is added before the
			 ** OP_IdxInsert to seek to the point within the b-tree where each key
			 ** should be inserted. This is faster.
			 **
			 ** If any of the indexed columns use a collation sequence other than
			 ** BINARY, this optimization is disabled. This is because the user
			 ** might change the definition of a collation sequence and then run
			 ** a VACUUM command. In that case keys may not be written in strictly
			 ** sorted order.  */
			i = 0
			for {
				if !(i < libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pSrcIdx)).FnColumn)) {
					break
				}
				zColl = **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pSrcIdx)).FazColl + uintptr(i)*8))
				if Xsqlite3_stricmp(tls, uintptr(unsafe.Pointer(&_sqlite3StrBINARY)), zColl) != 0 {
					break
				}
				goto _10
			_10:
				;
				i = i + 1
			}
			if i == libc.Int32FromUint16((*TIndex)(unsafe.Pointer(pSrcIdx)).FnColumn) {
				idxInsFlags = libc.Uint8FromInt32(libc.Int32FromInt32(OPFLAG_USESEEKRESULT) | libc.Int32FromInt32(OPFLAG_PREFORMAT))
				_sqlite3VdbeAddOp1(tls, v, int32(OP_SeekEnd), iDest)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_RowCell), iDest, iSrc)
			}
		} else {
			if !((*TTable)(unsafe.Pointer(pSrc)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pDestIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
				idxInsFlags = libc.Uint8FromInt32(int32(idxInsFlags) | libc.Int32FromInt32(OPFLAG_NCHANGE))
			}
		}
		if libc.Int32FromUint8(idxInsFlags) != libc.Int32FromInt32(OPFLAG_USESEEKRESULT)|libc.Int32FromInt32(OPFLAG_PREFORMAT) {
			_sqlite3VdbeAddOp3(tls, v, int32(OP_RowData), iSrc, regData, int32(1))
			if (*Tsqlite3)(unsafe.Pointer(db)).FmDbFlags&uint32(DBFLAG_Vacuum) == uint32(0) && !((*TTable)(unsafe.Pointer(pDest)).FtabFlags&libc.Uint32FromInt32(TF_WithoutRowid) == libc.Uint32FromInt32(0)) && int32(uint32(*(*uint16)(unsafe.Pointer(pDestIdx + 100))&0xc000>>14)) == int32(SQLITE_IDXTYPE_PRIMARYKEY) {
				_codeWithoutRowidPreupdate(tls, pParse, pDest, iDest, regData)
			}
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_IdxInsert), iDest, regData)
		_sqlite3VdbeChangeP5(tls, v, libc.Uint16FromInt32(libc.Int32FromUint8(idxInsFlags)|int32(OPFLAG_APPEND)))
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Next), iSrc, addr1+int32(1))
		_sqlite3VdbeJumpHere(tls, v, addr1)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), iSrc, 0)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), iDest, 0)
		goto _8
	_8:
		;
		pDestIdx = (*TIndex)(unsafe.Pointer(pDestIdx)).FpNext
	}
	if emptySrcTest != 0 {
		_sqlite3VdbeJumpHere(tls, v, emptySrcTest)
	}
	_sqlite3ReleaseTempReg(tls, pParse, regRowid)
	_sqlite3ReleaseTempReg(tls, pParse, regData)
	if emptyDestTest != 0 {
		_sqlite3AutoincrementEnd(tls, pParse)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Halt), SQLITE_OK, 0)
		_sqlite3VdbeJumpHere(tls, v, emptyDestTest)
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Close), iDest, 0)
		return 0
	} else {
		return int32(1)
	}
	return r
}

// C documentation
//
//	/*
//	** Perform a reduce action and the shift that must immediately
//	** follow the reduce.
//	**
//	** The yyLookahead and yyLookaheadToken parameters provide reduce actions
//	** access to the lookahead token (if any).  The yyLookahead will be YYNOCODE
//	** if the lookahead token has already been consumed.  As this procedure is
//	** only called from one place, optimizing compilers will in-line it, which
//	** means that the extra parameters have no performance impact.
//	*/
func _yy_reduce(tls *libc.TLS, yypParser uintptr, yyruleno uint32, yyLookahead int32, yyLookaheadToken TToken, pParse uintptr) (r uint16) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var bNot, bNot1, i, nExpr, yygoto, yysize, v353 int32
	var n Tu32
	var op Tu8
	var p, p1, p2, p3, p4, p5, pB, pDot, pFrom, pFromClause, pLeft, pLhs, pList, pList1, pList2, pList3, pList4, pNew, pOld, pRHS, pRhs, pRight, pSelect, pSelectRHS, pSrc, pSubquery, pSubquery1, temp1, temp11, temp2, temp21, temp3, temp4, yymsp, v352 uintptr
	var yyact uint16
	var v357 TToken
	var _ /* all at bp+112 */ TToken
	var _ /* as at bp+72 */ TToken
	var _ /* dest at bp+16 */ TSelectDest
	var _ /* iValue at bp+88 */ int32
	var _ /* t at bp+96 */ TToken
	var _ /* x at bp+56 */ TToken
	var _ /* yylhsminor at bp+0 */ TYYMINORTYPE
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = bNot, bNot1, i, n, nExpr, op, p, p1, p2, p3, p4, p5, pB, pDot, pFrom, pFromClause, pLeft, pLhs, pList, pList1, pList2, pList3, pList4, pNew, pOld, pRHS, pRhs, pRight, pSelect, pSelectRHS, pSrc, pSubquery, pSubquery1, temp1, temp11, temp2, temp21, temp3, temp4, yyact, yygoto, yymsp, yysize, v352, v353, v357 /* Amount to pop the stack */
	_ = yyLookahead
	_ = yyLookaheadToken
	yymsp = (*TyyParser)(unsafe.Pointer(yypParser)).Fyytos
	switch yyruleno {
	case uint32(0):
		goto _1
	case uint32(1):
		goto _2
	case uint32(2):
		goto _3
	case uint32(3):
		goto _4
	case uint32(4):
		goto _5
	case uint32(6):
		goto _6
	case uint32(5):
		goto _7
	case uint32(7):
		goto _8
	case uint32(328):
		goto _9
	case uint32(9):
		goto _10
	case uint32(8):
		goto _11
	case uint32(10):
		goto _12
	case uint32(11):
		goto _13
	case uint32(12):
		goto _14
	case uint32(13):
		goto _15
	case uint32(14):
		goto _16
	case uint32(18):
		goto _17
	case uint32(15):
		goto _18
	case uint32(47):
		goto _19
	case uint32(62):
		goto _20
	case uint32(72):
		goto _21
	case uint32(81):
		goto _22
	case uint32(100):
		goto _23
	case uint32(246):
		goto _24
	case uint32(16):
		goto _25
	case uint32(17):
		goto _26
	case uint32(19):
		goto _27
	case uint32(20):
		goto _28
	case uint32(21):
		goto _29
	case uint32(22):
		goto _30
	case uint32(23):
		goto _31
	case uint32(24):
		goto _32
	case uint32(25):
		goto _33
	case uint32(65):
		goto _34
	case uint32(26):
		goto _35
	case uint32(106):
		goto _36
	case uint32(27):
		goto _37
	case uint32(28):
		goto _38
	case uint32(29):
		goto _39
	case uint32(30):
		goto _40
	case uint32(31):
		goto _41
	case uint32(67):
		goto _42
	case uint32(32):
		goto _43
	case uint32(33):
		goto _44
	case uint32(34):
		goto _45
	case uint32(35):
		goto _46
	case uint32(36):
		goto _47
	case uint32(37):
		goto _48
	case uint32(38):
		goto _49
	case uint32(39):
		goto _50
	case uint32(40):
		goto _51
	case uint32(41):
		goto _52
	case uint32(42):
		goto _53
	case uint32(43):
		goto _54
	case uint32(44):
		goto _55
	case uint32(45):
		goto _56
	case uint32(46):
		goto _57
	case uint32(48):
		goto _58
	case uint32(49):
		goto _59
	case uint32(50):
		goto _60
	case uint32(51):
		goto _61
	case uint32(52):
		goto _62
	case uint32(53):
		goto _63
	case uint32(54):
		goto _64
	case uint32(55):
		goto _65
	case uint32(56):
		goto _66
	case uint32(57):
		goto _67
	case uint32(58):
		goto _68
	case uint32(59):
		goto _69
	case uint32(60):
		goto _70
	case uint32(76):
		goto _71
	case uint32(61):
		goto _72
	case uint32(173):
		goto _73
	case uint32(80):
		goto _74
	case uint32(63):
		goto _75
	case uint32(219):
		goto _76
	case uint32(222):
		goto _77
	case uint32(247):
		goto _78
	case uint32(64):
		goto _79
	case uint32(66):
		goto _80
	case uint32(68):
		goto _81
	case uint32(69):
		goto _82
	case uint32(70):
		goto _83
	case uint32(71):
		goto _84
	case uint32(75):
		goto _85
	case uint32(73):
		goto _86
	case uint32(74):
		goto _87
	case uint32(77):
		goto _88
	case uint32(174):
		goto _89
	case uint32(78):
		goto _90
	case uint32(79):
		goto _91
	case uint32(82):
		goto _92
	case uint32(83):
		goto _93
	case uint32(84):
		goto _94
	case uint32(85):
		goto _95
	case uint32(86):
		goto _96
	case uint32(87):
		goto _97
	case uint32(88):
		goto _98
	case uint32(91):
		goto _99
	case uint32(89):
		goto _100
	case uint32(90):
		goto _101
	case uint32(92):
		goto _102
	case uint32(93):
		goto _103
	case uint32(94):
		goto _104
	case uint32(95):
		goto _105
	case uint32(97):
		goto _106
	case uint32(96):
		goto _107
	case uint32(98):
		goto _108
	case uint32(99):
		goto _109
	case uint32(134):
		goto _110
	case uint32(101):
		goto _111
	case uint32(144):
		goto _112
	case uint32(234):
		goto _113
	case uint32(237):
		goto _114
	case uint32(242):
		goto _115
	case uint32(102):
		goto _116
	case uint32(103):
		goto _117
	case uint32(104):
		goto _118
	case uint32(117):
		goto _119
	case uint32(105):
		goto _120
	case uint32(258):
		goto _121
	case uint32(259):
		goto _122
	case uint32(110):
		goto _123
	case uint32(107):
		goto _124
	case uint32(108):
		goto _125
	case uint32(109):
		goto _126
	case uint32(111):
		goto _127
	case uint32(112):
		goto _128
	case uint32(113):
		goto _129
	case uint32(114):
		goto _130
	case uint32(115):
		goto _131
	case uint32(131):
		goto _132
	case uint32(116):
		goto _133
	case uint32(120):
		goto _134
	case uint32(118):
		goto _135
	case uint32(121):
		goto _136
	case uint32(119):
		goto _137
	case uint32(122):
		goto _138
	case uint32(123):
		goto _139
	case uint32(124):
		goto _140
	case uint32(125):
		goto _141
	case uint32(126):
		goto _142
	case uint32(127):
		goto _143
	case uint32(128):
		goto _144
	case uint32(129):
		goto _145
	case uint32(130):
		goto _146
	case uint32(132):
		goto _147
	case uint32(133):
		goto _148
	case uint32(145):
		goto _149
	case uint32(135):
		goto _150
	case uint32(136):
		goto _151
	case uint32(137):
		goto _152
	case uint32(138):
		goto _153
	case uint32(139):
		goto _154
	case uint32(143):
		goto _155
	case uint32(140):
		goto _156
	case uint32(141):
		goto _157
	case uint32(142):
		goto _158
	case uint32(148):
		goto _159
	case uint32(146):
		goto _160
	case uint32(153):
		goto _161
	case uint32(155):
		goto _162
	case uint32(232):
		goto _163
	case uint32(233):
		goto _164
	case uint32(252):
		goto _165
	case uint32(154):
		goto _166
	case uint32(147):
		goto _167
	case uint32(156):
		goto _168
	case uint32(231):
		goto _169
	case uint32(251):
		goto _170
	case uint32(149):
		goto _171
	case uint32(150):
		goto _172
	case uint32(151):
		goto _173
	case uint32(152):
		goto _174
	case uint32(157):
		goto _175
	case uint32(158):
		goto _176
	case uint32(159):
		goto _177
	case uint32(160):
		goto _178
	case uint32(161):
		goto _179
	case uint32(162):
		goto _180
	case uint32(163):
		goto _181
	case uint32(164):
		goto _182
	case uint32(165):
		goto _183
	case uint32(166):
		goto _184
	case uint32(167):
		goto _185
	case uint32(168):
		goto _186
	case uint32(169):
		goto _187
	case uint32(170):
		goto _188
	case uint32(171):
		goto _189
	case uint32(172):
		goto _190
	case uint32(175):
		goto _191
	case uint32(176):
		goto _192
	case uint32(177):
		goto _193
	case uint32(178):
		goto _194
	case uint32(179):
		goto _195
	case uint32(180):
		goto _196
	case uint32(181):
		goto _197
	case uint32(182):
		goto _198
	case uint32(184):
		goto _199
	case uint32(183):
		goto _200
	case uint32(185):
		goto _201
	case uint32(186):
		goto _202
	case uint32(187):
		goto _203
	case uint32(188):
		goto _204
	case uint32(189):
		goto _205
	case uint32(190):
		goto _206
	case uint32(191):
		goto _207
	case uint32(192):
		goto _208
	case uint32(193):
		goto _209
	case uint32(194):
		goto _210
	case uint32(195):
		goto _211
	case uint32(196):
		goto _212
	case uint32(197):
		goto _213
	case uint32(199):
		goto _214
	case uint32(198):
		goto _215
	case uint32(200):
		goto _216
	case uint32(201):
		goto _217
	case uint32(202):
		goto _218
	case uint32(203):
		goto _219
	case uint32(204):
		goto _220
	case uint32(205):
		goto _221
	case uint32(206):
		goto _222
	case uint32(207):
		goto _223
	case uint32(208):
		goto _224
	case uint32(209):
		goto _225
	case uint32(210):
		goto _226
	case uint32(211):
		goto _227
	case uint32(212):
		goto _228
	case uint32(213):
		goto _229
	case uint32(215):
		goto _230
	case uint32(214):
		goto _231
	case uint32(216):
		goto _232
	case uint32(217):
		goto _233
	case uint32(221):
		goto _234
	case uint32(218):
		goto _235
	case uint32(220):
		goto _236
	case uint32(223):
		goto _237
	case uint32(224):
		goto _238
	case uint32(225):
		goto _239
	case uint32(226):
		goto _240
	case uint32(227):
		goto _241
	case uint32(228):
		goto _242
	case uint32(229):
		goto _243
	case uint32(230):
		goto _244
	case uint32(235):
		goto _245
	case uint32(236):
		goto _246
	case uint32(243):
		goto _247
	case uint32(238):
		goto _248
	case uint32(239):
		goto _249
	case uint32(281):
		goto _250
	case uint32(240):
		goto _251
	case uint32(241):
		goto _252
	case uint32(244):
		goto _253
	case uint32(245):
		goto _254
	case uint32(248):
		goto _255
	case uint32(249):
		goto _256
	case uint32(250):
		goto _257
	case uint32(253):
		goto _258
	case uint32(254):
		goto _259
	case uint32(255):
		goto _260
	case uint32(256):
		goto _261
	case uint32(257):
		goto _262
	case uint32(260):
		goto _263
	case uint32(261):
		goto _264
	case uint32(262):
		goto _265
	case uint32(263):
		goto _266
	case uint32(264):
		goto _267
	case uint32(266):
		goto _268
	case uint32(265):
		goto _269
	case uint32(267):
		goto _270
	case uint32(286):
		goto _271
	case uint32(268):
		goto _272
	case uint32(287):
		goto _273
	case uint32(269):
		goto _274
	case uint32(270):
		goto _275
	case uint32(271):
		goto _276
	case uint32(272):
		goto _277
	case uint32(273):
		goto _278
	case uint32(274):
		goto _279
	case uint32(275):
		goto _280
	case uint32(276):
		goto _281
	case uint32(277):
		goto _282
	case uint32(278):
		goto _283
	case uint32(279):
		goto _284
	case uint32(280):
		goto _285
	case uint32(282):
		goto _286
	case uint32(283):
		goto _287
	case uint32(284):
		goto _288
	case uint32(285):
		goto _289
	case uint32(288):
		goto _290
	case uint32(289):
		goto _291
	case uint32(290):
		goto _292
	case uint32(291):
		goto _293
	case uint32(292):
		goto _294
	case uint32(293):
		goto _295
	case uint32(294):
		goto _296
	case uint32(295):
		goto _297
	case uint32(296):
		goto _298
	case uint32(297):
		goto _299
	case uint32(298):
		goto _300
	case uint32(299):
		goto _301
	case uint32(300):
		goto _302
	case uint32(301):
		goto _303
	case uint32(302):
		goto _304
	case uint32(303):
		goto _305
	case uint32(304):
		goto _306
	case uint32(305):
		goto _307
	case uint32(307):
		goto _308
	case uint32(306):
		goto _309
	case uint32(308):
		goto _310
	case uint32(310):
		goto _311
	case uint32(309):
		goto _312
	case uint32(311):
		goto _313
	case uint32(312):
		goto _314
	case uint32(313):
		goto _315
	case uint32(314):
		goto _316
	case uint32(315):
		goto _317
	case uint32(316):
		goto _318
	case uint32(317):
		goto _319
	case uint32(318):
		goto _320
	case uint32(319):
		goto _321
	case uint32(320):
		goto _322
	case uint32(321):
		goto _323
	case uint32(322):
		goto _324
	case uint32(323):
		goto _325
	case uint32(324):
		goto _326
	case uint32(325):
		goto _327
	case uint32(326):
		goto _328
	case uint32(327):
		goto _329
	case uint32(331):
		goto _330
	case uint32(329):
		goto _331
	case uint32(332):
		goto _332
	case uint32(330):
		goto _333
	case uint32(334):
		goto _334
	case uint32(333):
		goto _335
	case uint32(335):
		goto _336
	case uint32(336):
		goto _337
	case uint32(338):
		goto _338
	case uint32(337):
		goto _339
	case uint32(339):
		goto _340
	case uint32(340):
		goto _341
	case uint32(341):
		goto _342
	case uint32(342):
		goto _343
	case uint32(343):
		goto _344
	case uint32(344):
		goto _345
	case uint32(345):
		goto _346
	case uint32(346):
		goto _347
	case uint32(347):
		goto _348
	default:
		goto _349
	}
	goto _350
_1:
	; /* explain ::= EXPLAIN */
	if (*TParse)(unsafe.Pointer(pParse)).FpReprepare == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Fexplain = uint8(1)
	}
	goto _350
_2:
	; /* explain ::= EXPLAIN QUERY PLAN */
	if (*TParse)(unsafe.Pointer(pParse)).FpReprepare == uintptr(0) {
		(*TParse)(unsafe.Pointer(pParse)).Fexplain = uint8(2)
	}
	goto _350
_3:
	; /* cmdx ::= cmd */
	_sqlite3FinishCoding(tls, pParse)
	goto _350
_4:
	; /* cmd ::= BEGIN transtype trans_opt */
	_sqlite3BeginTransaction(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_5:
	; /* transtype ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = int32(TK_DEFERRED)
	goto _350
_7:
	; /* transtype ::= DEFERRED */
_6:
	;
_8:
	;
_9:
	;
	*(*int32)(unsafe.Pointer(yymsp + 8)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
	goto _350
_11:
	; /* cmd ::= COMMIT|END trans_opt */
_10:
	;
	_sqlite3EndTransaction(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*24))).Fmajor))
	goto _350
_12:
	; /* cmd ::= SAVEPOINT nm */
	_sqlite3Savepoint(tls, pParse, SAVEPOINT_BEGIN, yymsp+8)
	goto _350
_13:
	; /* cmd ::= RELEASE savepoint_opt nm */
	_sqlite3Savepoint(tls, pParse, int32(SAVEPOINT_RELEASE), yymsp+8)
	goto _350
_14:
	; /* cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
	_sqlite3Savepoint(tls, pParse, int32(SAVEPOINT_ROLLBACK), yymsp+8)
	goto _350
_15:
	; /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
	_sqlite3StartTable(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, yymsp+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), 0, 0, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	goto _350
_16:
	; /* createkw ::= CREATE */
	_disableLookaside(tls, pParse)
	goto _350
_18:
	; /* ifnotexists ::= */
_17:
	;
_19:
	;
_20:
	;
_21:
	;
_22:
	;
_23:
	;
_24:
	;
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = 0
	goto _350
_25:
	; /* ifnotexists ::= IF NOT EXISTS */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = int32(1)
	goto _350
_26:
	; /* temp ::= TEMP */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = libc.BoolInt32(libc.Int32FromUint8((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).Finit1.Fbusy) == 0)
	goto _350
_27:
	; /* create_table_args ::= LP columnlist conslist_opt RP table_option_set */
	_sqlite3EndTable(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, *(*Tu32)(unsafe.Pointer(yymsp + 8)), uintptr(0))
	goto _350
_28:
	; /* create_table_args ::= AS select */
	_sqlite3EndTable(tls, pParse, uintptr(0), uintptr(0), uint32(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_29:
	; /* table_option_set ::= */
	*(*Tu32)(unsafe.Pointer(yymsp + 1*24 + 8)) = uint32(0)
	goto _350
_30:
	; /* table_option_set ::= table_option_set COMMA table_option */
	*(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) | *(*Tu32)(unsafe.Pointer(yymsp + 8))
	*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_31:
	; /* table_option ::= WITHOUT nm */
	if *(*uint32)(unsafe.Pointer(yymsp + 8 + 8)) == uint32(5) && Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(yymsp + 8)), __ccgo_ts+17967, int32(5)) == 0 {
		*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = libc.Uint32FromInt32(libc.Int32FromInt32(TF_WithoutRowid) | libc.Int32FromInt32(TF_NoVisibleRowid))
	} else {
		*(*Tu32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = uint32(0)
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24999, libc.VaList(bp+136, *(*uint32)(unsafe.Pointer(yymsp + 8 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8))))
	}
	goto _350
_32:
	; /* table_option ::= nm */
	if *(*uint32)(unsafe.Pointer(yymsp + 8 + 8)) == uint32(6) && Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(yymsp + 8)), __ccgo_ts+17903, int32(6)) == 0 {
		*(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = uint32(TF_Strict)
	} else {
		*(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = uint32(0)
		_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+24999, libc.VaList(bp+136, *(*uint32)(unsafe.Pointer(yymsp + 8 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8))))
	}
	*(*Tu32)(unsafe.Pointer(yymsp + 8)) = *(*Tu32)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_33:
	; /* columnname ::= nm typetoken */
	_sqlite3AddColumn(tls, pParse, *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*TToken)(unsafe.Pointer(yymsp + 8)))
	goto _350
_35:
	; /* typetoken ::= */
_34:
	;
_36:
	;
	*(*uint32)(unsafe.Pointer(yymsp + 1*24 + 8 + 8)) = uint32(0)
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_37:
	; /* typetoken ::= typename LP signed RP */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8 + 8)) = libc.Uint32FromInt32(int32(t__predefined_ptrdiff_t(*(*uintptr)(unsafe.Pointer(yymsp + 8))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 8 + 8)))) - int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))))
	goto _350
_38:
	; /* typetoken ::= typename LP signed COMMA signed RP */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8 + 8)) = libc.Uint32FromInt32(int32(t__predefined_ptrdiff_t(*(*uintptr)(unsafe.Pointer(yymsp + 8))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 8 + 8)))) - int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)))))
	goto _350
_39:
	; /* typename ::= typename ID|STRING */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) = *(*uint32)(unsafe.Pointer(yymsp + 8 + 8)) + libc.Uint32FromInt32(int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + 8)))-int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))))
	goto _350
_40:
	; /* scanpt ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = yyLookaheadToken.Fz
	goto _350
_41:
	; /* scantok ::= */
	*(*TToken)(unsafe.Pointer(yymsp + 1*24 + 8)) = yyLookaheadToken
	goto _350
_43:
	; /* ccons ::= CONSTRAINT nm */
_42:
	;
	(*(*struct {
		FaddrCrTab      int32
		FregRowid       int32
		FregRoot        int32
		FconstraintName TToken
	})(unsafe.Pointer(pParse + 256))).FconstraintName = *(*TToken)(unsafe.Pointer(yymsp + 8))
	goto _350
_44:
	; /* ccons ::= DEFAULT scantok term */
	_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8))))
	goto _350
_45:
	; /* ccons ::= DEFAULT LP expr RP */
	_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))+uintptr(1), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_46:
	; /* ccons ::= DEFAULT PLUS scantok term */
	_sqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8))))
	goto _350
_47:
	; /* ccons ::= DEFAULT MINUS scantok term */
	p = _sqlite3PExpr(tls, pParse, int32(TK_UMINUS), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0))
	_sqlite3AddDefaultValue(tls, pParse, p, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8))))
	goto _350
_48:
	; /* ccons ::= DEFAULT scantok ID|INDEXED */
	p1 = _tokenExpr(tls, pParse, int32(TK_STRING), *(*TToken)(unsafe.Pointer(yymsp + 8)))
	if p1 != 0 {
		_sqlite3ExprIdToTrueFalse(tls, p1)
	}
	_sqlite3AddDefaultValue(tls, pParse, p1, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8))+uintptr(*(*uint32)(unsafe.Pointer(yymsp + 8 + 8))))
	goto _350
_49:
	; /* ccons ::= NOT NULL onconf */
	_sqlite3AddNotNull(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_50:
	; /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
	_sqlite3AddPrimaryKey(tls, pParse, uintptr(0), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	goto _350
_51:
	; /* ccons ::= UNIQUE onconf */
	_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), uintptr(0), *(*int32)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_UNIQUE))
	goto _350
_52:
	; /* ccons ::= CHECK LP expr RP */
	_sqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_53:
	; /* ccons ::= REFERENCES nm eidlist_opt refargs */
	_sqlite3CreateForeignKey(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_54:
	; /* ccons ::= defer_subclause */
	_sqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_55:
	; /* ccons ::= COLLATE ID|STRING */
	_sqlite3AddCollateType(tls, pParse, yymsp+8)
	goto _350
_56:
	; /* generated ::= LP expr RP */
	_sqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), uintptr(0))
	goto _350
_57:
	; /* generated ::= LP expr RP ID */
	_sqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), yymsp+8)
	goto _350
_58:
	; /* autoinc ::= AUTOINCR */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(1)
	goto _350
_59:
	;                                                                                                        /* refargs ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = libc.Int32FromInt32(OE_None) * libc.Int32FromInt32(0x0101) /* EV: R-19803-45884 */
	goto _350
_60:
	; /* refargs ::= refargs refarg */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) & ^*(*int32)(unsafe.Pointer(yymsp + 8 + 4)) | *(*int32)(unsafe.Pointer(yymsp + 8))
	goto _350
_61:
	; /* refarg ::= MATCH nm */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = 0
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 4)) = 0x000000
	goto _350
_62:
	; /* refarg ::= ON INSERT refact */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = 0
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8 + 4)) = 0x000000
	goto _350
_63:
	; /* refarg ::= ON DELETE refact */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8))
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8 + 4)) = int32(0x0000ff)
	goto _350
_64:
	; /* refarg ::= ON UPDATE refact */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8)) << int32(8)
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8 + 4)) = int32(0x00ff00)
	goto _350
_65:
	;                                                                                              /* refact ::= SET NULL */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = int32(OE_SetNull) /* EV: R-33326-45252 */
	goto _350
_66:
	;                                                                                              /* refact ::= SET DEFAULT */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = int32(OE_SetDflt) /* EV: R-33326-45252 */
	goto _350
_67:
	;                                                        /* refact ::= CASCADE */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Cascade) /* EV: R-33326-45252 */
	goto _350
_68:
	;                                                         /* refact ::= RESTRICT */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Restrict) /* EV: R-33326-45252 */
	goto _350
_69:
	;                                                                                    /* refact ::= NO ACTION */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = OE_None /* EV: R-33326-45252 */
	goto _350
_70:
	; /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = 0
	goto _350
_72:
	; /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
_71:
	;
_73:
	;
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8))
	goto _350
_75:
	; /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
_74:
	;
_76:
	;
_77:
	;
_78:
	;
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = int32(1)
	goto _350
_79:
	; /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = 0
	goto _350
_80:
	; /* tconscomma ::= COMMA */
	(*(*struct {
		FaddrCrTab      int32
		FregRowid       int32
		FregRoot        int32
		FconstraintName TToken
	})(unsafe.Pointer(pParse + 256))).FconstraintName.Fn = uint32(0)
	goto _350
_81:
	; /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
	_sqlite3AddPrimaryKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), 0)
	goto _350
_82:
	; /* tcons ::= UNIQUE LP sortlist RP onconf */
	_sqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0), 0, 0, uint8(SQLITE_IDXTYPE_UNIQUE))
	goto _350
_83:
	; /* tcons ::= CHECK LP expr RP onconf */
	_sqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_84:
	; /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
	_sqlite3CreateForeignKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	_sqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_86:
	; /* onconf ::= */
_85:
	;
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = int32(OE_Default)
	goto _350
_87:
	; /* onconf ::= ON CONFLICT resolvetype */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8))
	goto _350
_88:
	; /* resolvetype ::= IGNORE */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Ignore)
	goto _350
_90:
	; /* resolvetype ::= REPLACE */
_89:
	;
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Replace)
	goto _350
_91:
	; /* cmd ::= DROP TABLE ifexists fullname */
	_sqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), 0, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_92:
	; /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
	_sqlite3CreateView(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(8))*24+8, yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)))
	goto _350
_93:
	; /* cmd ::= DROP VIEW ifexists fullname */
	_sqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), int32(1), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_94:
	; /* cmd ::= select */
	**(**TSelectDest)(__ccgo_up(bp + 16)) = TSelectDest{
		FeDest: uint8(SRT_Output),
	}
	if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&uint32(DBFLAG_EncodingFixed) != uint32(0) || _sqlite3ReadSchema(tls, pParse) == SQLITE_OK {
		_sqlite3Select(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), bp+16)
	}
	_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_95:
	; /* select ::= WITH wqlist selectnowith */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_96:
	; /* select ::= WITH RECURSIVE wqlist selectnowith */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_97:
	; /* select ::= selectnowith */
	p2 = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	if p2 != 0 {
		_parserDoubleLinkSelect(tls, pParse, p2)
	}
	goto _350
_98:
	; /* selectnowith ::= selectnowith multiselect_op oneselect */
	pRhs = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	pLhs = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))
	if pRhs != 0 && (*TSelect)(unsafe.Pointer(pRhs)).FpPrior != 0 {
		(**(**TToken)(__ccgo_up(bp + 56))).Fn = uint32(0)
		_parserDoubleLinkSelect(tls, pParse, pRhs)
		pFrom = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+56, pRhs, uintptr(0))
		pRhs = _sqlite3SelectNew(tls, pParse, uintptr(0), pFrom, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
	}
	if pRhs != 0 {
		(*TSelect)(unsafe.Pointer(pRhs)).Fop = libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
		(*TSelect)(unsafe.Pointer(pRhs)).FpPrior = pLhs
		if pLhs != 0 {
			**(**Tu32)(__ccgo_up(pLhs + 4)) &= ^libc.Uint32FromInt32(SF_MultiValue)
		}
		**(**Tu32)(__ccgo_up(pRhs + 4)) &= ^libc.Uint32FromInt32(SF_MultiValue)
		if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) != int32(TK_ALL) {
			libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 13, 0x2000)
		}
	} else {
		_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pLhs)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = pRhs
	goto _350
_100:
	; /* multiselect_op ::= UNION */
_99:
	;
	*(*int32)(unsafe.Pointer(yymsp + 8)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-OP*/
	goto _350
_101:
	; /* multiselect_op ::= UNION ALL */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = int32(TK_ALL)
	goto _350
_102:
	; /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_103:
	; /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*24 + 8)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), libc.Uint32FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*24 + 8)) != 0 {
		(*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(9))*24 + 8)))).FpWinDefn = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))
	} else {
		_sqlite3WindowListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	}
	goto _350
_104:
	; /* values ::= VALUES LP nexprlist RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
	goto _350
_105:
	; /* oneselect ::= mvalues */
	_sqlite3MultiValuesEnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_107:
	; /* mvalues ::= values COMMA LP nexprlist RP */
_106:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3MultiValues(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_108:
	; /* distinct ::= DISTINCT */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(SF_Distinct)
	goto _350
_109:
	; /* distinct ::= ALL */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(SF_All)
	goto _350
_111:
	; /* sclp ::= */
_110:
	;
_112:
	;
_113:
	;
_114:
	;
_115:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_116:
	; /* selcollist ::= sclp scanpt expr scanpt as */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	if *(*uint32)(unsafe.Pointer(yymsp + 8 + 8)) > uint32(0) {
		_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), yymsp+8, int32(1))
	}
	_sqlite3ExprListSetSpan(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_117:
	; /* selcollist ::= sclp scanpt STAR */
	p3 = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_ASTERISK), uintptr(0))
	_sqlite3ExprSetErrorOffset(tls, p3, int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + 8)))-int64((*TParse)(unsafe.Pointer(pParse)).FzTail)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), p3)
	goto _350
_118:
	; /* selcollist ::= sclp scanpt nm DOT STAR */
	pRight = _sqlite3PExpr(tls, pParse, int32(TK_ASTERISK), uintptr(0), uintptr(0))
	_sqlite3ExprSetErrorOffset(tls, pRight, int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + 8)))-int64((*TParse)(unsafe.Pointer(pParse)).FzTail)))
	pLeft = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	pDot = _sqlite3PExpr(tls, pParse, int32(TK_DOT), pLeft, pRight)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), pDot)
	goto _350
_120:
	; /* as ::= AS nm */
_119:
	;
_121:
	;
_122:
	;
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*TToken)(unsafe.Pointer(yymsp + 8))
	goto _350
_124:
	; /* from ::= */
_123:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_125:
	; /* from ::= FROM seltablist */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	_sqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_126:
	; /* stl_prefix ::= seltablist joinop */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) != 0 && (*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FnSrc > 0 {
		(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) + 8 + uintptr((*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FnSrc-int32(1))*80))).Ffg.Fjointype = libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + 8)))
	}
	goto _350
_127:
	; /* seltablist ::= stl_prefix nm dbnm as on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, uintptr(0), yymsp+8)
	goto _350
_128:
	; /* seltablist ::= stl_prefix nm dbnm as indexed_by on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, uintptr(0), yymsp+8)
	_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8)
	goto _350
_129:
	; /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(6))*24+8, yymsp+uintptr(-libc.Int32FromInt32(5))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, uintptr(0), yymsp+8)
	_sqlite3SrcListFuncArgs(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))
	goto _350
_130:
	; /* seltablist ::= stl_prefix LP select RP as on_using */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), yymsp+8)
	goto _350
_131:
	; /* seltablist ::= stl_prefix LP seltablist RP as on_using */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) == uintptr(0) && *(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) == uint32(0) && *(*uintptr)(unsafe.Pointer(yymsp + 8)) == uintptr(0) && *(*uintptr)(unsafe.Pointer(yymsp + 8 + 8)) == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8))
	} else {
		if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != uintptr(0) && (*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))).FnSrc == int32(1) {
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, uintptr(0), yymsp+8)
			if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) != 0 {
				pNew = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) + 8 + uintptr((*TSrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)))).FnSrc-int32(1))*80
				pOld = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) + 8
				(*TSrcItem)(unsafe.Pointer(pNew)).FzName = (*TSrcItem)(unsafe.Pointer(pOld)).FzName
				if int32(*(*uint32)(unsafe.Pointer(pOld + 24 + 4))&0x20000000>>29) != 0 {
					libc.SetBitFieldPtr32Uint32(pNew+24+4, libc.Uint32FromInt32(1), 29, 0x20000000)
					*(*uintptr)(unsafe.Pointer(pNew + 72)) = *(*uintptr)(unsafe.Pointer(pOld + 72))
					*(*uintptr)(unsafe.Pointer(pOld + 72)) = uintptr(0)
					libc.SetBitFieldPtr32Uint32(pOld+24+4, libc.Uint32FromInt32(0), 29, 0x20000000)
					if (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNew + 72)))).FpSelect)).FselFlags&uint32(SF_NestedFrom) != uint32(0) {
						libc.SetBitFieldPtr32Uint32(pNew+24+4, libc.Uint32FromInt32(1), 17, 0x20000)
					}
				} else {
					*(*uintptr)(unsafe.Pointer(pNew + 72)) = *(*uintptr)(unsafe.Pointer(pOld + 72))
					*(*uintptr)(unsafe.Pointer(pOld + 72)) = uintptr(0)
				}
				if int32(*(*uint32)(unsafe.Pointer(pOld + 24 + 4))&0x10000000>>28) != 0 {
					*(*uintptr)(unsafe.Pointer(pNew + 48)) = *(*uintptr)(unsafe.Pointer(pOld + 48))
					*(*uintptr)(unsafe.Pointer(pOld + 48)) = uintptr(0)
					libc.SetBitFieldPtr32Uint32(pOld+24+4, libc.Uint32FromInt32(0), 28, 0x10000000)
					libc.SetBitFieldPtr32Uint32(pNew+24+4, libc.Uint32FromInt32(1), 28, 0x10000000)
				}
				(*TSrcItem)(unsafe.Pointer(pOld)).FzName = uintptr(0)
			}
			_sqlite3SrcListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))
		} else {
			_sqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))
			pSubquery = _sqlite3SelectNew(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, pSubquery, yymsp+8)
		}
	}
	goto _350
_133:
	; /* dbnm ::= */
_132:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	*(*uint32)(unsafe.Pointer(yymsp + 1*24 + 8 + 8)) = uint32(0)
	goto _350
_135:
	; /* fullname ::= nm */
_134:
	;
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+8, uintptr(0))
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
		_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+8)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_137:
	; /* fullname ::= nm DOT nm */
_136:
	;
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+8)
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
		_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+8)
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_138:
	; /* xfullname ::= nm AS nm */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, uintptr(0))
	if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8)
		} else {
			(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzAlias = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, yymsp+8)
		}
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_139:
	; /* xfullname ::= nm DOT nm AS nm */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8)
	if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
			_sqlite3RenameTokenMap(tls, pParse, (*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzName, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8)
		} else {
			(*(*TSrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 8))).FzAlias = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, yymsp+8)
		}
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_140:
	; /* joinop ::= COMMA|JOIN */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(JT_INNER)
	goto _350
_141:
	;                                                                                                                                                                               /* joinop ::= JOIN_KW JOIN */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, uintptr(0), uintptr(0)) /*X-overwrites-A*/
	goto _350
_142:
	;                                                                                                                                                                                                                /* joinop ::= JOIN_KW nm JOIN */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, uintptr(0)) /*X-overwrites-A*/
	goto _350
_143:
	;                                                                                                                                                                                                                                                 /* joinop ::= JOIN_KW nm nm JOIN */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3JoinType(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8) /*X-overwrites-A*/
	goto _350
_144:
	; /* on_using ::= ON expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) = uintptr(0)
	goto _350
_145:
	; /* on_using ::= USING LP idlist RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_146:
	; /* on_using ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8 + 8)) = uintptr(0)
	goto _350
_147:
	; /* indexed_by ::= INDEXED BY nm */
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*TToken)(unsafe.Pointer(yymsp + 8))
	goto _350
_148:
	; /* indexed_by ::= NOT INDEXED */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = uintptr(0)
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) = uint32(1)
	goto _350
_150:
	; /* orderby_opt ::= ORDER BY sortlist */
_149:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	goto _350
_151:
	; /* sortlist ::= sortlist COMMA expr sortorder nulls */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	_sqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_152:
	;                                                                                                                                                                                                            /* sortlist ::= expr sortorder nulls */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))) /*A-overwrites-Y*/
	_sqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_153:
	; /* sortorder ::= ASC */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = SQLITE_SO_ASC
	goto _350
_154:
	; /* sortorder ::= DESC */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(SQLITE_SO_DESC)
	goto _350
_156:
	; /* sortorder ::= */
_155:
	;
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = -int32(1)
	goto _350
_157:
	; /* nulls ::= NULLS FIRST */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = SQLITE_SO_ASC
	goto _350
_158:
	; /* nulls ::= NULLS LAST */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = int32(SQLITE_SO_DESC)
	goto _350
_160:
	; /* having_opt ::= */
_159:
	;
_161:
	;
_162:
	;
_163:
	;
_164:
	;
_165:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_167:
	; /* having_opt ::= HAVING expr */
_166:
	;
_168:
	;
_169:
	;
_170:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	goto _350
_171:
	; /* limit_opt ::= LIMIT expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0))
	goto _350
_172:
	; /* limit_opt ::= LIMIT expr OFFSET expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_173:
	; /* limit_opt ::= LIMIT expr COMMA expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_LIMIT), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	goto _350
_174:
	; /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt_ret */
	_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8)
	_sqlite3DeleteFrom(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0))
	goto _350
_175:
	; /* where_opt_ret ::= RETURNING selcollist */
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = uintptr(0)
	goto _350
_176:
	; /* where_opt_ret ::= WHERE expr RETURNING selcollist */
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))
	goto _350
_177:
	; /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */
	_sqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8)
	_sqlite3ExprListCheckLength(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), __ccgo_ts+25026)
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) != 0 {
		pFromClause = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
		if (*TSrcList)(unsafe.Pointer(pFromClause)).FnSrc > int32(1) {
			pSubquery1 = _sqlite3SelectNew(tls, pParse, uintptr(0), pFromClause, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
			(**(**TToken)(__ccgo_up(bp + 72))).Fn = uint32(0)
			(**(**TToken)(__ccgo_up(bp + 72))).Fz = uintptr(0)
			pFromClause = _sqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+72, pSubquery1, uintptr(0))
		}
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3SrcListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), pFromClause)
	}
	_sqlite3Update(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), uintptr(0), uintptr(0), uintptr(0))
	goto _350
_178:
	; /* setlist ::= setlist COMMA nm EQ expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, int32(1))
	goto _350
_179:
	; /* setlist ::= setlist COMMA LP idlist RP EQ expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)) = _sqlite3ExprListAppendVector(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_180:
	; /* setlist ::= nm EQ expr */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	_sqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, int32(1))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_181:
	; /* setlist ::= LP idlist RP EQ expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppendVector(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_182:
	; /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
	_sqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_183:
	; /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES returning */
	_sqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), uintptr(0))
	goto _350
_184:
	; /* upsert ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_185:
	; /* upsert ::= RETURNING selcollist */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = uintptr(0)
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_186:
	; /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt upsert */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(11))*24 + 8)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_187:
	; /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING upsert */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_188:
	; /* upsert ::= ON CONFLICT DO NOTHING returning */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	goto _350
_189:
	; /* upsert ::= ON CONFLICT DO UPDATE SET setlist where_opt returning */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)) = _sqlite3UpsertNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), uintptr(0))
	goto _350
_190:
	; /* returning ::= RETURNING selcollist */
	_sqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_191:
	; /* idlist_opt ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_192:
	; /* idlist_opt ::= LP idlist RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_193:
	; /* idlist ::= idlist COMMA nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3IdListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), yymsp+8)
	goto _350
_194:
	;                                                                                               /* idlist ::= nm */
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _sqlite3IdListAppend(tls, pParse, uintptr(0), yymsp+8) /*A-overwrites-Y*/
	goto _350
_195:
	; /* expr ::= LP expr RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_196:
	;                                                                                                                     /* expr ::= ID|INDEXED|JOIN_KW */
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 8))) /*A-overwrites-X*/
	goto _350
_197:
	; /* expr ::= nm DOT nm */
	temp1 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	temp2 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp1, temp2)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_198:
	; /* expr ::= nm DOT nm DOT nm */
	temp11 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
	temp21 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	temp3 = _tokenExpr(tls, pParse, int32(TK_ID), *(*TToken)(unsafe.Pointer(yymsp + 8)))
	temp4 = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp21, temp3)
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) {
		_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), temp11)
	}
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3PExpr(tls, pParse, int32(TK_DOT), temp11, temp4)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_200:
	; /* term ::= NULL|FLOAT|BLOB */
_199:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _tokenExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor), *(*TToken)(unsafe.Pointer(yymsp + 8))) /*A-overwrites-X*/
	goto _350
_201:
	; /* term ::= INTEGER */
	if _sqlite3GetInt32(tls, *(*uintptr)(unsafe.Pointer(yymsp + 8)), bp+88) == 0 {
		*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_INTEGER), yymsp+8, 0)
	} else {
		*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprInt32(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, **(**int32)(__ccgo_up(bp + 88)))
	}
	if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
		*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) + 52)) = int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + 8))) - int64((*TParse)(unsafe.Pointer(pParse)).FzTail))
	}
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_202:
	; /* expr ::= VARIABLE */
	if !(libc.Int32FromUint8(**(**uint8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + 8))))) == int32('#') && libc.Int32FromUint8(_sqlite3CtypeMap[uint8(**(**uint8)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + 8)) + 1)))])&int32(0x04) != 0) {
		n = *(*uint32)(unsafe.Pointer(yymsp + 8 + 8))
		*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _tokenExpr(tls, pParse, int32(TK_VARIABLE), *(*TToken)(unsafe.Pointer(yymsp + 8)))
		_sqlite3ExprAssignVarNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), n)
	} else {
		/* When doing a nested parse, one can include terms in an expression
		 ** that look like this:   #1 #2 ...  These terms refer to registers
		 ** in the virtual machine.  #N is the N-th register. */
		**(**TToken)(__ccgo_up(bp + 96)) = *(*TToken)(unsafe.Pointer(yymsp + 8)) /*A-overwrites-X*/
		if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).Fnested) == 0 {
			_parserSyntaxError(tls, pParse, bp+96)
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = uintptr(0)
		} else {
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_REGISTER), uintptr(0), uintptr(0))
			if *(*uintptr)(unsafe.Pointer(yymsp + 8)) != 0 {
				_sqlite3GetInt32(tls, (**(**TToken)(__ccgo_up(bp + 96))).Fz+1, *(*uintptr)(unsafe.Pointer(yymsp + 8))+44)
			}
		}
	}
	goto _350
_203:
	; /* expr ::= expr COLLATE ID|STRING */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3ExprAddCollateToken(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), yymsp+8, int32(1))
	goto _350
_204:
	; /* expr ::= CAST LP expr AS typetoken RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3ExprAlloc(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_CAST), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, int32(1))
	_sqlite3ExprAttachSubtrees(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), uintptr(0))
	goto _350
_205:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist RP */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_206:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist ORDER BY sortlist RP */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(7))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)))
	_sqlite3ExprAddFunctionOrderBy(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_207:
	; /* expr ::= ID|INDEXED|JOIN_KW LP STAR RP */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, 0)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_208:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist RP filter_over */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(5))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))
	_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_209:
	; /* expr ::= ID|INDEXED|JOIN_KW LP distinct exprlist ORDER BY sortlist RP filter_over */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(8))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)))
	_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	_sqlite3ExprAddFunctionOrderBy(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_210:
	; /* expr ::= ID|INDEXED|JOIN_KW LP STAR RP filter_over */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, 0)
	_sqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_211:
	; /* term ::= CTIME_KW */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+8, 0)
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_212:
	; /* expr ::= LP nexprlist COMMA expr RP */
	pList = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_VECTOR), uintptr(0), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) != 0 {
		*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) + 32)) = pList
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) + 4)) |= (*TExpr)(unsafe.Pointer((*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32))).FpExpr)).Fflags & libc.Uint32FromInt32(libc.Int32FromInt32(EP_Collate)|libc.Int32FromInt32(EP_Subquery)|libc.Int32FromInt32(EP_HasFunc))
			goto _351
		_351:
			;
			i = i + 1
		}
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	}
	goto _350
_213:
	; /* expr ::= expr AND expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3ExprAnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_215:
	; /* expr ::= expr OR expr */
_214:
	;
_216:
	;
_217:
	;
_218:
	;
_219:
	;
_220:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3PExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*24))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_221:
	; /* likeop ::= NOT LIKE_KW|MATCH */
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*TToken)(unsafe.Pointer(yymsp + 8))
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) |= uint32(0x80000000) /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/
	goto _350
_222:
	; /* expr ::= expr likeop expr */
	bNot = libc.Int32FromUint32(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) & uint32(0x80000000))
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) &= uint32(0x7fffffff)
	pList1 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	pList1 = _sqlite3ExprListAppend(tls, pParse, pList1, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3ExprFunction(tls, pParse, pList1, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, 0)
	if bNot != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), uintptr(0))
	}
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) != 0 {
		**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) + 4)) |= uint32(EP_InfixFunc)
	}
	goto _350
_223:
	; /* expr ::= expr likeop expr ESCAPE expr */
	bNot1 = libc.Int32FromUint32(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8 + 8)) & uint32(0x80000000))
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8 + 8)) &= uint32(0x7fffffff)
	pList2 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	pList2 = _sqlite3ExprListAppend(tls, pParse, pList2, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
	pList2 = _sqlite3ExprListAppend(tls, pParse, pList2, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprFunction(tls, pParse, pList2, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, 0)
	if bNot1 != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	}
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) != 0 {
		**(**Tu32)(__ccgo_up(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) + 4)) |= uint32(EP_InfixFunc)
	}
	goto _350
_224:
	; /* expr ::= expr ISNULL|NOTNULL */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = _sqlite3PExprIsNull(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_225:
	; /* expr ::= expr NOT NULL */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3PExprIsNull(tls, pParse, int32(TK_NOTNULL), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	goto _350
_226:
	; /* expr ::= expr IS expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3PExprIs(tls, pParse, int32(TK_IS), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_227:
	; /* expr ::= expr IS NOT expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3PExprIs(tls, pParse, int32(TK_ISNOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_228:
	; /* expr ::= expr IS NOT DISTINCT FROM expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3PExprIs(tls, pParse, int32(TK_IS), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_229:
	; /* expr ::= expr IS DISTINCT FROM expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExprIs(tls, pParse, int32(TK_ISNOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_231:
	; /* expr ::= NOT expr */
_230:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = _sqlite3PExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*24))).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0)) /*A-overwrites-B*/
	goto _350
_232:
	; /* expr ::= PLUS|MINUS expr */
	p4 = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	op = libc.Uint8FromInt32(libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*24))).Fmajor) + (libc.Int32FromInt32(TK_UPLUS) - libc.Int32FromInt32(TK_PLUS)))
	if p4 != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(p4)).Fop) == int32(TK_UPLUS) {
		(*TExpr)(unsafe.Pointer(p4)).Fop = op
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = p4
	} else {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = _sqlite3PExpr(tls, pParse, libc.Int32FromUint8(op), p4, uintptr(0))
		/*A-overwrites-B*/
	}
	goto _350
_233:
	; /* expr ::= expr PTR expr */
	pList3 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	pList3 = _sqlite3ExprListAppend(tls, pParse, pList3, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3ExprFunction(tls, pParse, pList3, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, 0)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_235:
	; /* between_op ::= BETWEEN */
_234:
	;
	*(*int32)(unsafe.Pointer(yymsp + 8)) = 0
	goto _350
_236:
	; /* expr ::= expr between_op expr AND expr */
	pList4 = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	pList4 = _sqlite3ExprListAppend(tls, pParse, pList4, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_BETWEEN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) != 0 {
		*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) + 32)) = pList4
		_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList4)
	}
	if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	}
	goto _350
_237:
	; /* expr ::= expr in_op LP exprlist RP */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) == uintptr(0) {
		if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
			v352 = __ccgo_ts + 8182
		} else {
			v352 = __ccgo_ts + 8187
		}
		/* Expressions of the form
		 **
		 **      expr1 IN ()
		 **      expr1 NOT IN ()
		 **
		 ** simplify to constants 0 (false) and 1 (true), respectively.
		 **
		 ** Except, do not apply this optimization if expr1 contains a function
		 ** because that function might be an aggregate (we don't know yet whether
		 ** it is or not) and if it is an aggregate, that could change the meaning
		 ** of the whole query.
		 */
		pB = _sqlite3Expr(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, int32(TK_STRING), v352)
		if pB != 0 {
			_sqlite3ExprIdToTrueFalse(tls, pB)
		}
		if !((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))).Fflags&libc.Uint32FromInt32(libc.Int32FromInt32(EP_HasFunc)) != libc.Uint32FromInt32(0)) {
			_sqlite3ExprUnmapAndDelete(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = pB
		} else {
			if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
				v353 = int32(TK_OR)
			} else {
				v353 = int32(TK_AND)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, v353, pB, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
		}
	} else {
		pRHS = (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) + 8))).FpExpr
		if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FnExpr == int32(1) && _sqlite3ExprIsConstant(tls, pParse, pRHS) != 0 && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))).Fop) != int32(TK_VECTOR) {
			(*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) + 8))).FpExpr = uintptr(0)
			_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
			pRHS = _sqlite3PExpr(tls, pParse, int32(TK_UPLUS), pRHS, uintptr(0))
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_EQ), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), pRHS)
		} else {
			if (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FnExpr == int32(1) && libc.Int32FromUint8((*TExpr)(unsafe.Pointer(pRHS)).Fop) == int32(TK_SELECT) {
				*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
				_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(pRHS + 32)))
				*(*uintptr)(unsafe.Pointer(pRHS + 32)) = uintptr(0)
				_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
			} else {
				*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) == uintptr(0) {
					_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
				} else {
					if libc.Int32FromUint8((*TExpr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))).FpLeft)).Fop) == int32(TK_VECTOR) {
						nExpr = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))).FpLeft + 32)))).FnExpr
						pSelectRHS = _sqlite3ExprListToValues(tls, pParse, nExpr, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
						if pSelectRHS != 0 {
							_parserDoubleLinkSelect(tls, pParse, pSelectRHS)
							_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), pSelectRHS)
						}
					} else {
						*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) + 32)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
						_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
					}
				}
			}
		}
		if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
			*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
		}
	}
	goto _350
_238:
	; /* expr ::= LP select RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_SELECT), uintptr(0), uintptr(0))
	_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_239:
	; /* expr ::= expr in_op LP select RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	}
	goto _350
_240:
	; /* expr ::= expr in_op nm dbnm paren_exprlist */
	pSrc = _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8)
	pSelect = _sqlite3SelectNew(tls, pParse, uintptr(0), pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + 8)) != 0 {
		if pSelect != 0 {
			v352 = pSrc
		} else {
			v352 = uintptr(0)
		}
		_sqlite3SrcListFuncArgs(tls, pParse, v352, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	}
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_IN), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	_sqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), pSelect)
	if *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
		*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_NOT), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uintptr(0))
	}
	goto _350
_241:
	; /* expr ::= EXISTS LP select RP */
	v352 = _sqlite3PExpr(tls, pParse, int32(TK_EXISTS), uintptr(0), uintptr(0))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = v352
	p5 = v352
	_sqlite3PExprAddSelect(tls, pParse, p5, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_242:
	; /* expr ::= CASE case_operand case_exprlist case_else END */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_CASE), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) != 0 {
		if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) != 0 {
			v352 = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
		} else {
			v352 = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))
		}
		*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) + 32)) = v352
		_sqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	}
	goto _350
_243:
	; /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_244:
	; /* case_exprlist ::= WHEN expr THEN expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_245:
	; /* nexprlist ::= nexprlist COMMA expr */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_246:
	;                                                                                                                                /* nexprlist ::= expr */
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _sqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8))) /*A-overwrites-Y*/
	goto _350
_248:
	; /* paren_exprlist ::= LP exprlist RP */
_247:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_249:
	; /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
	_sqlite3CreateIndex(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(7))*24+8, yymsp+uintptr(-libc.Int32FromInt32(6))*24+8, _sqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, uintptr(0)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(11))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + 8)), SQLITE_SO_ASC, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)), uint8(SQLITE_IDXTYPE_APPDEF))
	if libc.Int32FromUint8((*TParse)(unsafe.Pointer(pParse)).FeParseMode) >= int32(PARSE_MODE_RENAME) && (*TParse)(unsafe.Pointer(pParse)).FpNewIndex != 0 {
		_sqlite3RenameTokenMap(tls, pParse, (*TIndex)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).FpNewIndex)).FzName, yymsp+uintptr(-libc.Int32FromInt32(4))*24+8)
	}
	goto _350
_251:
	; /* uniqueflag ::= UNIQUE */
_250:
	;
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Abort)
	goto _350
_252:
	; /* uniqueflag ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = OE_None
	goto _350
_253:
	; /* eidlist ::= eidlist COMMA nm collate sortorder */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _parserAddExprIdListTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
	goto _350
_254:
	;                                                                                                                                                                                                                                                                                               /* eidlist ::= nm collate sortorder */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _parserAddExprIdListTerm(tls, pParse, uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8))) /*A-overwrites-Y*/
	goto _350
_255:
	; /* cmd ::= DROP INDEX ifexists fullname */
	_sqlite3DropIndex(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_256:
	; /* cmd ::= VACUUM vinto */
	_sqlite3Vacuum(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_257:
	; /* cmd ::= VACUUM nm vinto */
	_sqlite3Vacuum(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_258:
	; /* cmd ::= PRAGMA nm dbnm */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, yymsp+8, uintptr(0), 0)
	goto _350
_259:
	; /* cmd ::= PRAGMA nm dbnm EQ nmnum */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+8, 0)
	goto _350
_260:
	; /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, 0)
	goto _350
_261:
	; /* cmd ::= PRAGMA nm dbnm EQ minus_num */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+8, int32(1))
	goto _350
_262:
	; /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
	_sqlite3Pragma(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, int32(1))
	goto _350
_263:
	; /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
	(**(**TToken)(__ccgo_up(bp + 112))).Fz = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8))
	(**(**TToken)(__ccgo_up(bp + 112))).Fn = libc.Uint32FromInt32(int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + 8)))-int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8))))) + *(*uint32)(unsafe.Pointer(yymsp + 8 + 8))
	_sqlite3FinishTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), bp+112)
	goto _350
_264:
	; /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
	_sqlite3BeginTrigger(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(7))*24+8, yymsp+uintptr(-libc.Int32FromInt32(6))*24+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)))
	if *(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8 + 8)) == uint32(0) {
		v357 = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8))
	} else {
		v357 = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8))
	}
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(10))*24 + 8)) = v357 /*A-overwrites-T*/
	goto _350
_265:
	;                                                                                                           /* trigger_time ::= BEFORE|AFTER */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
	goto _350
_266:
	; /* trigger_time ::= INSTEAD OF */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = int32(TK_INSTEAD)
	goto _350
_267:
	; /* trigger_time ::= */
	*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = int32(TK_BEFORE)
	goto _350
_269:
	; /* trigger_event ::= DELETE|INSERT */
_268:
	;
	*(*int32)(unsafe.Pointer(yymsp + 8)) = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
	*(*uintptr)(unsafe.Pointer(yymsp + 8 + 8)) = uintptr(0)
	goto _350
_270:
	; /* trigger_event ::= UPDATE OF idlist */
	*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = int32(TK_UPDATE)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	goto _350
_272:
	; /* when_clause ::= */
_271:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
	goto _350
_274:
	; /* when_clause ::= WHEN expr */
_273:
	;
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	goto _350
_275:
	; /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
	(*TTriggerStep)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))).FpLast)).FpNext = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	(*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_276:
	; /* trigger_cmd_list ::= trigger_cmd SEMI */
	(*TTriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_277:
	; /* tridxby ::= INDEXED BY nm */
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25035, 0)
	goto _350
_278:
	; /* tridxby ::= NOT INDEXED */
	_sqlite3ErrorMsg(tls, pParse, __ccgo_ts+25119, 0)
	goto _350
_279:
	; /* trigger_cmd ::= UPDATE orconf xfullname tridxby SET setlist from where_opt scanpt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerUpdateStep(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_280:
	;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       /* trigger_cmd ::= scanpt insert_cmd INTO xfullname idlist_opt select upsert scanpt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerInsertStep(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8))) /*yylhsminor.yy427-overwrites-yymsp[-6].minor.yy144*/
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_281:
	; /* trigger_cmd ::= DELETE FROM xfullname tridxby where_opt scanpt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerDeleteStep(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_282:
	;                                                                                                                                                                                                                                                                                                                                           /* trigger_cmd ::= scanpt select scanpt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3TriggerSelectStep(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8))) /*yylhsminor.yy427-overwrites-yymsp[-1].minor.yy555*/
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_283:
	; /* expr ::= RAISE LP IGNORE RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), uintptr(0), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) != 0 {
		(*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))).FaffExpr = uint8(OE_Ignore)
	}
	goto _350
_284:
	; /* expr ::= RAISE LP raisetype COMMA expr RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3PExpr(tls, pParse, int32(TK_RAISE), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), uintptr(0))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) != 0 {
		(*TExpr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)))).FaffExpr = libc.Uint8FromInt32(*(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))
	}
	goto _350
_285:
	; /* raisetype ::= ROLLBACK */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Rollback)
	goto _350
_286:
	; /* raisetype ::= FAIL */
	*(*int32)(unsafe.Pointer(yymsp + 8)) = int32(OE_Fail)
	goto _350
_287:
	; /* cmd ::= DROP TRIGGER ifexists fullname */
	_sqlite3DropTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	goto _350
_288:
	; /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
	_sqlite3Attach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_289:
	; /* cmd ::= DETACH database_kw_opt expr */
	_sqlite3Detach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_290:
	; /* cmd ::= REINDEX */
	_sqlite3Reindex(tls, pParse, uintptr(0), uintptr(0))
	goto _350
_291:
	; /* cmd ::= REINDEX nm dbnm */
	_sqlite3Reindex(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, yymsp+8)
	goto _350
_292:
	; /* cmd ::= ANALYZE */
	_sqlite3Analyze(tls, pParse, uintptr(0), uintptr(0))
	goto _350
_293:
	; /* cmd ::= ANALYZE nm dbnm */
	_sqlite3Analyze(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8, yymsp+8)
	goto _350
_294:
	; /* cmd ::= ALTER TABLE fullname RENAME TO nm */
	_sqlite3AlterRenameTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), yymsp+8)
	goto _350
_295:
	; /* cmd ::= alter_add carglist */
	*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)) = libc.Uint32FromInt32(int32(int64((*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))))) + (*TParse)(unsafe.Pointer(pParse)).FsLastToken.Fn
	_sqlite3AlterFinishAddColumn(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(1))*24+8)
	goto _350
_296:
	; /* alter_add ::= ALTER TABLE fullname ADD kwcolumn_opt nm typetoken */
	_disableLookaside(tls, pParse)
	_sqlite3AlterBeginAddColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
	_sqlite3AddColumn(tls, pParse, *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*TToken)(unsafe.Pointer(yymsp + 8)))
	*(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)) = *(*TToken)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_297:
	; /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
	_sqlite3AlterDropColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), yymsp+8)
	goto _350
_298:
	; /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
	_sqlite3AlterRenameColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+8)
	goto _350
_299:
	; /* cmd ::= ALTER TABLE fullname DROP CONSTRAINT nm */
	_sqlite3AlterDropConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), yymsp+8, uintptr(0))
	goto _350
_300:
	; /* cmd ::= ALTER TABLE fullname ALTER kwcolumn_opt nm DROP NOT NULL */
	_sqlite3AlterDropConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(3))*24+8)
	goto _350
_301:
	; /* cmd ::= ALTER TABLE fullname ALTER kwcolumn_opt nm SET NOT NULL onconf */
	_sqlite3AlterSetNotNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(7))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8)
	goto _350
_302:
	; /* cmd ::= ALTER TABLE fullname ADD CONSTRAINT nm CHECK LP expr RP onconf */
	_sqlite3AlterAddConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(8))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(6))*24+8, yymsp+uintptr(-libc.Int32FromInt32(5))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8))+uintptr(1), int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))-int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))-libc.Int64FromInt32(1)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	goto _350
_303:
	; /* cmd ::= ALTER TABLE fullname ADD CHECK LP expr RP onconf */
	_sqlite3AlterAddConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(6))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8))+uintptr(1), int32(int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))-int64(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)))-libc.Int64FromInt32(1)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	goto _350
_304:
	; /* cmd ::= create_vtab */
	_sqlite3VtabFinishParse(tls, pParse, uintptr(0))
	goto _350
_305:
	; /* cmd ::= create_vtab LP vtabarglist RP */
	_sqlite3VtabFinishParse(tls, pParse, yymsp+8)
	goto _350
_306:
	; /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
	_sqlite3VtabBeginParse(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(3))*24+8, yymsp+uintptr(-libc.Int32FromInt32(2))*24+8, yymsp+8, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)))
	goto _350
_307:
	; /* vtabarg ::= */
	_sqlite3VtabArgInit(tls, pParse)
	goto _350
_309:
	; /* vtabargtoken ::= ANY */
_308:
	;
_310:
	;
	_sqlite3VtabArgExtend(tls, pParse, yymsp+8)
	goto _350
_312:
	; /* with ::= WITH wqlist */
_311:
	;
	_sqlite3WithPush(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uint8(1))
	goto _350
_313:
	; /* wqas ::= AS */
	*(*Tu8)(unsafe.Pointer(yymsp + 8)) = uint8(M10d_Any)
	goto _350
_314:
	; /* wqas ::= AS MATERIALIZED */
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = uint8(M10d_Yes)
	goto _350
_315:
	; /* wqas ::= AS NOT MATERIALIZED */
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = uint8(M10d_No)
	goto _350
_316:
	;                                                                                                                                                                                                                                                                                                                                                                                             /* wqitem ::= withnm eidlist_opt wqas LP select RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = _sqlite3CteNew(tls, pParse, yymsp+uintptr(-libc.Int32FromInt32(5))*24+8, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8))) /*A-overwrites-X*/
	goto _350
_317:
	; /* withnm ::= nm */
	libc.SetBitFieldPtr16Uint32(pParse+40, libc.Uint32FromInt32(1), 9, 0x200)
	goto _350
_318:
	;                                                                                                                         /* wqlist ::= wqitem */
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = _sqlite3WithAdd(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8))) /*A-overwrites-X*/
	goto _350
_319:
	; /* wqlist ::= wqlist COMMA wqitem */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = _sqlite3WithAdd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	goto _350
_320:
	; /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
	_sqlite3WindowChain(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)))
	(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 8)))).FpNextWin = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8))
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_321:
	; /* windowdefn ::= nm AS LP window RP */
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FzName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)), uint64(*(*uint32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8 + 8))))
	}
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_322:
	; /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), uintptr(0))
	goto _350
_323:
	; /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(5))*24+8)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_324:
	; /* window ::= ORDER BY sortlist frame_opt */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), uintptr(0))
	goto _350
_325:
	; /* window ::= nm ORDER BY sortlist frame_opt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), yymsp+uintptr(-libc.Int32FromInt32(4))*24+8)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_326:
	; /* window ::= nm frame_opt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0), yymsp+uintptr(-libc.Int32FromInt32(1))*24+8)
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_327:
	; /* frame_opt ::= */
	*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = _sqlite3WindowAlloc(tls, pParse, 0, int32(TK_UNBOUNDED), uintptr(0), int32(TK_CURRENT), uintptr(0), uint8(0))
	goto _350
_328:
	; /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)), int32(TK_CURRENT), uintptr(0), *(*Tu8)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(2))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_329:
	; /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8 + 8)), *(*int32)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8 + 8)), *(*Tu8)(unsafe.Pointer(yymsp + 8)))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(5))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_331:
	; /* frame_bound_s ::= frame_bound */
_330:
	;
	*(*TFrameBound)(unsafe.Pointer(bp)) = *(*TFrameBound)(unsafe.Pointer(yymsp + 8))
	*(*TFrameBound)(unsafe.Pointer(yymsp + 8)) = *(*TFrameBound)(unsafe.Pointer(bp))
	goto _350
_333:
	; /* frame_bound_s ::= UNBOUNDED PRECEDING */
_332:
	;
_334:
	;
	(*(*TFrameBound)(unsafe.Pointer(bp))).FeType = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*24))).Fmajor)
	(*(*TFrameBound)(unsafe.Pointer(bp))).FpExpr = uintptr(0)
	*(*TFrameBound)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*TFrameBound)(unsafe.Pointer(bp))
	goto _350
_335:
	; /* frame_bound ::= expr PRECEDING|FOLLOWING */
	(*(*TFrameBound)(unsafe.Pointer(bp))).FeType = libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor)
	(*(*TFrameBound)(unsafe.Pointer(bp))).FpExpr = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	*(*TFrameBound)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*TFrameBound)(unsafe.Pointer(bp))
	goto _350
_336:
	; /* frame_exclude_opt ::= */
	*(*Tu8)(unsafe.Pointer(yymsp + 1*24 + 8)) = uint8(0)
	goto _350
_337:
	; /* frame_exclude_opt ::= EXCLUDE frame_exclude */
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*Tu8)(unsafe.Pointer(yymsp + 8))
	goto _350
_339:
	; /* frame_exclude ::= NO OTHERS */
_338:
	;
	*(*Tu8)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = uint8((**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(-libc.Int32FromInt32(1))*24))).Fmajor) /*A-overwrites-X*/
	goto _350
_340:
	;                                                                                          /* frame_exclude ::= GROUP|TIES */
	*(*Tu8)(unsafe.Pointer(yymsp + 8)) = uint8((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor) /*A-overwrites-X*/
	goto _350
_341:
	; /* window_clause ::= WINDOW windowdefn_list */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	goto _350
_342:
	; /* filter_over ::= filter_clause over_clause */
	if *(*uintptr)(unsafe.Pointer(yymsp + 8)) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 8)))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))
	}
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_343:
	; /* filter_over ::= over_clause */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_344:
	; /* filter_over ::= filter_clause */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(144))
	if *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))))).FeFrmType = uint8(TK_FILTER)
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + 8))
	} else {
		_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
	}
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_345:
	; /* over_clause ::= OVER LP window RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(3))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_346:
	; /* over_clause ::= OVER nm */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) = _sqlite3DbMallocZero(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(144))
	if *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)) != 0 {
		(*TWindow)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8)))).FzName = _sqlite3DbStrNDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uint64(*(*uint32)(unsafe.Pointer(yymsp + 8 + 8))))
	}
	goto _350
_347:
	; /* filter_clause ::= FILTER LP WHERE expr RP */
	*(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(4))*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + uintptr(-libc.Int32FromInt32(1))*24 + 8))
	goto _350
_348:
	; /* term ::= QNUMBER */
	*(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))) = _tokenExpr(tls, pParse, libc.Int32FromUint16((**(**TyyStackEntry)(__ccgo_up(yymsp))).Fmajor), *(*TToken)(unsafe.Pointer(yymsp + 8)))
	_sqlite3DequoteNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp)))))
	*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(&**(**TYYMINORTYPE)(__ccgo_up(bp))))
	goto _350
_349:
	;
	goto _350
	/********** End reduce actions ************************************************/
_350:
	;
	yygoto = libc.Int32FromUint16(_yyRuleInfoLhs[yyruleno])
	yysize = int32(_yyRuleInfoNRhs[yyruleno])
	yyact = _yy_find_reduce_action(tls, (**(**TyyStackEntry)(__ccgo_up(yymsp + uintptr(yysize)*24))).Fstateno, libc.Uint16FromInt32(yygoto))
	/* There are no SHIFTREDUCE actions on nonterminals because the table
	 ** generator has simplified them to pure REDUCE actions. */
	/* It is not possible for a REDUCE to be followed by an error */
	yymsp = yymsp + uintptr(yysize+int32(1))*24
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos = yymsp
	(*TyyStackEntry)(unsafe.Pointer(yymsp)).Fstateno = yyact
	(*TyyStackEntry)(unsafe.Pointer(yymsp)).Fmajor = libc.Uint16FromInt32(yygoto)
	return yyact
}

/*
** The following code executes when the parse fails
 */
